Android车联网TCU开发总结

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_<ifname>,而是采用DhcpClient.java发送dhcpcd协议的UDP包直接请求IP地址,同时使用一个状态机IpManager.java来管理dhcpcd是成功还是失败。

config_ethernet_iface_regex = (eth|ueth)\\d or ueth\\d

静态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 Android静态IP配置
ifconfig eth0 192.168.0.100 netmask 255.255.255.0 up
ip route add default via 192.168.0.1 dev eth0 table main

# 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 all lookup main pref 9999
# 上一条命令等价于在netd中添加modifyIpRule(RTM_NEWRULE, 9999, 254, 0, 0);
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 <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.0.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.0.1

6)Set <netid> as default network
ndc network default set <netid>
# 这条命令的作用参考本文3.2的4)。
ndc network default set 100

2.4 网络脚本sepolicy
allowxperm wificond self:udp_socket ioctl { SIOCSIFFLAGS };

3 Android路由表操作
3.1 查看路由表
1)Android支持255个路由表
我们自己添加了一个0,254,255之外的路由表之后,这个路由表是不会正常工作的,路由表只是数据库,查不查询,怎么查询是由路由策略决定的。自己添加了路由表之后要想让这个路由表被查询,需要添加一个对应的路由策略。默认的路由策略都是lookup,就是我们通常意义的查询行为。
ip route list table [ID]
0 - 显示全部表
253 - default
254 - main
255 - local

2)例子
ip route list table 255
or
ip route list table local

3.2 多张路由table遍历优先级的查看方式
1)ip rule list
返回的字符串中最前面的数字表示优先级,数字越小优先级越高;lookup后的字符串就是table名字。

2)新建一个路由table
ip rule add from all table ${ID} prio ${PRIO}
ID:table号index,必须是数字
PRIO:优先级index,必须是数字

3)修改ip rule后若需立刻生效,需要执行如下命令
ip route flush cache

4)Android默认gateway
Android Framework激活一个网络后,会用网络的名字(wlan0或者eth0)创建一个ip rule(kernel函数fib_nl_newrule)作为default gateway,优先级等于22000(RULE_PRIORITY_DEFAULT_NETWORK,参考netd),当目的IP不是局域网地址,并且对下面的三个表做LPM(最长匹配,Longest Prefix Match)后,仍旧不匹配,会使用这个表(kernel函数fib_select_default)。

ip route list table default
ip route list table main
ip route list table local

可以用如下的方式查看优先级是22000的那个ip rule。
ip route list table eth0
ip route list table wlan0

3.3 VLAN show case
ip link add link eth0 name vlan50 type vlan id 50
ip -d link show vlan50
ifconfig vlan50 192.168.5.200/24 up

ip route ACTION SELECTOR
ip route get 192.168.5.5
ip link delete vlan50

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

China Unicom: 3gnet
China Mobile: cmnet
China Telecom: ctnet

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

5.2 Android netd ndc
adb shell ndc monitor

5.3 dropwatch
CONFIG_NET_DROP_MONITOR=m
echo 0 > /proc/sys/kernel/kptr_restrict

libncurses.a (new curses) for Android
https://github.com/CyanogenMod/android_external_libncurses

libhistory.a and libreadline.a for Android
https://github.com/LineageOS/android_external_bash

libnl.a
external/libnl
libpcap.a
external/libpcap

dropwatch
https://github.com/nhorman/dropwatch

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

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

5.5 ss
ss -4tu0
ss -tan state time-wait | wc -l

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

6 Wireshark SOMEIP plugin
6.1 插件安装
https://github.com/jamores/eth-ws-someip
Wireshark插件目录:Help -> About Wireshark -> Folders/Plugins
解压后,将所有后缀是lua的文件拷贝到Wireshark安装目录plugins/2.4.10/下。
Wireshark 3.2 has builtin SOME/IP plugin.

6.2 时间戳调整为UTC显示格式
View -> Time Display Format -> Date and Time of Day

6.3 常用过滤关键字
Wireshark解析MAC地址时会把前三个字节解析为一个公司的名字。
1)someip
2)ip.src == 192.168.1.1 - 改到对应的ip地址
3)ip.src == 192.168.1.1 and ip.dst == 192.168.1.2 - 改到对应的ip地址
4)someip.messageid == 0xffff8100 and ip.src == 192.168.1.2 - 改到对应的ip地址
5)dns - 调试域名解析
6)tcp.port == 8000
7)!(tcp.analysis.retransmission)
8)tcp.flags.syn==1 or tcp.flags.ack==0
9)tcp.flags.fin == 1
10)usb.src == "1.6.1" and usb.dst == "host" - 改到对应的USB bus_no.addr.ep_no
11)OFFER_SERVICE
12)FIND_SERVICE
13)SUBSCRIBE

6.4 SOMEIP TCP连接心跳包
SOMEIP TCP连接心跳包(4个字节):0x dead beef

6.5 tcpdump抓到的log循环写
tcpdump -X -i eth0 -s 0 -C 20 -W 3 -w /data/eth_sniff.pcap -Z root
-i:设备名
-s:过滤包大小限制
-C:定义生成文件大小,兆(Mega Bytes)为单位,取整数
-W:可生成多少个文件
-w:指定生成文件的路径
-Z:用户组,user或者root;Linux如果想循环写文件,此选项必须有,Android不需要

6.6 Wireshark安装目录下的2个工具
1) editcap
2) mergecap

7 Abbreviations
7.1 General
ADASIS:Advanced Driver Assistant Systems Interface Specifications
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
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
eno1:Ethernet Onboard
ETS:TC8 Enhanced Testability Service
FIB:Forward Information Base,fib_lookup
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
Jumbo frame: Jumbo frame (9000 bytes) was raised by Alteon Networks in 1998.
LDS:Link Discovery Signal
LRE:Long Range Ethernet,长距离以太网
MOST环:Media Oriented System Transport,车载面向媒体的系统传输总线
mt2731: TBOX芯片平台
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
SOME/IP:Scalable service-Oriented Middleware over IP,德国Vector公司提供SOME/IP协议栈的私有实现
TC8:Technical Committees 8,车载以太网测试规范
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的软件实现

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:组播方案

  • 5
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值