summaryrefslogtreecommitdiff
authorkejun.gao <kejun.gao@amlogic.com>2014-11-18 09:39:43 (GMT)
committer Sandy lUo <sandy.luo@amlogic.com>2014-12-09 11:20:07 (GMT)
commitc50047cad754b54f66b45e993b16b70c32c28e65 (patch)
tree897c92db073777196b6a0fe453191b10adcab333
parent89d1fbed1339a98f3ae01c35b7274a0f33c6bbde (diff)
downloadpppoe-c50047cad754b54f66b45e993b16b70c32c28e65.zip
pppoe-c50047cad754b54f66b45e993b16b70c32c28e65.tar.gz
pppoe-c50047cad754b54f66b45e993b16b70c32c28e65.tar.bz2
PD#99831. pppoe_wrapper manages the status of pppoe connection.
Change-Id: Ib7378b0b56b95bc07704848c4d8320ad49773e72
Diffstat
-rwxr-xr-xjni/pppoe_jni.cpp18
-rwxr-xr-xjni/src/pppoe_status.c60
-rwxr-xr-xjni/src/pppoe_status.h1
-rwxr-xr-xjni/src/pppoe_wrapper.c107
4 files changed, 119 insertions, 67 deletions
diff --git a/jni/pppoe_jni.cpp b/jni/pppoe_jni.cpp
index 385c100..6757a31 100755
--- a/jni/pppoe_jni.cpp
+++ b/jni/pppoe_jni.cpp
@@ -44,13 +44,12 @@ 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];
@@ -248,15 +247,20 @@ 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");
- p_ifname = (char *)env->GetStringUTFChars(jstr_if_name, NULL);
- status = get_pppoe_status(p_ifname);
-
- env->ReleaseStringUTFChars(jstr_if_name, p_ifname);
+ 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));
+
+ netwrapper_ctrl_close(ctrl);
return status;
}
diff --git a/jni/src/pppoe_status.c b/jni/src/pppoe_status.c
index 6417d22..a6f6d42 100755
--- a/jni/src/pppoe_status.c
+++ b/jni/src/pppoe_status.c
@@ -75,63 +75,3 @@ int get_net_updown(const char *phy_if_name)
}
}
-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 3ae2979..ade631d 100755
--- a/jni/src/pppoe_status.h
+++ b/jni/src/pppoe_status.h
@@ -4,6 +4,7 @@
#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"
#define PPPOE_PIDFILE _ROOT_PATH "/etc/ppp/pppoe.pid"
diff --git a/jni/src/pppoe_wrapper.c b/jni/src/pppoe_wrapper.c
index 800f9e4..1615d00 100755
--- a/jni/src/pppoe_wrapper.c
+++ b/jni/src/pppoe_wrapper.c
@@ -26,12 +26,23 @@
#include <android/log.h>
#include <netutils/ifc.h>
+#include <linux/if.h>
+#include <linux/sockios.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;
@@ -76,6 +87,7 @@ 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.
@@ -102,6 +114,8 @@ 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;
}
@@ -121,6 +135,21 @@ 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");
@@ -129,14 +158,92 @@ 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);