领导从国外拿回来一个USB Camera让我接在自家的产品上看看能否使用,试了几乎所有产品,接上后无法识别到camera,也没有生成/dev/video节点。看起来就是个普通的USB 摄像头,应该都是走的USB标准的协议,但是就是识别不到,只能看见log里面显示发现新设备UID PID这些信息,接上电脑后也没有设别到摄像头,而是发现了串口,网络适配器这些玩意,和客户那边东拉西扯一通发现,原来这个是USB转以太网设备,App和设备通过以太网通信的,要让它注册为一个以太网设备,这个usb以太网设备默认的名字是usb0,通过命令ifconfig usb0 up 可以让它唤起,但是无法正常和App通信,通过客户那边能正常使用的设备测试 ifconfig查看发现 应该注册为eth1
修改kernel/drivers/net/usb/usbnet.c
// heuristic: "usb%d" for links we know are two-host,
// else "eth%d" when there's reasonable doubt. userspace
// can rename the link if it knows better.
+ strcpy (net->name, "eth%d");
编译kernel烧录后,发现设备注册为eth1了,而且还分配了IP地址,以太网显示连接上了,这时问题来了,系统将它识别成了正常的以太网口,但是它毕竟是摄像头不能连接外网,这样会导致WIFI和正常的以太网口无法使用,而且他们的App是要通过wifi或以太网来连接服务器的,还要通过eth1和camera通信采集数据的,那就是这个eth1只能是作为本地网络设备,通过网上查找双网口相关信息,找到了一个双网口相关的代码,eth0连接外网,eth1连接内网,编译固件烧录后,连接摄像头,客户App就可以正常使用了。
frameworks/opt/net/ethernet$ git diff
diff --git a/java/com/android/server/ethernet/EthernetTracker.java b/java/com/android/server/ethernet/EthernetTracker.java
index 1813812..fa166f1 100755
--- a/java/com/android/server/ethernet/EthernetTracker.java
+++ b/java/com/android/server/ethernet/EthernetTracker.java
@@ -78,6 +78,7 @@ final class EthernetTracker {
private final Handler mHandler;
private final EthernetNetworkFactory mFactory;
private final EthernetConfigStore mConfigStore;
+ private final EthernetNetworkFactoryExt mFactoryExt;
private final RemoteCallbackList<IEthernetServiceListener> mListeners =
new RemoteCallbackList<>();
@@ -107,6 +108,8 @@ final class EthernetTracker {
NetworkCapabilities nc = createNetworkCapabilities(true /* clear default capabilities */);
mFactory = new EthernetNetworkFactory(handler, context, nc);
mFactory.register();
+
+ mFactoryExt = new EthernetNetworkFactoryExt();
}
void start() {
@@ -126,6 +129,9 @@ final class EthernetTracker {
}
mHandler.post(this::trackAvailableInterfaces);
+
+ mFactoryExt.start(mContext, null);
+
}
void updateIpConfiguration(String iface, IpConfiguration ipConfiguration) {
@@ -228,7 +234,8 @@ final class EthernetTracker {
Log.d(TAG, "Started tracking interface " + iface);
mFactory.addInterface(iface, hwAddress, nc, ipConfiguration);
// Note: if the interface already has link (e.g., if we crashed and got
// restarted while it was running), we need to fake a link up notification so we
// start configuring it.
@@ -294,7 +301,14 @@ final class EthernetTracker {
if (DBG) {
Log.i(TAG, "interfaceLinkStateChanged, iface: " + iface + ", up: " + up);
}
- mHandler.post(() -> updateInterfaceState(iface, up));
+
+
+ if("eth0".equals(iface)){
+ mHandler.post(() -> updateInterfaceState(iface, up));
+ }else if("eth1".equals(iface)){
+ mHandler.post(() -> mFactoryExt.interfaceLinkStateChanged(iface, up));
+ }
+
/*int mm = Settings.System.getInt(mContext.getContentResolver(), Settings.System.IS_ETHERNET_ON,1);
if(up == true && mm == 1){
mHandler.post(() -> updateInterfaceState(iface, true));
@@ -309,12 +323,26 @@ final class EthernetTracker {
@Override
public void interfaceAdded(String iface) {
- mHandler.post(() -> maybeTrackInterface(iface));
+
+ Log.d(TAG, "interfaceAdded iface = " + iface);
+ if("eth1".equals(iface)){
+ mHandler.post(() -> mFactoryExt.interfaceAdded(iface));
+ }else{
+ mHandler.post(() -> maybeTrackInterface(iface));
+ }
+
}
@Override
public void interfaceRemoved(String iface) {
- mHandler.post(() -> removeInterface(iface));
+
+ Log.d(TAG, "interfaceRemoved iface = " + iface);
+ if("eth1".equals(iface)){
+ mHandler.post(() -> mFactoryExt.interfaceRemoved(iface));
+ }else{
+ mHandler.post(() -> removeInterface(iface));
+ }
+
}
}
源文件:
链接:
https://share.weiyun.com/XvKCWxga 密码:j7xcu2