1
|
#!/system/bin/sh
|
2
|
#
|
3
|
# Copyright (C) 2017 Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>
|
4
|
#
|
5
|
# This program is free software: you can redistribute it and/or modify
|
6
|
# it under the terms of the GNU General Public License as published by
|
7
|
# the Free Software Foundation, either version 3 of the License, or
|
8
|
# (at your option) any later version.
|
9
|
#
|
10
|
# This program is distributed in the hope that it will be useful,
|
11
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
# GNU General Public License for more details.
|
14
|
#
|
15
|
# You should have received a copy of the GNU General Public License
|
16
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
|
18
|
|
19
|
# Set SSID and password of your wifi access point
|
20
|
# WPA-Personal authentication method is assumed
|
21
|
SSID="yourSSID"
|
22
|
PASSWORD="yourPassword"
|
23
|
|
24
|
# OpenNIC DNS servers
|
25
|
DNS1="193.183.98.154"
|
26
|
DNS2="87.98.175.85"
|
27
|
|
28
|
|
29
|
# wpa_supplicant
|
30
|
workdir="/data/misc/wifi"
|
31
|
iface="wlan0"
|
32
|
socket="$workdir/sockets/"
|
33
|
pid="$workdir/pidfile"
|
34
|
|
35
|
wpa_comm="wpa_cli -p$socket -P$pid -i$iface"
|
36
|
|
37
|
sup_pid=$(pidof wpa_supplicant)
|
38
|
dhcp_pid=$(pidof dhcpcd)
|
39
|
|
40
|
if ! [ -z "$sup_pid" ]; then
|
41
|
killall -SIGINT wpa_supplicant
|
42
|
fi
|
43
|
|
44
|
if ! [ -z "$dhcp_pid" ]; then
|
45
|
killall -SIGINT dhcpcd
|
46
|
fi
|
47
|
|
48
|
sleep 1s
|
49
|
|
50
|
ndc network destroy 1
|
51
|
ndc interface clearaddrs "$iface"
|
52
|
|
53
|
wpa_supplicant -B -dd -i"$iface" -C"$socket" -P"$pid" -I/system/etc/wifi/wpa_supplicant_overlay.conf -e/data/misc/wifi/entropy.bin
|
54
|
|
55
|
sleep 1s
|
56
|
|
57
|
$wpa_comm add_network
|
58
|
$wpa_comm set_network 0 ssid '"'"$SSID"'"'
|
59
|
$wpa_comm set_network 0 psk '"'"$PASSWORD"'"'
|
60
|
$wpa_comm select_network 0
|
61
|
$wpa_comm enable_network 0
|
62
|
$wpa_comm reassociate
|
63
|
|
64
|
# negotiate a dhcp leasing
|
65
|
dhcpcd "$iface"
|
66
|
|
67
|
# get gateway
|
68
|
gateway=$(ip route show 0.0.0.0/0 dev wlan0 | cut -d\ -f3)
|
69
|
|
70
|
ndc network create 1
|
71
|
ndc network interface add 1 "$iface"
|
72
|
ndc network route add 1 "$iface" 0.0.0.0/0 "$gateway"
|
73
|
ndc resolver setnetdns 1 "" "$DNS1" "$DNS2"
|
74
|
ndc network default set 1
|