A working DHCPCD Hook system
2016-04-04 09:32
459 查看
原文链接:http://forum.xda-developers.com/showthread.php?t=1392343
if you like to play around with the shell on Android, it might come in handy to have some proper hooks for
the wifi and dhcp. By default (in custom roms anyway), we have hooks for dhcp. However this does not invoke anything on the dhcp state "STOP". Also there are no hooks for when wifi is turned on, only when dhcp configurations are made to it. Which means that
you cannot invoke hooks when turning on/off wifi tethering.
Personally I have an SSHd and SMBd running in the background. These exists as android apps, but I preferer not having android classes running in the background
for a such simple task. Specially when I always have these running on wifi. And both SSHd and SMBd works locally on wifi tethering, which is why this hook is a good tool to have.
Also on regular wifi with dhcp, it would be great to have these turn off when wifi connection is off.
The below code will provide these missing features by using some small property hacks in the init.<device>.rc file.
init.<device>.rc
Code:
/system/etc/dhcpcd/dhcpcd-hook
Code:
/system/etc/dhcpcd/dhcpcd.d/01-configure
Code:
/system/etc/wifi/wifi-hook
Code:
if you like to play around with the shell on Android, it might come in handy to have some proper hooks for
the wifi and dhcp. By default (in custom roms anyway), we have hooks for dhcp. However this does not invoke anything on the dhcp state "STOP". Also there are no hooks for when wifi is turned on, only when dhcp configurations are made to it. Which means that
you cannot invoke hooks when turning on/off wifi tethering.
Personally I have an SSHd and SMBd running in the background. These exists as android apps, but I preferer not having android classes running in the background
for a such simple task. Specially when I always have these running on wifi. And both SSHd and SMBd works locally on wifi tethering, which is why this hook is a good tool to have.
Also on regular wifi with dhcp, it would be great to have these turn off when wifi connection is off.
The below code will provide these missing features by using some small property hacks in the init.<device>.rc file.
init.<device>.rc
Code:
# This provides the missing 'STOP' state invoke in dhcpcd on property:init.svc.dhcpcd_eth0=stopped restart dhcpcdstate # This provides the wifi on/off hook invoke on property:wlan.driver.status=* restart wifistate service dhcpcdstate /system/etc/dhcpcd/dhcpcd-hook STOP eth0 disabled oneshot service wifistate /system/etc/wifi/wifi-hook eth0 disabled oneshot # ------------------------------------ # The below should be changed according to your device. # The important thing here is the path to --config and --script service dhcpcd_eth0 /system/bin/dhcpcd -ABKL --config /system/etc/dhcpcd/dhcpcd.conf --script /system/etc/dhcpcd/dhcpcd-hook class main disabled oneshot service iprenew_eth0 /system/bin/dhcpcd -n --config /system/etc/dhcpcd/dhcpcd.conf --script /system/etc/dhcpcd/dhcpcd-hook class main disabled oneshot
/system/etc/dhcpcd/dhcpcd-hook
Code:
#!/system/bin/sh if [ -z "${reason}" ] || -z "${interface}"; then reason="$1" interface="$2" fi for i in /system/etc/dhcpcd/dhcpcd.d/*; do if [ -f $i ] || [ -L $i ]; then . "$i" fi done
/system/etc/dhcpcd/dhcpcd.d/01-configure
Code:
case "${reason}" in BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) setprop dhcp.${interface}.ipaddress "${new_ip_address}" setprop dhcp.${interface}.gateway "${new_routers%% *}" setprop dhcp.${interface}.mask "${new_subnet_mask}" setprop dhcp.${interface}.leasetime "${new_dhcp_lease_time}" setprop dhcp.${interface}.server "${new_dhcp_server_identifier}" setprop dhcp.${interface}.ndns "${new_domain_name_servers}" setprop dhcp.${interface}.reason "${reason}" setprop dhcp.${interface}.result "ok" if [ ! -z "${new_domain_name_servers}" ]; then for i in 1 2 3 4; do setprop dhcp.${interface}.dns$i "" done count=1 for dnsaddr in "${new_domain_name_servers}"; do setprop dhcp.${interface}.dns$count $dnsaddr count=$(($count + 1)) done fi ;; EXPIRE|FAIL|IPV4LL|RELEASE|STOP) setprop dhcp.${interface}.result "failed" for i in 1 2 3 4; do setprop dhcp.${interface}.dns$i "" done ;; RELEASE) setprop dhcp.${interface}.result "released" ;; esac
/system/etc/wifi/wifi-hook
Code:
#!/system/bin/sh status=`getprop wlan.driver.status` interface="$1" for i in /system/etc/wifi/wifi.d/*; do if [ -f $i ] || [ -L $i ]; then . "$i" fi done
相关文章推荐
- 非侵入式
- linux下创建库函数
- android中horizontal和vertical的区别
- MySQL 学习笔记(2)2016-04-04
- View.inflate和LayoutInflater的inflate方法区别
- 包装类怎么参与运算的
- 内购
- [转]Flex 布局教程:语法篇
- 2016中山市邀请赛
- LayoutTransition(布局容器动画)
- swift可选类型
- CodeForces - 659B Qualifying Contest (模拟)水
- C# 读取EXCEL文件的三种经典方法
- 8种基本数据类型和运算(隐式转换和强制转换)
- MySQL 学习笔记(1)2016-04-02
- python 实现类似tweproxy 和codes的功能的redis代理功能
- PHP微信表白墙重构(一)概述
- jquery给h1和span赋值
- 【java集合框架源码剖析系列】java源码剖析之TreeMap
- 【java集合框架源码剖析系列】java源码剖析之TreeMap