Android车载以太网开发总结

1 以太网Framework配置
1.1 Common Configurations
In frameworks/base/core/res/res/values/config.xml, search networkAttributes, append the following line "ethernet,9,9,0,-1,true" , 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 ”9,1”, which is illustrated as below:
[ConnectivityManager connectionType],[simultaneous connection types]

For tethering, search config_tether_upstream_types,
Add 9

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//common/rootdir/etc/init..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.0.100 netmask 255.255.255.0 up
#ip route add 192.168.0.0/24 dev eth0 table local proto static scope link  ######## ​​​table名字:local

#ip route

Remove one route
#ip route del 192.168.0.1

2.2 默认网关的作用
syntax:
ip route add {NETWORK/MASK} via {GATEWAYIP}
ip route add {NETWORK/MASK} dev {DEVICE}
ip route add default {NETWORK/MASK} dev {DEVICE}
ip route add default {NETWORK/MASK} via {GATEWAYIP}

ip route add default via 192.168.0.1 dev eth0 table 1

ip rule add from 192.168.0.0/24 table 1
ip rule add to 192.168.0.0/24 table 1
table 1中包含了eth0默认网关,而table main中包含了正常的eth0路由。

2.3 基于Android ndc的静态IP配置
1)Enable dhcp on eth0
静态:
ifconfig eth0 192.168.0.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

ndc network create 100

3)add eth0 to the network
ndc network interface add eth0

ndc network interface add 100 eth0

4)Add a default gateway
ndc network route add eth0 0.0.0.0/0

ndc network route add 100 eth0 192.168.0.0/24

5)Setup dns (for domain I just use empty quotes: "")
ndc resolver setnetdns ...

ndc resolver setnetdns eth0 "" 8.8.8.8 192.168.0.1

6)Set as default network
ndc network default set

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 以太网当移动网络使用配置
4.1 基于HIDL的rild
1)rild支持多SIM卡
device.mk
SIM_COUNT := 2

service ril-daemon /vendor/bin/hw/rild
lshal |grep -i slot

2)framework支持多SIM卡
TelephonyProperties.java
persist.radio.multisim.config配置为dsds或者dsda或者tsts
ro.telephony.default_network配置为0

4.2 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相关的路由信息

hardware/ril/include/telephony/ril.h
RIL_Data_Call_Response_v6中的字段dnses或者gateways,可以传多个IP给Framework,用空格隔开。
例如:responses[i].dnses = "8.8.8.8 8.8.4.4"

4.3 APN配置文件
/system/etc/apns-conf.xml

5 Android以太网debug
5.1 3个网络使能函数
void setEthernetEnabled(boolean enabled); - 模仿Wifi自己添加
void setMobileDataEnabled(boolean enabled);
void setWifiEnabled(boolean enabled);

5.2 判断系统走哪个网络
1)
tcpdump -i eth0
ping xxxx

2)
tcpdump -i wlan0
ping xxxx

3)
tcpdump -i rmnet0
ping xxxx

5.3 netstat
查看所有进程打开的TCP连接
netstat -apnt

查看所有进程打开的UDP连接
netstat -apnu

5.4 ss
ss -tan state time-wait | wc -l

ss:Socket Statistics。ss的优势在于它能够显示更多更详细的有关TCP和连接状态的信息,而且比netstat更快速更高效。
ss快的秘诀在于,它利用到了TCP协议栈中tcp_diag。tcp_diag是一个用于分析统计的模块,可以获得Linux内核中第一手的信息,这就确保了ss的快捷高效。

5.5 Android netd ndc
adb shell ndc monitor

6 Abbreviations
6.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
PVID:Port default VID,PVID属于IEEE 802.1Q,不属于Port-based VLAN
RFC:Request for Comments,请求评论,包含了关于Internet的几乎所有重要的文字资料
SAP:BT SIM Access Profile for rild
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

6.2 Network Card
CS8900:Cirrus Logic
DM9000:Davicom
NE2000:Novell Ethernet

6.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:整形,在一个数据包发送之前进行适当的延迟,以免超过事先规定好的最大速率,这种处理叫做“整形”。整形在出对处进行。习惯上,通过丢包来降速也经常被称为整形。

你可能感兴趣的:(Network)