summaryrefslogtreecommitdiff
authorkejun.gao <kejun.gao@amlogic.com>2012-04-12 07:02:59 (GMT)
committer kejun.gao <kejun.gao@amlogic.com>2012-04-12 07:03:56 (GMT)
commit10d94acac125f198f3b2542cdc625ed8b14497f1 (patch)
tree1ab0c4be9dbeec24e6c5407b124a0cb869d9777a
parentf63a58b9757eb2403b5115621a7245fe834db609 (diff)
downloadpppoe-10d94acac125f198f3b2542cdc625ed8b14497f1.zip
pppoe-10d94acac125f198f3b2542cdc625ed8b14497f1.tar.gz
pppoe-10d94acac125f198f3b2542cdc625ed8b14497f1.tar.bz2
Support pppoe over wifi
Diffstat
-rwxr-xr-xjni/pppoe_jni.cpp31
-rwxr-xr-xjni/src/pppoe_status.c12
-rwxr-xr-xsrc/com/amlogic/pppoe/PppoeOperation.java4
3 files changed, 29 insertions, 18 deletions
diff --git a/jni/pppoe_jni.cpp b/jni/pppoe_jni.cpp
index 0fecc10..9650e11 100755
--- a/jni/pppoe_jni.cpp
+++ b/jni/pppoe_jni.cpp
@@ -25,6 +25,8 @@ dalvik/libnativehelper/include/nativehelper/jni.h
#include "pppoe_status.h"
#include <android/log.h>
+#include "cutils/properties.h"
+
#define PPPOE_PLUGIN_CMD_LEN_MAX 256
#define PPPOE_CONNECT_CMD_LEN_MAX 512
@@ -40,7 +42,7 @@ struct fields_t {
static struct fields_t fields;
-extern int get_pppoe_status( const char *ether_if_name);
+extern int get_pppoe_status( const char *phy_if_name);
static char pppoe_connect_cmd[PPPOE_CONNECT_CMD_LEN_MAX];
@@ -54,12 +56,12 @@ static char pppd_options[PPPD_OPTIONS_LEN + 1] = {"debug logfd 1 noipdefault noa
-static char* create_pppoe_plugin_cmd(char *pid_file, char *ether_if)
+static char* create_pppoe_plugin_cmd(char *pid_file, char *phy_if)
{
int len;
len = snprintf(pppoe_plugin_cmd, PPPOE_PLUGIN_CMD_LEN_MAX,
"'pppoe -p %s -I %s -T 80 -U -m 1412'",
- pid_file, ether_if);
+ pid_file, phy_if);
if ( len < 0 || len >= PPPOE_PLUGIN_CMD_LEN_MAX ) {
return NULL;
}
@@ -112,10 +114,12 @@ static ssize_t get_line(char **line, size_t *len, FILE *fp)
return last;
}
+static const char PPPOE_PHY_IF_PROP_NAME[] = "net.pppoe.phyif";
static jboolean com_amlogic_PppoeOperation_connect
-(JNIEnv *env, jobject obj, jstring jstr_account, jstring jstr_passwd)
+(JNIEnv *env, jobject obj, jstring jstr_if_name, jstring jstr_account, jstring jstr_passwd)
{
+ char *p_ifname;
char *p_user;
char *p_passwd;
struct netwrapper_ctrl * ctrl;
@@ -138,10 +142,13 @@ static jboolean com_amlogic_PppoeOperation_connect
fclose(f);
}
+ p_ifname = (char *)env->GetStringUTFChars(jstr_if_name, NULL);
p_user = (char *)env->GetStringUTFChars(jstr_account, NULL);
p_passwd = (char *)env->GetStringUTFChars(jstr_passwd, NULL);
- p = create_pppoe_plugin_cmd((char*)PPPOE_PIDFILE, (char*)"eth0");
+ property_set(PPPOE_PHY_IF_PROP_NAME, p_ifname);
+
+ p = create_pppoe_plugin_cmd((char*)PPPOE_PIDFILE, p_ifname);
if (!p) {
__android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,"failed to create plug_in command\n");
return -1;
@@ -170,6 +177,7 @@ static jboolean com_amlogic_PppoeOperation_connect
netwrapper_ctrl_close(ctrl);
+ env->ReleaseStringUTFChars(jstr_if_name, p_ifname);
env->ReleaseStringUTFChars(jstr_account, p_user);
env->ReleaseStringUTFChars(jstr_passwd, p_passwd);
@@ -200,22 +208,27 @@ jboolean com_amlogic_PppoeOperation_disconnect
jint com_amlogic_PppoeOperation_status
-(JNIEnv *env, jobject obj)
+(JNIEnv *env, jobject obj, jstring jstr_if_name)
{
+ char *p_ifname;
int status;
__android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,"ppp.status\n");
- status = get_pppoe_status("eth0");
+ p_ifname = (char *)env->GetStringUTFChars(jstr_if_name, NULL);
+ status = get_pppoe_status(p_ifname);
+
+ env->ReleaseStringUTFChars(jstr_if_name, p_ifname);
+
return status;
}
static JNINativeMethod gPppoeJNIMethods[] = {
/* name, signature, funcPtr */
- { "connect", "(Ljava/lang/String;Ljava/lang/String;)Z", (void*) com_amlogic_PppoeOperation_connect },
+ { "connect", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z", (void*) com_amlogic_PppoeOperation_connect },
{ "disconnect", "()Z", (void*) com_amlogic_PppoeOperation_disconnect },
- { "status", "()I", (void*) com_amlogic_PppoeOperation_status },
+ { "status", "(Ljava/lang/String;)I", (void*) com_amlogic_PppoeOperation_status },
};
diff --git a/jni/src/pppoe_status.c b/jni/src/pppoe_status.c
index 15de623..f542921 100755
--- a/jni/src/pppoe_status.c
+++ b/jni/src/pppoe_status.c
@@ -54,14 +54,14 @@ done:
#define PPP_IF_NAME "ppp0"
-int get_pppoe_status( const char *ether_if_name)
+int get_pppoe_status( const char *phy_if_name)
{
int ret;
- ret = if_is_up(ether_if_name);
+ ret = if_is_up(phy_if_name);
if (ret < 0){
- if ( ENODEV == -ret )
- PRINTF( "No such device(%s)\n", ether_if_name );
+ if ( ENODEV == -ret )
+ PRINTF( "No such device(%s)\n", phy_if_name );
PRINTF("ppp_status: DISCONNECTED\n");
__android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,
@@ -71,7 +71,7 @@ int get_pppoe_status( const char *ether_if_name)
}
if (0 == ret ) {
- PRINTF( "%s is DOWN\n", ether_if_name );
+ PRINTF( "%s is DOWN\n", phy_if_name );
PRINTF("ppp_status: DISCONNECTED\n");
__android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,
@@ -103,8 +103,6 @@ int get_pppoe_status( const char *ether_if_name)
"ppp_status: CONNECTED\n");
return PPP_STATUS_CONNECTED;
}
-
-
}
/*
diff --git a/src/com/amlogic/pppoe/PppoeOperation.java b/src/com/amlogic/pppoe/PppoeOperation.java
index 9419cee..24f010a 100755
--- a/src/com/amlogic/pppoe/PppoeOperation.java
+++ b/src/com/amlogic/pppoe/PppoeOperation.java
@@ -6,9 +6,9 @@ public class PppoeOperation
public static final int PPP_STATUS_DISCONNECTED = 0x20;
public static final int PPP_STATUS_CONNECTING = 0x40;
- public native boolean connect(String account, String passwd);
+ public native boolean connect(String ifname, String account, String passwd);
public native boolean disconnect();
- public native int status();
+ public native int status(String ifname);
static {
System.loadLibrary("pppoejni");
}