com_android_server_wifi_WifiNative.cpp revision 21602b3d7fc39a4dfa32b174c93ba77990f9e777
1155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande/* 2155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Copyright 2008, The Android Open Source Project 3155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 4155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Licensed under the Apache License, Version 2.0 (the "License"); 5155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * you may not use this file except in compliance with the License. 6155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * You may obtain a copy of the License at 7155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 8155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * http://www.apache.org/licenses/LICENSE-2.0 9155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * 10155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * Unless required by applicable law or agreed to in writing, software 11155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * distributed under the License is distributed on an "AS IS" BASIS, 12155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * See the License for the specific language governing permissions and 14155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * limitations under the License. 15155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 16155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 17155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande#define LOG_TAG "wifi" 18155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 19155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande#include "jni.h" 20155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande#include <ScopedUtfChars.h> 21155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande#include <utils/misc.h> 22155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande#include <android_runtime/AndroidRuntime.h> 23155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande#include <utils/Log.h> 24155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande#include <utils/String16.h> 25e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde#include <ctype.h> 26be3b27a3749af234b5fd7340aefb9f25060fb433xinhe#include <sys/socket.h> 27be3b27a3749af234b5fd7340aefb9f25060fb433xinhe#include <linux/if.h> 28155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 29155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande#include "wifi.h" 307ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde#include "wifi_hal.h" 317f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde#include "jni_helper.h" 3212cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe#include "rtt.h" 33628199920e1d1fa86caabaf13874e7dc601e7b06xinhe#include "wifi_hal_stub.h" 34155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 35155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande#define REPLY_BUF_SIZE 4096 // wpa_supplicant's maximum size. 36155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande#define EVENT_BUF_SIZE 2048 37155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 38155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandenamespace android { 39155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 40155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandestatic jint DBG = false; 41155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 42628199920e1d1fa86caabaf13874e7dc601e7b06xinhe//Please put all HAL function call here and call from the function table instead of directly call 43628199920e1d1fa86caabaf13874e7dc601e7b06xinhestatic wifi_hal_fn hal_fn; 44628199920e1d1fa86caabaf13874e7dc601e7b06xinheint init_wifi_hal_func_table(wifi_hal_fn *hal_fn) { 45628199920e1d1fa86caabaf13874e7dc601e7b06xinhe if (hal_fn == NULL) { 46628199920e1d1fa86caabaf13874e7dc601e7b06xinhe return -1; 47628199920e1d1fa86caabaf13874e7dc601e7b06xinhe } 48628199920e1d1fa86caabaf13874e7dc601e7b06xinhe 49628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_initialize = wifi_initialize_stub; 50628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_cleanup = wifi_cleanup_stub; 51628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_event_loop = wifi_event_loop_stub; 52628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_get_error_info = wifi_get_error_info_stub; 53628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_get_supported_feature_set = wifi_get_supported_feature_set_stub; 54628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_get_concurrency_matrix = wifi_get_concurrency_matrix_stub; 55628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_set_scanning_mac_oui = wifi_set_scanning_mac_oui_stub; 56628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_get_supported_channels = wifi_get_supported_channels_stub; 57628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_is_epr_supported = wifi_is_epr_supported_stub; 58628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_get_ifaces = wifi_get_ifaces_stub; 59628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_get_iface_name = wifi_get_iface_name_stub; 60628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_reset_iface_event_handler = wifi_reset_iface_event_handler_stub; 61628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_start_gscan = wifi_start_gscan_stub; 62628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_stop_gscan = wifi_stop_gscan_stub; 63628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_get_cached_gscan_results = wifi_get_cached_gscan_results_stub; 64628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_set_bssid_hotlist = wifi_set_bssid_hotlist_stub; 65628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_reset_bssid_hotlist = wifi_reset_bssid_hotlist_stub; 66628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_set_significant_change_handler = wifi_set_significant_change_handler_stub; 67628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_reset_significant_change_handler = wifi_reset_significant_change_handler_stub; 68628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_get_gscan_capabilities = wifi_get_gscan_capabilities_stub; 69628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_set_link_stats = wifi_set_link_stats_stub; 70628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_get_link_stats = wifi_get_link_stats_stub; 71628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_clear_link_stats = wifi_clear_link_stats_stub; 72628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_get_valid_channels = wifi_get_valid_channels_stub; 73628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_rtt_range_request = wifi_rtt_range_request_stub; 74628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_rtt_range_cancel = wifi_rtt_range_cancel_stub; 75628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_get_rtt_capabilities = wifi_get_rtt_capabilities_stub; 76628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_start_logging = wifi_start_logging_stub; 77628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_set_epno_list = wifi_set_epno_list_stub; 78628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn->wifi_set_country_code = wifi_set_country_code_stub; 79d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe hal_fn->wifi_enable_tdls = wifi_enable_tdls_stub; 80d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe hal_fn->wifi_disable_tdls = wifi_disable_tdls_stub; 81d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe hal_fn->wifi_get_tdls_status = wifi_get_tdls_status_stub; 82d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe hal_fn->wifi_get_tdls_capabilities = wifi_get_tdls_capabilities_stub; 8321602b3d7fc39a4dfa32b174c93ba77990f9e777xinhe hal_fn->wifi_get_firmware_memory_dump = wifi_get_firmware_memory_dump_stub; 8421602b3d7fc39a4dfa32b174c93ba77990f9e777xinhe hal_fn->wifi_set_log_handler = wifi_set_log_handler_stub; 8521602b3d7fc39a4dfa32b174c93ba77990f9e777xinhe hal_fn->wifi_set_alert_handler = wifi_set_alert_handler_stub; 8621602b3d7fc39a4dfa32b174c93ba77990f9e777xinhe hal_fn->wifi_get_firmware_version = wifi_get_firmware_version_stub; 8721602b3d7fc39a4dfa32b174c93ba77990f9e777xinhe hal_fn->wifi_get_ring_buffers_status = wifi_get_ring_buffers_status_stub; 8821602b3d7fc39a4dfa32b174c93ba77990f9e777xinhe hal_fn->wifi_get_logger_supported_feature_set = wifi_get_logger_supported_feature_set_stub; 8921602b3d7fc39a4dfa32b174c93ba77990f9e777xinhe hal_fn->wifi_get_ring_data = wifi_get_ring_data_stub; 9021602b3d7fc39a4dfa32b174c93ba77990f9e777xinhe hal_fn->wifi_get_driver_version = wifi_get_driver_version_stub; 91628199920e1d1fa86caabaf13874e7dc601e7b06xinhe return 0; 92628199920e1d1fa86caabaf13874e7dc601e7b06xinhe} 93628199920e1d1fa86caabaf13874e7dc601e7b06xinhe 94628199920e1d1fa86caabaf13874e7dc601e7b06xinhe 95155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandestatic bool doCommand(JNIEnv* env, jstring javaCommand, 96155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande char* reply, size_t reply_len) { 97155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ScopedUtfChars command(env, javaCommand); 98155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (command.c_str() == NULL) { 99155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; // ScopedUtfChars already threw on error. 100155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 101155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 102155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (DBG) { 103155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ALOGD("doCommand: %s", command.c_str()); 104155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 105155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 106155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande --reply_len; // Ensure we have room to add NUL termination. 107155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (::wifi_command(command.c_str(), reply, &reply_len) != 0) { 108155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return false; 109155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 110155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 111155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande // Strip off trailing newline. 112155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (reply_len > 0 && reply[reply_len-1] == '\n') { 113155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande reply[reply_len-1] = '\0'; 114155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 115155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande reply[reply_len] = '\0'; 116155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 117155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return true; 118155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 119155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 120155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandestatic jint doIntCommand(JNIEnv* env, jstring javaCommand) { 121155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande char reply[REPLY_BUF_SIZE]; 122155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (!doCommand(env, javaCommand, reply, sizeof(reply))) { 123155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return -1; 124155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 125155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return static_cast<jint>(atoi(reply)); 126155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 127155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 128155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandestatic jboolean doBooleanCommand(JNIEnv* env, jstring javaCommand) { 129155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande char reply[REPLY_BUF_SIZE]; 130155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (!doCommand(env, javaCommand, reply, sizeof(reply))) { 131155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return JNI_FALSE; 132155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 133155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return (strcmp(reply, "OK") == 0); 134155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 135155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 136155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande// Send a command to the supplicant, and return the reply as a String. 137155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandestatic jstring doStringCommand(JNIEnv* env, jstring javaCommand) { 138155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande char reply[REPLY_BUF_SIZE]; 139155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (!doCommand(env, javaCommand, reply, sizeof(reply))) { 140155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return NULL; 141155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 142155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return env->NewStringUTF(reply); 143155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 144155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 145155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandestatic jboolean android_net_wifi_isDriverLoaded(JNIEnv* env, jobject) 146155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande{ 147155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return (::is_wifi_driver_loaded() == 1); 148155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 149155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 150155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandestatic jboolean android_net_wifi_loadDriver(JNIEnv* env, jobject) 151155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande{ 152155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return (::wifi_load_driver() == 0); 153155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 154155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 155155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandestatic jboolean android_net_wifi_unloadDriver(JNIEnv* env, jobject) 156155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande{ 157155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return (::wifi_unload_driver() == 0); 158155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 159155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 160155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandestatic jboolean android_net_wifi_startSupplicant(JNIEnv* env, jobject, jboolean p2pSupported) 161155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande{ 162155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return (::wifi_start_supplicant(p2pSupported) == 0); 163155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 164155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 165155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandestatic jboolean android_net_wifi_killSupplicant(JNIEnv* env, jobject, jboolean p2pSupported) 166155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande{ 167155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return (::wifi_stop_supplicant(p2pSupported) == 0); 168155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 169155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 170155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandestatic jboolean android_net_wifi_connectToSupplicant(JNIEnv* env, jobject) 171155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande{ 172155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return (::wifi_connect_to_supplicant() == 0); 173155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 174155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 175155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandestatic void android_net_wifi_closeSupplicantConnection(JNIEnv* env, jobject) 176155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande{ 177155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande ::wifi_close_supplicant_connection(); 178155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 179155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 180155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandestatic jstring android_net_wifi_waitForEvent(JNIEnv* env, jobject) 181155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande{ 182155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande char buf[EVENT_BUF_SIZE]; 183155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande int nread = ::wifi_wait_for_event(buf, sizeof buf); 184155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande if (nread > 0) { 185155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return env->NewStringUTF(buf); 186155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } else { 187155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return NULL; 188155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande } 189155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 190155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 191155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandestatic jboolean android_net_wifi_doBooleanCommand(JNIEnv* env, jobject, jstring javaCommand) { 192155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doBooleanCommand(env, javaCommand); 193155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 194155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 195155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandestatic jint android_net_wifi_doIntCommand(JNIEnv* env, jobject, jstring javaCommand) { 196155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doIntCommand(env, javaCommand); 197155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 198155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 199155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandestatic jstring android_net_wifi_doStringCommand(JNIEnv* env, jobject, jstring javaCommand) { 200155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return doStringCommand(env,javaCommand); 201155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 202155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 2037f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde/* wifi_hal <==> WifiNative bridge */ 2047f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 205b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpandestatic jclass mCls; /* saved WifiNative object */ 2067f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapndestatic JavaVM *mVM; /* saved JVM pointer */ 2077f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 208aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwallestatic const char *WifiHandleVarName = "sWifiHalHandle"; 209aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwallestatic const char *WifiIfaceHandleVarName = "sWifiIfaceHandles"; 2107f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapndestatic jmethodID OnScanResultsMethodID; 2117f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 2127f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapndestatic JNIEnv *getEnv() { 2137f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde JNIEnv *env = NULL; 2147f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde mVM->AttachCurrentThread(&env, NULL); 2157f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde return env; 2167f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde} 2177f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 218b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpandestatic wifi_handle getWifiHandle(JNIEnv *env, jclass cls) { 219b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande return (wifi_handle) getStaticLongField(env, cls, WifiHandleVarName); 2207f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde} 2217f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 222b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpandestatic wifi_interface_handle getIfaceHandle(JNIEnv *env, jclass cls, jint index) { 223b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande return (wifi_interface_handle) getStaticLongArrayField(env, cls, WifiIfaceHandleVarName, index); 2247f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde} 2257f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 226b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpandestatic jobject createScanResult(JNIEnv *env, wifi_scan_result *result) { 227f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 228b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande // ALOGD("creating scan result"); 229f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 230f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde jobject scanResult = createObject(env, "android/net/wifi/ScanResult"); 231f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde if (scanResult == NULL) { 232f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde ALOGE("Error in creating scan result"); 233f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde return NULL; 234f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde } 235f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 236dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGE("setting SSID to %s", result->ssid); 237dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle //jstring jssid = env->NewStringUTF(result->ssid); 238b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande setStringField(env, scanResult, "SSID", result->ssid); 239f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 240f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde char bssid[32]; 241b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", result->bssid[0], result->bssid[1], 242b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande result->bssid[2], result->bssid[3], result->bssid[4], result->bssid[5]); 243dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle //jstring jbssid = env->NewStringUTF(bssid); 244f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 245f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde setStringField(env, scanResult, "BSSID", bssid); 246f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 247b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande setIntField(env, scanResult, "level", result->rssi); 248b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande setIntField(env, scanResult, "frequency", result->channel); 249b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande setLongField(env, scanResult, "timestamp", result->ts); 250f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 251f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde return scanResult; 252f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde} 253f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 254be3b27a3749af234b5fd7340aefb9f25060fb433xinheint set_iface_flags(const char *ifname, int dev_up) { 255be3b27a3749af234b5fd7340aefb9f25060fb433xinhe struct ifreq ifr; 256be3b27a3749af234b5fd7340aefb9f25060fb433xinhe int ret; 257be3b27a3749af234b5fd7340aefb9f25060fb433xinhe int sock = socket(PF_INET, SOCK_DGRAM, 0); 258be3b27a3749af234b5fd7340aefb9f25060fb433xinhe if (sock < 0) { 259be3b27a3749af234b5fd7340aefb9f25060fb433xinhe ALOGD("Bad socket: %d\n", sock); 260be3b27a3749af234b5fd7340aefb9f25060fb433xinhe return -errno; 261be3b27a3749af234b5fd7340aefb9f25060fb433xinhe } 262be3b27a3749af234b5fd7340aefb9f25060fb433xinhe 263dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle //ALOGD("setting interface %s flags (%s)\n", ifname, dev_up ? "UP" : "DOWN"); 264be3b27a3749af234b5fd7340aefb9f25060fb433xinhe 265be3b27a3749af234b5fd7340aefb9f25060fb433xinhe memset(&ifr, 0, sizeof(ifr)); 266be3b27a3749af234b5fd7340aefb9f25060fb433xinhe strlcpy(ifr.ifr_name, ifname, IFNAMSIZ); 267be3b27a3749af234b5fd7340aefb9f25060fb433xinhe 268dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle //ALOGD("reading old value\n"); 269be3b27a3749af234b5fd7340aefb9f25060fb433xinhe 270be3b27a3749af234b5fd7340aefb9f25060fb433xinhe if (ioctl(sock, SIOCGIFFLAGS, &ifr) != 0) { 271be3b27a3749af234b5fd7340aefb9f25060fb433xinhe ret = errno ? -errno : -999; 27270be7f18b526243679eaaa5f03b7f53417ecf1c7Vinit Deshpande ALOGE("Could not read interface %s flags: %d\n", ifname, errno); 273be3b27a3749af234b5fd7340aefb9f25060fb433xinhe close(sock); 274be3b27a3749af234b5fd7340aefb9f25060fb433xinhe return ret; 275be3b27a3749af234b5fd7340aefb9f25060fb433xinhe } else { 276dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle //ALOGD("writing new value\n"); 277be3b27a3749af234b5fd7340aefb9f25060fb433xinhe } 278be3b27a3749af234b5fd7340aefb9f25060fb433xinhe 279be3b27a3749af234b5fd7340aefb9f25060fb433xinhe if (dev_up) { 280be3b27a3749af234b5fd7340aefb9f25060fb433xinhe if (ifr.ifr_flags & IFF_UP) { 28170be7f18b526243679eaaa5f03b7f53417ecf1c7Vinit Deshpande // ALOGD("interface %s is already up\n", ifname); 282be3b27a3749af234b5fd7340aefb9f25060fb433xinhe close(sock); 283be3b27a3749af234b5fd7340aefb9f25060fb433xinhe return 0; 284be3b27a3749af234b5fd7340aefb9f25060fb433xinhe } 285be3b27a3749af234b5fd7340aefb9f25060fb433xinhe ifr.ifr_flags |= IFF_UP; 286be3b27a3749af234b5fd7340aefb9f25060fb433xinhe } else { 287be3b27a3749af234b5fd7340aefb9f25060fb433xinhe if (!(ifr.ifr_flags & IFF_UP)) { 28870be7f18b526243679eaaa5f03b7f53417ecf1c7Vinit Deshpande // ALOGD("interface %s is already down\n", ifname); 289be3b27a3749af234b5fd7340aefb9f25060fb433xinhe close(sock); 290be3b27a3749af234b5fd7340aefb9f25060fb433xinhe return 0; 291be3b27a3749af234b5fd7340aefb9f25060fb433xinhe } 292be3b27a3749af234b5fd7340aefb9f25060fb433xinhe ifr.ifr_flags &= ~IFF_UP; 293be3b27a3749af234b5fd7340aefb9f25060fb433xinhe } 294be3b27a3749af234b5fd7340aefb9f25060fb433xinhe 295be3b27a3749af234b5fd7340aefb9f25060fb433xinhe if (ioctl(sock, SIOCSIFFLAGS, &ifr) != 0) { 29670be7f18b526243679eaaa5f03b7f53417ecf1c7Vinit Deshpande ALOGE("Could not set interface %s flags \n", ifname); 297be3b27a3749af234b5fd7340aefb9f25060fb433xinhe close(sock); 298be3b27a3749af234b5fd7340aefb9f25060fb433xinhe return ret; 299be3b27a3749af234b5fd7340aefb9f25060fb433xinhe } else { 300be3b27a3749af234b5fd7340aefb9f25060fb433xinhe ALOGD("set interface %s flags (%s)\n", ifname, dev_up ? "UP" : "DOWN"); 301be3b27a3749af234b5fd7340aefb9f25060fb433xinhe } 302be3b27a3749af234b5fd7340aefb9f25060fb433xinhe close(sock); 303be3b27a3749af234b5fd7340aefb9f25060fb433xinhe return 0; 304be3b27a3749af234b5fd7340aefb9f25060fb433xinhe} 305be3b27a3749af234b5fd7340aefb9f25060fb433xinhe 306b830d76fbf5fa4077531b516066faa2fdbb92e81xinhestatic jboolean android_net_wifi_toggle_interface(JNIEnv* env, jclass cls, int toggle) { 307b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe return(set_iface_flags("wlan0", toggle) == 0); 308b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe} 309b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe 310b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpandestatic jboolean android_net_wifi_startHal(JNIEnv* env, jclass cls) { 311b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande wifi_handle halHandle = getWifiHandle(env, cls); 3127ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde if (halHandle == NULL) { 313628199920e1d1fa86caabaf13874e7dc601e7b06xinhe 314628199920e1d1fa86caabaf13874e7dc601e7b06xinhe if(init_wifi_hal_func_table(&hal_fn) != 0 ) { 315628199920e1d1fa86caabaf13874e7dc601e7b06xinhe ALOGD("Can not initialize the basic function pointer table"); 316628199920e1d1fa86caabaf13874e7dc601e7b06xinhe return false; 317628199920e1d1fa86caabaf13874e7dc601e7b06xinhe } 318628199920e1d1fa86caabaf13874e7dc601e7b06xinhe 319628199920e1d1fa86caabaf13874e7dc601e7b06xinhe wifi_error res = init_wifi_vendor_hal_func_table(&hal_fn); 320628199920e1d1fa86caabaf13874e7dc601e7b06xinhe if (res != WIFI_SUCCESS) { 321628199920e1d1fa86caabaf13874e7dc601e7b06xinhe ALOGD("Can not initialize the vendor function pointer table"); 322628199920e1d1fa86caabaf13874e7dc601e7b06xinhe return false; 323628199920e1d1fa86caabaf13874e7dc601e7b06xinhe } 324628199920e1d1fa86caabaf13874e7dc601e7b06xinhe 325be3b27a3749af234b5fd7340aefb9f25060fb433xinhe int ret = set_iface_flags("wlan0", 1); 326be3b27a3749af234b5fd7340aefb9f25060fb433xinhe if(ret != 0) { 327be3b27a3749af234b5fd7340aefb9f25060fb433xinhe return false; 328be3b27a3749af234b5fd7340aefb9f25060fb433xinhe } 329628199920e1d1fa86caabaf13874e7dc601e7b06xinhe 330628199920e1d1fa86caabaf13874e7dc601e7b06xinhe res = hal_fn.wifi_initialize(&halHandle); 3317f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde if (res == WIFI_SUCCESS) { 332b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande setStaticLongField(env, cls, WifiHandleVarName, (jlong)halHandle); 333aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle ALOGD("Did set static halHandle = %p", halHandle); 3347f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 3357f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde env->GetJavaVM(&mVM); 336b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande mCls = (jclass) env->NewGlobalRef(cls); 337b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande ALOGD("halHandle = %p, mVM = %p, mCls = %p", halHandle, mVM, mCls); 3387ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde return res == WIFI_SUCCESS; 3397f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } else { 340826282265badbd85c5386573fbced1755696fe83xinhe return (set_iface_flags("wlan0", 1) == 0); 3417ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde } 3427ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde} 3437ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde 3447ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapndevoid android_net_wifi_hal_cleaned_up_handler(wifi_handle handle) { 3457ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde ALOGD("In wifi cleaned up handler"); 3467f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 3477f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde JNIEnv * env = getEnv(); 348b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande setStaticLongField(env, mCls, WifiHandleVarName, 0); 349b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande env->DeleteGlobalRef(mCls); 350b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande mCls = NULL; 3517f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde mVM = NULL; 3527ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde} 3537ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde 354b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpandestatic void android_net_wifi_stopHal(JNIEnv* env, jclass cls) { 3557ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde ALOGD("In wifi stop Hal"); 356b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe 357b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande wifi_handle halHandle = getWifiHandle(env, cls); 358628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn.wifi_cleanup(halHandle, android_net_wifi_hal_cleaned_up_handler); 359be3b27a3749af234b5fd7340aefb9f25060fb433xinhe set_iface_flags("wlan0", 0); 3607ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde} 3617ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde 362b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpandestatic void android_net_wifi_waitForHalEvents(JNIEnv* env, jclass cls) { 3637f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 364b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande ALOGD("waitForHalEvents called, vm = %p, obj = %p, env = %p", mVM, mCls, env); 3657f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 366b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande wifi_handle halHandle = getWifiHandle(env, cls); 367628199920e1d1fa86caabaf13874e7dc601e7b06xinhe hal_fn.wifi_event_loop(halHandle); 3687ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde} 3697ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde 370b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpandestatic int android_net_wifi_getInterfaces(JNIEnv *env, jclass cls) { 3717f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde int n = 0; 372b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande wifi_handle halHandle = getWifiHandle(env, cls); 3737f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde wifi_interface_handle *ifaceHandles = NULL; 374628199920e1d1fa86caabaf13874e7dc601e7b06xinhe int result = hal_fn.wifi_get_ifaces(halHandle, &n, &ifaceHandles); 3757f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde if (result < 0) { 3767f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde return result; 3777f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 3787f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 37907ce33c64db470e749f580ef2c83d21e50fbbb27Vinit Deshpande if (n < 0) { 38007ce33c64db470e749f580ef2c83d21e50fbbb27Vinit Deshpande THROW(env, "android_net_wifi_getInterfaces no interfaces"); 381aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return 0; 382aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 383aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 384aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle if (ifaceHandles == NULL) { 385aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle THROW(env, "android_net_wifi_getInterfaces null interface array"); 386aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return 0; 387aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 388aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 38907ce33c64db470e749f580ef2c83d21e50fbbb27Vinit Deshpande if (n > 8) { 39007ce33c64db470e749f580ef2c83d21e50fbbb27Vinit Deshpande THROW(env, "Too many interfaces"); 39107ce33c64db470e749f580ef2c83d21e50fbbb27Vinit Deshpande return 0; 39207ce33c64db470e749f580ef2c83d21e50fbbb27Vinit Deshpande } 39307ce33c64db470e749f580ef2c83d21e50fbbb27Vinit Deshpande 3947f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde jlongArray array = (env)->NewLongArray(n); 3957f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde if (array == NULL) { 3967f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde THROW(env, "Error in accessing array"); 3977f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde return 0; 3987f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 3997f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 4007f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde jlong elems[8]; 4017f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde for (int i = 0; i < n; i++) { 4027f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde elems[i] = reinterpret_cast<jlong>(ifaceHandles[i]); 4037f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 4047f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde env->SetLongArrayRegion(array, 0, n, elems); 405b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande setStaticLongArrayField(env, cls, WifiIfaceHandleVarName, array); 4067f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 4077f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde return (result < 0) ? result : n; 4087f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde} 4097f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 410b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpandestatic jstring android_net_wifi_getInterfaceName(JNIEnv *env, jclass cls, jint i) { 4117f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde char buf[EVENT_BUF_SIZE]; 4127f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 413b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande jlong value = getStaticLongArrayField(env, cls, WifiIfaceHandleVarName, i); 4147f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde wifi_interface_handle handle = (wifi_interface_handle) value; 415628199920e1d1fa86caabaf13874e7dc601e7b06xinhe int result = hal_fn.wifi_get_iface_name(handle, buf, sizeof(buf)); 4167f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde if (result < 0) { 4177f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde return NULL; 4187f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } else { 4197f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde return env->NewStringUTF(buf); 4207f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 4217f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde} 4227f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 423b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande 424766cb4b1fa3b93c146952eacbf6756f67f172ec1Vinit Deshapndestatic void onScanResultsAvailable(wifi_request_id id, unsigned num_results) { 425766cb4b1fa3b93c146952eacbf6756f67f172ec1Vinit Deshapnde 4267f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde JNIEnv *env = NULL; 4277f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde mVM->AttachCurrentThread(&env, NULL); 4287f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 429b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande ALOGD("onScanResultsAvailable called, vm = %p, obj = %p, env = %p", mVM, mCls, env); 430766cb4b1fa3b93c146952eacbf6756f67f172ec1Vinit Deshapnde 431b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande reportEvent(env, mCls, "onScanResultsAvailable", "(I)V", id); 432e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde} 433e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 434b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpandestatic void onScanEvent(wifi_scan_event event, unsigned status) { 435b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande JNIEnv *env = NULL; 436b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande mVM->AttachCurrentThread(&env, NULL); 437b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande 438b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande ALOGD("onScanStatus called, vm = %p, obj = %p, env = %p", mVM, mCls, env); 439b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande 440827bc400bfb327a7c0bb2ed03f17d88c56cf85aaNavtej Singh Mann reportEvent(env, mCls, "onScanStatus", "(I)V", event); 441b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande} 442b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande 443f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapndestatic void onFullScanResult(wifi_request_id id, wifi_scan_result *result) { 444f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 445f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde JNIEnv *env = NULL; 446f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde mVM->AttachCurrentThread(&env, NULL); 447f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 448b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande ALOGD("onFullScanResult called, vm = %p, obj = %p, env = %p", mVM, mCls, env); 449f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 450b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande jobject scanResult = createScanResult(env, result); 451f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 452f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde ALOGD("Creating a byte array of length %d", result->ie_length); 453f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 454f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde jbyteArray elements = env->NewByteArray(result->ie_length); 455f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde if (elements == NULL) { 456f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde ALOGE("Error in allocating array"); 457f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde return; 458f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde } 459f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 460f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde ALOGE("Setting byte array"); 461f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 462f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde jbyte *bytes = (jbyte *)&(result->ie_data[0]); 463f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde env->SetByteArrayRegion(elements, 0, result->ie_length, bytes); 464f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 465f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde ALOGE("Returning result"); 466f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 467b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande reportEvent(env, mCls, "onFullScanResult", "(ILandroid/net/wifi/ScanResult;[B)V", id, 468f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde scanResult, elements); 469b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande 470b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande env->DeleteLocalRef(scanResult); 471b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande env->DeleteLocalRef(elements); 472f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde} 473f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde 474e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndestatic jboolean android_net_wifi_startScan( 475b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande JNIEnv *env, jclass cls, jint iface, jint id, jobject settings) { 476e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 477b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 478e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("starting scan on interface[%d] = %p", iface, handle); 479e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 480e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde wifi_scan_cmd_params params; 481e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde memset(¶ms, 0, sizeof(params)); 482aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 483e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde params.base_period = getIntField(env, settings, "base_period_ms"); 484e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde params.max_ap_per_scan = getIntField(env, settings, "max_ap_per_scan"); 48583a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande params.report_threshold_percent = getIntField(env, settings, "report_threshold_percent"); 48683a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande params.report_threshold_num_scans = getIntField(env, settings, "report_threshold_num_scans"); 487aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 48883a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande ALOGD("Initialized common fields %d, %d, %d, %d", params.base_period, params.max_ap_per_scan, 48983a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande params.report_threshold_percent, params.report_threshold_num_scans); 490e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 491e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde const char *bucket_array_type = "[Lcom/android/server/wifi/WifiNative$BucketSettings;"; 492e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde const char *channel_array_type = "[Lcom/android/server/wifi/WifiNative$ChannelSettings;"; 493aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 494e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde jobjectArray buckets = (jobjectArray)getObjectField(env, settings, "buckets", bucket_array_type); 495e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde params.num_buckets = getIntField(env, settings, "num_buckets"); 496aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 497e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("Initialized num_buckets to %d", params.num_buckets); 498e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 499e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde for (int i = 0; i < params.num_buckets; i++) { 500e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde jobject bucket = getObjectArrayField(env, settings, "buckets", bucket_array_type, i); 501aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 502e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde params.buckets[i].bucket = getIntField(env, bucket, "bucket"); 503e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde params.buckets[i].band = (wifi_band) getIntField(env, bucket, "band"); 504e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde params.buckets[i].period = getIntField(env, bucket, "period_ms"); 505aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 506e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("Initialized common bucket fields %d:%d:%d", params.buckets[i].bucket, 507e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde params.buckets[i].band, params.buckets[i].period); 508e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 509e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde int report_events = getIntField(env, bucket, "report_events"); 510e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde params.buckets[i].report_events = report_events; 511aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 512e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("Initialized report events to %d", params.buckets[i].report_events); 513e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 514e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde jobjectArray channels = (jobjectArray)getObjectField( 515e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde env, bucket, "channels", channel_array_type); 516aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 517e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde params.buckets[i].num_channels = getIntField(env, bucket, "num_channels"); 518e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("Initialized num_channels to %d", params.buckets[i].num_channels); 519e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 520e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde for (int j = 0; j < params.buckets[i].num_channels; j++) { 521e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde jobject channel = getObjectArrayField(env, bucket, "channels", channel_array_type, j); 522aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 523e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde params.buckets[i].channels[j].channel = getIntField(env, channel, "frequency"); 524e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde params.buckets[i].channels[j].dwellTimeMs = getIntField(env, channel, "dwell_time_ms"); 525aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 526e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde bool passive = getBoolField(env, channel, "passive"); 527e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde params.buckets[i].channels[j].passive = (passive ? 1 : 0); 528e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 52970be7f18b526243679eaaa5f03b7f53417ecf1c7Vinit Deshpande // ALOGD("Initialized channel %d", params.buckets[i].channels[j].channel); 530e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 531e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 532e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 533e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("Initialized all fields"); 534e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 535e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde wifi_scan_result_handler handler; 536e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde memset(&handler, 0, sizeof(handler)); 537e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde handler.on_scan_results_available = &onScanResultsAvailable; 538f1daf9342b66bf134d13fa0a42e929a008f1ca62Vinit Deshapnde handler.on_full_scan_result = &onFullScanResult; 539b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande handler.on_scan_event = &onScanEvent; 540e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 541628199920e1d1fa86caabaf13874e7dc601e7b06xinhe return hal_fn.wifi_start_gscan(id, handle, params, handler) == WIFI_SUCCESS; 542e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde} 543e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 544b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpandestatic jboolean android_net_wifi_stopScan(JNIEnv *env, jclass cls, jint iface, jint id) { 545b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 546e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("stopping scan on interface[%d] = %p", iface, handle); 547e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 548628199920e1d1fa86caabaf13874e7dc601e7b06xinhe return hal_fn.wifi_stop_gscan(id, handle) == WIFI_SUCCESS; 549e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde} 550e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 55183a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpandestatic int compare_scan_result_timestamp(const void *v1, const void *v2) { 55283a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande const wifi_scan_result *result1 = static_cast<const wifi_scan_result *>(v1); 55383a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande const wifi_scan_result *result2 = static_cast<const wifi_scan_result *>(v2); 55483a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande return result1->ts - result2->ts; 55583a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande} 55683a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande 557e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndestatic jobject android_net_wifi_getScanResults( 558b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande JNIEnv *env, jclass cls, jint iface, jboolean flush) { 559c8b61ce3b41d92a0f17a4b3f39ccdbf819060939Navtej Singh Mann 56083a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande wifi_cached_scan_results scan_data[64]; 56183a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande int num_scan_data = 64; 562c8b61ce3b41d92a0f17a4b3f39ccdbf819060939Navtej Singh Mann 563b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 564e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("getting scan results on interface[%d] = %p", iface, handle); 56583a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande 566c8b61ce3b41d92a0f17a4b3f39ccdbf819060939Navtej Singh Mann byte b = flush ? 0xFF : 0; 567628199920e1d1fa86caabaf13874e7dc601e7b06xinhe int result = hal_fn.wifi_get_cached_gscan_results(handle, b, num_scan_data, scan_data, &num_scan_data); 568e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde if (result == WIFI_SUCCESS) { 56983a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande jobjectArray scanData = createObjectArray(env, 57083a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande "android/net/wifi/WifiScanner$ScanData", num_scan_data); 57183a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande if (scanData == NULL) { 57283a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande ALOGE("Error in allocating array of scanData"); 573e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return NULL; 574e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 575e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 57683a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande for (int i = 0; i < num_scan_data; i++) { 57783a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande 57883a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande jobject data = createObject(env, "android/net/wifi/WifiScanner$ScanData"); 57983a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande if (data == NULL) { 58083a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande ALOGE("Error in allocating scanData"); 58183a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande return NULL; 58283a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande } 583e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 58483a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande setIntField(env, data, "mId", scan_data[i].scan_id); 58583a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande setIntField(env, data, "mFlags", scan_data[i].flags); 586e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 58783a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande /* sort all scan results by timestamp */ 58883a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande qsort(scan_data[i].results, scan_data[i].num_results, 58983a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande sizeof(wifi_scan_result), compare_scan_result_timestamp); 59083a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande 59183a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande jobjectArray scanResults = createObjectArray(env, 59283a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande "android/net/wifi/ScanResult", scan_data[i].num_results); 59383a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande if (scanResults == NULL) { 59483a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande ALOGE("Error in allocating scanResult array"); 595e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return NULL; 596e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 597e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 59883a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande wifi_scan_result *results = scan_data[i].results; 59983a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande for (int j = 0; j < scan_data[i].num_results; j++) { 60083a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande 60183a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande jobject scanResult = createObject(env, "android/net/wifi/ScanResult"); 60283a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande if (scanResult == NULL) { 60383a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande ALOGE("Error in creating scan result"); 60483a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande return NULL; 60583a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande } 6067f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 60783a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande setStringField(env, scanResult, "SSID", results[j].ssid); 608e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 60983a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande char bssid[32]; 61083a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", results[j].bssid[0], 61183a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande results[j].bssid[1], results[j].bssid[2], results[j].bssid[3], 61283a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande results[j].bssid[4], results[j].bssid[5]); 613e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 61483a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande setStringField(env, scanResult, "BSSID", bssid); 61583a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande 61683a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande setIntField(env, scanResult, "level", results[j].rssi); 61783a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande setIntField(env, scanResult, "frequency", results[j].channel); 61883a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande setLongField(env, scanResult, "timestamp", results[j].ts); 61983a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande 62083a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande env->SetObjectArrayElement(scanResults, j, scanResult); 62183a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande env->DeleteLocalRef(scanResult); 62283a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande } 623e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 62483a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande setObjectField(env, data, "mResults", "[Landroid/net/wifi/ScanResult;", scanResults); 62583a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande env->SetObjectArrayElement(scanData, i, data); 626e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 627e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 62883a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande return scanData; 629e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } else { 630e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return NULL; 631e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 632e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde} 633e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 634e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 635e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndestatic jboolean android_net_wifi_getScanCapabilities( 636b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande JNIEnv *env, jclass cls, jint iface, jobject capabilities) { 637e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 638b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 639e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("getting scan capabilities on interface[%d] = %p", iface, handle); 640e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 641e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde wifi_gscan_capabilities c; 642e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde memset(&c, 0, sizeof(c)); 643628199920e1d1fa86caabaf13874e7dc601e7b06xinhe int result = hal_fn.wifi_get_gscan_capabilities(handle, &c); 644e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde if (result != WIFI_SUCCESS) { 645e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("failed to get capabilities : %d", result); 646e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return JNI_FALSE; 647e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 648e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 649e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde setIntField(env, capabilities, "max_scan_cache_size", c.max_scan_cache_size); 650e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde setIntField(env, capabilities, "max_scan_buckets", c.max_scan_buckets); 651e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde setIntField(env, capabilities, "max_ap_cache_per_scan", c.max_ap_cache_per_scan); 652e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde setIntField(env, capabilities, "max_rssi_sample_size", c.max_rssi_sample_size); 653e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde setIntField(env, capabilities, "max_scan_reporting_threshold", c.max_scan_reporting_threshold); 654c03c14696493a3763948feed7f1e75e77e2a2f9bPierre Vandwalle setIntField(env, capabilities, "max_hotlist_bssids", c.max_hotlist_bssids); 655e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde setIntField(env, capabilities, "max_significant_wifi_change_aps", 656e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde c.max_significant_wifi_change_aps); 657e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 658e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return JNI_TRUE; 659e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde} 660e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 661e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 662e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndestatic byte parseHexChar(char ch) { 663e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde if (isdigit(ch)) 664e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return ch - '0'; 665e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde else if ('A' <= ch && ch <= 'F') 666e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return ch - 'A' + 10; 667e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde else if ('a' <= ch && ch <= 'f') 668e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return ch - 'a' + 10; 669e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde else { 670e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGE("invalid character in bssid %c", ch); 671e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return 0; 672e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 673e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde} 674e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 675e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndestatic byte parseHexByte(const char * &str) { 676e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde byte b = parseHexChar(str[0]); 677e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde if (str[1] == ':' || str[1] == '\0') { 678e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde str += 2; 679e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return b; 680e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } else { 681e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde b = b << 4 | parseHexChar(str[1]); 682e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde str += 3; 683e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return b; 684e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 685e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde} 686e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 687e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndestatic void parseMacAddress(const char *str, mac_addr addr) { 688e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde addr[0] = parseHexByte(str); 689e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde addr[1] = parseHexByte(str); 690e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde addr[2] = parseHexByte(str); 691e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde addr[3] = parseHexByte(str); 692e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde addr[4] = parseHexByte(str); 693e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde addr[5] = parseHexByte(str); 694e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde} 695e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 696143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpandestatic bool parseMacAddress(JNIEnv *env, jobject obj, mac_addr addr) { 697143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande jstring macAddrString = (jstring) getObjectField( 698143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande env, obj, "bssid", "Ljava/lang/String;"); 699143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 700143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande if (macAddrString == NULL) { 701143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande ALOGE("Error getting bssid field"); 702143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande return false; 703143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 704143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 705143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande const char *bssid = env->GetStringUTFChars(macAddrString, NULL); 706143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande if (bssid == NULL) { 707143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande ALOGE("Error getting bssid"); 708143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande return false; 709143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 710143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 711143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande parseMacAddress(bssid, addr); 712143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande return true; 713143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande} 714143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 715e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndestatic void onHotlistApFound(wifi_request_id id, 716e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde unsigned num_results, wifi_scan_result *results) { 717e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 718e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde JNIEnv *env = NULL; 719e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde mVM->AttachCurrentThread(&env, NULL); 720e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 721e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("onHotlistApFound called, vm = %p, obj = %p, env = %p, num_results = %d", 722b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande mVM, mCls, env, num_results); 723e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 724e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde jclass clsScanResult = (env)->FindClass("android/net/wifi/ScanResult"); 7257f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde if (clsScanResult == NULL) { 7267f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde ALOGE("Error in accessing class"); 7277f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde return; 7287f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 7297f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 7307f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde jobjectArray scanResults = env->NewObjectArray(num_results, clsScanResult, NULL); 7317f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde if (scanResults == NULL) { 7327f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde ALOGE("Error in allocating array"); 7337f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde return; 7347f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 7357f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 7367f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde for (unsigned i = 0; i < num_results; i++) { 7377f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 738e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde jobject scanResult = createObject(env, "android/net/wifi/ScanResult"); 7397f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde if (scanResult == NULL) { 7407f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde ALOGE("Error in creating scan result"); 7417f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde return; 7427f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 7437f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 7447f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde setStringField(env, scanResult, "SSID", results[i].ssid); 7457f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 7467f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde char bssid[32]; 747e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", results[i].bssid[0], results[i].bssid[1], 7487f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde results[i].bssid[2], results[i].bssid[3], results[i].bssid[4], results[i].bssid[5]); 7497f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 7507f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde setStringField(env, scanResult, "BSSID", bssid); 7517f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 7527f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde setIntField(env, scanResult, "level", results[i].rssi); 753e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde setIntField(env, scanResult, "frequency", results[i].channel); 7547f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde setLongField(env, scanResult, "timestamp", results[i].ts); 755e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 756e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde env->SetObjectArrayElement(scanResults, i, scanResult); 757e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 758e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("Found AP %32s %s", results[i].ssid, bssid); 759e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 760e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 761b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande reportEvent(env, mCls, "onHotlistApFound", "(I[Landroid/net/wifi/ScanResult;)V", 762e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde id, scanResults); 763e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde} 764e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 765d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpandestatic void onHotlistApLost(wifi_request_id id, 766d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande unsigned num_results, wifi_scan_result *results) { 767d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 768d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande JNIEnv *env = NULL; 769d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande mVM->AttachCurrentThread(&env, NULL); 770d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 771d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande ALOGD("onHotlistApLost called, vm = %p, obj = %p, env = %p, num_results = %d", 772d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande mVM, mCls, env, num_results); 773d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 774d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande jclass clsScanResult = (env)->FindClass("android/net/wifi/ScanResult"); 775d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande if (clsScanResult == NULL) { 776d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande ALOGE("Error in accessing class"); 777d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande return; 778d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande } 779d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 780d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande jobjectArray scanResults = env->NewObjectArray(num_results, clsScanResult, NULL); 781d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande if (scanResults == NULL) { 782d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande ALOGE("Error in allocating array"); 783d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande return; 784d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande } 785d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 786d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande for (unsigned i = 0; i < num_results; i++) { 787d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 788d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande jobject scanResult = createObject(env, "android/net/wifi/ScanResult"); 789d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande if (scanResult == NULL) { 790d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande ALOGE("Error in creating scan result"); 791d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande return; 792d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande } 793d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 794d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande setStringField(env, scanResult, "SSID", results[i].ssid); 795d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 796d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande char bssid[32]; 797d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", results[i].bssid[0], results[i].bssid[1], 798d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande results[i].bssid[2], results[i].bssid[3], results[i].bssid[4], results[i].bssid[5]); 799d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 800d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande setStringField(env, scanResult, "BSSID", bssid); 801d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 802d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande setIntField(env, scanResult, "level", results[i].rssi); 803d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande setIntField(env, scanResult, "frequency", results[i].channel); 804d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande setLongField(env, scanResult, "timestamp", results[i].ts); 805d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 806d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande env->SetObjectArrayElement(scanResults, i, scanResult); 807d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 808d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande ALOGD("Lost AP %32s %s", results[i].ssid, bssid); 809d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande } 810d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 811d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande reportEvent(env, mCls, "onHotlistApLost", "(I[Landroid/net/wifi/ScanResult;)V", 812d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande id, scanResults); 813d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande} 814d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 815d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 816e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndestatic jboolean android_net_wifi_setHotlist( 817b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande JNIEnv *env, jclass cls, jint iface, jint id, jobject ap) { 818e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 819b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 820e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("setting hotlist on interface[%d] = %p", iface, handle); 821e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 822e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde wifi_bssid_hotlist_params params; 823e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde memset(¶ms, 0, sizeof(params)); 824e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 825d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande params.lost_ap_sample_size = getIntField(env, ap, "apLostThreshold"); 826d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande 827e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde jobjectArray array = (jobjectArray) getObjectField(env, ap, 828b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande "bssidInfos", "[Landroid/net/wifi/WifiScanner$BssidInfo;"); 829c03c14696493a3763948feed7f1e75e77e2a2f9bPierre Vandwalle params.num_bssid = env->GetArrayLength(array); 830e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 831c03c14696493a3763948feed7f1e75e77e2a2f9bPierre Vandwalle if (params.num_bssid == 0) { 832e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGE("Error in accesing array"); 833e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 834e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 835e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 836c03c14696493a3763948feed7f1e75e77e2a2f9bPierre Vandwalle for (int i = 0; i < params.num_bssid; i++) { 837e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde jobject objAp = env->GetObjectArrayElement(array, i); 838e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 839e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde jstring macAddrString = (jstring) getObjectField( 840e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde env, objAp, "bssid", "Ljava/lang/String;"); 841e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde if (macAddrString == NULL) { 842e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGE("Error getting bssid field"); 843e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 844e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 845e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 846e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde const char *bssid = env->GetStringUTFChars(macAddrString, NULL); 847e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde if (bssid == NULL) { 848e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGE("Error getting bssid"); 849e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 850e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 851a59fae6bd96ead6d3c8772b3cc5e69cd08444400Vinit Deshpande parseMacAddress(bssid, params.ap[i].bssid); 852e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 853e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde mac_addr addr; 854a59fae6bd96ead6d3c8772b3cc5e69cd08444400Vinit Deshpande memcpy(addr, params.ap[i].bssid, sizeof(mac_addr)); 855e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 856e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde char bssidOut[32]; 857e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde sprintf(bssidOut, "%0x:%0x:%0x:%0x:%0x:%0x", addr[0], addr[1], 858e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde addr[2], addr[3], addr[4], addr[5]); 859e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 860e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("Added bssid %s", bssidOut); 861e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 862a59fae6bd96ead6d3c8772b3cc5e69cd08444400Vinit Deshpande params.ap[i].low = getIntField(env, objAp, "low"); 863a59fae6bd96ead6d3c8772b3cc5e69cd08444400Vinit Deshpande params.ap[i].high = getIntField(env, objAp, "high"); 864e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 865e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 866e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde wifi_hotlist_ap_found_handler handler; 867e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde memset(&handler, 0, sizeof(handler)); 868e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 869e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde handler.on_hotlist_ap_found = &onHotlistApFound; 870d4762401ec14be6bdd2d27aff2478ddbf8d6ce2aVinit Deshpande handler.on_hotlist_ap_lost = &onHotlistApLost; 871628199920e1d1fa86caabaf13874e7dc601e7b06xinhe return hal_fn.wifi_set_bssid_hotlist(id, handle, params, handler) == WIFI_SUCCESS; 872e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde} 873e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 874e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndestatic jboolean android_net_wifi_resetHotlist( 875b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande JNIEnv *env, jclass cls, jint iface, jint id) { 876e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 877b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 878e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("resetting hotlist on interface[%d] = %p", iface, handle); 879e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 880628199920e1d1fa86caabaf13874e7dc601e7b06xinhe return hal_fn.wifi_reset_bssid_hotlist(id, handle) == WIFI_SUCCESS; 881e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde} 882e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 883a59fae6bd96ead6d3c8772b3cc5e69cd08444400Vinit Deshpandevoid onSignificantWifiChange(wifi_request_id id, 884a59fae6bd96ead6d3c8772b3cc5e69cd08444400Vinit Deshpande unsigned num_results, wifi_significant_change_result **results) { 885e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde JNIEnv *env = NULL; 886e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde mVM->AttachCurrentThread(&env, NULL); 887e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 888b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande ALOGD("onSignificantWifiChange called, vm = %p, obj = %p, env = %p", mVM, mCls, env); 889e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 890e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde jclass clsScanResult = (env)->FindClass("android/net/wifi/ScanResult"); 891e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde if (clsScanResult == NULL) { 892e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGE("Error in accessing class"); 893e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return; 894e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 895e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 896e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde jobjectArray scanResults = env->NewObjectArray(num_results, clsScanResult, NULL); 897e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde if (scanResults == NULL) { 898e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGE("Error in allocating array"); 899e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return; 900e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 901e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 902e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde for (unsigned i = 0; i < num_results; i++) { 903e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 904a59fae6bd96ead6d3c8772b3cc5e69cd08444400Vinit Deshpande wifi_significant_change_result result = *(results[i]); 905a59fae6bd96ead6d3c8772b3cc5e69cd08444400Vinit Deshpande 906e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde jobject scanResult = createObject(env, "android/net/wifi/ScanResult"); 907e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde if (scanResult == NULL) { 908e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGE("Error in creating scan result"); 909e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return; 910e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 911e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 912a59fae6bd96ead6d3c8772b3cc5e69cd08444400Vinit Deshpande // setStringField(env, scanResult, "SSID", results[i].ssid); 913e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 914e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde char bssid[32]; 915a59fae6bd96ead6d3c8772b3cc5e69cd08444400Vinit Deshpande sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", result.bssid[0], result.bssid[1], 916a59fae6bd96ead6d3c8772b3cc5e69cd08444400Vinit Deshpande result.bssid[2], result.bssid[3], result.bssid[4], result.bssid[5]); 917e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 918e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde setStringField(env, scanResult, "BSSID", bssid); 919e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 9204dbfefd99e51ab1cca058026c90f8093b099198bVinit Deshpande setIntField(env, scanResult, "level", result.rssi[0]); 921a59fae6bd96ead6d3c8772b3cc5e69cd08444400Vinit Deshpande setIntField(env, scanResult, "frequency", result.channel); 922a59fae6bd96ead6d3c8772b3cc5e69cd08444400Vinit Deshpande // setLongField(env, scanResult, "timestamp", result.ts); 9237f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 9247f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde env->SetObjectArrayElement(scanResults, i, scanResult); 9257f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde } 9267f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 927b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande reportEvent(env, mCls, "onSignificantWifiChange", "(I[Landroid/net/wifi/ScanResult;)V", 928e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde id, scanResults); 929e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 9307f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde} 9317f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 932e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndestatic jboolean android_net_wifi_trackSignificantWifiChange( 933b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande JNIEnv *env, jclass cls, jint iface, jint id, jobject settings) { 9347f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 935b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 936e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("tracking significant wifi change on interface[%d] = %p", iface, handle); 9377f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 938e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde wifi_significant_change_params params; 9397f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde memset(¶ms, 0, sizeof(params)); 9407f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 941e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde params.rssi_sample_size = getIntField(env, settings, "rssiSampleSize"); 942e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde params.lost_ap_sample_size = getIntField(env, settings, "lostApSampleSize"); 943e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde params.min_breaching = getIntField(env, settings, "minApsBreachingThreshold"); 944e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 945b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande const char *bssid_info_array_type = "[Landroid/net/wifi/WifiScanner$BssidInfo;"; 946b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande jobjectArray bssids = (jobjectArray)getObjectField( 947b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande env, settings, "bssidInfos", bssid_info_array_type); 948c03c14696493a3763948feed7f1e75e77e2a2f9bPierre Vandwalle params.num_bssid = env->GetArrayLength(bssids); 949e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 950c03c14696493a3763948feed7f1e75e77e2a2f9bPierre Vandwalle if (params.num_bssid == 0) { 951aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle ALOGE("Error in accessing array"); 952e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 953e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 954e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 955e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("Initialized common fields %d, %d, %d, %d", params.rssi_sample_size, 956c03c14696493a3763948feed7f1e75e77e2a2f9bPierre Vandwalle params.lost_ap_sample_size, params.min_breaching, params.num_bssid); 957e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 958c03c14696493a3763948feed7f1e75e77e2a2f9bPierre Vandwalle for (int i = 0; i < params.num_bssid; i++) { 959b7cc309f06da8a18224057c21ba086f8550367d6Vinit Deshpande jobject objAp = env->GetObjectArrayElement(bssids, i); 960e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 961e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde jstring macAddrString = (jstring) getObjectField( 962e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde env, objAp, "bssid", "Ljava/lang/String;"); 963e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde if (macAddrString == NULL) { 964e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGE("Error getting bssid field"); 965e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 966e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 967e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 968e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde const char *bssid = env->GetStringUTFChars(macAddrString, NULL); 969e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde if (bssid == NULL) { 970e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGE("Error getting bssid"); 971e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde return false; 972e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 973e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 974e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde mac_addr addr; 975e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde parseMacAddress(bssid, addr); 976a59fae6bd96ead6d3c8772b3cc5e69cd08444400Vinit Deshpande memcpy(params.ap[i].bssid, addr, sizeof(mac_addr)); 977e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 978e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde char bssidOut[32]; 9794dbfefd99e51ab1cca058026c90f8093b099198bVinit Deshpande sprintf(bssidOut, "%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1], 980e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde addr[2], addr[3], addr[4], addr[5]); 981e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 982a59fae6bd96ead6d3c8772b3cc5e69cd08444400Vinit Deshpande params.ap[i].low = getIntField(env, objAp, "low"); 983a59fae6bd96ead6d3c8772b3cc5e69cd08444400Vinit Deshpande params.ap[i].high = getIntField(env, objAp, "high"); 984e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 985a59fae6bd96ead6d3c8772b3cc5e69cd08444400Vinit Deshpande ALOGD("Added bssid %s, [%04d, %04d]", bssidOut, params.ap[i].low, params.ap[i].high); 986e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde } 987e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 988c03c14696493a3763948feed7f1e75e77e2a2f9bPierre Vandwalle ALOGD("Added %d bssids", params.num_bssid); 989e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 990e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde wifi_significant_change_handler handler; 9917f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde memset(&handler, 0, sizeof(handler)); 9927f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 993e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde handler.on_significant_change = &onSignificantWifiChange; 994628199920e1d1fa86caabaf13874e7dc601e7b06xinhe return hal_fn.wifi_set_significant_change_handler(id, handle, params, handler) == WIFI_SUCCESS; 9957f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde} 9967f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 997e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapndestatic jboolean android_net_wifi_untrackSignificantWifiChange( 998b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande JNIEnv *env, jclass cls, jint iface, jint id) { 999e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1000b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 1001e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde ALOGD("resetting significant wifi change on interface[%d] = %p", iface, handle); 10027f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde 1003628199920e1d1fa86caabaf13874e7dc601e7b06xinhe return hal_fn.wifi_reset_significant_change_handler(id, handle) == WIFI_SUCCESS; 10047f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde} 10057ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde 1006aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwallewifi_iface_stat link_stat; 1007200e8ee5097134010a6edee8d031bb02ff7eeb5avandwallewifi_radio_stat radio_stat; // L release has support for only one radio 1008aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 1009aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwallevoid onLinkStatsResults(wifi_request_id id, wifi_iface_stat *iface_stat, 1010200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle int num_radios, wifi_radio_stat *radio_stats) 1011aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle{ 1012200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle if (iface_stat != 0) { 1013200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle memcpy(&link_stat, iface_stat, sizeof(wifi_iface_stat)); 1014200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle } else { 1015200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle memset(&link_stat, 0, sizeof(wifi_iface_stat)); 1016200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle } 1017200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle 1018200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle if (num_radios > 0 && radio_stats != 0) { 1019200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle memcpy(&radio_stat, radio_stats, sizeof(wifi_radio_stat)); 1020200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle } else { 1021200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle memset(&radio_stat, 0, sizeof(wifi_radio_stat)); 1022200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle } 1023aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle} 1024aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 1025b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpandestatic jobject android_net_wifi_getLinkLayerStats (JNIEnv *env, jclass cls, jint iface) { 1026aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 1027aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle wifi_stats_result_handler handler; 1028aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle memset(&handler, 0, sizeof(handler)); 1029aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle handler.on_link_stats_results = &onLinkStatsResults; 1030b0b1d59786de7ff1fc98e31a16a7d710458bf549Vinit Deshpande wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 1031628199920e1d1fa86caabaf13874e7dc601e7b06xinhe int result = hal_fn.wifi_get_link_stats(0, handle, handler); 1032aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle if (result < 0) { 1033200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle ALOGE("android_net_wifi_getLinkLayerStats: failed to get link statistics\n"); 1034aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return NULL; 1035aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 1036aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 1037aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle jobject wifiLinkLayerStats = createObject(env, "android/net/wifi/WifiLinkLayerStats"); 1038aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle if (wifiLinkLayerStats == NULL) { 1039aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle ALOGE("Error in allocating wifiLinkLayerStats"); 1040aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return NULL; 1041aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle } 1042aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 1043aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setIntField(env, wifiLinkLayerStats, "beacon_rx", link_stat.beacon_rx); 1044aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setIntField(env, wifiLinkLayerStats, "rssi_mgmt", link_stat.rssi_mgmt); 1045aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setLongField(env, wifiLinkLayerStats, "rxmpdu_be", link_stat.ac[WIFI_AC_BE].rx_mpdu); 1046aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setLongField(env, wifiLinkLayerStats, "rxmpdu_bk", link_stat.ac[WIFI_AC_BK].rx_mpdu); 1047aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setLongField(env, wifiLinkLayerStats, "rxmpdu_vi", link_stat.ac[WIFI_AC_VI].rx_mpdu); 1048aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setLongField(env, wifiLinkLayerStats, "rxmpdu_vo", link_stat.ac[WIFI_AC_VO].rx_mpdu); 1049aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setLongField(env, wifiLinkLayerStats, "txmpdu_be", link_stat.ac[WIFI_AC_BE].tx_mpdu); 1050aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setLongField(env, wifiLinkLayerStats, "txmpdu_bk", link_stat.ac[WIFI_AC_BK].tx_mpdu); 1051aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setLongField(env, wifiLinkLayerStats, "txmpdu_vi", link_stat.ac[WIFI_AC_VI].tx_mpdu); 1052aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setLongField(env, wifiLinkLayerStats, "txmpdu_vo", link_stat.ac[WIFI_AC_VO].tx_mpdu); 1053aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setLongField(env, wifiLinkLayerStats, "lostmpdu_be", link_stat.ac[WIFI_AC_BE].mpdu_lost); 1054aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setLongField(env, wifiLinkLayerStats, "lostmpdu_bk", link_stat.ac[WIFI_AC_BK].mpdu_lost); 1055aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setLongField(env, wifiLinkLayerStats, "lostmpdu_vi", link_stat.ac[WIFI_AC_VI].mpdu_lost); 1056aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setLongField(env, wifiLinkLayerStats, "lostmpdu_vo", link_stat.ac[WIFI_AC_VO].mpdu_lost); 1057aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setLongField(env, wifiLinkLayerStats, "retries_be", link_stat.ac[WIFI_AC_BE].retries); 1058aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setLongField(env, wifiLinkLayerStats, "retries_bk", link_stat.ac[WIFI_AC_BK].retries); 1059aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setLongField(env, wifiLinkLayerStats, "retries_vi", link_stat.ac[WIFI_AC_VI].retries); 1060aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle setLongField(env, wifiLinkLayerStats, "retries_vo", link_stat.ac[WIFI_AC_VO].retries); 1061aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle 1062200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle 1063200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle setIntField(env, wifiLinkLayerStats, "on_time", radio_stat.on_time); 1064200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle setIntField(env, wifiLinkLayerStats, "tx_time", radio_stat.tx_time); 1065200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle setIntField(env, wifiLinkLayerStats, "rx_time", radio_stat.rx_time); 1066200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle setIntField(env, wifiLinkLayerStats, "on_time_scan", radio_stat.on_time_scan); 1067200e8ee5097134010a6edee8d031bb02ff7eeb5avandwalle 1068aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle return wifiLinkLayerStats; 1069aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle} 1070e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde 1071c35361d54d4885c3174499e4ad46d3324387a9bbVinit Deshpandestatic jint android_net_wifi_getSupportedFeatures(JNIEnv *env, jclass cls, jint iface) { 1072c35361d54d4885c3174499e4ad46d3324387a9bbVinit Deshpande wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 1073a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande feature_set set = 0; 1074a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande 1075a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande wifi_error result = WIFI_SUCCESS; 1076c35361d54d4885c3174499e4ad46d3324387a9bbVinit Deshpande /* 1077a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande set = WIFI_FEATURE_INFRA 1078a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande | WIFI_FEATURE_INFRA_5G 1079a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande | WIFI_FEATURE_HOTSPOT 1080a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande | WIFI_FEATURE_P2P 1081a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande | WIFI_FEATURE_SOFT_AP 1082a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande | WIFI_FEATURE_GSCAN 1083a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande | WIFI_FEATURE_PNO 1084a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande | WIFI_FEATURE_TDLS 1085a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande | WIFI_FEATURE_EPR; 1086c35361d54d4885c3174499e4ad46d3324387a9bbVinit Deshpande */ 1087a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande 1088628199920e1d1fa86caabaf13874e7dc601e7b06xinhe result = hal_fn.wifi_get_supported_feature_set(handle, &set); 1089a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande if (result == WIFI_SUCCESS) { 1090c35361d54d4885c3174499e4ad46d3324387a9bbVinit Deshpande ALOGD("wifi_get_supported_feature_set returned set = 0x%x", set); 1091a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande return set; 1092a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande } else { 1093c35361d54d4885c3174499e4ad46d3324387a9bbVinit Deshpande ALOGD("wifi_get_supported_feature_set returned error = 0x%x", result); 1094a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande return 0; 1095a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande } 1096a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande} 1097a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande 109806a3ebada2343fe3f083339973f143b39d62b3c4xinhestatic void onRttResults(wifi_request_id id, unsigned num_results, wifi_rtt_result* results[]) { 1099143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande JNIEnv *env = NULL; 1100143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande mVM->AttachCurrentThread(&env, NULL); 1101143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1102143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande ALOGD("onRttResults called, vm = %p, obj = %p, env = %p", mVM, mCls, env); 1103143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1104143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande jclass clsRttResult = (env)->FindClass("android/net/wifi/RttManager$RttResult"); 1105143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande if (clsRttResult == NULL) { 1106143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande ALOGE("Error in accessing class"); 1107143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande return; 1108143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1109143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1110143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande jobjectArray rttResults = env->NewObjectArray(num_results, clsRttResult, NULL); 1111143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande if (rttResults == NULL) { 1112143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande ALOGE("Error in allocating array"); 1113143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande return; 1114143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1115143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1116143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande for (unsigned i = 0; i < num_results; i++) { 1117143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 111806a3ebada2343fe3f083339973f143b39d62b3c4xinhe wifi_rtt_result *result = results[i]; 1119143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1120143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande jobject rttResult = createObject(env, "android/net/wifi/RttManager$RttResult"); 1121143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande if (rttResult == NULL) { 1122143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande ALOGE("Error in creating rtt result"); 1123143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande return; 1124143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1125143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1126143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande char bssid[32]; 112706a3ebada2343fe3f083339973f143b39d62b3c4xinhe sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", result->addr[0], result->addr[1], 112806a3ebada2343fe3f083339973f143b39d62b3c4xinhe result->addr[2], result->addr[3], result->addr[4], result->addr[5]); 1129143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1130143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande setStringField(env, rttResult, "bssid", bssid); 113106a3ebada2343fe3f083339973f143b39d62b3c4xinhe setIntField(env, rttResult, "burstNumber", result->burst_num); 113206a3ebada2343fe3f083339973f143b39d62b3c4xinhe setIntField(env, rttResult, "measurementFrameNumber", result->measurement_number); 113306a3ebada2343fe3f083339973f143b39d62b3c4xinhe setIntField(env, rttResult, "successMeasurementFrameNumber", result->success_number); 113406a3ebada2343fe3f083339973f143b39d62b3c4xinhe setIntField(env, rttResult, "frameNumberPerBurstPeer", result->number_per_burst_peer); 113506a3ebada2343fe3f083339973f143b39d62b3c4xinhe setIntField(env, rttResult, "status", result->status); 113606a3ebada2343fe3f083339973f143b39d62b3c4xinhe setIntField(env, rttResult, "measurementType", result->type); 113706a3ebada2343fe3f083339973f143b39d62b3c4xinhe setIntField(env, rttResult, "retryAfterDuration", result->retry_after_duration); 113806a3ebada2343fe3f083339973f143b39d62b3c4xinhe setLongField(env, rttResult, "ts", result->ts); 113906a3ebada2343fe3f083339973f143b39d62b3c4xinhe setIntField(env, rttResult, "rssi", result->rssi); 114006a3ebada2343fe3f083339973f143b39d62b3c4xinhe setIntField(env, rttResult, "rssiSpread", result->rssi_spread); 114106a3ebada2343fe3f083339973f143b39d62b3c4xinhe setIntField(env, rttResult, "txRate", result->tx_rate.bitrate); 114206a3ebada2343fe3f083339973f143b39d62b3c4xinhe setIntField(env, rttResult, "rxRate", result->rx_rate.bitrate); 114306a3ebada2343fe3f083339973f143b39d62b3c4xinhe setLongField(env, rttResult, "rtt", result->rtt); 114406a3ebada2343fe3f083339973f143b39d62b3c4xinhe setLongField(env, rttResult, "rttStandardDeviation", result->rtt_sd); 114506a3ebada2343fe3f083339973f143b39d62b3c4xinhe setIntField(env, rttResult, "distance", result->distance); 114606a3ebada2343fe3f083339973f143b39d62b3c4xinhe setIntField(env, rttResult, "distanceStandardDeviation", result->distance_sd); 114706a3ebada2343fe3f083339973f143b39d62b3c4xinhe setIntField(env, rttResult, "distanceSpread", result->distance_spread); 114806a3ebada2343fe3f083339973f143b39d62b3c4xinhe setIntField(env, rttResult, "burstDuration", result->burst_duration); 1149c96feb800590f43b7be76d1000ab5d949e5c6790xinhe setIntField(env, rttResult, "negotiatedBurstNum", result->negotiated_burst_num); 1150c96feb800590f43b7be76d1000ab5d949e5c6790xinhe jobject LCI = createObject(env, "android/net/wifi/RttManager$WifiInformationElement"); 1151c96feb800590f43b7be76d1000ab5d949e5c6790xinhe if (result->LCI != NULL && result->LCI->len > 0) { 1152c96feb800590f43b7be76d1000ab5d949e5c6790xinhe ALOGD("Add LCI in result"); 1153c96feb800590f43b7be76d1000ab5d949e5c6790xinhe setByteField(env, LCI, "id", result->LCI->id); 1154c96feb800590f43b7be76d1000ab5d949e5c6790xinhe jbyteArray elements = env->NewByteArray(result->LCI->len); 1155c96feb800590f43b7be76d1000ab5d949e5c6790xinhe jbyte *bytes = (jbyte *)&(result->LCI->data[0]); 1156c96feb800590f43b7be76d1000ab5d949e5c6790xinhe env->SetByteArrayRegion(elements, 0, result->LCI->len, bytes); 1157c96feb800590f43b7be76d1000ab5d949e5c6790xinhe setObjectField(env, LCI, "data", "[B", elements); 115893a1dbd961f05335635ede08eae6481284690c7dxinhe env->DeleteLocalRef(elements); 1159c96feb800590f43b7be76d1000ab5d949e5c6790xinhe } else { 1160c96feb800590f43b7be76d1000ab5d949e5c6790xinhe ALOGD("No LCI in result"); 1161c96feb800590f43b7be76d1000ab5d949e5c6790xinhe setByteField(env, LCI, "id", (byte)(0xff)); 1162c96feb800590f43b7be76d1000ab5d949e5c6790xinhe } 1163c96feb800590f43b7be76d1000ab5d949e5c6790xinhe setObjectField(env, rttResult, "LCI", 1164c96feb800590f43b7be76d1000ab5d949e5c6790xinhe "Landroid/net/wifi/RttManager$WifiInformationElement;", LCI); 1165c96feb800590f43b7be76d1000ab5d949e5c6790xinhe 1166c96feb800590f43b7be76d1000ab5d949e5c6790xinhe jobject LCR = createObject(env, "android/net/wifi/RttManager$WifiInformationElement"); 1167c96feb800590f43b7be76d1000ab5d949e5c6790xinhe if (result->LCR != NULL && result->LCR->len > 0) { 1168c96feb800590f43b7be76d1000ab5d949e5c6790xinhe ALOGD("Add LCR in result"); 1169c96feb800590f43b7be76d1000ab5d949e5c6790xinhe setByteField(env, LCR, "id", result->LCR->id); 1170c96feb800590f43b7be76d1000ab5d949e5c6790xinhe jbyteArray elements = env->NewByteArray(result->LCI->len); 1171c96feb800590f43b7be76d1000ab5d949e5c6790xinhe jbyte *bytes = (jbyte *)&(result->LCR->data[0]); 1172c96feb800590f43b7be76d1000ab5d949e5c6790xinhe env->SetByteArrayRegion(elements, 0, result->LCI->len, bytes); 1173c96feb800590f43b7be76d1000ab5d949e5c6790xinhe setObjectField(env, LCR, "data", "[B", elements); 117493a1dbd961f05335635ede08eae6481284690c7dxinhe env->DeleteLocalRef(elements); 1175c96feb800590f43b7be76d1000ab5d949e5c6790xinhe } else { 117693a1dbd961f05335635ede08eae6481284690c7dxinhe ALOGD("No LCR in result"); 1177c96feb800590f43b7be76d1000ab5d949e5c6790xinhe setByteField(env, LCR, "id", (byte)(0xff)); 1178c96feb800590f43b7be76d1000ab5d949e5c6790xinhe } 1179c96feb800590f43b7be76d1000ab5d949e5c6790xinhe setObjectField(env, rttResult, "LCR", 1180c96feb800590f43b7be76d1000ab5d949e5c6790xinhe "Landroid/net/wifi/RttManager$WifiInformationElement;", LCR); 1181143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1182143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande env->SetObjectArrayElement(rttResults, i, rttResult); 118393a1dbd961f05335635ede08eae6481284690c7dxinhe env->DeleteLocalRef(LCI); 118493a1dbd961f05335635ede08eae6481284690c7dxinhe env->DeleteLocalRef(LCR); 118593a1dbd961f05335635ede08eae6481284690c7dxinhe env->DeleteLocalRef(rttResult); 1186143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande } 1187143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1188143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande reportEvent(env, mCls, "onRttResults", "(I[Landroid/net/wifi/RttManager$RttResult;)V", 1189143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande id, rttResults); 119093a1dbd961f05335635ede08eae6481284690c7dxinhe 119193a1dbd961f05335635ede08eae6481284690c7dxinhe //clean the local reference 119293a1dbd961f05335635ede08eae6481284690c7dxinhe env->DeleteLocalRef(rttResults); 119393a1dbd961f05335635ede08eae6481284690c7dxinhe env->DeleteLocalRef(clsRttResult); 119493a1dbd961f05335635ede08eae6481284690c7dxinhe 1195143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande} 1196143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 119702a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpandeconst int MaxRttConfigs = 16; 119802a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande 1199143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpandestatic jboolean android_net_wifi_requestRange( 1200143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande JNIEnv *env, jclass cls, jint iface, jint id, jobject params) { 1201143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1202143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 1203143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande ALOGD("sending rtt request [%d] = %p", id, handle); 1204143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 120502a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande wifi_rtt_config configs[MaxRttConfigs]; 120602a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande memset(&configs, 0, sizeof(configs)); 120702a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande 120802a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande int len = env->GetArrayLength((jobjectArray)params); 120902a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande if (len > MaxRttConfigs) { 121002a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande return false; 121102a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande } 121202a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande 121302a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande for (int i = 0; i < len; i++) { 121402a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande 121502a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande jobject param = env->GetObjectArrayElement((jobjectArray)params, i); 121602a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande if (param == NULL) { 121702a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande ALOGD("could not get element %d", i); 121802a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande continue; 121902a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande } 1220143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 122102a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande wifi_rtt_config &config = configs[i]; 122202a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande 122302a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande parseMacAddress(env, param, config.addr); 122402a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande config.type = (wifi_rtt_type)getIntField(env, param, "requestType"); 1225c96feb800590f43b7be76d1000ab5d949e5c6790xinhe config.peer = (rtt_peer_type)getIntField(env, param, "deviceType"); 122602a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande config.channel.center_freq = getIntField(env, param, "frequency"); 122712cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe config.channel.width = (wifi_channel_width) getIntField(env, param, "channelWidth"); 122812cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe config.channel.center_freq0 = getIntField(env, param, "centerFreq0"); 122912cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe config.channel.center_freq1 = getIntField(env, param, "centerFreq1"); 123012cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe 123112cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe config.num_burst = getIntField(env, param, "numberBurst"); 1232c96feb800590f43b7be76d1000ab5d949e5c6790xinhe config.burst_period = (unsigned) getIntField(env, param, "interval"); 123312cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe config.num_frames_per_burst = (unsigned) getIntField(env, param, "numSamplesPerBurst"); 1234c96feb800590f43b7be76d1000ab5d949e5c6790xinhe config.num_retries_per_rtt_frame = (unsigned) getIntField(env, param, 123512cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe "numRetriesPerMeasurementFrame"); 123612cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe config.num_retries_per_ftmr = (unsigned) getIntField(env, param, "numRetriesPerFTMR"); 123712cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe config.LCI_request = getBoolField(env, param, "LCIRequest") ? 1 : 0; 123812cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe config.LCR_request = getBoolField(env, param, "LCRRequest") ? 1 : 0; 1239c96feb800590f43b7be76d1000ab5d949e5c6790xinhe config.burst_duration = (unsigned) getIntField(env, param, "burstTimeout"); 1240c96feb800590f43b7be76d1000ab5d949e5c6790xinhe config.preamble = (wifi_rtt_preamble) getIntField(env, param, "preamble"); 1241c96feb800590f43b7be76d1000ab5d949e5c6790xinhe config.bw = (wifi_rtt_bw) getIntField(env, param, "bandwidth"); 124212cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe 124312cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe ALOGD("RTT request destination %d: type is %d, peer is %d, bw is %d, center_freq is %d ", i, 124412cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe config.type,config.peer, config.channel.width, config.channel.center_freq0); 124512cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe ALOGD("center_freq0 is %d, center_freq1 is %d, num_burst is %d,interval is %d", 124612cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe config.channel.center_freq0, config.channel.center_freq1, config.num_burst, 1247c96feb800590f43b7be76d1000ab5d949e5c6790xinhe config.burst_period); 124812cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe ALOGD("frames_per_burst is %d, retries of measurement frame is %d, retries_per_ftmr is %d", 1249c96feb800590f43b7be76d1000ab5d949e5c6790xinhe config.num_frames_per_burst, config.num_retries_per_rtt_frame, 125012cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe config.num_retries_per_ftmr); 125112cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe ALOGD("LCI_requestis %d, LCR_request is %d, burst_timeout is %d, preamble is %d, bw is %d", 1252c96feb800590f43b7be76d1000ab5d949e5c6790xinhe config.LCI_request, config.LCR_request, config.burst_duration, config.preamble, 125312cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe config.bw); 125402a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande } 1255143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1256143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande wifi_rtt_event_handler handler; 1257143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande handler.on_rtt_results = &onRttResults; 1258143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1259628199920e1d1fa86caabaf13874e7dc601e7b06xinhe return hal_fn.wifi_rtt_range_request(id, handle, len, configs, handler) == WIFI_SUCCESS; 1260143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande} 1261143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1262143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpandestatic jboolean android_net_wifi_cancelRange( 1263042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande JNIEnv *env, jclass cls, jint iface, jint id, jobject params) { 1264143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1265143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 1266143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande ALOGD("cancelling rtt request [%d] = %p", id, handle); 1267143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 126802a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande mac_addr addrs[MaxRttConfigs]; 126902a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande memset(&addrs, 0, sizeof(addrs)); 127002a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande 127102a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande int len = env->GetArrayLength((jobjectArray)params); 127202a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande if (len > MaxRttConfigs) { 127302a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande return false; 127402a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande } 1275143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 127602a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande for (int i = 0; i < len; i++) { 127702a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande 127802a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande jobject param = env->GetObjectArrayElement((jobjectArray)params, i); 127902a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande if (param == NULL) { 128002a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande ALOGD("could not get element %d", i); 128102a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande continue; 128202a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande } 128302a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande 128402a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande parseMacAddress(env, param, addrs[i]); 128502a1f98f2cecb8ae2d466d6f9fab06b473f970ddVinit Deshpande } 1286143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1287628199920e1d1fa86caabaf13874e7dc601e7b06xinhe return hal_fn.wifi_rtt_range_cancel(id, handle, len, addrs) == WIFI_SUCCESS; 1288143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande} 1289143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande 1290042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpandestatic jboolean android_net_wifi_setScanningMacOui(JNIEnv *env, jclass cls, 1291042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande jint iface, jbyteArray param) { 1292042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande 1293042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 1294042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande ALOGD("setting scan oui %p", handle); 1295042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande 1296042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande static const unsigned oui_len = 3; /* OUI is upper 3 bytes of mac_address */ 1297042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande int len = env->GetArrayLength(param); 1298042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande if (len != oui_len) { 1299042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande ALOGE("invalid oui length %d", len); 1300042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande return false; 1301042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande } 1302042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande 1303042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande jbyte* bytes = env->GetByteArrayElements(param, NULL); 1304042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande if (bytes == NULL) { 1305042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande ALOGE("failed to get array"); 1306042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande return false; 1307042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande } 1308042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande 1309628199920e1d1fa86caabaf13874e7dc601e7b06xinhe return hal_fn.wifi_set_scanning_mac_oui(handle, (byte *)bytes) == WIFI_SUCCESS; 1310042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande} 1311042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande 1312efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpandestatic jintArray android_net_wifi_getValidChannels(JNIEnv *env, jclass cls, 1313efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande jint iface, jint band) { 1314efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande 1315efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 1316efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande ALOGD("getting valid channels %p", handle); 1317efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande 1318efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande static const int MaxChannels = 64; 1319efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande wifi_channel channels[64]; 1320efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande int num_channels = 0; 1321628199920e1d1fa86caabaf13874e7dc601e7b06xinhe wifi_error result = hal_fn.wifi_get_valid_channels(handle, band, MaxChannels, 1322efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande channels, &num_channels); 1323efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande 1324efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande if (result == WIFI_SUCCESS) { 1325efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande jintArray channelArray = env->NewIntArray(num_channels); 1326efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande if (channelArray == NULL) { 1327efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande ALOGE("failed to allocate channel list"); 1328efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande return NULL; 1329efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande } 1330efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande 1331efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande env->SetIntArrayRegion(channelArray, 0, num_channels, channels); 1332efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande return channelArray; 1333efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande } else { 1334efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande ALOGE("failed to get channel list : %d", result); 1335efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande return NULL; 1336efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande } 1337efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande} 1338efa77c1826499b0a3e57998bd6b3073b107e45d7Vinit Deshpande 13390465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpandestatic jboolean android_net_wifi_setDfsFlag(JNIEnv *env, jclass cls, jint iface, jboolean dfs) { 13400465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 13410465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande ALOGD("setting dfs flag to %s, %p", dfs ? "true" : "false", handle); 13420465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande 13430465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande u32 nodfs = dfs ? 0 : 1; 1344628199920e1d1fa86caabaf13874e7dc601e7b06xinhe wifi_error result = hal_fn.wifi_set_nodfs_flag(handle, nodfs); 13450465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande return result == WIFI_SUCCESS; 13460465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande} 13470465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande 134812cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhestatic jobject android_net_wifi_get_rtt_capabilities(JNIEnv *env, jclass cls, jint iface) { 134912cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe wifi_rtt_capabilities rtt_capabilities; 135012cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 1351628199920e1d1fa86caabaf13874e7dc601e7b06xinhe wifi_error ret = hal_fn.wifi_get_rtt_capabilities(handle, &rtt_capabilities); 135212cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe 135312cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe if(WIFI_SUCCESS == ret) { 135412cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe jobject capabilities = createObject(env, "android/net/wifi/RttManager$RttCapabilities"); 135512cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe setBooleanField(env, capabilities, "oneSidedRttSupported", 135612cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe rtt_capabilities.rtt_one_sided_supported == 1); 135712cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe setBooleanField(env, capabilities, "twoSided11McRttSupported", 135812cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe rtt_capabilities.rtt_ftm_supported == 1); 135912cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe setBooleanField(env, capabilities, "lciSupported", 136012cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe rtt_capabilities.lci_support); 136112cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe setBooleanField(env,capabilities, "lcrSupported", 136212cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe rtt_capabilities.lcr_support); 136312cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe setIntField(env, capabilities, "preambleSupported", 136412cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe rtt_capabilities.preamble_support); 136512cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe setIntField(env, capabilities, "bwSupported", 136612cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe rtt_capabilities.bw_support); 136712cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe ALOGD("One side RTT is: %s", rtt_capabilities.rtt_one_sided_supported ==1 ? "support" : 136812cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe "not support"); 136912cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe ALOGD("Two side RTT is: %s", rtt_capabilities.rtt_ftm_supported == 1 ? "support" : 137012cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe "not support"); 137112cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe ALOGD("LCR is: %s", rtt_capabilities.lcr_support == 1 ? "support" : "not support"); 137212cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe 137312cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe ALOGD("LCI is: %s", rtt_capabilities.lci_support == 1 ? "support" : "not support"); 137412cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe 137512cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe ALOGD("Support Preamble is : %d support BW is %d", rtt_capabilities.preamble_support, 137612cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe rtt_capabilities.bw_support); 137712cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe return capabilities; 137812cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe } else { 137912cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe return NULL; 138012cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe } 138112cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe} 138212cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe 1383939177ff615062ec826601d536466875d8457375xinhestatic jboolean android_net_wifi_set_Country_Code_Hal(JNIEnv *env,jclass cls, jint iface, 1384939177ff615062ec826601d536466875d8457375xinhe jstring country_code) { 1385939177ff615062ec826601d536466875d8457375xinhe 1386939177ff615062ec826601d536466875d8457375xinhe wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 1387939177ff615062ec826601d536466875d8457375xinhe const char *country = env->GetStringUTFChars(country_code, NULL); 1388939177ff615062ec826601d536466875d8457375xinhe 1389939177ff615062ec826601d536466875d8457375xinhe ALOGD("set country code: %s", country); 1390628199920e1d1fa86caabaf13874e7dc601e7b06xinhe wifi_error res = hal_fn.wifi_set_country_code(handle, country); 1391939177ff615062ec826601d536466875d8457375xinhe env->ReleaseStringUTFChars(country_code, country); 1392939177ff615062ec826601d536466875d8457375xinhe 1393939177ff615062ec826601d536466875d8457375xinhe return res == WIFI_SUCCESS; 1394939177ff615062ec826601d536466875d8457375xinhe} 1395d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1396d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhestatic jboolean android_net_wifi_enable_disable_tdls(JNIEnv *env,jclass cls, jint iface, 1397d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe jboolean enable, jstring addr) { 1398d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 1399d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1400d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe mac_addr address; 1401d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe parseMacAddress(env, addr, address); 1402d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe wifi_tdls_handler tdls_handler; 1403d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe //tdls_handler.on_tdls_state_changed = &on_tdls_state_changed; 1404d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1405d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe if(enable) { 1406d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return (hal_fn.wifi_enable_tdls(handle, address, NULL, tdls_handler) == WIFI_SUCCESS); 1407d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } else { 1408d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return (hal_fn.wifi_disable_tdls(handle, address) == WIFI_SUCCESS); 1409d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 1410d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe} 1411d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1412d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhestatic void on_tdls_state_changed(mac_addr addr, wifi_tdls_status status) { 1413d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe JNIEnv *env = NULL; 1414d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe mVM->AttachCurrentThread(&env, NULL); 1415d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1416d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe ALOGD("on_tdls_state_changed is called: vm = %p, obj = %p, env = %p", mVM, mCls, env); 1417d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1418d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe char mac[32]; 1419d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1], addr[2], addr[3], addr[4], 1420d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe addr[5]); 1421d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1422d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe jstring mac_address = env->NewStringUTF(mac); 1423d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe reportEvent(env, mCls, "onTdlsStatus", "(Ljava/lang/StringII;)V", 1424d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe mac_address, status.state, status.reason); 1425d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1426d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe} 1427d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1428d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhestatic jobject android_net_wifi_get_tdls_status(JNIEnv *env,jclass cls, jint iface,jstring addr) { 1429d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 1430d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1431d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe mac_addr address; 1432d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe parseMacAddress(env, addr, address); 1433d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1434d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe wifi_tdls_status status; 1435d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1436d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe wifi_error ret; 1437d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe ret = hal_fn.wifi_get_tdls_status(handle, address, &status ); 1438d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1439d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe if (ret != WIFI_SUCCESS) { 1440d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return NULL; 1441d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } else { 1442d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe jobject tdls_status = createObject(env, "com/android/server/wifi/WifiNative$TdlsStatus"); 1443d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe setIntField(env, tdls_status, "channel", status.channel); 1444d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe setIntField(env, tdls_status, "global_operating_class", status.global_operating_class); 1445d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe setIntField(env, tdls_status, "state", status.state); 1446d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe setIntField(env, tdls_status, "reason", status.reason); 1447d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return tdls_status; 1448d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 1449d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe} 1450d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1451d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhestatic jobject android_net_wifi_get_tdls_capabilities(JNIEnv *env, jclass cls, jint iface) { 1452d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe wifi_tdls_capabilities tdls_capabilities; 1453d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 1454d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe wifi_error ret = hal_fn.wifi_get_tdls_capabilities(handle, &tdls_capabilities); 1455d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1456d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe if(WIFI_SUCCESS == ret) { 1457d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe jobject capabilities = createObject(env, 1458d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe "com/android/server/wifi/WifiNative$TdlsCapabilities"); 1459d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe setIntField(env, capabilities, "maxConcurrentTdlsSessionNumber", 1460d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe tdls_capabilities.max_concurrent_tdls_session_num); 1461d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe setBooleanField(env, capabilities, "isGlobalTdlsSupported", 1462d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe tdls_capabilities.is_global_tdls_supported == 1); 1463d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe setBooleanField(env, capabilities, "isPerMacTdlsSupported", 1464d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe tdls_capabilities.is_per_mac_tdls_supported == 1); 1465d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe setBooleanField(env,capabilities, "isOffChannelTdlsSupported", 1466d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe tdls_capabilities.is_off_channel_tdls_supported); 1467d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1468d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe ALOGD("TDLS Max Concurrent Tdls Session Number is: %d", 1469d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe tdls_capabilities.max_concurrent_tdls_session_num); 1470d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe ALOGD("Global Tdls is: %s", tdls_capabilities.is_global_tdls_supported == 1 ? "support" : 1471d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe "not support"); 1472d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe ALOGD("Per Mac Tdls is: %s", tdls_capabilities.is_per_mac_tdls_supported == 1 ? "support" : 1473d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe "not support"); 1474d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe ALOGD("Off Channel Tdls is: %s", tdls_capabilities.is_off_channel_tdls_supported == 1 ? 1475d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe "support" : "not support"); 1476d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1477d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return capabilities; 1478d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } else { 1479d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe return NULL; 1480d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe } 1481d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe} 1482d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe 1483155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande// ---------------------------------------------------------------------------- 1484a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle// Debug framework 1485a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle// ---------------------------------------------------------------------------- 1486a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 14875faa29da989a82096e1e17c46126604eecfc0780Pierre Vandwallestatic void onRingBufferData(char * ring_name, char * buffer, 1488a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalleint buffer_size, wifi_ring_buffer_status *status) { 1489a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle JNIEnv *env = NULL; 1490a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle mVM->AttachCurrentThread(&env, NULL); 1491a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 1492a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle ALOGD("onRingBufferData called, vm = %p, obj = %p, env = %p", mVM, mCls, env); 1493a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 1494a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle reportEvent(env, mCls, "onDataAvailable", "(I[Landroid/net/wifi/WiFiLogger$LogData;)V", 1495a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 0, 0); 1496a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle} 1497a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 1498d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhestatic jboolean android_net_wifi_start_logging(JNIEnv *env, jclass cls, jint iface) { 1499a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 1500a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 15017d6301ead19afdf3de37455e9ed133c25b4938cdVinit Deshpande ALOGD("android_net_wifi_start_logging = %p", handle); 1502a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 1503a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle if (handle == 0) { 1504a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle return WIFI_ERROR_UNINITIALIZED; 1505a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle } 1506a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle wifi_ring_buffer_data_handler handler; 1507a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle handler.on_ring_buffer_data = &onRingBufferData; 1508a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 1509a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle wifi_error result = WIFI_SUCCESS; //ifi_start_logging(handle, 1, 0, 5, 4*1024,(u8*)"wifi_connectivity_events", handler); 1510a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 1511a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle return result; 1512a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle} 1513a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 1514dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle// ---------------------------------------------------------------------------- 1515dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle// ePno framework 1516dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle// ---------------------------------------------------------------------------- 1517dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1518dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1519dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwallestatic void onPnoNetworkFound(wifi_request_id id, 1520dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle unsigned num_results, wifi_scan_result *results) { 1521dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle JNIEnv *env = NULL; 1522dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle mVM->AttachCurrentThread(&env, NULL); 1523dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1524dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGD("onPnoNetworkFound called, vm = %p, obj = %p, env = %p, num_results %u", 1525dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle mVM, mCls, env, num_results); 1526dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1527dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (results == 0 || num_results == 0) { 1528dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGE("onPnoNetworkFound: Error no results"); 1529dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle return; 1530dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1531dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1532dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle jobject scanResult; 1533dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle jbyte *bytes; 1534dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle jobjectArray scanResults; 1535dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle //jbyteArray elements; 1536dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1537dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle for (unsigned i=0; i<num_results; i++) { 1538dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1539dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle scanResult = createScanResult(env, &results[i]); 1540dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (i == 0) { 1541dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle scanResults = env->NewObjectArray(num_results, 1542dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle env->FindClass("android/net/wifi/ScanResult"), scanResult); 1543dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (scanResults == 0) { 1544dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGD("cant allocate array"); 1545dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } else { 1546dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGD("allocated array %u", env->GetArrayLength(scanResults)); 1547dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1548dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } else { 1549dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle env->SetObjectArrayElement(scanResults, i, scanResult); 1550dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1551dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1552dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGD("Scan result with ie length %d, i %u, <%s> rssi=%d %02x:%02x:%02x:%02x:%02x:%02x", results->ie_length, i, 1553dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle results[i].ssid, results[i].rssi, results[i].bssid[0], results[i].bssid[1], 1554dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle results[i].bssid[2], results[i].bssid[3], results[i].bssid[4], results[i].bssid[5]); 1555dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1556dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle /*elements = env->NewByteArray(results->ie_length); 1557dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (elements == NULL) { 1558dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGE("Error in allocating array"); 1559dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle return; 1560dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle }*/ 1561dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1562dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle //ALOGD("onPnoNetworkFound: Setting byte array"); 1563dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1564dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle //bytes = (jbyte *)&(results->ie_data[0]); 1565dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle //env->SetByteArrayRegion(elements, 0, results->ie_length, bytes); 1566dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1567dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle //ALOGD("onPnoNetworkFound: Returning result"); 1568dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1569dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1570dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1571dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGD("calling report"); 1572dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1573dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle reportEvent(env, mCls, "onPnoNetworkFound", "(I[Landroid/net/wifi/ScanResult;)V", id, 1574dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle scanResults); 1575dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGD("free ref"); 1576dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1577dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle env->DeleteLocalRef(scanResults); 1578dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle //env->DeleteLocalRef(elements); 1579dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle} 1580dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1581dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwallestatic jboolean android_net_wifi_setPnoListNative( 1582dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle JNIEnv *env, jclass cls, jint iface, jint id, jobject list) { 1583dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1584dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle wifi_epno_handler handler; 1585dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle handler.on_network_found = &onPnoNetworkFound; 1586dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1587dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle wifi_interface_handle handle = getIfaceHandle(env, cls, iface); 1588dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGD("configure ePno list request [%d] = %p", id, handle); 1589dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1590dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (list == NULL) { 1591dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle // stop pno 1592dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle int result = hal_fn.wifi_set_epno_list(id, handle, 0, NULL, handler); 1593dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGE(" setPnoListNative: STOP result = %d", result); 1594dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle return result; 1595dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1596dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1597dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle wifi_epno_network net_list[MAX_PNO_SSID]; 1598dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle memset(&net_list, 0, sizeof(net_list)); 1599dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1600dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle size_t len = env->GetArrayLength((jobjectArray)list); 1601dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (len > (size_t)MAX_PNO_SSID) { 1602dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle return false; 1603dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1604dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1605dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle for (unsigned int i = 0; i < len; i++) { 1606dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1607dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle jobject pno_net = env->GetObjectArrayElement((jobjectArray)list, i); 1608dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (pno_net == NULL) { 1609dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGD("setPnoListNative: could not get element %d", i); 1610dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle continue; 1611dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1612dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1613dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle jstring sssid = (jstring) getObjectField( 1614dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle env, pno_net, "SSID", "Ljava/lang/String;"); 1615dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (sssid == NULL) { 1616dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGE("Error setPnoListNative: getting ssid field"); 1617dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle return false; 1618dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1619dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1620dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle const char *ssid = env->GetStringUTFChars(sssid, NULL); 1621dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (ssid == NULL) { 1622dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGE("Error setPnoListNative: getting ssid"); 1623dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle return false; 1624dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1625dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle int ssid_len = strnlen((const char*)ssid, 33); 1626dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (ssid_len > 32) { 1627dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGE("Error setPnoListNative: long ssid %u", strnlen((const char*)ssid, 256)); 1628dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle return false; 1629dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1630dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (ssid_len > 1 && ssid[0] == '"' && ssid[ssid_len-1]) 1631dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle { 1632dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle // strip leading and trailing '"' 1633dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ssid++; 1634dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ssid_len-=2; 1635dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1636dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle if (ssid_len == 0) { 1637dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGE("Error setPnoListNative: zero length ssid, skip it"); 1638dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle continue; 1639dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1640dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle memcpy(net_list[i].ssid, ssid, ssid_len); 1641dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1642dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle int rssit = getIntField(env, pno_net, "rssi_threshold"); 1643dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle net_list[i].rssi_threshold = (byte)rssit; 1644dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle int a = getIntField(env, pno_net, "auth"); 1645dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle net_list[i].auth_bit_field = a; 1646dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle int f = getIntField(env, pno_net, "flags"); 1647dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle net_list[i].flags = f; 1648dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGE(" setPnoListNative: idx %u rssi %d/%d auth %x/%x flags %x/%x [%s]", i, (signed byte)net_list[i].rssi_threshold, net_list[i].rssi_threshold, net_list[i].auth_bit_field, a, net_list[i].flags, f, net_list[i].ssid); 1649dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle } 1650dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1651dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle int result = hal_fn.wifi_set_epno_list(id, handle, len, net_list, handler); 1652dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle ALOGE(" setPnoListNative: result %d", result); 1653dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle 1654dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle return result >= 0; 1655dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle} 1656a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle 1657a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle// ---------------------------------------------------------------------------- 1658155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1659155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande/* 1660155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande * JNI registration. 1661155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande */ 1662155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandestatic JNINativeMethod gWifiMethods[] = { 1663155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande /* name, signature, funcPtr */ 1664155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1665155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande { "loadDriver", "()Z", (void *)android_net_wifi_loadDriver }, 1666155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande { "isDriverLoaded", "()Z", (void *)android_net_wifi_isDriverLoaded }, 1667155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande { "unloadDriver", "()Z", (void *)android_net_wifi_unloadDriver }, 1668155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande { "startSupplicant", "(Z)Z", (void *)android_net_wifi_startSupplicant }, 1669155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande { "killSupplicant", "(Z)Z", (void *)android_net_wifi_killSupplicant }, 1670155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande { "connectToSupplicantNative", "()Z", (void *)android_net_wifi_connectToSupplicant }, 1671155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande { "closeSupplicantConnectionNative", "()V", 1672155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande (void *)android_net_wifi_closeSupplicantConnection }, 1673155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande { "waitForEventNative", "()Ljava/lang/String;", (void*)android_net_wifi_waitForEvent }, 1674155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande { "doBooleanCommandNative", "(Ljava/lang/String;)Z", (void*)android_net_wifi_doBooleanCommand }, 1675155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande { "doIntCommandNative", "(Ljava/lang/String;)I", (void*)android_net_wifi_doIntCommand }, 1676155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande { "doStringCommandNative", "(Ljava/lang/String;)Ljava/lang/String;", 1677155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande (void*) android_net_wifi_doStringCommand }, 16787ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde { "startHalNative", "()Z", (void*) android_net_wifi_startHal }, 16797ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde { "stopHalNative", "()V", (void*) android_net_wifi_stopHal }, 16807ef73dd1b6e43c72b3841723504cd86dc402a134Vinit Deshapnde { "waitForHalEventNative", "()V", (void*) android_net_wifi_waitForHalEvents }, 16817f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde { "getInterfacesNative", "()I", (void*) android_net_wifi_getInterfaces}, 16827f9a15d554f69311a0db43347d6473a7c4c46e2eVinit Deshapnde { "getInterfaceNameNative", "(I)Ljava/lang/String;", (void*) android_net_wifi_getInterfaceName}, 1683e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde { "getScanCapabilitiesNative", "(ILcom/android/server/wifi/WifiNative$ScanCapabilities;)Z", 1684e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde (void *) android_net_wifi_getScanCapabilities}, 1685e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde { "startScanNative", "(IILcom/android/server/wifi/WifiNative$ScanSettings;)Z", 1686e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde (void*) android_net_wifi_startScan}, 1687e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde { "stopScanNative", "(II)Z", (void*) android_net_wifi_stopScan}, 168883a674a18c84ff4f01377bbfd8988699dec93bc2Vinit Deshpande { "getScanResultsNative", "(IZ)[Landroid/net/wifi/WifiScanner$ScanData;", 1689e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde (void *) android_net_wifi_getScanResults}, 1690e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde { "setHotlistNative", "(IILandroid/net/wifi/WifiScanner$HotlistSettings;)Z", 1691e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde (void*) android_net_wifi_setHotlist}, 1692e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde { "resetHotlistNative", "(II)Z", (void*) android_net_wifi_resetHotlist}, 1693e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde { "trackSignificantWifiChangeNative", "(IILandroid/net/wifi/WifiScanner$WifiChangeSettings;)Z", 1694e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde (void*) android_net_wifi_trackSignificantWifiChange}, 1695e4e3750390bec0a849a9153348b7c21b2cc8b843Vinit Deshapnde { "untrackSignificantWifiChangeNative", "(II)Z", 1696aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle (void*) android_net_wifi_untrackSignificantWifiChange}, 1697aabe7a9f2f32915fd1f25416a6d2034a844005d6vandwalle { "getWifiLinkLayerStatsNative", "(I)Landroid/net/wifi/WifiLinkLayerStats;", 1698a632d8a6edd350c7644b593b18eceaa5b368505bVinit Deshpande (void*) android_net_wifi_getLinkLayerStats}, 1699c35361d54d4885c3174499e4ad46d3324387a9bbVinit Deshpande { "getSupportedFeatureSetNative", "(I)I", 1700143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande (void*) android_net_wifi_getSupportedFeatures}, 1701143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande { "requestRangeNative", "(II[Landroid/net/wifi/RttManager$RttParams;)Z", 1702143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande (void*) android_net_wifi_requestRange}, 1703143657392bf0702a155fe688171a5abbf4c86570Vinit Deshpande { "cancelRangeRequestNative", "(II[Landroid/net/wifi/RttManager$RttParams;)Z", 1704042c54bfd5144ce8e720585b2093796e7e28de5eVinit Deshpande (void*) android_net_wifi_cancelRange}, 17050465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande { "setScanningMacOuiNative", "(I[B)Z", (void*) android_net_wifi_setScanningMacOui}, 17060465ff513cdccf7e883a505e14c5b78758e7e458Vinit Deshpande { "getChannelsForBandNative", "(II)[I", (void*) android_net_wifi_getValidChannels}, 1707b830d76fbf5fa4077531b516066faa2fdbb92e81xinhe { "setDfsFlagNative", "(IZ)Z", (void*) android_net_wifi_setDfsFlag}, 170812cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe { "toggleInterfaceNative", "(I)Z", (void*) android_net_wifi_toggle_interface}, 170912cf388ecf3b2aa5ba66ed680b931fa356ab75b5xinhe { "getRttCapabilitiesNative", "(I)Landroid/net/wifi/RttManager$RttCapabilities;", 1710a0d34d3626bd9631039a485d2d428b1b7de390e2Pierre Vandwalle (void*) android_net_wifi_get_rtt_capabilities}, 1711939177ff615062ec826601d536466875d8457375xinhe { "startLogging", "(I)Z", (void*) android_net_wifi_start_logging}, 1712939177ff615062ec826601d536466875d8457375xinhe {"setCountryCodeHalNative", "(ILjava/lang/String;)Z", 1713dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle (void*) android_net_wifi_set_Country_Code_Hal}, 1714dd490cf1df37b70a8625dc4ec8e712f740dd1e4aPierre Vandwalle { "setPnoListNative", "(II[Lcom/android/server/wifi/WifiNative$WifiPnoNetwork;)Z", 1715d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe (void*) android_net_wifi_setPnoListNative}, 1716d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe {"enableDisableTdlsNative", "(IZLjava/lang/String;)Z", 1717d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe (void*) android_net_wifi_enable_disable_tdls}, 1718d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe {"getTdlsStatusNative", "(ILjava/lang/String;)Lcom/android/server/wifi/WifiNative$TdlsStatus;", 1719d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe (void*) android_net_wifi_get_tdls_status}, 1720d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe {"getTdlsCapabilitiesNative", "(I)Lcom/android/server/wifi/WifiNative$TdlsCapabilities;", 1721d57f630f6a7a5fca872d2b96fc4cce1905daee5dxinhe (void*) android_net_wifi_get_tdls_capabilities} 1722155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande}; 1723155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1724155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeint register_android_net_wifi_WifiNative(JNIEnv* env) { 1725155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return AndroidRuntime::registerNativeMethods(env, 1726155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande "com/android/server/wifi/WifiNative", gWifiMethods, NELEM(gWifiMethods)); 1727155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 1728155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1729155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1730155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande/* User to register native functions */ 1731155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandeextern "C" 1732155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpandejint Java_com_android_server_wifi_WifiNative_registerNatives(JNIEnv* env, jclass clazz) { 1733155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande return AndroidRuntime::registerNativeMethods(env, 1734155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande "com/android/server/wifi/WifiNative", gWifiMethods, NELEM(gWifiMethods)); 1735155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande} 1736155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande 1737155b9d09ef9b8ead3ca617afdd91e74070d3f0cbVinit Deshpande}; // namespace android 1738