author | Zhiwei Gong <zhiwei.gong@amlogic.com> | 2015-10-14 01:26:12 (GMT) |
---|---|---|
committer | zhiwei.gong <zhiwei.gong@amlogic.com> | 2015-10-15 09:04:23 (GMT) |
commit | 32ccc64a8a7595b4f5efba77a1a8baf424a7e7a5 (patch) | |
tree | 022760784045f264ea169af85a464b43de4b7481 | |
parent | 04c69ffda2d8f9b6478d3159b7effab80139b53e (diff) | |
download | pppoe-32ccc64a8a7595b4f5efba77a1a8baf424a7e7a5.zip pppoe-32ccc64a8a7595b4f5efba77a1a8baf424a7e7a5.tar.gz pppoe-32ccc64a8a7595b4f5efba77a1a8baf424a7e7a5.tar.bz2 |
PD#113238:Pppoe Code finishing
Change-Id: I25eb63379a4dd46618b5852b9979fa3e1db72df2
-rw-r--r-- | java/src/com/droidlogic/pppoe/PppoeDevInfo.java | 2 | ||||
-rw-r--r-- | java/src/com/droidlogic/pppoe/PppoeMonitor.java | 2 | ||||
-rw-r--r-- | java/src/com/droidlogic/pppoe/PppoeService.java | 28 | ||||
-rw-r--r-- | java/src/com/droidlogic/pppoe/PppoeStateTracker.java | 32 | ||||
-rw-r--r-- | jni/com_droidlogic_common.cpp | 56 | ||||
-rw-r--r-- | jni/com_droidlogic_common.h | 2 | ||||
-rw-r--r-- | jni/com_droidlogic_pppoe.cpp | 18 |
7 files changed, 63 insertions, 77 deletions
diff --git a/java/src/com/droidlogic/pppoe/PppoeDevInfo.java b/java/src/com/droidlogic/pppoe/PppoeDevInfo.java index e70d18c..f91f6b9 100644 --- a/java/src/com/droidlogic/pppoe/PppoeDevInfo.java +++ b/java/src/com/droidlogic/pppoe/PppoeDevInfo.java @@ -12,7 +12,7 @@ public class PppoeDevInfo implements Parcelable { private String route; private String dns; private String mode; - public static final String PPPOE_CONN_MODE_DHCP= "dhcp"; + public static final String PPPOE_CONN_MODE_DHCP = "dhcp"; public static final String PPPOE_CONN_MODE_MANUAL = "manual"; public PppoeDevInfo () { diff --git a/java/src/com/droidlogic/pppoe/PppoeMonitor.java b/java/src/com/droidlogic/pppoe/PppoeMonitor.java index 9348701..d8d9dd8 100644 --- a/java/src/com/droidlogic/pppoe/PppoeMonitor.java +++ b/java/src/com/droidlogic/pppoe/PppoeMonitor.java @@ -21,7 +21,7 @@ public class PppoeMonitor { private static final int INTERFACE_UP = 3; private static final int DEV_ADDED = 4; private static final int DEV_REMOVED = 5; - private static final String connectedEvent = "CONNECTED"; + private static final String connectedEvent = "CONNECTED"; private static final String disconnectedEvent = "DISCONNECTED"; private static final int NEW_LINK = 16; diff --git a/java/src/com/droidlogic/pppoe/PppoeService.java b/java/src/com/droidlogic/pppoe/PppoeService.java index c333b56..84a5dbb 100644 --- a/java/src/com/droidlogic/pppoe/PppoeService.java +++ b/java/src/com/droidlogic/pppoe/PppoeService.java @@ -42,7 +42,7 @@ public class PppoeService<syncronized> extends IPppoeManager.Stub{ private String[] DevName; private static final String TAG = "PppoeService"; private int isPppoeEnabled ; - private int mPppoeState= PppoeManager.PPPOE_STATE_UNKNOWN; + private int mPppoeState = PppoeManager.PPPOE_STATE_UNKNOWN; /** {@hide} */ public static final String PPPOE_ON = "pppoe_on"; /** {@hide} */ @@ -58,7 +58,7 @@ public class PppoeService<syncronized> extends IPppoeManager.Stub{ /** {@hide} */ public static final String PPPOE_IFNAME = "pppoe_ifname"; - public PppoeService(Context context, PppoeStateTracker Tracker){ + public PppoeService(Context context, PppoeStateTracker Tracker) { mTracker = Tracker; mContext = context; @@ -66,7 +66,6 @@ public class PppoeService<syncronized> extends IPppoeManager.Stub{ Slog.i(TAG,"Pppoe dev enabled " + isPppoeEnabled ); getDeviceNameList(); setPppoeState(isPppoeEnabled); - registerForBroadcasts(); Slog.i(TAG, "Trigger the pppoe monitor"); mTracker.StartPolling(); } @@ -129,12 +128,6 @@ public class PppoeService<syncronized> extends IPppoeManager.Stub{ Settings.Secure.putString(cr, PPPOE_ROUTE, info.getRouteAddr()); Settings.Secure.putString(cr, PPPOE_MASK,info.getNetMask()); } - private void registerForBroadcasts() { - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(Intent.ACTION_SCREEN_ON); - intentFilter.addAction(Intent.ACTION_SCREEN_OFF); - mContext.registerReceiver(mReceiver, intentFilter); - } public int getTotalInterface() { return PppoeNative.getInterfaceCnt(); @@ -179,23 +172,6 @@ public class PppoeService<syncronized> extends IPppoeManager.Stub{ enabled ? PppoeManager.PPPOE_STATE_ENABLED : PppoeManager.PPPOE_STATE_DISABLED); } - private final BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - if (action.equals(Intent.ACTION_SCREEN_ON)) { - Slog.d(TAG, "ACTION_SCREEN_ON"); - try { - mTracker.resetInterface(); - } catch (UnknownHostException e) { - Slog.e(TAG, "Wrong pppoe configuration"); - } - } else if (action.equals(Intent.ACTION_SCREEN_OFF)) { - Slog.d(TAG, "ACTION_SCREEN_OFF"); - mTracker.stopInterface(false); - } - } - }; public synchronized void setPppoeState(int state) { Slog.i(TAG, "setPppoeState from " + mPppoeState + " to "+ state); diff --git a/java/src/com/droidlogic/pppoe/PppoeStateTracker.java b/java/src/com/droidlogic/pppoe/PppoeStateTracker.java index 3b952f8..eb9b80e 100644 --- a/java/src/com/droidlogic/pppoe/PppoeStateTracker.java +++ b/java/src/com/droidlogic/pppoe/PppoeStateTracker.java @@ -52,7 +52,7 @@ import android.util.Slog; */ public class PppoeStateTracker implements NetworkStateTracker { - private static final String TAG="PppoeStateTracker"; + private static final String TAG = "PppoeStateTracker"; private static final String PROP_PPP_ADDR = "dhcp.ppp0.ipaddress"; private static final String PROP_PPP_MASK = "dhcp.ppp0.mask"; private static final String PROP_PPP_DNS1 = "dhcp.ppp0.dns1"; @@ -73,7 +73,9 @@ public class PppoeStateTracker implements NetworkStateTracker { private PppoeManager mEM; private boolean mServiceStarted; private boolean mInterfaceStopped; + private boolean mPppoeConnectStates; private String mInterfaceName = "ppp0"; + private String mInterfaceName1 = "ppp1"; private DhcpInfoInternal mDhcpInfoInternal; private PppoeMonitor mMonitor; @@ -100,7 +102,8 @@ public class PppoeStateTracker implements NetworkStateTracker { mNetworkInfo = new NetworkInfo(netType, 0, networkName, ""); mNetworkInfo.setIsAvailable(false); setTeardownRequested(false); - mLooper=looper; + mLooper = looper; + mPppoeConnectStates = false; mLinkProperties = new LinkProperties(); mNetworkCapabilities = new NetworkCapabilities(); mNetworkCapabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); @@ -177,7 +180,7 @@ public class PppoeStateTracker implements NetworkStateTracker { private boolean configureInterface(PppoeDevInfo info) throws UnknownHostException { mInterfaceStopped = false; - Info=info; + Info = info; mDhcpInfoInternal = new DhcpInfoInternal(); mDhcpInfoInternal.ipAddress = info.getIpAddress(); mDhcpInfoInternal.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(info.getRouteAddr()))); @@ -404,7 +407,7 @@ public class PppoeStateTracker implements NetworkStateTracker { Slog.i(TAG, "[EVENT: PPP UP]"); newNetworkstate = true; - int i=0; + int i = 0; info.setIfName(mInterfaceName); String prop_val = null; @@ -418,7 +421,7 @@ public class PppoeStateTracker implements NetworkStateTracker { // Shut up! } i++; - } while(i<10); + } while (i < 10); prop_val = SystemProperties.get(PROP_PPP_MASK, "0.0.0.0"); info.setNetMask(prop_val); @@ -458,6 +461,7 @@ public class PppoeStateTracker implements NetworkStateTracker { break; } } + mPppoeConnectStates = false; return true; } }; @@ -472,12 +476,16 @@ public class PppoeStateTracker implements NetworkStateTracker { } public void notifyStateChange(String ifname,DetailedState state) { Slog.i(TAG, "report state change:" + mLastState.toString() + "->" + state.toString() + " on dev " + ifname); - if (ifname.equals(mInterfaceName)) { + if ((ifname.equals(mInterfaceName) && mLastState != state)) { mLastState = state; + mPppoeConnectStates = true; synchronized(this) { mTrackerTarget.sendEmptyMessage(state.equals(DetailedState.CONNECTED) ? EVENT_CONNECTED : EVENT_DISCONNECTED); } + } else if (ifname.equals(mInterfaceName1) && !mPppoeConnectStates) { + mPppoeConnectStates = true; + mTrackerTarget.sendEmptyMessage(EVENT_DISCONNECTED); } } @@ -569,33 +577,33 @@ public class PppoeStateTracker implements NetworkStateTracker { /** * Informs the state tracker that another interface is stacked on top of it. **/ - public void addStackedLink(LinkProperties link){ + public void addStackedLink(LinkProperties link) { } /** * Informs the state tracker that a stacked interface has been removed. **/ - public void removeStackedLink(LinkProperties link){ + public void removeStackedLink(LinkProperties link) { } /* * Called once to setup async channel between this and * the underlying network specific code. */ - public void supplyMessenger(Messenger messenger){ + public void supplyMessenger(Messenger messenger) { } /* * Network interface name that we'll lookup for sampling data */ - public String getNetworkInterfaceName(){ + public String getNetworkInterfaceName() { return null; } /* * Save the starting sample */ - public void startSampling(SamplingDataTracker.SamplingSnapshot s){ + public void startSampling(SamplingDataTracker.SamplingSnapshot s) { } /* @@ -613,7 +621,7 @@ public class PppoeStateTracker implements NetworkStateTracker { * Get interesting information about this network link * @return a copy of link information, null if not available */ - public LinkQualityInfo getLinkQualityInfo(){ + public LinkQualityInfo getLinkQualityInfo() { return null; } } diff --git a/jni/com_droidlogic_common.cpp b/jni/com_droidlogic_common.cpp index 4131303..5f72839 100644 --- a/jni/com_droidlogic_common.cpp +++ b/jni/com_droidlogic_common.cpp @@ -74,16 +74,14 @@ static const char * flag_desc_tbl[32] = { "UNDEFINED", }; -static char* if_flags_desc(int flags, char *desc) { +static void if_flags_desc(int flags, char *desc) { desc[0] = '\0'; for (int i = 18; i >= 0; i--) { - if (flags & (1<<i)) { + if (flags & (1 << i)) { strcat(desc, " "); strcat(desc, flag_desc_tbl[i]); } } - - return desc; } @@ -146,6 +144,7 @@ pfunc_is_interested_event pfunc_check) } if (pfunc_check && !pfunc_check(ifname)) { + ALOGI("pfunc_check error"); return -1; } ALOGI("Address %s %s/%d %s %u %u" , @@ -242,12 +241,13 @@ static void parseBinaryNetlinkMessage } desc = (char*)((type == RTM_DELLINK) ? "DELLINK" : "NEWLINK"); + if_flags_desc(einfo->ifi_flags, flags_desc); - ALOGI("%s: %s(%d), flags=0X%X(%s)", ifname, desc, type, einfo->ifi_flags, if_flags_desc(einfo->ifi_flags, flags_desc)); + ALOGI("%s: %s(%d), flags=0X%X(%s)", ifname, desc, type, einfo->ifi_flags, flags_desc); snprintf(result,rbufsize-guard, "%s:%d:",ifname,type); guard += strlen(result); - result +=guard; + result += guard; *pguard = guard; } else if (nh->nlmsg_type == RTM_DELADDR || nh->nlmsg_type == RTM_NEWADDR) { @@ -267,7 +267,7 @@ static void parseBinaryNetlinkMessage } snprintf(result,rbufsize-guard, "%s:%d:",ifname,nh->nlmsg_type); guard += strlen(result); - result +=guard; + result += guard; *pguard = guard; } @@ -307,7 +307,6 @@ static void parseAsciiNetlinkMessage int param_idx = 0; int i; int first = 1; - char *path = NULL; const char *action = NULL; int seq; char *subsys = NULL; @@ -340,7 +339,6 @@ static void parseAsciiNetlinkMessage return; } } - path = strdup(p+1); first = 0; } else { const char* a; @@ -368,6 +366,10 @@ static void parseAsciiNetlinkMessage guard += strlen(result); } } + if (net_if != NULL) + free(net_if); + if (subsys != NULL) + free(subsys); rbuf[guard] = '\0'; *pguard = guard; if (rbuf[0]) ALOGI("%s",rbuf); @@ -375,7 +377,7 @@ static void parseAsciiNetlinkMessage } -static char* waitForNetInterfaceEvent +static int waitForNetInterfaceEvent (int nl_socket_netlink_route, int nl_socket_kobj_uevent, char *rbuf, int *pguard, pfunc_update_interface_list pfunc, @@ -400,12 +402,12 @@ pfunc_is_interested_event pfunc_check) iov.iov_base = buff; iov.iov_len = NL_POLL_MSG_SZ; msg.msg_name = NULL; - msg.msg_namelen = 0; - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_control = NULL; - msg.msg_controllen = 0; - msg.msg_flags = 0; + msg.msg_namelen = 0; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = NULL; + msg.msg_controllen = 0; + msg.msg_flags = 0; maxfd = (nl_socket_netlink_route >= nl_socket_kobj_uevent) ? nl_socket_netlink_route: nl_socket_kobj_uevent; @@ -431,7 +433,7 @@ pfunc_is_interested_event pfunc_check) if (FD_ISSET(nl_socket_netlink_route, &readable)) { old_guard = *pguard; - if ((len = recvmsg(nl_socket_netlink_route, &msg, 0))>= 0) { + if ((len = recvmsg(nl_socket_netlink_route, &msg, 0)) >= 0) { parseBinaryNetlinkMessage(buff, len, rbuf, RET_STR_SZ, pguard,pfunc_check); } @@ -441,7 +443,7 @@ pfunc_is_interested_event pfunc_check) if (FD_ISSET(nl_socket_kobj_uevent, &readable)) { old_guard = *pguard; - if ((len = recvmsg(nl_socket_kobj_uevent, &msg, 0))>= 0) { + if ((len = recvmsg(nl_socket_kobj_uevent, &msg, 0)) >= 0) { parseAsciiNetlinkMessage(buff, len, rbuf, RET_STR_SZ, pguard,pfunc_check); pfunc(); } @@ -452,12 +454,12 @@ pfunc_is_interested_event pfunc_check) if (buff) { free(buff); } - return rbuf; + return 0; error: if (buff) free(buff); - return NULL; + return -1; } @@ -492,7 +494,7 @@ static int open_NETLINK_socket(int netlinkFamily, int groups) return mysocket; error: ALOGE("%s failed" ,__FUNCTION__); - if (mysocket >0) + if (mysocket > 0) close(mysocket); return ret; } @@ -501,7 +503,7 @@ error: static int find_empty_node(interface_info_t *node_table, int nr_nodes) { int i; - for ( i = 0; i <nr_nodes; i++) { + for ( i = 0; i < nr_nodes; i++) { if (node_table[i].if_index == -1) return i; } @@ -529,13 +531,12 @@ static int add_interface_node_to_list(interface_info_t *node_table, int nr_nodes static int getInterfaceName(interface_info_t *node_table, int nr_nodes, - int index, char *ifname) -{ + int index, char *ifname) { int i, j; interface_info_t *info; for ( i = 0, j = -1; i < nr_nodes; i++) { - info= node_table + i; + info = node_table + i; if (node_table[i].if_index != -1) j++; if (j == index) { @@ -545,10 +546,7 @@ static int getInterfaceName(interface_info_t *node_table, int nr_nodes, } } - ifname[0]='\0'; + ifname[0] = '\0'; return -1; } - -//}; - diff --git a/jni/com_droidlogic_common.h b/jni/com_droidlogic_common.h index f6d44cd..7dfdbc5 100644 --- a/jni/com_droidlogic_common.h +++ b/jni/com_droidlogic_common.h @@ -53,7 +53,7 @@ static void parseAsciiNetlinkMessage static void parseBinaryNetlinkMessage (char *buff, int len, char *rbuf, int rbufsize, int *pguard, pfunc_is_interested_event pfunc_check); -static char* waitForNetInterfaceEvent +static int waitForNetInterfaceEvent (int nl_socket_netlink_route, int nl_socket_kobj_uevent, char *rbuf, int *pguard, pfunc_update_interface_list pfunc); static int find_empty_node(interface_info_t *node_table, int nr_nodes); diff --git a/jni/com_droidlogic_pppoe.cpp b/jni/com_droidlogic_pppoe.cpp index 80fed3d..69654ad 100644 --- a/jni/com_droidlogic_pppoe.cpp +++ b/jni/com_droidlogic_pppoe.cpp @@ -31,6 +31,7 @@ #define PPPOE_PKG_NAME "com/droidlogic/pppoe/PppoeNative" +#define MAX_FGETS_LEN 4 namespace android { static struct fieldIds { @@ -85,12 +86,13 @@ static int netlink_init_pppoe_list(void) interface_info_t *intfinfo; int index; FILE *ifidx; - #define MAX_FGETS_LEN 4 char idx[MAX_FGETS_LEN+1]; int i; for ( i = 0; i < NR_ETHER_INTERFACES; i++) { pppoe_if_list[i].if_index = -1; + if (pppoe_if_list[i].name != NULL) + free(pppoe_if_list[i].name); pppoe_if_list[i].name = NULL; nr_pppoe_if = 0; } @@ -112,6 +114,9 @@ static int netlink_init_pppoe_list(void) fclose(typefd); if (type >= ARPHRD_TUNNEL && type < ARPHRD_IEEE802_TR) continue; + } else { + ALOGE("Can not open %s for read",path); + continue; } snprintf(path, SYSFS_PATH_MAX,"%s/%s/ifindex",SYSFS_CLASS_NET,de->d_name); @@ -135,9 +140,8 @@ static int netlink_init_pppoe_list(void) } } closedir(netdir); + ret = 0; } - ret = 0; -error: return ret; } @@ -168,9 +172,9 @@ static jint com_droidlogic_pppoe_PppoeNative_initPppoeNative return ret; error: ALOGE("%s exited with error",__FUNCTION__); - if (nl_socket_netlink_route >0) + if (nl_socket_netlink_route >= 0) close(nl_socket_netlink_route); - if (nl_socket_kobj_uevent >0) + if (nl_socket_kobj_uevent >= 0) close(nl_socket_kobj_uevent); return ret; } @@ -180,7 +184,7 @@ static jstring com_droidlogic_pppoe_PppoeNative_getInterfaceName (JNIEnv *env, jobject clazz, jint index) { int ret; - char ifname[IFNAMSIZ+1]= {0}; + char ifname[IFNAMSIZ+1] = {0}; ALOGI("User ask for device name on %d, total:%d",index, nr_pppoe_if); if (nr_pppoe_if == 0 || index >= nr_pppoe_if) { @@ -193,7 +197,7 @@ static jstring com_droidlogic_pppoe_PppoeNative_getInterfaceName ALOGI("No device name found"); } - return env->NewStringUTF(ret==0 ? ifname:NULL); + return env->NewStringUTF(ret == 0 ? ifname:NULL); } |