Skip to content

Commit

Permalink
Network config web ui and fallback wifi hotspot (EliasKotlyar#1655)
Browse files Browse the repository at this point in the history
  • Loading branch information
xdissent authored Dec 22, 2020
1 parent 43d73c3 commit e7c84dd
Show file tree
Hide file tree
Showing 10 changed files with 480 additions and 46 deletions.
14 changes: 14 additions & 0 deletions firmware_mod/config/hostapd.conf.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
interface=wlan0
ctrl_interface=/var/run/hostapd
channel=6
driver=nl80211
beacon_int=100
hw_mode=g
wme_enabled=1
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
max_num_sta=8
wpa_group_rekey=86400
ssid=dafang
wpa=2
wpa_passphrase=ismart12
6 changes: 6 additions & 0 deletions firmware_mod/config/udhcpd.conf.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
start 10.0.0.2
end 10.0.0.10
interface wlan0
lease_file /tmp/udhcpd.leases
option router 10.0.0.1
option subnet 255.0.0.0
2 changes: 2 additions & 0 deletions firmware_mod/config/wifi.conf.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connect_timeout=60
scan_interval=30
45 changes: 11 additions & 34 deletions firmware_mod/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,18 @@ if [ -f $CONFIGPATH/usb_eth_driver.conf ]; then
insmod /system/sdcard/driver/usbnet.ko
insmod /system/sdcard/driver/asix.ko

network_interface_name="eth0"
## Configure network address
if [ -f "$CONFIGPATH/staticip.conf" ]; then
configure_static_net_iface eth0 >> $LOGPATH
else
# Configure with DHCP client
ifconfig eth0 up
udhcpc_status=$(udhcpc -i eth0 -p /var/run/udhcpc.eth0.pid -b -x hostname:"$(hostname)")
echo "udhcpc: $udhcpc_status" >> $LOGPATH
fi
else
## Start Wifi:
if [ ! -f $CONFIGPATH/wpa_supplicant.conf ]; then
echo "Warning: You have to configure wpa_supplicant in order to use wifi. Please see /system/sdcard/config/wpa_supplicant.conf.dist for further instructions."
fi
MAC=$(grep MAC < /params/config/.product_config | cut -c16-27 | sed 's/\(..\)/\1:/g;s/:$//')
MAC=$(get_wifi_mac)
if [ -f /driver/8189es.ko ]; then
# Its a DaFang
insmod /driver/8189es.ko rtw_initmac="$MAC"
Expand All @@ -138,35 +143,7 @@ else
# Its a Wyzecam V2
insmod /driver/rtl8189ftv.ko rtw_initmac="$MAC"
fi
wpa_supplicant_status="$(wpa_supplicant -d -B -i wlan0 -c $CONFIGPATH/wpa_supplicant.conf -P /var/run/wpa_supplicant.pid)"
echo "wpa_supplicant: $wpa_supplicant_status" >> $LOGPATH

network_interface_name="wlan0"
fi

## Configure network address
if [ -f "$CONFIGPATH/staticip.conf" ]; then
# Install a resolv.conf if present so DNS can work
if [ -f "$CONFIGPATH/resolv.conf" ]; then
cp "$CONFIGPATH/resolv.conf" /etc/resolv.conf
fi

# Configure staticip/netmask from config/staticip.conf
staticip_and_netmask=$(cat "$CONFIGPATH/staticip.conf" | grep -v "^$" | grep -v "^#")
ifconfig "$network_interface_name" $staticip_and_netmask
ifconfig "$network_interface_name" up
# Configure default gateway
if [ -f "$CONFIGPATH/defaultgw.conf" ]; then
defaultgw=$(cat "$CONFIGPATH/defaultgw.conf" | grep -v "^$" | grep -v "^#")
route add default gw $defaultgw $network_interface_name
echo "Configured $defaultgw as default gateway" >> $LOGPATH
fi
echo "Configured $network_interface_name with static address $staticip_and_netmask" >> $LOGPATH
else
# Configure with DHCP client
ifconfig "$network_interface_name" up
udhcpc_status=$(udhcpc -i "$network_interface_name" -p /var/run/udhcpc.pid -b -x hostname:"$(hostname)")
echo "udhcpc: $udhcpc_status" >> $LOGPATH
/system/sdcard/scripts/wifi.sh start >> $LOGPATH
fi

## Set Timezone
Expand Down
46 changes: 46 additions & 0 deletions firmware_mod/scripts/common_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -832,3 +832,49 @@ getFonts() {
echo -n ">`/system/sdcard/bin/busybox basename $i` </option>"
done
}

get_wifi_mac() {
grep MAC < /params/config/.product_config | cut -c16-27 | sed 's/\(..\)/\1:/g;s/:$//'
}

configure_static_net_iface() {
local network_interface_name="$1"
local CONFIGPATH=/system/sdcard/config

# Install a resolv.conf if present so DNS can work
if [ -f "$CONFIGPATH/resolv.conf" ]; then
cp "$CONFIGPATH/resolv.conf" /etc/resolv.conf
fi

# Configure staticip/netmask from config/staticip.conf
local staticip_and_netmask=$(cat "$CONFIGPATH/staticip.conf" | grep -v "^$" | grep -v "^#")
ifconfig "$network_interface_name" $staticip_and_netmask
ifconfig "$network_interface_name" up
# Configure default gateway
if [ -f "$CONFIGPATH/defaultgw.conf" ]; then
local defaultgw=$(cat "$CONFIGPATH/defaultgw.conf" | grep -v "^$" | grep -v "^#")
route add default gw $defaultgw $network_interface_name
echo "Configured $defaultgw as default gateway"
fi
echo "Configured $network_interface_name with static address $staticip_and_netmask"
}

wpa_config_set() {
local wpa_config=/system/sdcard/config/wpa_supplicant.conf
local key="$1"
local val="$2"
if [ ! -s "$wpa_config" ]; then cp "$wpa_config.dist" "$wpa_config"; fi
if grep -q "^[[:space:]]*$key=" "$wpa_config"; then
sed -i "s/^[[:space:]]*$key=.*\$/$key=$val/" "$wpa_config"
else
sed -i "/}/i $key=$val" "$wpa_config"
fi
}

wpa_config_get() {
local wpa_config=/system/sdcard/config/wpa_supplicant.conf
local key="$1"
if [ -s "$wpa_config" ]; then
grep "^[[:space:]]*$key=" "$wpa_config" | cut -d "=" -f2
fi
}
Loading

0 comments on commit e7c84dd

Please sign in to comment.