diff options
Diffstat (limited to 'core/jni')
-rw-r--r-- | core/jni/android_net_NetUtils.cpp | 25 | ||||
-rw-r--r-- | core/jni/android_net_wifi_Wifi.cpp | 69 |
2 files changed, 17 insertions, 77 deletions
diff --git a/core/jni/android_net_NetUtils.cpp b/core/jni/android_net_NetUtils.cpp index feb0dad..50df9d3 100644 --- a/core/jni/android_net_NetUtils.cpp +++ b/core/jni/android_net_NetUtils.cpp @@ -22,29 +22,8 @@ #include <utils/Log.h> #include <arpa/inet.h> -extern "C" { -int ifc_enable(const char *ifname); -int ifc_disable(const char *ifname); -int ifc_add_host_route(const char *ifname, uint32_t addr); -int ifc_remove_host_routes(const char *ifname); -int ifc_set_default_route(const char *ifname, uint32_t gateway); -int ifc_get_default_route(const char *ifname); -int ifc_remove_default_route(const char *ifname); -int ifc_reset_connections(const char *ifname); -int ifc_configure(const char *ifname, in_addr_t ipaddr, in_addr_t netmask, in_addr_t gateway, in_addr_t dns1, in_addr_t dns2); - -int dhcp_do_request(const char *ifname, - in_addr_t *ipaddr, - in_addr_t *gateway, - in_addr_t *mask, - in_addr_t *dns1, - in_addr_t *dns2, - in_addr_t *server, - uint32_t *lease); -int dhcp_stop(const char *ifname); -int dhcp_release_lease(const char *ifname); -char *dhcp_get_errmsg(); -} +#include <netutils/ifc.h> +#include <netutils/dhcp.h> #define NETUTILS_PKG_NAME "android/net/NetworkUtils" diff --git a/core/jni/android_net_wifi_Wifi.cpp b/core/jni/android_net_wifi_Wifi.cpp index 46000c9..3fc0d58 100644 --- a/core/jni/android_net_wifi_Wifi.cpp +++ b/core/jni/android_net_wifi_Wifi.cpp @@ -30,23 +30,6 @@ namespace android { static jboolean sScanModeActive = false; -/* - * The following remembers the jfieldID's of the fields - * of the DhcpInfo Java object, so that we don't have - * to look them up every time. - */ -static struct fieldIds { - jclass dhcpInfoClass; - jmethodID constructorId; - jfieldID ipaddress; - jfieldID gateway; - jfieldID netmask; - jfieldID dns1; - jfieldID dns2; - jfieldID serverAddress; - jfieldID leaseDuration; -} dhcpInfoFieldIds; - static int doCommand(const char *cmd, char *replybuf, int replybuflen) { size_t reply_len = replybuflen - 1; @@ -392,6 +375,20 @@ static jboolean android_net_wifi_setPowerModeCommand(JNIEnv* env, jobject clazz, return (jboolean)!cmdTooLong && doBooleanCommand(cmdstr, "OK"); } +static jint android_net_wifi_getPowerModeCommand(JNIEnv* env, jobject clazz) +{ + char reply[256]; + int power; + + if (doCommand("DRIVER GETPOWER", reply, sizeof(reply)) != 0) { + return (jint)-1; + } + // reply comes back in the form "powermode = XX" where XX is the + // number we're interested in. + sscanf(reply, "%*s = %u", &power); + return (jint)power; +} + static jboolean android_net_wifi_setNumAllowedChannelsCommand(JNIEnv* env, jobject clazz, jint numChannels) { char cmdstr[256]; @@ -479,28 +476,6 @@ static jboolean android_net_wifi_clearBlacklistCommand(JNIEnv* env, jobject claz return doBooleanCommand("BLACKLIST clear", "OK"); } -static jboolean android_net_wifi_doDhcpRequest(JNIEnv* env, jobject clazz, jobject info) -{ - jint ipaddr, gateway, mask, dns1, dns2, server, lease; - jboolean succeeded = ((jboolean)::do_dhcp_request(&ipaddr, &gateway, &mask, - &dns1, &dns2, &server, &lease) == 0); - if (succeeded && dhcpInfoFieldIds.dhcpInfoClass != NULL) { - env->SetIntField(info, dhcpInfoFieldIds.ipaddress, ipaddr); - env->SetIntField(info, dhcpInfoFieldIds.gateway, gateway); - env->SetIntField(info, dhcpInfoFieldIds.netmask, mask); - env->SetIntField(info, dhcpInfoFieldIds.dns1, dns1); - env->SetIntField(info, dhcpInfoFieldIds.dns2, dns2); - env->SetIntField(info, dhcpInfoFieldIds.serverAddress, server); - env->SetIntField(info, dhcpInfoFieldIds.leaseDuration, lease); - } - return succeeded; -} - -static jstring android_net_wifi_getDhcpError(JNIEnv* env, jobject clazz) -{ - return env->NewStringUTF(::get_dhcp_error_string()); -} - // ---------------------------------------------------------------------------- /* @@ -540,6 +515,7 @@ static JNINativeMethod gWifiMethods[] = { { "startPacketFiltering", "()Z", (void*) android_net_wifi_startPacketFiltering }, { "stopPacketFiltering", "()Z", (void*) android_net_wifi_stopPacketFiltering }, { "setPowerModeCommand", "(I)Z", (void*) android_net_wifi_setPowerModeCommand }, + { "getPowerModeCommand", "()I", (void*) android_net_wifi_getPowerModeCommand }, { "setNumAllowedChannelsCommand", "(I)Z", (void*) android_net_wifi_setNumAllowedChannelsCommand }, { "getNumAllowedChannelsCommand", "()I", (void*) android_net_wifi_getNumAllowedChannelsCommand }, { "setBluetoothCoexistenceModeCommand", "(I)Z", @@ -556,9 +532,6 @@ static JNINativeMethod gWifiMethods[] = { { "setScanResultHandlingCommand", "(I)Z", (void*) android_net_wifi_setScanResultHandlingCommand }, { "addToBlacklistCommand", "(Ljava/lang/String;)Z", (void*) android_net_wifi_addToBlacklistCommand }, { "clearBlacklistCommand", "()Z", (void*) android_net_wifi_clearBlacklistCommand }, - - { "doDhcpRequest", "(Landroid/net/DhcpInfo;)Z", (void*) android_net_wifi_doDhcpRequest }, - { "getDhcpError", "()Ljava/lang/String;", (void*) android_net_wifi_getDhcpError }, }; int register_android_net_wifi_WifiManager(JNIEnv* env) @@ -566,18 +539,6 @@ int register_android_net_wifi_WifiManager(JNIEnv* env) jclass wifi = env->FindClass(WIFI_PKG_NAME); LOG_FATAL_IF(wifi == NULL, "Unable to find class " WIFI_PKG_NAME); - dhcpInfoFieldIds.dhcpInfoClass = env->FindClass("android/net/DhcpInfo"); - if (dhcpInfoFieldIds.dhcpInfoClass != NULL) { - dhcpInfoFieldIds.constructorId = env->GetMethodID(dhcpInfoFieldIds.dhcpInfoClass, "<init>", "()V"); - dhcpInfoFieldIds.ipaddress = env->GetFieldID(dhcpInfoFieldIds.dhcpInfoClass, "ipAddress", "I"); - dhcpInfoFieldIds.gateway = env->GetFieldID(dhcpInfoFieldIds.dhcpInfoClass, "gateway", "I"); - dhcpInfoFieldIds.netmask = env->GetFieldID(dhcpInfoFieldIds.dhcpInfoClass, "netmask", "I"); - dhcpInfoFieldIds.dns1 = env->GetFieldID(dhcpInfoFieldIds.dhcpInfoClass, "dns1", "I"); - dhcpInfoFieldIds.dns2 = env->GetFieldID(dhcpInfoFieldIds.dhcpInfoClass, "dns2", "I"); - dhcpInfoFieldIds.serverAddress = env->GetFieldID(dhcpInfoFieldIds.dhcpInfoClass, "serverAddress", "I"); - dhcpInfoFieldIds.leaseDuration = env->GetFieldID(dhcpInfoFieldIds.dhcpInfoClass, "leaseDuration", "I"); - } - return AndroidRuntime::registerNativeMethods(env, WIFI_PKG_NAME, gWifiMethods, NELEM(gWifiMethods)); } |