summaryrefslogtreecommitdiff
authorZhiwei Gong <zhiwei.gong@amlogic.com>2014-12-31 08:55:30 (GMT)
committer zhiwei.gong <zhiwei.gong@amlogic.com>2015-01-19 01:57:53 (GMT)
commit33e171f0e1ca51c87e37b06da11543a04d3c5625 (patch)
tree70cf8ad1ae054c2c4639f04c818c09ff2193d030
parentc50047cad754b54f66b45e993b16b70c32c28e65 (diff)
downloadpppoe-33e171f0e1ca51c87e37b06da11543a04d3c5625.zip
pppoe-33e171f0e1ca51c87e37b06da11543a04d3c5625.tar.gz
pppoe-33e171f0e1ca51c87e37b06da11543a04d3c5625.tar.bz2
add pppoe suppport
Change-Id: I0a34d6ef16ac0aac83509419ab6c923949858446
Diffstat
-rwxr-xr-xAndroid.mk35
-rw-r--r--droidlogic.external.pppoe.xml (renamed from amlogic.pppoe.xml)4
-rwxr-xr-xjni/pppoe_jni.cpp23
-rwxr-xr-xjni/src/common.c3
-rw-r--r--jni/src/netwrapper.c360
-rw-r--r--jni/src/netwrapper.h39
-rwxr-xr-xjni/src/pppoe_cli.c2
-rwxr-xr-xjni/src/pppoe_status.c66
-rwxr-xr-xjni/src/pppoe_status.h4
-rwxr-xr-xjni/src/pppoe_wrapper.c109
10 files changed, 503 insertions, 142 deletions
diff --git a/Android.mk b/Android.mk
index 2b8442b..ebc24a7 100755
--- a/Android.mk
+++ b/Android.mk
@@ -7,14 +7,14 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_JNI_SHARED_LIBRARIES := libpppoejni
LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE := amlogic.pppoe
+LOCAL_MODULE := droidlogic.external.pppoe
include $(BUILD_JAVA_LIBRARY)
#MAKE_XML
include $(CLEAR_VARS)
-LOCAL_MODULE := amlogic.pppoe.xml
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_CLASS := ETC
+LOCAL_MODULE := droidlogic.external.pppoe.xml
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/permissions
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)
@@ -26,7 +26,8 @@ LOCAL_SRC_FILES := jni/src/pppoe.c \
jni/src/debug.c \
jni/src/common.c \
jni/src/ppp.c \
- jni/src/discovery.c
+ jni/src/discovery.c \
+ jni/src/netwrapper.c
LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
LOCAL_SHARED_LIBRARIES := libcutils
LOCAL_MODULE = pppoe
@@ -36,10 +37,18 @@ include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= jni/src/pppoe_status.c \
- jni/pppoe_jni.cpp
+ jni/pppoe_jni.cpp \
+ jni/src/netwrapper.c
+
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ liblog \
+ libselinux
+
-LOCAL_SHARED_LIBRARIES := libandroid_runtime libnativehelper
-LOCAL_SHARED_LIBRARIES += libc libcutils libnetutils
+LOCAL_SHARED_LIBRARIES += libandroid_runtime libnativehelper
+LOCAL_SHARED_LIBRARIES += libc libcutils libnetutils
LOCAL_C_INCLUDES := $(JNI_H_INCLUDE) $(LOCAL_PATH)/jni/src
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libpppoejni
@@ -49,19 +58,21 @@ include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= jni/src/pppoe_cli.c \
- jni/src/common.c
+ jni/src/common.c \
+ jni/src/netwrapper.c
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := pcli
-LOCAL_SHARED_LIBRARIES := libcutils libnetutils
+LOCAL_SHARED_LIBRARIES := libcutils libnetutils libselinux
include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= jni/src/pppoe_wrapper.c \
- jni/src/common.c
+ jni/src/common.c \
+ jni/src/netwrapper.c
LOCAL_SHARED_LIBRARIES := \
- libcutils libcrypto libnetutils
+ libcutils libcrypto libnetutils libselinux
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/include
diff --git a/amlogic.pppoe.xml b/droidlogic.external.pppoe.xml
index 21ec172..99b664d 100644
--- a/amlogic.pppoe.xml
+++ b/droidlogic.external.pppoe.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<permissions>
-<library
+<library
name="AmlogicPPPoE"
-file="/system/framework/amlogic.pppoe.jar"
+file="/system/framework/droidlogic.external.pppoe.jar"
/>
</permissions>
diff --git a/jni/pppoe_jni.cpp b/jni/pppoe_jni.cpp
index 6757a31..48f497a 100755
--- a/jni/pppoe_jni.cpp
+++ b/jni/pppoe_jni.cpp
@@ -21,7 +21,7 @@ dalvik/libnativehelper/include/nativehelper/jni.h
#include <netinet/in.h>
#include <sys/un.h>
-#include <netwrapper.h>
+#include "netwrapper.h"
#include "pppoe_status.h"
#include <android/log.h>
@@ -44,12 +44,13 @@ struct fields_t {
static struct fields_t fields;
+extern int get_eth0_updown();
+extern int get_pppoe_status( const char *phy_if_name);
static char pppoe_connect_cmd[PPPOE_CONNECT_CMD_LEN_MAX];
static char pppoe_disconnect_cmd[512] = "ppp-stop";
static char pppoe_terminate_cmd[512] = "ppp-terminate";
-static char pppoe_status_cmd[512] = "ppp-status";
static char pppoe_plugin_cmd[PPPOE_PLUGIN_CMD_LEN_MAX];
@@ -86,7 +87,8 @@ static char* create_pppoe_connect_cmd
return pppoe_connect_cmd;
}
-#include "../../ppp/pppd/pathnames.h"
+//#ifndef _ROOT_PATH
+#define _ROOT_PATH "/data/misc"
#define CONFIG_FILE _ROOT_PATH "/etc/ppp/pppd_options.conf"
@@ -238,7 +240,7 @@ jint com_amlogic_PppoeOperation_isNetAdded
p_ifname = (char *)env->GetStringUTFChars(jstr_if_name, NULL);
status = get_net_updown(p_ifname);
-
+
env->ReleaseStringUTFChars(jstr_if_name, p_ifname);
return status;
@@ -247,20 +249,15 @@ jint com_amlogic_PppoeOperation_isNetAdded
jint com_amlogic_PppoeOperation_status
(JNIEnv *env, jobject obj, jstring jstr_if_name)
{
+ char *p_ifname;
int status;
- struct netwrapper_ctrl * ctrl;
__android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,"ppp.status\n");
- ctrl = netwrapper_ctrl_open(PPPOE_WRAPPER_CLIENT_PATH, PPPOE_WRAPPER_SERVER_PATH);
- if (ctrl == NULL) {
- __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG, "Failed to connect to pppd\n");
- return -1;
- }
-
- status = netwrapper_ctrl_request(ctrl, pppoe_status_cmd, strlen(pppoe_status_cmd));
+ p_ifname = (char *)env->GetStringUTFChars(jstr_if_name, NULL);
+ status = get_pppoe_status(p_ifname);
- netwrapper_ctrl_close(ctrl);
+ env->ReleaseStringUTFChars(jstr_if_name, p_ifname);
return status;
}
diff --git a/jni/src/common.c b/jni/src/common.c
index 63d5e58..afc5670 100755
--- a/jni/src/common.c
+++ b/jni/src/common.c
@@ -45,7 +45,8 @@ static char const RCSID[] =
#include <sys/types.h>
#include <pwd.h>
-#include "../../ppp/pppd/pathnames.h"
+//#ifndef _ROOT_PATH
+#define _ROOT_PATH "/data/misc"
/* Are we running SUID or SGID? */
int IsSetID = 0;
diff --git a/jni/src/netwrapper.c b/jni/src/netwrapper.c
new file mode 100644
index 0000000..1d73181
--- a/dev/null
+++ b/jni/src/netwrapper.c
@@ -0,0 +1,360 @@
+#include <stdarg.h>
+#include <stdio.h>
+#include <time.h>
+#include <ftw.h>
+
+
+/* for ANDROID_SOCKET_* */
+#include <cutils/sockets.h>
+
+#include <private/android_filesystem_config.h>
+
+
+
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <syslog.h>
+#include <netdb.h>
+#include <utmp.h>
+#include <pwd.h>
+#include <setjmp.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <cutils/properties.h>
+#include <sys/un.h>
+
+#include <selinux/label.h>
+#include <selinux/android.h>
+
+#include <cutils/sockets.h>
+
+#include <android/log.h>
+
+#include "netwrapper.h"
+#include "../../../../../system/core/init/init.h"
+#include "../../../../../system/core/init/util.h"
+
+#define LOCAL_TAG "NETWRAPPER"
+
+
+static char request_buf[REQUEST_BUF_LEN];
+
+
+struct request_handler_map
+{
+ char request[REQUEST_BUF_LEN];
+ pf_request_handler handler;
+ struct request_handler_map *next;
+};
+
+
+static struct request_handler_map *map_list = NULL;
+
+#define ACK_BUF_LEN 128
+#define RESEND_CNT_MAX 10
+
+static char request_buf[REQUEST_BUF_LEN];
+static char ack_buf[ACK_BUF_LEN];
+static int req_no = 0;
+struct selabel_handle *sehandle;
+
+struct netwrapper_ctrl * netwrapper_ctrl_open
+(const char *client_path, const char *server_path)
+{
+ struct netwrapper_ctrl *ctrl;
+ int ret;
+ char *filecon;
+ size_t res;
+ int tries = 0;
+ struct stat buf;
+ uid_t uid,euid;
+ sehandle = selinux_android_file_context_handle();
+ ctrl = malloc(sizeof(*ctrl));
+ if (ctrl == NULL)
+ return NULL;
+ memset(ctrl, 0, sizeof(*ctrl));
+
+ ctrl->s = socket(PF_UNIX, SOCK_DGRAM, 0);
+ if (ctrl->s < 0) {
+ free(ctrl);
+ return NULL;
+ }
+ ctrl->local.sun_family = AF_UNIX;
+
+try_again:
+ ret = snprintf(ctrl->local.sun_path, sizeof(ctrl->local.sun_path)-1,
+ "%s-%d", client_path, getpid());
+ if (ret < 0 || (size_t) ret >= sizeof(ctrl->local.sun_path)) {
+ close(ctrl->s);
+ free(ctrl);
+ return NULL;
+ }
+ tries++;
+ ret = unlink(ctrl->local.sun_path);
+ if (ret != 0 && errno != ENOENT) {
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,"Failed to unlink old socket : %s\n",strerror(errno));
+ }
+ filecon = NULL;
+ if (0 == stat(ctrl->local.sun_path , &buf))
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,"stat sun path filed");
+ if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
+ sizeof(ctrl->local)) < 0) {
+ if (errno == EADDRINUSE && tries < 2) {
+ /*
+ * getpid() returns unique identifier for this instance
+ * of netwrapper_ctrl, so the existing socket file must have
+ * been left by unclean termination of an earlier run.
+ * Remove the file and try again.
+ */
+ unlink(ctrl->local.sun_path);
+ __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,"%s: bind failed(%s)\n", __FUNCTION__, strerror(errno));
+ goto try_again;
+ }
+ __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,"%s: bind failed(%s)\n", __FUNCTION__, strerror(errno));
+ close(ctrl->s);
+ free(ctrl);
+ return NULL;
+ }
+ ctrl->dest.sun_family = AF_UNIX;
+ res = strlcpy(ctrl->dest.sun_path, server_path,
+ sizeof(ctrl->dest.sun_path));
+ if (res >= sizeof(ctrl->dest.sun_path)) {
+ close(ctrl->s);
+ free(ctrl);
+ return NULL;
+ }
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,"%s: error: %d\n", __FUNCTION__, chmod(ctrl->dest.sun_path, 0x777));
+ if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
+ sizeof(ctrl->dest)) < 0) {
+ close(ctrl->s);
+ __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,"%s: connection failed, error :%s\n", __FUNCTION__, strerror(errno));
+ unlink(ctrl->local.sun_path);
+ free(ctrl);
+ return NULL;
+ }
+ return ctrl;
+}
+
+
+void netwrapper_ctrl_close(struct netwrapper_ctrl *ctrl)
+{
+ if (ctrl == NULL)
+ return;
+ unlink(ctrl->local.sun_path);
+ if (ctrl->s >= 0)
+ close(ctrl->s);
+ free(ctrl);
+}
+
+
+int netwrapper_ctrl_request(struct netwrapper_ctrl *ctrl, const char *cmd, size_t cmd_len)
+{
+ int nwritten = -1;
+ int acked = 0;
+ fd_set rfds;
+ struct timeval tv;
+ int res;
+ int pid_and_reqno_len =0;
+ int resend_cnt = 0;
+ cmd_len=cmd_len;
+ do {
+ request_buf[0] = 0;
+ nwritten = sprintf(request_buf, "%d\t", getpid());
+ nwritten += sprintf(request_buf + nwritten, "%d\t", req_no++);
+ pid_and_reqno_len = nwritten;
+ nwritten += sprintf(request_buf + nwritten, "%s", cmd);
+ if (send(ctrl->s, request_buf, nwritten, 0) < 0) {
+ __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,"send command[%s] failed(%s)\n", cmd, strerror(errno));
+ goto exit_func;
+ }
+ resend_cnt++;
+ tv.tv_sec = 10;
+ tv.tv_usec = 0;
+ FD_ZERO(&rfds);
+ FD_SET(ctrl->s, &rfds);
+ res = select(ctrl->s + 1, &rfds, NULL, NULL, &tv);
+ if ( res < 0 ) {
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,"failed to select(%s)\n", strerror(errno));
+ goto exit_func;
+ } else if ( 0 == res ){
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,"Timeout to recv ack, resend request\n");
+ continue;
+ }else if (FD_ISSET(ctrl->s, &rfds)) {
+ res = recv(ctrl->s, ack_buf, ACK_BUF_LEN-1, 0);
+ if (res < 0) {
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,"failed to recv ack(%s)\n", strerror(errno));
+ goto exit_func;
+ }
+
+ if (0 == strncmp(ack_buf, request_buf,pid_and_reqno_len)) {
+ acked = 1;
+ }
+ else {
+ ack_buf[pid_and_reqno_len] = 0;
+ request_buf[pid_and_reqno_len] = 0;
+ }
+ }
+ }while(!acked && resend_cnt < RESEND_CNT_MAX);
+
+exit_func:
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,"send command[%s] %s\n", cmd, acked ? "OK" : "failed");
+ return acked ? 0 : -1;
+}
+
+
+int netwrapper_register_handler(const char *request, pf_request_handler handler)
+{
+ struct request_handler_map *map = malloc(sizeof(struct request_handler_map));
+
+ if (!map) {
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG, "malloc failed");
+ return -1;
+ }
+
+ memset(map, '\0', sizeof(*map));
+ map->handler = handler;
+ strncpy(map->request, request,sizeof(map->request) - 1);
+
+ if (!map_list) {
+ map_list = map;
+ }
+ else {
+ map->next = map_list;
+ map_list = map;
+ }
+
+ return 0;
+}
+
+
+
+static pf_request_handler get_handler(const char *request)
+{
+ struct request_handler_map *map;
+
+ for (map = map_list; map; map = map->next) {
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,
+ "map->request[%s]\n",map->request);
+ if ( 0 == strncmp(map->request, request, strlen(map->request)))
+ return map->handler;
+ }
+
+ return (pf_request_handler)NULL;
+}
+
+
+static const char NETWRAPPER_SELECT_TO_PROP_NAME[] = "net.wrapper.select.timeout";
+int netwrapper_main(const char *server_path)
+{
+ int socket_fd;
+ struct sockaddr_un cli_addr, serv_addr;
+ int i, len, clilen = 0;
+ int ret;
+ char *filecon;
+ sehandle = selinux_android_file_context_handle();
+ socket_fd = socket(PF_UNIX, SOCK_DGRAM, 0);
+ if (socket_fd < 0) {
+ __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,
+ "failed to create socket(%s)\n", strerror(errno));
+ exit(-1);
+ }
+
+ memset(&serv_addr,0,sizeof(serv_addr));
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,
+ "create AF_UNIX socket:%d OK\n",socket_fd);
+
+ unlink(server_path);
+ serv_addr.sun_family = AF_UNIX;
+ strncpy(serv_addr.sun_path, server_path, sizeof(serv_addr.sun_path) - 1);
+ filecon = NULL;
+ if (sehandle) {
+ ret = selabel_lookup(sehandle, &filecon, server_path, S_IFSOCK);
+ if (ret == 0)
+ setfscreatecon(filecon);
+ }
+ if (bind(socket_fd, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr_un)) < 0) {
+ __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,
+ "failed to bind socket(%s)\n", strerror(errno));
+ exit(-1);
+ }
+ chmod(server_path, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP | S_IWGRP |S_IXGRP |S_IROTH |S_IWOTH |S_IXOTH );
+ setfscreatecon(NULL);
+ freecon(filecon);
+
+ struct timeval tv;
+ int res;
+ fd_set rfds;
+ char *cmd;
+
+ for (;;) {
+ char str_to[PROPERTY_VALUE_MAX] = {0,};
+ property_get(NETWRAPPER_SELECT_TO_PROP_NAME, str_to, "10");
+ tv.tv_sec = atoi(str_to);
+ tv.tv_usec = 0;
+ FD_ZERO(&rfds);
+ FD_SET(socket_fd, &rfds);
+ res = select(socket_fd + 1, &rfds, NULL, NULL, &tv);
+ if (res > 0 && FD_ISSET(socket_fd, &rfds)) {
+ clilen = sizeof (struct sockaddr_un);
+ res = recvfrom(socket_fd, request_buf, REQUEST_BUF_LEN-1, 0,
+ (struct sockaddr *)&cli_addr,&clilen);
+ if (res < 0) {
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,
+ "FAILED TO RECVFROM\n");
+ return res;
+ }
+
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,
+ "client: [%s][%d]\n",
+ cli_addr.sun_path, clilen);
+
+ request_buf[res] = '\0';
+
+ cmd = strchr(request_buf, '\t');
+ if (!cmd) {
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,
+ "recv invalid request(No TAB found): [%s]\n",request_buf);
+ continue;
+ }
+ cmd++;
+ cmd = strchr(cmd, '\t');
+ if (!cmd) {
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,
+ "recv invalid request(Second TAB NOT found): [%s]\n",request_buf);
+ continue;
+ }
+ cmd++;
+ if (sendto(socket_fd, request_buf, cmd - request_buf, 0,
+ (struct sockaddr *)&cli_addr, clilen) < 0) {
+ __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,"failed to send ACK(%s)\n", strerror(errno));
+ continue;
+ }
+ pf_request_handler handler = get_handler(cmd);
+ if ( handler ) {
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG, "handler ret = %d\n", handler(cmd));
+ }
+ else {
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,
+ "no handler found for request\n");
+ }
+ }
+ }
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG, "EXIT\n");
+ close(socket_fd);
+ return 0;
+}
+
diff --git a/jni/src/netwrapper.h b/jni/src/netwrapper.h
new file mode 100644
index 0000000..167746e
--- a/dev/null
+++ b/jni/src/netwrapper.h
@@ -0,0 +1,39 @@
+#ifndef NETWRAPPER_CTRL_H
+#define NETWRAPPER_CTRL_H
+
+#define REQUEST_BUF_LEN 512
+
+extern struct selabel_handle *sehandle;
+
+typedef int (*pf_request_handler)(char * request);
+
+
+struct netwrapper_ctrl {
+ int s;
+ struct sockaddr_un local;
+ struct sockaddr_un dest;
+};
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct netwrapper_ctrl * netwrapper_ctrl_open
+(const char *client_path, const char *server_path);
+
+void netwrapper_ctrl_close(struct netwrapper_ctrl *ctrl);
+
+int netwrapper_ctrl_request(struct netwrapper_ctrl *ctrl, const char *cmd, size_t cmd_len);
+
+int netwrapper_register_handler(const char *request, pf_request_handler handler);
+
+
+int netwrapper_main(const char *server_path);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
diff --git a/jni/src/pppoe_cli.c b/jni/src/pppoe_cli.c
index 0f90264..acd05ca 100755
--- a/jni/src/pppoe_cli.c
+++ b/jni/src/pppoe_cli.c
@@ -12,7 +12,7 @@
#include <netinet/in.h>
#include <sys/un.h>
-#include <netwrapper.h>
+#include "netwrapper.h"
#include "pppoe_status.h"
diff --git a/jni/src/pppoe_status.c b/jni/src/pppoe_status.c
index a6f6d42..40615d6 100755
--- a/jni/src/pppoe_status.c
+++ b/jni/src/pppoe_status.c
@@ -57,7 +57,7 @@ done:
int get_net_updown(const char *phy_if_name)
{
int ret;
-
+
ret = if_is_up(phy_if_name);
if(ret < 0){
if(ENODEV == -ret)
@@ -66,12 +66,72 @@ int get_net_updown(const char *phy_if_name)
}
if(0 == ret) {
- __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG, "%s is DOWN\n", phy_if_name);
+ __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG, "%s is DOWN\n", phy_if_name);
return 0;
}
else {
- __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG, "%s is UP\n", phy_if_name);
+ __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG, "%s is UP\n", phy_if_name);
return 1;
}
}
+int get_pppoe_status(const char *phy_if_name)
+{
+ int ret;
+
+ ret = if_is_up(phy_if_name);
+ if (ret < 0) {
+ 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,
+ "ppp_status: DISCONNECTED\n");
+
+ return PPP_STATUS_DISCONNECTED;
+ }
+
+ if (0 == ret) {
+ PRINTF("%s is DOWN\n", phy_if_name);
+
+ PRINTF("ppp_status: DISCONNECTED\n");
+ __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,
+ "ppp_status: DISCONNECTED\n");
+ return PPP_STATUS_DISCONNECTED;
+ }
+
+ ret = if_is_up(PPP_IF_NAME);
+ if (ret < 0) {
+ if (ENODEV == -ret)
+ PRINTF("No such device(%s)\n", PPP_IF_NAME);
+
+ PRINTF("ppp_status: DISCONNECTED\n");
+ __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,
+ "ppp_status: DISCONNECTED\n");
+ return PPP_STATUS_DISCONNECTED;
+ }
+
+ if (0 == ret) {
+ PRINTF("ppp_status: CONNECTING\n");
+
+ __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,
+ "ppp_status: CONNECTING\n");
+ return PPP_STATUS_CONNECTING;
+ }
+ else {
+ PRINTF("ppp_status: CONNECTED\n");
+ __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,
+ "ppp_status: CONNECTED\n");
+ return PPP_STATUS_CONNECTED;
+ }
+}
+
+/*
+int
+main(int argc, char **argv)
+{
+ get_pppoe_status(( 1 == argc ) ? "eth0" : argv[1]);
+
+ return 0;
+}
+*/
diff --git a/jni/src/pppoe_status.h b/jni/src/pppoe_status.h
index ade631d..599ee0b 100755
--- a/jni/src/pppoe_status.h
+++ b/jni/src/pppoe_status.h
@@ -4,9 +4,9 @@
#define PPP_STATUS_CONNECTED 0x10
#define PPP_STATUS_DISCONNECTED 0x20
#define PPP_STATUS_CONNECTING 0x40
-#define PPP_STATUS_DISCONNECTING 0x80
-#include "../../../ppp/pppd/pathnames.h"
+//#ifndef _ROOT_PATH
+#define _ROOT_PATH "/data/misc"
#define PPPOE_PIDFILE _ROOT_PATH "/etc/ppp/pppoe.pid"
#define PPPOE_WRAPPER_CLIENT_PATH _ROOT_PATH "/etc/ppp/pppoe"
#define PPPOE_WRAPPER_SERVER_PATH "/dev/socket/pppoe_wrapper"
diff --git a/jni/src/pppoe_wrapper.c b/jni/src/pppoe_wrapper.c
index 1615d00..c45cc73 100755
--- a/jni/src/pppoe_wrapper.c
+++ b/jni/src/pppoe_wrapper.c
@@ -26,23 +26,12 @@
#include <android/log.h>
#include <netutils/ifc.h>
-#include <linux/if.h>
-#include <linux/sockios.h>
-
-#include <netwrapper.h>
+#include "netwrapper.h"
#include "pppoe_status.h"
-#define PPP_IF_NAME "ppp0"
-
#define LOCAL_TAG "PPPOE_WRAPPER"
-#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG, __VA_ARGS__)
-#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG, __VA_ARGS__)
-
-static int pppoe_status = PPP_STATUS_DISCONNECTED;
-static char phy_if_name[IFNAMSIZ + 1] = "unknown";
-
static pid_t read_pid(const char *pidfile)
{
FILE *fp;
@@ -87,7 +76,6 @@ static int pppoe_disconnect_handler(char *request)
return -1;
}
- pppoe_status = PPP_STATUS_DISCONNECTING;
/*
The signals SIGKILL and SIGSTOP cannot
be caught, blocked, or ignored.
@@ -114,8 +102,6 @@ static int pppoe_disconnect_handler(char *request)
__android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,
"removed %s\n", PPPOE_PIDFILE );
- pppoe_status = PPP_STATUS_DISCONNECTED;
-
return 0;
}
@@ -135,21 +121,6 @@ static int pppoe_terminate_handler(char *request)
static int pppoe_connect_handler(char *request)
{
- char *phy_if,*pSpace;
- strcpy(phy_if_name, "unkown");
-
- phy_if = strstr(request, " -I ");
- if (phy_if) {
- phy_if += strlen(" -I ");
- pSpace = strchr(phy_if, ' ');
- if (pSpace && pSpace - phy_if < IFNAMSIZ) {
- strncpy(phy_if_name, phy_if, pSpace - phy_if);
- phy_if_name[pSpace - phy_if]='\0';
- }
- }
-
- LOGI("Physical interface: %s\n", phy_if_name);
-
if (strstr(request, "eth0")) {
__android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,
"FIXME!!! SHOULD NOT clear eth0 ip address. Reference to bug#98924.\n");
@@ -158,92 +129,14 @@ static int pppoe_connect_handler(char *request)
ifc_close();
}
- pppoe_status = PPP_STATUS_CONNECTING;
-
return system(request);
}
-static int get_interface_state(const char *if_name)
-{
- struct ifreq ifr;
- int s, ret;
-
- strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
-
- s = socket(AF_INET, SOCK_DGRAM, 0);
- if (s < 0) {
- LOGE("if_is_up(%s): failed to create socket(%s)\n", if_name, strerror(errno));
-
- return -1;
- }
- ret = ioctl(s, SIOCGIFFLAGS, &ifr);
- if (ret < 0) {
- ret = -errno;
- LOGE("if_is_up(%s): failed to ioctl(%s)\n", if_name, strerror(errno));
- goto done;
- }
-
- ret = (ifr.ifr_flags &= IFF_UP) ? 1 : 0;
- LOGI("%s is %s\n", if_name, ret ? "UP" : "DOWN");
-
-done:
- close(s);
- return ret;
-}
-
-
-static int pppoe_status_handler(char *request)
-{
- int ret;
-
- ret = get_interface_state(phy_if_name);
- if (ret < 0){
- if (ENODEV == -ret)
- LOGE("physical interface %s not found\n", phy_if_name);
-
- LOGI("DISCONNECTED\n");
-
- return PPP_STATUS_DISCONNECTED;
- }
-
- if (0 == ret) {
- LOGI("physical interface %s is DOWN\n", phy_if_name);
- LOGI("DISCONNECTED\n");
- return PPP_STATUS_DISCONNECTED;
- }
-
- if (pppoe_status == PPP_STATUS_CONNECTING) {
- ret = get_interface_state(PPP_IF_NAME);
- if (ret < 0){
- if (ENODEV == -ret)
- LOGI("wait to create interface %s...\n", PPP_IF_NAME);
-
- return PPP_STATUS_CONNECTING;
- }
-
- if (0 == ret) {
- LOGI("waiting interface %s up\n", PPP_IF_NAME);
- LOGI("CONNECTING\n");
- return PPP_STATUS_CONNECTING;
- }
- else {
- LOGI("interface %s has up\n", PPP_IF_NAME);
- LOGI("CONNECTED\n");
- pppoe_status = PPP_STATUS_CONNECTED;
- return pppoe_status;
- }
- }
-
- return pppoe_status;
-}
-
-
int main(int argc, char* argv[])
{
netwrapper_register_handler("ppp-stop", pppoe_disconnect_handler);
netwrapper_register_handler("ppp-terminate", pppoe_terminate_handler);
- netwrapper_register_handler("ppp-status", pppoe_status_handler);
netwrapper_register_handler("pppd pty", pppoe_connect_handler);
netwrapper_main(PPPOE_WRAPPER_SERVER_PATH);