Discuz! Board
标题:
RJ45的整个插入检测方法
[打印本页]
作者:
zangcf
时间:
2016-4-9 22:12
标题:
RJ45的整个插入检测方法
已经不同模块的通知方法分析
作者:
zangcf
时间:
2016-4-9 22:35
首先,
1)SocketClient检测到RJ45插入信息。
2)这个事件被EthernetMonitor发现。
public void run() {
//noinspection InfiniteLoopStatement
for (;;) {
int index;
int i;
int cmd;
String dev;
if (localLOGV) Slog.v(TAG, "zcfdebug go poll events");
String eventName = EthernetNative.waitForEvent();
if (eventName == null) {
if (localLOGV) Slog.v(TAG, "zcfdebug no ethernet monitor events");
continue;
}
if (localLOGV) Slog.v(TAG, "zcfdebug get event " + eventName);
/*
* Map event name into event enum
*/
if (eventName.length()==0) {
EthUeventFail=true;
Slog.v(TAG, "the eventName length is " + eventName.length());
}
i = 0;
作者:
zangcf
时间:
2016-4-9 23:41
本帖最后由 zangcf 于 2016-4-11 12:12 编辑
3,然后,通知给Tracker:
mTracker.notifyStateChange(ifname,NetworkInfo.DetailedState.CONNECTED); //zcfdebug++
采用
public void notifyStateChange(String ifname,DetailedState state) {
Log.e(TAG,"notifyStateChange in EthernetStateTracker!");
if(state.equals(DetailedState.CONNECTED)){
Log.e(TAG,"Ethernet connected in EthernetStateTracker!");
}else
{
Log.e(TAG,"Ethernet disconnected in EthernetStateTracker!");
setState(mHWConnected = false, EVENT_HW_DISCONNECTED); //zcfdebug++20150508
}
if (localLOGV) Slog.i(TAG, "zcfdebug report new state " + state.toString() + " on dev " + ifname);
if (ifname.equals(mInterfaceName)) {
if (localLOGV) Slog.v(TAG, "zcfdebug update network state tracker");
synchronized(this) {
this.sendEmptyMessage(state.equals(DetailedState.CONNECTED)
? EVENT_HW_CONNECTED : EVENT_HW_DISCONNECTED);
}
}
}
作者:
zangcf
时间:
2016-4-10 22:58
本帖最后由 zangcf 于 2016-4-11 12:16 编辑
4,进入
case EVENT_HW_CONNECTED:
if (localLOGV) Slog.i(TAG, "zcfdebug received HW connected, stack=" + mStackConnected + " HW=" + mHWConnected);
mHWConnected = true;
mStackConnected = true; //zcfdebug++
if (mStackConnected)
setState(true, msg.what);
break;
作者:
zangcf
时间:
2016-4-10 23:07
5,下一步运行到
case EVENT_HW_PHYCONNECTED:
if (localLOGV) Slog.i(TAG, "interface up event, kick off connection request");
if (!mStartingDhcp) {
int state = mEM.getState();
if (state != mEM.ETHERNET_STATE_DISABLED) {
EthernetDevInfo info = mEM.getSavedConfig();
if (info != null && mEM.isConfigured()) {
try {
configureInterface(info);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
Slog.e(TAG, "Cannot configure interface");
}
}
}
}
break;
作者:
zangcf
时间:
2016-4-10 23:19
6,看看配置
private boolean configureInterface(EthernetDevInfo info) throws UnknownHostException {
DhcpInfo infoDhcp = new DhcpInfo();//zcfdebug++
mStackConnected = false;
mHWConnected = false;
mInterfaceStopped = false;
mStartingDhcp = true;
NetworkUtils.resetConnections(info.getIfName(), NetworkUtils.RESET_ALL_ADDRESSES);//zcfdebug++
if (info.getConnectMode().equals(EthernetDevInfo.ETHERNET_CONN_MODE_DHCP)) {
if (localLOGV) Slog.i(TAG, "trigger dhcp for device " + info.getIfName());
sDnsPropNames = new String[] {
"dhcp." + mInterfaceName + ".dns1",
"dhcp." + mInterfaceName + ".dns2"
};
mDhcpTarget.sendEmptyMessage(EVENT_DHCP_START);
作者:
zangcf
时间:
2016-4-11 11:15
关于Tethering部分,后面应该删除:
D/zcfdebug Tethering( 460): interfaceLinkStateChanged eth0, true
D/zcfdebug Tethering( 460): interfaceStatusChanged eth0, true
D/zcfdebug Tethering( 460): Eth0 interface been found
D/zcfdebug Tethering( 460): setLastError: 0
D/zcfdebug Tethering( 460): setLastError: 16
D/zcfdebug Tethering( 460): [ISM_Initial] enter, sendTetherStateChangedBroadcast
作者:
zangcf
时间:
2016-4-11 11:16
关于Tethering部分,后面应该删除:
D/zcfdebug Tethering( 460): interfaceLinkStateChanged eth0, true
D/zcfdebug Tethering( 460): interfaceStatusChanged eth0, true
D/zcfdebug Tethering( 460): Eth0 interface been found
D/zcfdebug Tethering( 460): setLastError: 0
D/zcfdebug Tethering( 460): setLastError: 16
D/zcfdebug Tethering( 460): [ISM_Initial] enter, sendTetherStateChangedBroadcast
作者:
zangcf
时间:
2016-4-11 11:18
switch (msg.what) {
case EVENT_DHCP_START:
synchronized (mDhcpTarget) {
if (!mInterfaceStopped) {
if (localLOGV) {
Slog.d(TAG, "DhcpHandler: DHCP request started");
Slog.d(TAG, "DhcpHandler: postNotification(msg.what)");
//zcfdebug++<<
// case EVENT_HW_CONNECTED:
// if (localLOGV) Slog.i(TAG, "zcfdebug received HW connected, stack=" + mStackConnected + " HW=" + mHWConnected);
// mHWConnected = true;
// mStackConnected = true; //zcfdebug++
// if (mStackConnected)
// setState(true, EVENT_HW_CONNECTED);
//zcfdebug>>++
//postNotification(msg.what);
}
if (NetworkUtils.runDhcp(mInterfaceName, mDhcpInfo)) {
event = EVENT_INTERFACE_CONFIGURATION_SUCCEEDED;
//zcfdebug-- if (localLOGV) Slog.d(TAG, "DhcpHandler: DHCP request succeeded: " + mDhcpInfo.toString());
//zcfdebug++<<
//FBR : patch for handling DHCP DNS
SystemProperties.set("net.dns1", mDhcpInfo.dns1);
SystemProperties.set("net." + mInterfaceName + ".dns1", mDhcpInfo.dns1);
if (localLOGV) Slog.d(TAG, "DhcpHandler: DHCP request succeeded: " + mDhcpInfo.toString());
//zcfdebug++<<
mLinkProperties = mDhcpInfo.makeLinkProperties();
mLinkProperties.setInterfaceName("eth0");
mNetworkInfo.setDetailedState(DetailedState.CONNECTED, null, null);
mNetworkInfo.setIsAvailable(true); //zcfdebug++20150510
msg = mCsHandler.obtainMessage(EVENT_DHCP_START_OK, mNetworkInfo);
msg.sendToTarget();
Slog.d(TAG, "zcfdebug send message EVENT_DHCP_START_OK!!!");
//zcfdebug>>++
infoDhcp = mDhcpInfo.makeDhcpInfo();
if (!NetworkUtils.configureInterface(mInterfaceName, infoDhcp)) {
event = EVENT_INTERFACE_CONFIGURATION_FAILED;
}
//zcfdebug>>++
} else {
event = EVENT_INTERFACE_CONFIGURATION_FAILED;
Slog.e(TAG, "DhcpHandler: DHCP request failed: " + NetworkUtils.getDhcpError());
//zcfdebug--201500505 mHWConnected = false;
//zcfdebug--201500505 mStackConnected = true;
//zcfdebug--201500505 if (mStackConnected)
//zcfdebug--201500505 setState(false, EVENT_HW_DISCONNECTED);
//zcfdebug--201500505
}
mTrackerTarget.sendEmptyMessage(event);
} else {
mInterfaceStopped = false;
}
mStartingDhcp = false;
}
//zcfdebug++<<
欢迎光临 Discuz! Board (http://47.89.242.157:9000/bbs/discuz/)
Powered by Discuz! X3.2