1 以太网Framework配置
1.1 Common Configurations
In frameworks/base/core/res/res/values/config.xml, search networkAttributes, append the following line <item>"ethernet,9,9,0,-1,true"</item> , which is illustrated as below:
[Connection name],
[ConnectivityManager.TYPE_xxxx],
[associated radio-type],
[priority],
[restoral-timer(ms)],
[dependencyMet]
Then search radioAttributes, append the following line <item>”9,1”</item>, which is illustrated as below:
[ConnectivityManager connectionType],[simultaneous connection types]
For tethering, search config_tether_upstream_types,
Add <item>9</item>
In Android, EthernetNetworkFactory.java can be found under frameworks/opt/net/ethernet/java/com/android/server/ethernet/, please add logs in this file when debug android ethernet function.
Add Ethernet feature under device/qcom/msm8xxx/msm8xxx.mk as shown below:
PRODUCT_COPY_FILES += \
frameworks/native/data/etc/android.hardware.ethernet.xml:system/etc/permissions/android.hardware.ethernet.xml
1.2 Android N之前请求IP地址的方式
Add two services device/<OEM>/common/rootdir/etc/init.<OEM>.rc like as below:
service dhcpcd_eth0 /system/bin/dhcpcd -ABKL
class main
disabled
oneshot
service iprenew_eth0 /system/bin/dhcpcd -n
class main
disabled
oneshot
1.3 Android N后新的IP地址请求机制
Android N后抛弃了init.rc中的service dhcpcd_INTFx,而是采用DhcpClient.java发送dhcpcd协议的UDP包直接请求IP地址,同时使用一个状态机IpManager.java来管理dhcpcd是成功还是失败。
config_ethernet_iface_regex
静态IP地址配置:
@ EthernetConfigStore.java
/data/misc/ethernet/ipconfig.txt
调试手段:
1)参考如下网址的代码生成配置文件/data/misc/ethernet/ipconfig.txt
Android以太网固定ip
https://www.jianshu.com/p/e1191c41d70a
2)使用静态IP时,如果发现以太网NetworkInfo不更新,就需要调用方法updateAgent()进行更新
3)以太网模块编译后生成jar包:ethernet-service.jar
4)可以使用如下的命令来查看以太网当前的工作状态
adb shell dumpsys ethernet
2 IP地址配置
2.1 兼容PC Linux的Android静态IP配置
$su
#ifconfig eth0 192.168.1.22 netmask 255.255.255.0 up
#ip route add 192.168.1.X/24 dev eth0 table local proto static scope link ######## table名字:local
#ip route
Remove one route
#ip route del 192.168.1.1
2.2 IP地址配置到main路由表中
ip route add 192.168.1.0/24 via 192.168.0.100 table main
ip route list table main
2.3 基于Android ndc的静态IP配置
1)Enable dhcp on eth0
静态:
ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
动态打开:
dhcpcd eth0
动态关闭:
ifconfig eth0 down
2)Create a netid. Try one until it succeeds I can use 100.
ndc network create <netid>
ndc network create 100
3)add eth0 to the network
ndc network interface add <netid> eth0
ndc network interface add 100 eth0
4)Add a default gateway
ndc network route add <netid> eth0 0.0.0.0/0
ndc network route add 100 eth0 192.168.1.0/24
5)Setup dns (for domain I just use empty quotes: "")
ndc resolver setnetdns <netid> <domain> <dns1> <dns2> ...
ndc resolver setnetdns eth0 "" 8.8.8.8 192.168.1.1
6)Set <netid> as default network
ndc network default set <netid>
ndc network default set 100
2.4 网络脚本sepolicy
allowxperm wificond self:udp_socket ioctl { SIOCSIFFLAGS };
3 Android路由表操作
3.1 查看路由表
ip route是设置静态路由用的,后面第一个ip地址和掩码表示源地址,第二个ip地址表示下一跳路由器的ip地址。
Android支持255个路由表。
ip route list table [ID]
0 - 显示全部表
253 - default
254 - main
255 - local
例子:
ip route list table 255
or
ip route list table local
3.2 多张路由table遍历优先级的查看方式
ip rule list
返回的字符串中最前面的数字表示优先级,数字越小优先级越高;lookup后的字符串就是table名字
新建一个路由table:
ip rule add from all table ${ID} prio ${PRIO}
ID:table号index,必须是数字
PRIO:优先级index,必须是数字
修改ip rule后若需立刻生效,需要执行如下命令:
ip route flush cache
4 Android多网络并发机制
4.1 多网络时路由查找配置
1)首先添加一main lookup规则
ip rule add from all lookup main pref 9999
2)使用ip route命令检查,确保所有网络在main表中都配置了路由
3)使用ip ru(ip rule)确保规则中包含了local和main查找表
4)查找时,先在local lookup中查找,找不到,进入下一步
5)在main lookup中查找,找到了路由
比如说有192.168.1.0/24这样的条目,FIB把IP包的目标地址192.168.1.X & 255.255.255.0等于192.168.1.0。所以hit(命中)这条路由。
4.2 Android网络打分处理 - 优先级
使用命令dumpsys connectivity查看激活的网络和该网络的得分。
5 以太网当移动网络使用配置
5.1 TBOX使用静态IP的eth0模拟成rmnet0
RIL_REQUEST_SETUP_DATA_CALL - 成功后,rild返回已经设置好的IP、DNS和GW给framework,当成是静态分配的IP地址即可,后面由framework把这些数据发送给netd配置路由
RIL_REQUEST_DEACTIVATE_DATA_CALL - 成功后,framework会发送命令到netd,删除与eth0相关的路由信息
5.2 URLs
Android7.0 数据业务长连接拨号过程
https://m.2cto.com/kf/201609/544624.html?from=singlemessage
Android——4.2 - 3G移植之路之 reference-ril .pppd 拨号上网 (三)
https://blog.csdn.net/bzw073/article/details/42212025
6 Android以太网debug
6.1 3个网络使能函数
void setEthernetEnabled(boolean enabled); - 模仿Wifi自己添加
void setMobileDataEnabled(boolean enabled);
void setWifiEnabled(boolean enabled);
6.2 判断系统走哪个网络
1)
tcpdump -i eth0
ping xxxx
2)
tcpdump -i wlan0
ping xxxx
3)
tcpdump -i rmnet0
ping xxxx
6.3 netstat
查看所有进程打开的TCP连接
netstat -apnt
查看所有进程打开的UDP连接
netstat -apnu
6.4 Android netd ndc
adb shell ndc monitor
7 Abbreviations
7.1 General
ADASIS:Advanced Driver Assistant Systems Interface Specifications
ARC:Argonant RISC Core
ARL:Address Resolution Logic table,地址解析逻辑,交换机Switch中可以配置MAC地址过滤等
ARP:Address Resolution Protocol,是根据IP地址获取MAC地址的一个TCP/IP协议
BOM:Byte Order Mark,指定SOME/IP字符串编码类型
BR Cable:BroadR-Reach,车载以太网线缆
CANoe:CAN open environment
CC2530:TI ChipCon2530
config_tether_upstream_types:Android手机配置为ApCli(AP-Client)时,作为Client的一方
config_tether_usb_regexs:regular expressions,正则表达式
DMS:Driver Monitoring System,疲劳驾驶监控,使用GHS INTEGRITY RTOS系统,通过车载以太网通信(PHY工作在Master模式,连接时,会主动和Slave PHY进行链路训练),法国Valeo提供方案
DoIP:Diagnostic over IP
DWC2:Design Ware Controller 2,Apple的嵌入式设备,包括iPad和iPhone都是使用的DWC2
eno1:Ethernet Onboard
ETS:TC8 Enhanced Testability Service
FIB:Forward Information Base,fib_lookup
FPDLINK/GMSL:Flat Plane Display Link,用于360度全景(AVM)
Franca IDL:Franca Interface Definition Language,developed by GENIVI
GHS:Green Hills Software,提供GHS hypervisor(类似于QNX hypervisor)、仪表专用RTOS、MCU开发IDE
IAR:后两个字母取之于创始人名字Anders Rundgren的首字母,瑞典语Ingenjörsfirman Anders Rundgren,意为Anders Rundgren工程公司
igb_avb:Intel Gigabit Audio Video Bridging
IOP:TC8 Interoperability
ISP1161:Philips' Integrated host Solution Pairs 1161,“Firms introduce USB host controllers”,https://www.eetimes.com/document.asp?doc_id=1290054
jumbo frames:巨型帧,又称大型帧,是指有效负载超过IEEE 802.3标准所限制的1500字节的以太网帧
LDS:Link Discovery Signal
LRE:Long Range Ethernet,长距离以太网
MOST环:Media Oriented System Transport,车载面向媒体的系统传输总线
multicast:有人翻译成组播,有人翻译成多播,一个意思
ndc:Native Daemon Connector
PING:Packet Internet Groper
PMA:TC8 Physical Medium Attachment - SerDes眼图测试
PoDL:Power over Data Lines
RFC:Request for Comments,请求评论,包含了关于Internet的几乎所有重要的文字资料
SL811HS:Cypress/ScanLogic 811 Host/Slave,性能上与ISP1161(Integrated host Solution Pairs 1161)相当
SOME/IP:Scalable service-Oriented Middleware over IP,德国Vector公司提供SOME/IP协议栈的私有实现
TC8:Technical Committees 8,车载以太网测试规范
TDI:TransDimension Inc.,该公司首先发明了将TT集成到EHCI RootHub中的方法,这样对于嵌入式系统来说,就省去了OHCI/UHCI的硬件,同时降低了成本,作为对该公司的纪念,Linux内核定义了宏ehci_is_TDI(ehci);产品UHC124表示USB Host Controller;收购了ARC USB技术;现已被chipidea收购,chipidea又被mips收购
TLV:TI Low Value,高性价比
TPS:TI Performance Solution
TT:Transaction Translator(事务转换器,将USB2.0的包转换成USB1.1的包)
USB BH reset:Bigger Hammer or Brad Hosler,表示warm reset;you may be confused why the USB 3.0 spec calls the same type of reset "warm reset" in some places and "BH reset" in other places. "BH" reset is supposed to stand for "Big Hammer" reset, but it also stands for "Brad Hosler". Brad died shortly after the USB 3.0 bus specification was started, and they decided to name the reset after him. The suggestion was made shortly before the spec was finalized, so the wording is a bit inconsistent.
vsomeip:GENIVI对SOME/IP的软件实现
主机厂:OEMs
7.2 Network Card
CS8900:Cirrus Logic
DM9000:Davicom
NE2000:Novell Ethernet
7.3 TCP/IP专业术语
TSO:TCP segmentation offload
UFO:UDP fragmentation offload
GSO:generic segmentation offload
GRO:generic receive offload
QDisc:Queueing Disciplines,长度有txqueuelen控制
multicast scheme:组播方案
Shaping:整形,在一个数据包发送之前进行适当的延迟,以免超过事先规定好的最大速率,这种处理叫做“整形”。整形在出对处进行。习惯上,通过丢包来降速也经常被称为整形。
来源:CSDN
作者:George-seu
链接:https://blog.csdn.net/zoosenpin/article/details/81902007