|
#!/system/bin/sh
|
|
#
|
|
# Copyright (C) 2017 Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
# Set SSID and password of your wifi access point
|
|
# WPA-Personal authentication method is assumed
|
|
SSID="yourSSID"
|
|
PASSWORD="yourPassword"
|
|
|
|
# OpenNIC DNS servers
|
|
DNS1="193.183.98.154"
|
|
DNS2="87.98.175.85"
|
|
|
|
|
|
# wpa_supplicant
|
|
workdir="/data/misc/wifi"
|
|
iface="wlan0"
|
|
socket="$workdir/sockets/"
|
|
pid="$workdir/pidfile"
|
|
|
|
wpa_comm="wpa_cli -p$socket -P$pid -i$iface"
|
|
|
|
sup_pid=$(pidof wpa_supplicant)
|
|
dhcp_pid=$(pidof dhcpcd)
|
|
|
|
if ! [ -z "$sup_pid" ]; then
|
|
killall -SIGINT wpa_supplicant
|
|
fi
|
|
|
|
if ! [ -z "$dhcp_pid" ]; then
|
|
killall -SIGINT dhcpcd
|
|
fi
|
|
|
|
sleep 1s
|
|
|
|
ndc network destroy 1
|
|
ndc interface clearaddrs "$iface"
|
|
|
|
wpa_supplicant -B -dd -i"$iface" -C"$socket" -P"$pid" -I/system/etc/wifi/wpa_supplicant_overlay.conf -e/data/misc/wifi/entropy.bin
|
|
|
|
sleep 1s
|
|
|
|
$wpa_comm add_network
|
|
$wpa_comm set_network 0 ssid '"'"$SSID"'"'
|
|
$wpa_comm set_network 0 psk '"'"$PASSWORD"'"'
|
|
$wpa_comm select_network 0
|
|
$wpa_comm enable_network 0
|
|
$wpa_comm reassociate
|
|
|
|
# negotiate a dhcp leasing
|
|
dhcpcd "$iface"
|
|
|
|
# get gateway
|
|
gateway=$(ip route show 0.0.0.0/0 dev wlan0 | cut -d\ -f3)
|
|
|
|
ndc network create 1
|
|
ndc network interface add 1 "$iface"
|
|
ndc network route add 1 "$iface" 0.0.0.0/0 "$gateway"
|
|
ndc resolver setnetdns 1 "" "$DNS1" "$DNS2"
|
|
ndc network default set 1
|