1、OS:Linux3.18 + Android4.4
问题点: 开发板已经接入4G模块,可以正常上网,现在要通过开启Wifi热点共享网络,在设置里开启AP模式时,wifi一直在不停的开关,不能打开热点。
原本不加4G模块,ap功能是正常的,添加后不能用,以为是4g模块和wifi驱动冲突,看kernel和logcat,一点点找,iptables这部分存在问题。
具体的natcontroller功能及runcmd功能列表看Android系统中iptables的应用(三)NatController,
这时候看logcat
09-18 09:49:02.853 D/Tethering( 2130): TetheredState.processMessage what=12
09-18 09:49:02.853 V/NatController( 1429): enableNat(intIface=<wlan0>, extIface=<usb0>)
09-18 09:49:02.863 D/MobileDataStateTracker( 2130): hipri: Broadcast received: android.intent.action.ANY_DATA_STATE apnType=hipri
09-18 09:49:02.863 D/MobileDataStateTracker( 2130): hipri: Received state=DISCONNECTED, old=CONNECTED, reason=dataDisabled
09-18 09:49:02.863 D/MobileDataStateTracker( 2130): hipri: setDetailed state, old =CONNECTED and new state=DISCONNECTED
09-18 09:49:02.863 D/ConnectivityService( 2130): ConnectivityChange for mobile_hipri: DISCONNECTED/DISCONNECTED
09-18 09:49:02.913 V/NatController( 1429): runCmd(/system/bin/ip route flush cache) res=0
09-18 09:49:02.923 V/NatController( 1429): runCmd(/system/bin/iptables -t nat -A natctrl_nat_POSTROUTING -o usb0 -j MASQUERADE) res=3
09-18 09:49:02.923 E/NatController( 1429): Error seting postroute rule: iface=usb0
09-18 09:49:02.933 D/dalvikvm( 2130): GC_CONCURRENT freed 773K, 15% free 6215K/7236K, paused 4ms+9ms, total 61ms
09-18 09:49:02.973 V/NatController( 1429): runCmd(/system/bin/ip route flush cache) res=0
09-18 09:49:02.993 V/NatController( 1429): runCmd(/system/bin/iptables -F natctrl_FORWARD) res=0
09-18 09:49:02.993 V/NatController( 1429): runCmd(/system/bin/iptables -A natctrl_FORWARD -j DROP) res=0
09-18 09:49:03.003 V/NatController( 1429): runCmd(/system/bin/iptables -t nat -F natctrl_nat_POSTROUTING) res=3
09-18 09:49:03.003 E/Tethering( 2130): Exception enabling Nat: java.lang.IllegalStateException: command '129 nat enable wlan0 usb0 2 fe80::/64 192.168.43.0/24' failed with '400 129 Nat operation failed (Cannot assign requested address)'
09-18 09:49:03.023 D/TetherController( 1429): untetherInterface(wlan0)
09-18 09:49:03.033 D/BluetoothAdapter( 2651): 1099669424: getState() : mService = null. Returning STATE_OFF
在runCmd(/system/bin/iptables -t nat -A natctrl_nat_POSTROUTING -o usb0 -j MASQUERADE) res=3这行已经错误,正常res=0,尝试在开发板串口输入
iptables -t nat -A natctrl_nat_POSTROUTING -o usb0 -j MASQUERADE
会出现
iptables v1.4.11.1: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
这时候已经明白原因,Linux内核没有添加nat模块,在内核添加nat后,ap热点可以正常使用。
2、OS:Linux4.14 + Android9
10-18 14:06:16.770 1721 2571 D unicore_gps: nmea parse(pos=91,f=00): $GYOACC,,,0.004634,-0.000892,0.000872,100,-0.000168,6.745954,-7.517619,100,35,-200,100,1*22
10-18 14:06:16.789 1638 1683 W IptablesRestoreController: iptables-restore process 9347 terminated status=256
10-18 14:06:16.789 1638 1683 E IptablesRestoreController: iptables error:
10-18 14:06:16.789 1638 1683 E IptablesRestoreController: ------- COMMAND -------
10-18 14:06:16.789 1638 1683 E IptablesRestoreController: *raw
10-18 14:06:16.789 1638 1683 E IptablesRestoreController: -D tetherctrl_raw_PREROUTING -p tcp --dport 21 -i wlan0 -j CT --helper ftp
10-18 14:06:16.789 1638 1683 E IptablesRestoreController: COMMIT
10-18 14:06:16.789 1638 1683 E IptablesRestoreController: *filter
10-18 14:06:16.789 1638 1683 E IptablesRestoreController: -D tetherctrl_FORWARD -i tbox0 -o wlan0 -m state --state ESTABLISHED,RELATED -g tetherctrl_counters
10-18 14:06:16.789 1638 1683 E IptablesRestoreController: -D tetherctrl_FORWARD -i wlan0 -o tbox0 -m state --state INVALID -j DROP
10-18 14:06:16.789 1638 1683 E IptablesRestoreController: -D tetherctrl_FORWARD -i wlan0 -o tbox0 -g tetherctrl_counters
10-18 14:06:16.789 1638 1683 E IptablesRestoreController: COMMIT
10-18 14:06:16.789 1638 1683 E IptablesRestoreController:
10-18 14:06:16.789 1638 1683 E IptablesRestoreController: ------- ERROR -------
10-18 14:06:16.789 1638 1683 E IptablesRestoreController: iptables-restore: line 2 failed
10-18 14:06:16.789 1638 1683 E IptablesRestoreController: ----------------------
10-18 14:06:16.789 1638 1683 E TetherController: Error setting forward rules
10-18 14:06:16.802 1721 2571 D unicore_gps: nmea parse(pos=19,f=00): $SNRSTAT,1,1,0,0*5D
10-18 14:06:16.804 1721 2571 D unicore_gps: nmea parse(pos=56,f=00): $NOTICE,1,,,,-1999,0.0000,1,0001,00,0002,0010,0000,67*0E
10-18 14:06:16.805 1721 2571 D unicore_gps: nmea parse(pos=25,f=00): $GNRMC,,V,,,,,,,,,,N,V*37
10-18 14:06:16.813 1721 2571 D unicore_gps: __check_rnss_mode:3268
10-18 14:06:16.813 1721 2571 D unicore_gps: init_cmds 12
10-18 14:06:16.813 1721 2571 D unicore_gps: Get chip config
10-18 14:06:16.813 1721 2571 D unicore_gps: function gps_dev_send: $PDTINFO
10-18 14:06:16.816 1721 2571 D unicore_gps: function gps_dev_send: $CFGPRT
10-18 14:06:16.824 2009 2069 E Tethering: [wlan0] ERROR Exception enabling NAT: java.lang.IllegalStateException: command '353 nat enable wlan0 tbox0 1 192.168.43.0/24' failed with '400 353 Nat operation failed (No such device)'
在内核的配置文件中添加CONFIG_NETFILTER_XT_TARGET_CT=y
[All] - Android 9 - Can't enable wifi tethering · Issue #228 · sonyxperiadev/bug_tracker · GitHub