diff --git a/Config.in b/Config.in index bc02b373..6f3da828 100644 --- a/Config.in +++ b/Config.in @@ -17,6 +17,10 @@ config FLASHMAN_PUBKEY_FNAME string "Public key file name. This key will be used for remote SSH access." default "id_rsa.pub" +config PROVIDER_PUBKEY_FNAME + string "Provider Public key file name. This key will be used to authorize lua access." + default "provider.pubkey" + config FLASHMAN_SERVER_ADDR string "Flashman server IP or FQDN" default "" @@ -60,6 +64,9 @@ config FLASHMAN_CLIENT_ORG string "FlashMan image client organization identification" default "MyCompany" +config ZABBIX_SUPPORT + bool "Install custom zabbix agent" + config NTP_SERVER_ADDR string "First NTP server IP or FQDN" default "a.st1.ntp.br" @@ -87,19 +94,17 @@ choice bool "PPPoE" endchoice -if FLASHMAN_WAN_PROTO_PPPOE - config FLASHMAN_PPPOE_USER - string "PPPoE username. Remember to escape hashtags and dollar signs with a slash." - default "flashman-user" +config FLASHMAN_PPPOE_USER + string "PPPoE username. Remember to escape hashtags and dollar signs with a slash." + default "flashman-user" - config FLASHMAN_PPPOE_PASSWD - string "PPPoE password. Remember to escape hashtags and dollar signs with a slash." - default "Flashman!" +config FLASHMAN_PPPOE_PASSWD + string "PPPoE password. Remember to escape hashtags and dollar signs with a slash." + default "Flashman!" - config FLASHMAN_PPPOE_SERVICE - string "PPPoE service. Remember to escape hashtags and dollar signs with a slash." - default "auto" -endif +config FLASHMAN_PPPOE_SERVICE + string "PPPoE service. Remember to escape hashtags and dollar signs with a slash." + default "auto" config FLASHMAN_WAN_MTU string "WAN MTU" @@ -121,6 +126,10 @@ config FLASHMAN_LAN_IPV6_PREFIX string "LAN ÏPV6 Prefix for Prefix Delegation" default "64" +config FLASHMAN_DHCP_NOPROXY + string "Do not use router as a DNS proxy" + default "0" + config MQTT_PORT string "MQTT port" default "1883" diff --git a/Makefile b/Makefile index 4cd9170c..a1c9b7a0 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=flasman-plugin -PKG_VERSION:=0.16.0 +PKG_VERSION:=0.30.2 PKG_RELEASE:=1 PKG_LICENSE:=GPL @@ -47,18 +47,19 @@ define Package/flashman-plugin DEPENDS:=+curl \ +iputils-ping \ +iputils-ping6 \ - +wireless-tools \ +uhttpd \ +uhttpd-mod-lua \ +px5g-mbedtls \ +libustream-mbedtls \ +libuuid \ - +libcares \ +rpcd \ +libuci-lua \ +libubus-lua \ +libmbedtls \ - +iptables-mod-conntrack-extra + +iptables-mod-conntrack-extra \ + +anlix-miniupnpd \ + +anlix-minisapo \ + +flash-measure MENU:=1 endef @@ -79,61 +80,94 @@ FILE_DIR= endif CUSTOM_FILE_DIR= - ifeq ($(CONFIG_TARGET_ramips_mt76x8_DEVICE_archer-c20-v4), y) - CUSTOM_FILE_DIR="custom-files/archer-c20-v4" - else ifeq ($(CONFIG_TARGET_ramips_mt7620_DEVICE_ArcherC5v4), y) - CUSTOM_FILE_DIR="custom-files/archer-c5-v4" - else ifeq ($(CONFIG_TARGET_ramips_mt7620_DEVICE_dl-dwr116-a3), y) - CUSTOM_FILE_DIR="custom-files/dl-dwr116-a3" - else ifeq ($(CONFIG_TARGET_ramips_mt7620_DEVICE_itlb-ncloud-v1), y) - CUSTOM_FILE_DIR="custom-files/itlb-ncloud-v1" - else ifeq ($(CONFIG_TARGET_ramips_mt7620_DEVICE_dir-819-a1), y) - CUSTOM_FILE_DIR="custom-files/dir-819-a1" - else ifeq ($(CONFIG_TARGET_ar71xx_tiny_DEVICE_tl-wr741nd-v4), y) - CUSTOM_FILE_DIR="custom-files/tl-wr741nd-v4" - else ifeq ($(CONFIG_TARGET_ar71xx_tiny_DEVICE_tl-wr841-v7), y) - CUSTOM_FILE_DIR="custom-files/tl-wr841-v7" - else ifeq ($(CONFIG_TARGET_ar71xx_tiny_DEVICE_tl-wr841-v8), y) - CUSTOM_FILE_DIR="custom-files/tl-wr841-v8" - else ifeq ($(CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wr842n-v3), y) - CUSTOM_FILE_DIR="custom-files/tl-wr842n-v3" - else ifeq ($(CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wdr3500-v1), y) - CUSTOM_FILE_DIR="custom-files/tl-wdr3500-v1" - else ifeq ($(CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wdr3600-v1), y) - CUSTOM_FILE_DIR="custom-files/tl-wdr3600-v1" - else ifeq ($(CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wdr4300-v1), y) - CUSTOM_FILE_DIR="custom-files/tl-wdr4300-v1" - else ifeq ($(CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wr2543-v1), y) - CUSTOM_FILE_DIR="custom-files/tl-wr2543-v1" - else ifeq ($(CONFIG_TARGET_ramips_mt76x8_DEVICE_tl-wr840n-v4), y) - CUSTOM_FILE_DIR="custom-files/tl-wr840n-v4" - else ifeq ($(CONFIG_TARGET_ramips_mt76x8_DEVICE_tl-wr840n-v5preset), y) - CUSTOM_FILE_DIR="custom-files/tl-wr840n-v5preset" +CUSTOM_FILE_ARQ= + ifeq ($(CONFIG_TARGET_ramips_mt7620_DEVICE_tplink_c2-v1), y) + CUSTOM_FILE_ARQ="tplink_archer-c2-v1" + else ifeq ($(CONFIG_TARGET_ramips_mt7620_DEVICE_tplink_c20-v1), y) + CUSTOM_FILE_ARQ="tplink_archer-c20-v1" + else ifeq ($(CONFIG_TARGET_ramips_mt76x8_DEVICE_tplink_c20-v4), y) + CUSTOM_FILE_ARQ="tplink_archer-c20-v4" + else ifeq ($(CONFIG_TARGET_ramips_mt76x8_DEVICE_tplink_c20-v5), y) + CUSTOM_FILE_ARQ="tplink_archer-c20-v5" + else ifeq ($(CONFIG_TARGET_ramips_mt76x8_DEVICE_tplink_c20-v5w), y) + CUSTOM_FILE_ARQ="tplink_archer-c20-v5W" + else ifeq ($(CONFIG_TARGET_ramips_mt7620_DEVICE_tplink_c5-v4), y) + CUSTOM_FILE_ARQ="tplink_archer-c5-v4" + else ifeq ($(CONFIG_TARGET_ramips_mt76x8_DEVICE_tplink_c50-v3), y) + CUSTOM_FILE_ARQ="tplink_archer-c50-v3" + else ifeq ($(CONFIG_TARGET_ramips_mt76x8_DEVICE_tplink_c50-v4), y) + CUSTOM_FILE_ARQ="tplink_archer-c50-v4" + else ifeq ($(CONFIG_TARGET_ramips_mt7620_DEVICE_zyxel_emg1702-t10a-a1), y) + CUSTOM_FILE_ARQ="tbs" + else ifeq ($(CONFIG_TARGET_ath79_generic_DEVICE_tplink_archer-c60-v2), y) + CUSTOM_FILE_ARQ="tplink_archer-c60-v2" + else ifeq ($(CONFIG_TARGET_ath79_generic_DEVICE_tplink_archer-c60-v3), y) + CUSTOM_FILE_ARQ="tplink_archer-c60-v3" + else ifeq ($(CONFIG_TARGET_ath79_generic_DEVICE_tplink_archer-c6-v2-us), y) + CUSTOM_FILE_ARQ="tplink_archer-c6-v2US" + else ifeq ($(CONFIG_TARGET_ath79_generic_DEVICE_tplink_archer-c7-v5), y) + CUSTOM_FILE_ARQ="tplink_archer-c7-v5" + else ifeq ($(CONFIG_TARGET_ath79_generic_DEVICE_dlink_covr-c1200-a1), y) + CUSTOM_FILE_ARQ="dlink_covr-c1200-a1" + else ifeq ($(CONFIG_TARGET_ramips_mt7620_DEVICE_dlink_dir-819-a1), y) + CUSTOM_FILE_ARQ="tbs" + else ifeq ($(CONFIG_TARGET_ath79_tiny_DEVICE_tplink_tl-wr740n-v4), y) + CUSTOM_FILE_ARQ="tplink_tl-wr740n" + else ifeq ($(CONFIG_TARGET_ath79_tiny_DEVICE_tplink_tl-wr740n-v5), y) + CUSTOM_FILE_ARQ="tplink_tl-wr740n" + else ifeq ($(CONFIG_TARGET_ar71xx_tiny_DEVICE_tl-wr740n-v6), y) + CUSTOM_FILE_ARQ="tplink_tl-wr740n" + else ifeq ($(CONFIG_TARGET_ath79_tiny_DEVICE_tplink_tl-wr741nd-v4), y) + CUSTOM_FILE_ARQ="tplink_tl-wr741n" + else ifeq ($(CONFIG_TARGET_ath79_tiny_DEVICE_tplink_tl-wr841-v7), y) + CUSTOM_FILE_ARQ="tplink_tl-wr841n" + else ifeq ($(CONFIG_TARGET_ath79_tiny_DEVICE_tplink_tl-wr841-v8), y) + CUSTOM_FILE_ARQ="tplink_tl-wr841n" + else ifeq ($(CONFIG_TARGET_ath79_generic_DEVICE_tplink_tl-wr842n-v3), y) + CUSTOM_FILE_ARQ="tplink_tl-wr842n" + else ifeq ($(CONFIG_TARGET_ath79_generic_DEVICE_tplink_tl-wr2543-v1), y) + CUSTOM_FILE_ARQ="tplink_tl-wr2543nd" else ifeq ($(CONFIG_TARGET_ramips_mt76x8_DEVICE_tl-wr840n-v5), y) - CUSTOM_FILE_DIR="custom-files/tl-wr840n-v5" + CUSTOM_FILE_ARQ="tplink_tl-wr84Xn-v5-v6" else ifeq ($(CONFIG_TARGET_ramips_mt76x8_DEVICE_tl-wr840n-v6), y) - CUSTOM_FILE_DIR="custom-files/tl-wr840n-v6" - else ifeq ($(CONFIG_TARGET_ramips_mt76x8_DEVICE_tl-wr840n-v6preset), y) - CUSTOM_FILE_DIR="custom-files/tl-wr840n-v6preset" - else ifeq ($(CONFIG_TARGET_ramips_mt76x8_DEVICE_tl-wr845n-v3), y) - CUSTOM_FILE_DIR="custom-files/tl-wr845n-v3" - else ifeq ($(CONFIG_TARGET_ramips_mt76x8_DEVICE_tl-wr845n-v4), y) - CUSTOM_FILE_DIR="custom-files/tl-wr845n-v4" - else ifeq ($(CONFIG_TARGET_ramips_mt76x8_DEVICE_tl-wr849n-v4), y) - CUSTOM_FILE_DIR="custom-files/tl-wr849n-v4" + CUSTOM_FILE_ARQ="tplink_tl-wr84Xn-v5-v6" else ifeq ($(CONFIG_TARGET_ramips_mt76x8_DEVICE_tl-wr849n-v5), y) - CUSTOM_FILE_DIR="custom-files/tl-wr849n-v5" + CUSTOM_FILE_ARQ="tplink_tl-wr84Xn-v5-v6" else ifeq ($(CONFIG_TARGET_ramips_mt76x8_DEVICE_tl-wr849n-v6), y) - CUSTOM_FILE_DIR="custom-files/tl-wr849n-v6" - else ifeq ($(CONFIG_TARGET_ramips_mt76x8_DEVICE_tl-wr849n-v62), y) - CUSTOM_FILE_DIR="custom-files/tl-wr849n-v62" - else ifeq ($(CONFIG_TARGET_ar71xx_tiny_DEVICE_tl-wr940n-v6), y) - CUSTOM_FILE_DIR="custom-files/tl-wr940n-v6" - else ifeq ($(CONFIG_TARGET_ar71xx_tiny_DEVICE_tl-wr949n-v6), y) - CUSTOM_FILE_DIR="custom-files/tl-wr949n-v6" - else - CUSTOM_FILE_DIR="custom-files/default" - endif + CUSTOM_FILE_ARQ="tplink_tl-wr84Xn-v5-v6" + else ifeq ($(CONFIG_TARGET_ath79_tiny_DEVICE_tplink_tl-wr940n-v5), y) + CUSTOM_FILE_ARQ="tplink_tl-wr940n-v5" + else ifeq ($(CONFIG_TARGET_ath79_tiny_DEVICE_tplink_tl-wr940n-v6), y) + CUSTOM_FILE_ARQ="tplink_tl-wr94Xn-v6" + else ifeq ($(CONFIG_TARGET_ath79_tiny_DEVICE_tplink_tl-wr949n-v6), y) + CUSTOM_FILE_ARQ="tplink_tl-wr94Xn-v6" + else ifeq ($(CONFIG_TARGET_ath79_generic_DEVICE_tplink_tl-wdr3500-v1), y) + CUSTOM_FILE_ARQ="tplink_tl-wdr3500" + else ifeq ($(CONFIG_TARGET_ramips_mt7620_DEVICE_dlink_dwr-116-a1), y) + CUSTOM_FILE_ARQ="dlink_dl-dwr116-a3" + else ifeq ($(CONFIG_TARGET_ramips_mt7620_DEVICE_itlb-ncloud-v1), y) + CUSTOM_FILE_DIR="custom-files/itlb-ncloud-v1" + else ifeq ($(CONFIG_TARGET_realtek_rtl8197d_DEVICE_DIR815D1), y) + CUSTOM_FILE_DIR="custom-files/dir-815-d1" + else ifeq ($(CONFIG_TARGET_realtek_rtl8196e_DEVICE_GWR300N), y) + CUSTOM_FILE_ARQ="greatek_gwr300-v1" + else ifeq ($(CONFIG_TARGET_realtek_rtl8197f_DEVICE_GWR1200AC-V1), y) + CUSTOM_FILE_ARQ="greatek_gwr1200-v1" + else ifeq ($(CONFIG_TARGET_realtek_rtl8197f_DEVICE_GWR1200AC-V2), y) + CUSTOM_FILE_ARQ="greatek_gwr1200-v2" + else ifeq ($(CONFIG_TARGET_realtek_rtl8196e_DEVICE_RE172), y) + CUSTOM_FILE_ARQ="multilaser_re172-v1" + else ifeq ($(CONFIG_TARGET_realtek_rtl8197f_DEVICE_RE708), y) + CUSTOM_FILE_ARQ="multilaser_re708-v1" + else ifeq ($(CONFIG_TARGET_realtek_rtl8197f_DEVICE_ACTIONRF1200), y) + CUSTOM_FILE_ARQ="intelbras_rf1200-v1" + else ifeq ($(CONFIG_TARGET_realtek_rtl8197f_DEVICE_ACTIONRG1200), y) + CUSTOM_FILE_ARQ="intelbras_rg1200-v1" + else ifeq ($(CONFIG_TARGET_realtek_rtl8197f_DEVICE_GF1200), y) + CUSTOM_FILE_ARQ="intelbras_gf1200-v1" + else ifeq ($(CONFIG_TARGET_realtek_rtl8197f_DEVICE_W51200F), y) + CUSTOM_FILE_ARQ="intelbras_w51200f-v1" + endif WAN_PROTO= ifeq ($(CONFIG_FLASHMAN_WAN_PROTO_DHCP), y) @@ -155,10 +189,20 @@ SSID_SUFFIX= define Package/flashman-plugin/install $(CP) ./$(FILE_DIR)/* $(1)/ +ifneq ($(CUSTOM_FILE_DIR),) $(CP) ./$(CUSTOM_FILE_DIR)/* $(1)/ - +endif +ifneq ($(CUSTOM_FILE_ARQ),) + $(CP) ./custom-files/$(CUSTOM_FILE_ARQ).sh $(1)/usr/share/functions/custom_device.sh + if [ -d ./calibration/$(CUSTOM_FILE_ARQ) ]; then \ + mkdir -p $(1)/lib/firmware ; \ + $(CP) ./calibration/$(CUSTOM_FILE_ARQ)/* $(1)/lib/firmware/ ; \ + fi +endif + $(INSTALL_DIR) $(1)/usr/bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/anlix-mqtt $(1)/usr/bin/ + $(INSTALL_BIN) $(PKG_BUILD_DIR)/pk $(1)/usr/bin/ mkdir -p $(1)/usr/share echo 'FLM_SSID_SUFFIX=$(SSID_SUFFIX)' >>$(1)/usr/share/flashman_init.conf @@ -179,14 +223,12 @@ define Package/flashman-plugin/install echo 'FLM_LAN_SUBNET=$(CONFIG_FLASHMAN_LAN_SUBNET)' >>$(1)/usr/share/flashman_init.conf echo 'FLM_LAN_NETMASK=$(CONFIG_FLASHMAN_LAN_NETMASK)' >>$(1)/usr/share/flashman_init.conf echo 'FLM_LAN_IPV6_PREFIX=$(CONFIG_FLASHMAN_LAN_IPV6_PREFIX)' >>$(1)/usr/share/flashman_init.conf + echo 'FLM_DHCP_NOPROXY=$(CONFIG_FLASHMAN_DHCP_NOPROXY)' >>$(1)/usr/share/flashman_init.conf echo 'MQTT_PORT=$(CONFIG_MQTT_PORT)' >>$(1)/usr/share/flashman_init.conf echo 'FLM_CLIENT_ORG=$(CONFIG_FLASHMAN_CLIENT_ORG)' >>$(1)/usr/share/flashman_init.conf - -ifeq ($(WAN_PROTO), "pppoe") echo 'FLM_WAN_PPPOE_USER=$(CONFIG_FLASHMAN_PPPOE_USER)' >>$(1)/usr/share/flashman_init.conf echo 'FLM_WAN_PPPOE_PASSWD=$(CONFIG_FLASHMAN_PPPOE_PASSWD)' >>$(1)/usr/share/flashman_init.conf echo 'FLM_WAN_PPPOE_SERVICE=$(CONFIG_FLASHMAN_PPPOE_SERVICE)' >>$(1)/usr/share/flashman_init.conf -endif echo 'FLM_USE_AUTH_SVADDR=$(CONFIG_FLASHMAN_USE_AUTH_SERVER)' >>$(1)/usr/share/flashman_init.conf @@ -195,12 +237,17 @@ ifeq ($(CONFIG_FLASHMAN_USE_AUTH_SERVER), y) echo 'FLM_CLIENT_SECRET=$(CONFIG_FLASHMAN_CLIENT_SECRET)' >>$(1)/usr/share/flashman_init.conf endif + echo 'ZBX_SUPPORT=$(CONFIG_ZABBIX_SUPPORT)' >>$(1)/usr/share/flashman_init.conf + echo $(PKG_VERSION) > $(1)/etc/anlix_version mkdir -p $(1)/etc/dropbear cat $(CONFIG_FLASHMAN_KEYS_PATH)/$(CONFIG_FLASHMAN_PUBKEY_FNAME) >>$(1)/etc/dropbear/authorized_keys chmod 0600 $(1)/etc/dropbear/authorized_keys + cat $(CONFIG_FLASHMAN_KEYS_PATH)/$(CONFIG_PROVIDER_PUBKEY_FNAME) >>$(1)/etc/provider.pubkey + chmod 0600 $(1)/etc/provider.pubkey + endef $(eval $(call BuildPackage,flashman-plugin)) diff --git a/calibration/tplink_archer-c20-v4/wlan.mt7628.bin b/calibration/tplink_archer-c20-v4/wlan.mt7628.bin new file mode 100755 index 00000000..4984c50d Binary files /dev/null and b/calibration/tplink_archer-c20-v4/wlan.mt7628.bin differ diff --git a/calibration/tplink_archer-c20-v5/wlan.mt7628.bin b/calibration/tplink_archer-c20-v5/wlan.mt7628.bin new file mode 100755 index 00000000..4984c50d Binary files /dev/null and b/calibration/tplink_archer-c20-v5/wlan.mt7628.bin differ diff --git a/calibration/tplink_archer-c20-v5W/wlan.mt7628.bin b/calibration/tplink_archer-c20-v5W/wlan.mt7628.bin new file mode 100755 index 00000000..4984c50d Binary files /dev/null and b/calibration/tplink_archer-c20-v5W/wlan.mt7628.bin differ diff --git a/calibration/tplink_archer-c50-v4/wlan.mt7628.bin b/calibration/tplink_archer-c50-v4/wlan.mt7628.bin new file mode 100644 index 00000000..17f07fb3 Binary files /dev/null and b/calibration/tplink_archer-c50-v4/wlan.mt7628.bin differ diff --git a/custom-files/archer-c20-v4/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/archer-c20-v4/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 11c18eff..00000000 --- a/custom-files/archer-c20-v4/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" -# LEDs -uci set system.led_wifi_led.dev="ra0" -uci set system.led_wlan2g.dev="ra0" -uci set system.led_wlan5g=led -uci set system.led_wlan5g.name='wlan5g' -uci set system.led_wlan5g.sysfs='archer-c20-v4:green:wlan5g' -uci set system.led_wlan5g.trigger='netdev' -uci set system.led_wlan5g.dev='rai0' -uci set system.led_wlan5g.mode='link tx rx' - -uci commit system - -exit 0 diff --git a/custom-files/archer-c20-v4/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/archer-c20-v4/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index a11f95d6..00000000 --- a/custom-files/archer-c20-v4/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,120 +0,0 @@ -#!/bin/sh - -# -# WARNING! This file might be a symbolic link! Check your sources! -# - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh -. /lib/functions/system.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -LOWERMAC=$(get_mac | awk '{ print tolower($1) }') -LOWERMAC_5=$(macaddr_add "$LOWERMAC" 2) -SUFFIX_5="-5GHz" - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - touch /etc/config/wireless - - uci set wireless.radio0=wifi-device - # Disable the interface! - # MT7628 use a dat file, we only get the parameters from here - uci set wireless.@wifi-device[0].type="ralink" - uci set wireless.@wifi-device[0].txpower="100" - uci set wireless.@wifi-device[0].variant="mt7628" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].wifimode="9" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - uci set wireless.@wifi-device[0].ht_bsscoexist="0" - uci set wireless.@wifi-device[0].bw="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - fi - - uci set wireless.@wifi-device[0].disabled="1" - uci set wireless.default_radio0=wifi-iface - uci set wireless.@wifi-iface[0].ifname="ra0" - uci set wireless.@wifi-iface[0].mode="ap" - uci set wireless.@wifi-iface[0].network="lan" - uci set wireless.@wifi-iface[0].device="radio0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - # 5GHz - MT7610e - uci set wireless.radio1=wifi-device - # Disable the interface! - # MT7610e use a dat file, we only get the parameters from here - uci set wireless.@wifi-device[1].type="ralink" - uci set wireless.@wifi-device[1].txpower="100" - uci set wireless.@wifi-device[1].variant="mt7610e" - uci set wireless.@wifi-device[1].channel="$FLM_50_CHANNEL" - uci set wireless.@wifi-device[1].hwmode="11ac" - uci set wireless.@wifi-device[1].wifimode="15" - uci set wireless.@wifi-device[1].country="BR" - uci set wireless.@wifi-device[1].htmode="VHT80" - uci set wireless.@wifi-device[1].noscan="1" - uci set wireless.@wifi-device[1].ht_bsscoexist="0" - uci set wireless.@wifi-device[1].bw="2" - uci set wireless.@wifi-device[1].disabled="1" - uci set wireless.default_radio1=wifi-iface - uci set wireless.@wifi-iface[1].ifname="rai0" - uci set wireless.@wifi-iface[1].mode="ap" - uci set wireless.@wifi-iface[1].network="lan" - uci set wireless.@wifi-iface[1].device="radio1" - uci set wireless.@wifi-iface[1].ssid="$setssid$SUFFIX_5" - uci set wireless.@wifi-iface[1].encryption="psk2" - uci set wireless.@wifi-iface[1].key="$FLM_PASSWD" - - uci commit wireless -fi - -/usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -printf "MacAddress=$LOWERMAC\n\n" >> /etc/wireless/mt7628/mt7628.dat -insmod /lib/modules/`uname -r`/mt7628.ko mac=$LOWERMAC -echo "mt7628 mac=$LOWERMAC" >> /etc/modules.d/50-mt7628 -# 5 GHz -/usr/bin/uci2dat -d radio1 -f /etc/Wireless/iNIC/iNIC_ap.dat > /dev/null -printf "MacAddress=$LOWERMAC_5\n\n" >> /etc/Wireless/iNIC/iNIC_ap.dat -insmod /lib/modules/`uname -r`/mt7610e.ko mac=$LOWERMAC_5 -echo "mt7610e mac=$LOWERMAC_5" >> /etc/modules.d/51-mt7610e - -[ -e /sbin/wifi ] && mv /sbin/wifi /sbin/wifi_legacy -cp /sbin/mtkwifi /sbin/wifi -# MT7628 driver needs to reload the first time it loads -/sbin/wifi reload - -exit 0 diff --git a/custom-files/archer-c20-v4/usr/share/functions/device_functions.sh b/custom-files/archer-c20-v4/usr/share/functions/device_functions.sh deleted file mode 100644 index 16236bff..00000000 --- a/custom-files/archer-c20-v4/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,282 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless - /usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null - /usr/bin/uci2dat -d radio1 -f /etc/Wireless/iNIC/iNIC_ap.dat > /dev/null -} - -is_5ghz_capable() { - # true - echo "1" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info="" - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - local _wifi_stats="" - local _ap_freq="2.4" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_num="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_num | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac > /dev/null - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx)" - break - fi - done - fi - - # 5 GHz search - _wifi_itf="rai0" - _dev_num="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_num | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac > /dev/null - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx)" - _ap_freq="5.0" - break - fi - done - fi - - if [ "$_dev_info" != "" ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="0.0" - local _dev_mode="$(echo "$_dev_info" | grep 'caps:' | \ - awk '{print $2}')" - local _dev_signal="$(echo "$_dev_info" | grep 'RSSI:' | \ - awk '{print $2}')" - local _dev_snr="$(echo "$_dev_info" | grep 'SNR:' | \ - awk '{print $2}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'TxBytes:' | \ - awk '{print $2}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'RxBytes:' | \ - awk '{print $2}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'TxPackets:' | \ - awk '{print $2}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'RxPackets:' | \ - awk '{print $2}')" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mode" == "VHT" ] - then - # AC - _wifi_stats="$_wifi_stats AC" - elif [ "$_dev_mode" == "HT" ] - then - # N - _wifi_stats="$_wifi_stats N" - else - # G - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_info | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - return 0 - fi - done - fi - - # 5 GHz search - _wifi_itf="rai0" - _dev_info="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_info | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - return 0 - fi - done - fi - - # Not found - return 1 - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - led_on /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power - # bug on archer's lan led - echo "0" > \ - /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:lan/port_mask - echo "0x1e" > \ - /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:lan/port_mask -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - led_off /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power - # we cant turn on orange and blue at same time in this model - ledsoff=$(ls -d /sys/class/leds/*green*) - - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - - if [ ! -z "$(awk '{ print toupper($1) }' /sys/class/net/eth0/address)" ] - then - _mac_address_tag=$(awk '{ print toupper($1) }' /sys/class/net/eth0/address) - fi - - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch0 port 0 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch0 port 0 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/archer-c5-v4/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/archer-c5-v4/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 28d6c158..00000000 --- a/custom-files/archer-c5-v4/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" - -# LEDs -uci set system.led_wlan2g.dev='ra0' -uci set system.led_wlan5g.dev='rai0' - -uci commit system - -exit 0 diff --git a/custom-files/archer-c5-v4/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/archer-c5-v4/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index c1a4b920..00000000 --- a/custom-files/archer-c5-v4/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/sh - -# -# WARNING! This file might be a symbolic link! Check your sources! -# - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh -. /lib/functions/system.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -LOWERMAC=$(get_mac | awk '{ print tolower($1) }') -LOWERMAC_5=$(macaddr_add "$LOWERMAC" 2) -SUFFIX_5="-5GHz" - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - touch /etc/config/wireless - - uci set wireless.radio0=wifi-device - # Disable the interface! - # MT7620 use a dat file, we only get the parameters from here - uci set wireless.@wifi-device[0].type="ralink" - uci set wireless.@wifi-device[0].txpower="100" - uci set wireless.@wifi-device[0].variant="mt7620" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].wifimode="9" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - uci set wireless.@wifi-device[0].ht_bsscoexist="0" - uci set wireless.@wifi-device[0].bw="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - fi - - uci set wireless.@wifi-device[0].disabled="1" - uci set wireless.default_radio0=wifi-iface - uci set wireless.@wifi-iface[0].ifname="ra0" - uci set wireless.@wifi-iface[0].mode="ap" - uci set wireless.@wifi-iface[0].network="lan" - uci set wireless.@wifi-iface[0].device="radio0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - # 5GHz - MT7612e - uci set wireless.radio1=wifi-device - # Disable the interface! - # MT7612e use a dat file, we only get the parameters from here - uci set wireless.@wifi-device[1].type="ralink" - uci set wireless.@wifi-device[1].txpower="100" - uci set wireless.@wifi-device[1].variant="mt7612e" - uci set wireless.@wifi-device[1].channel="$FLM_50_CHANNEL" - uci set wireless.@wifi-device[1].hwmode="11ac" - uci set wireless.@wifi-device[1].wifimode="15" - uci set wireless.@wifi-device[1].country="BR" - uci set wireless.@wifi-device[1].htmode="VHT80" - uci set wireless.@wifi-device[1].noscan="1" - uci set wireless.@wifi-device[1].ht_bsscoexist="0" - uci set wireless.@wifi-device[1].bw="2" - uci set wireless.@wifi-device[1].disabled="1" - uci set wireless.default_radio1=wifi-iface - uci set wireless.@wifi-iface[1].ifname="rai0" - uci set wireless.@wifi-iface[1].mode="ap" - uci set wireless.@wifi-iface[1].network="lan" - uci set wireless.@wifi-iface[1].device="radio1" - uci set wireless.@wifi-iface[1].ssid="$setssid$SUFFIX_5" - uci set wireless.@wifi-iface[1].encryption="psk2" - uci set wireless.@wifi-iface[1].key="$FLM_PASSWD" - - uci commit wireless -fi - -#Dump firmware in /lib/firmware -dd if=/dev/mtd8ro of=/lib/firmware/MT7620_AP_2T2R-4L_V15.BIN bs=1 count=512 -dd if=/dev/mtd8ro of=/lib/firmware/MT7612E_EEPROM.bin bs=1k skip=32 count=32 - -/usr/bin/uci2dat -d radio0 -f /etc/Wireless/mt7620/mt7620.dat > /dev/null -printf "MacAddress=$LOWERMAC\n\n" >> /etc/Wireless/mt7620/mt7620.dat - -# 5 GHz -/usr/bin/uci2dat -d radio1 -f /etc/Wireless/mt7612/mt7612.dat > /dev/null -printf "MacAddress=$LOWERMAC_5\n\n" >> /etc/Wireless/mt7612/mt7612.dat - -insmod /lib/modules/`uname -r`/mt76x2ap.ko -echo "mt76x2ap" >> /etc/modules.d/50-mt76x2 - -[ -e /sbin/wifi ] && mv /sbin/wifi /sbin/wifi_legacy -cp /sbin/mtkwifi /sbin/wifi -# MT7620 driver needs to reload the first time it loads -/sbin/wifi reload - -exit 0 diff --git a/custom-files/archer-c5-v4/usr/share/functions/device_functions.sh b/custom-files/archer-c5-v4/usr/share/functions/device_functions.sh deleted file mode 100644 index 1f6fddae..00000000 --- a/custom-files/archer-c5-v4/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,281 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless - /usr/bin/uci2dat -d radio0 -f /etc/Wireless/mt7620/mt7620.dat > /dev/null - /usr/bin/uci2dat -d radio1 -f /etc/Wireless/mt7612/mt7612.dat > /dev/null -} - -is_5ghz_capable() { - # true - echo "1" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info="" - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - local _wifi_stats="" - local _ap_freq="2.4" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_num="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_num | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac > /dev/null - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx)" - break - fi - done - fi - - # 5 GHz search - _wifi_itf="rai0" - _dev_num="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_num | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac > /dev/null - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx)" - _ap_freq="5.0" - break - fi - done - fi - - if [ "$_dev_info" != "" ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="0.0" - local _dev_mode="$(echo "$_dev_info" | grep 'caps:' | \ - awk '{print $2}')" - local _dev_signal="$(echo "$_dev_info" | grep 'RSSI:' | \ - awk '{print $2}')" - local _dev_snr="$(echo "$_dev_info" | grep 'SNR:' | \ - awk '{print $2}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'TxBytes:' | \ - awk '{print $2}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'RxBytes:' | \ - awk '{print $2}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'TxPackets:' | \ - awk '{print $2}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'RxPackets:' | \ - awk '{print $2}')" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mode" == "VHT" ] - then - # AC - _wifi_stats="$_wifi_stats AC" - elif [ "$_dev_mode" == "HT" ] - then - # N - _wifi_stats="$_wifi_stats N" - else - # G - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_info | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - return 0 - fi - done - fi - - # 5 GHz search - _wifi_itf="rai0" - _dev_info="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_info | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - return 0 - fi - done - fi - - # Not found - return 1 - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - # bug on archer's lan led - echo "0" > \ - /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:lan/port_mask - echo "0xf" > \ - /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:lan/port_mask -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - led_off /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power - # we cant turn on orange and blue at same time in this model - ledsoff=$(ls -d /sys/class/leds/*green*) - - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - - if [ ! -z "$(awk '{ print toupper($1) }' /sys/class/net/eth0/address)" ] - then - _mac_address_tag=$(awk '{ print toupper($1) }' /sys/class/net/eth0/address) - fi - - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch1 port 4 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch1 port 4 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch1" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/default/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/default/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index 56063df1..00000000 --- a/custom-files/default/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/sh - -# -# WARNING! This file may be replaced depending on the selected target! -# - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -SUFFIX_5="-5GHz" - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - - uci set wireless.@wifi-device[0].type="mac80211" - uci set wireless.@wifi-device[0].txpower="17" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - fi - - uci set wireless.@wifi-device[0].disabled="0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - # 5GHz 802.11 a/n mode - if [ "$(uci -q get wireless.@wifi-iface[1])" ] - then - uci set wireless.@wifi-device[1].type="mac80211" - uci set wireless.@wifi-device[1].txpower="17" - uci set wireless.@wifi-device[1].channel="$FLM_50_CHANNEL" - uci set wireless.@wifi-device[1].hwmode="11na" - uci set wireless.@wifi-device[1].country="BR" - uci set wireless.@wifi-device[1].htmode="HT40" - uci set wireless.@wifi-device[1].noscan="1" - uci set wireless.@wifi-device[1].disabled="0" - uci set wireless.@wifi-iface[1].ssid="$setssid$SUFFIX_5" - uci set wireless.@wifi-iface[1].encryption="psk2" - uci set wireless.@wifi-iface[1].key="$FLM_PASSWD" - fi - uci commit wireless -fi - -exit 0 diff --git a/custom-files/default/usr/share/functions/device_functions.sh b/custom-files/default/usr/share/functions/device_functions.sh deleted file mode 100644 index 71052820..00000000 --- a/custom-files/default/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,232 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_info - local _wifi_stats="" - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - local _ap_freq="2.4" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -ne 0 ] - then - _wifi_itf="wlan1" - _ap_freq="5.0" - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - fi - - if [ $_retstatus -eq 0 ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="$(echo "$_dev_info" | grep 'rx bitrate:' | \ - awk '{print $3}')" - local _dev_mcs="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $5}')" - local _dev_signal="$(echo "$_dev_info" | grep 'signal:' | \ - awk '{print $2}' | awk -F. '{print $1}')" - local _ap_noise="$(iwinfo $_wifi_itf info | grep 'Noise:' | \ - awk '{print $5}' | awk -F. '{print $1}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'tx bytes:' | \ - awk '{print $3}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'rx bytes:' | \ - awk '{print $3}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'tx packets:' | \ - awk '{print $3}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'rx packets:' | \ - awk '{print $3}')" - - # Calculate SNR - local _dev_snr="$(($_dev_signal - $_ap_noise))" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mcs" == "MCS" ] - then - # N or AC - _wifi_stats="$_wifi_stats N" - else - # G Mode - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -ne 0 ] - then - _wifi_itf="wlan1" - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - fi - - if [ $_retstatus -eq 0 ] - then - return 0 - else - return 1 - fi - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - for system_led in /sys/class/leds/*system* - do - led_on "$system_led" - done - - # reset hardware lan ports if any - for lan_led in /sys/class/leds/*lan* - do - if [ -f "$lan_led"/enable_hw_mode ] - then - echo 1 > "$lan_led"/enable_hw_mode - fi - done - - # reset hardware wan port if any - for wan_led in /sys/class/leds/*wan* - do - if [ -f "$wan_led"/enable_hw_mode ] - then - echo 1 > "$wan_led"/enable_hw_mode - fi - done - - # reset atheros 5G led - if [ -f /sys/class/leds/ath9k-phy1/trigger ] - then - echo "phy1tpt" > /sys/class/leds/ath9k-phy1/trigger - fi -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - ledsoff=$(ls -d /sys/class/leds/*) - for trigger_path in $ledsoff - do - led_off "$trigger_path" - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - local _p0 - local _p1 - _p0=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy0/macaddress) - - if [ ! -d "/sys/class/ieee80211/phy1" ] - then - if [ ! -z "$_p0" ] - then - _mac_address_tag=$_p0 - fi - else - _p1=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy1/macaddress) - if [ ! -z "$_p1" ] - then - _mac_address_tag=$_p1 - fi - fi - echo "$_mac_address_tag" -} - -# Possible values: 10 or 100 -get_wan_negotiated_speed() { - cat /sys/class/net/eth0/speed -} - -# Possible values: half or full -get_wan_negotiated_duplex() { - cat /sys/class/net/eth0/duplex -} - -get_lan_dev_negotiated_speed() { - local _mac="$1" - local _swport - local _speed - - _swport="$(swconfig dev switch0 show | grep $_mac | \ - awk -F: '{print $1}' | awk '{print $2}')" - _speed="$(swconfig dev switch0 port $_swport get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - echo "$_speed" -} diff --git a/custom-files/dir-815-d1/etc/init.d/rtl8192cd b/custom-files/dir-815-d1/etc/init.d/rtl8192cd new file mode 100755 index 00000000..38479707 --- /dev/null +++ b/custom-files/dir-815-d1/etc/init.d/rtl8192cd @@ -0,0 +1,26 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2006-2011 OpenWrt.org + +START=18 + +boot() { + ifconfig wlan0 up + ifconfig wlan1 up + + iwpriv wlan0 set_mib xcap=30 + iwpriv wlan0 set_mib ther=32 + iwpriv wlan0 set_mib pwrlevelCCK_A=2828282828282828282828282828 + iwpriv wlan0 set_mib pwrlevelCCK_B=2d2d2d2d2d2d2d2d2d2d2d2d2d2d + iwpriv wlan0 set_mib pwrlevelHT40_1S_A=2c2c2c2c2c2c2c2c2c2c2c2c2c2c + iwpriv wlan0 set_mib pwrlevelHT40_1S_B=3030303030303030303030303030 + + iwpriv wlan1 set_mib xcap=40 + iwpriv wlan1 set_mib ther=27 + iwpriv wlan1 set_mib pwrlevel5GHT40_1S_A=0000000000000000000000000000000000000000000000000000000000000000000000262626262626262626262626262020202020202020202020202020202021212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121211d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d00000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrlevel5GHT40_1S_B=0000000000000000000000000000000000000000000000000000000000000000000000262626262626262626262626262020202020202020202020202020202022222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222221b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b00000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_80BW1S_160BW1S_A=0000000000000000000000000000000000000000000000000000000000000000000000d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d000000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_80BW1S_160BW1S_B=0000000000000000000000000000000000000000000000000000000000000000000000d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d000000000000000000000000000000000000000 + + ifconfig wlan0 down + ifconfig wlan1 down +} diff --git a/custom-files/default/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/dir-815-d1/etc/uci-defaults/z001_flashbox-system.sh similarity index 100% rename from custom-files/default/etc/uci-defaults/z001_flashbox-system.sh rename to custom-files/dir-815-d1/etc/uci-defaults/z001_flashbox-system.sh diff --git a/custom-files/tl-wdr3500-v1/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/dir-815-d1/etc/uci-defaults/z005_flashbox-wireless.sh similarity index 74% rename from custom-files/tl-wdr3500-v1/etc/uci-defaults/z005_flashbox-wireless.sh rename to custom-files/dir-815-d1/etc/uci-defaults/z005_flashbox-wireless.sh index 48e14b53..49e178bf 100644 --- a/custom-files/tl-wdr3500-v1/etc/uci-defaults/z005_flashbox-wireless.sh +++ b/custom-files/dir-815-d1/etc/uci-defaults/z005_flashbox-wireless.sh @@ -7,6 +7,9 @@ . /usr/share/flashman_init.conf . /usr/share/functions/device_functions.sh +LOWERMAC=$(get_mac | awk '{ print tolower($1) }') +MAC_WIFI=$(macaddr_add "$LOWERMAC" 2) +MAC_WIFI_5=$(macaddr_add "$LOWERMAC" 3) MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) @@ -54,23 +57,33 @@ then uci set wireless.@wifi-iface[0].ssid="$setssid" uci set wireless.@wifi-iface[0].encryption="psk2" uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - uci set wireless.@wifi-iface[0].max_inactivity="3000" + uci set wireless.@wifi-iface[0].macaddr="$MAC_WIFI" - # 5GHz + # 5GHz 802.11 ac mode if [ "$(uci -q get wireless.@wifi-iface[1])" ] then uci set wireless.@wifi-device[1].type="mac80211" uci set wireless.@wifi-device[1].txpower="17" uci set wireless.@wifi-device[1].channel="$FLM_50_CHANNEL" - uci set wireless.@wifi-device[1].hwmode="11na" + uci set wireless.@wifi-device[1].hwmode="11a" uci set wireless.@wifi-device[1].country="BR" - uci set wireless.@wifi-device[1].htmode="HT40" - uci set wireless.@wifi-device[1].noscan="1" + uci set wireless.@wifi-device[1].htmode="VHT80" + uci set wireless.@wifi-device[1].noscan="0" uci set wireless.@wifi-device[1].disabled="0" uci set wireless.@wifi-iface[1].ssid="$setssid$SUFFIX_5" uci set wireless.@wifi-iface[1].encryption="psk2" uci set wireless.@wifi-iface[1].key="$FLM_PASSWD" - uci set wireless.@wifi-iface[1].max_inactivity="3000" + uci set wireless.@wifi-iface[1].macaddr="$MAC_WIFI_5" + fi + uci commit wireless +else + # Fix a bug present in version 0.25.2 + uci set wireless.@wifi-iface[0].macaddr="$MAC_WIFI" + uci set wireless.@wifi-iface[0].encryption="psk2" + if [ "$(uci -q get wireless.@wifi-iface[1])" ] + then + uci set wireless.@wifi-iface[1].macaddr="$MAC_WIFI_5" + uci set wireless.@wifi-iface[1].encryption="psk2" fi uci commit wireless fi diff --git a/custom-files/tl-wr841-v8/usr/share/functions/device_functions.sh b/custom-files/dir-815-d1/usr/share/functions/device_functions.sh similarity index 76% rename from custom-files/tl-wr841-v8/usr/share/functions/device_functions.sh rename to custom-files/dir-815-d1/usr/share/functions/device_functions.sh index 355ab3aa..3408908a 100644 --- a/custom-files/tl-wr841-v8/usr/share/functions/device_functions.sh +++ b/custom-files/dir-815-d1/usr/share/functions/device_functions.sh @@ -1,12 +1,8 @@ #!/bin/sh -save_wifi_local_config() { - uci commit wireless -} - is_5ghz_capable() { - # false - echo "0" + # true + echo "1" } get_wifi_device_stats() { @@ -26,6 +22,14 @@ get_wifi_device_stats() { _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" _retstatus=$? + if [ $_retstatus -ne 0 ] + then + _wifi_itf="wlan1" + _ap_freq="5.0" + _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" + _retstatus=$? + fi + if [ $_retstatus -eq 0 ] then local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ @@ -53,13 +57,13 @@ get_wifi_device_stats() { _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - if [ "$_dev_mcs" == "MCS" ] + if [ "$_dev_mcs" == "VHT-MCS" ] then # N or AC - _wifi_stats="$_wifi_stats N" + _wifi_stats="$_wifi_stats AC" else # G Mode - _wifi_stats="$_wifi_stats G" + _wifi_stats="$_wifi_stats N" fi # Traffic data _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" @@ -89,6 +93,13 @@ is_device_wireless() { _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" _retstatus=$? + if [ $_retstatus -ne 0 ] + then + _wifi_itf="wlan1" + _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" + _retstatus=$? + fi + if [ $_retstatus -eq 0 ] then return 0 @@ -150,11 +161,6 @@ reset_leds() { echo 1 > "$wan_led"/enable_hw_mode fi done - - if [ -f /sys/class/leds/ath9k-phy0/trigger ] - then - echo "phy0tpt" > /sys/class/leds/ath9k-phy0/trigger - fi } blink_leds() { @@ -165,7 +171,6 @@ blink_leds() { ledsoff=$(ls -d /sys/class/leds/*) for trigger_path in $ledsoff do - led_off "$trigger_path" echo "timer" > "$trigger_path"/trigger done fi @@ -173,36 +178,39 @@ blink_leds() { get_mac() { local _mac_address_tag="" - local _p0 - _p0=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy0/macaddress) + local _p1 - if [ ! -z "$_p0" ] + _p1=$(awk '{print toupper($1)}' /sys/class/net/eth1/address) + if [ ! -z "$_p1" ] then - _mac_address_tag=$_p0 + _mac_address_tag=$_p1 fi + echo "$_mac_address_tag" } -# Possible values: 10 or 100 +# Possible values: empty, 10, 100 or 100 get_wan_negotiated_speed() { - cat /sys/class/net/eth0/speed + swconfig dev switch0 port 4 get link | \ + awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' } -# Possible values: half or full +# Possible values: empty, half or full get_wan_negotiated_duplex() { - cat /sys/class/net/eth0/duplex + swconfig dev switch0 port 4 get link | \ + awk '{print $4}' | awk -F- '{print $1}' } get_lan_dev_negotiated_speed() { local _speed="0" local _switch="switch0" - local _vlan="1" + local _vlan="9" local _retstatus for _port in $(swconfig dev $_switch vlan $_vlan get ports) do # Check if it's not a bridge port - echo "$_port" | grep -q "t" + echo "$_port" | grep -q "6" _retstatus=$? if [ $_retstatus -eq 1 ] then @@ -227,3 +235,26 @@ get_lan_dev_negotiated_speed() { echo "$_speed" } + +# Enable/disable ethernet connection on LAN physical ports when in bridge mode +set_switch_bridge_mode_on_boot() { + local _disable_lan_ports="$1" + + if [ "$_disable_lan_ports" = "y" ] + then + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '4 6' + else + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '0 1 2 3 4 6' + fi +} + +# Needs reboot to validate switch config +needs_reboot_bridge_mode() { + reboot +} diff --git a/custom-files/dir-819-a1/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/dir-819-a1/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 35712f2d..00000000 --- a/custom-files/dir-819-a1/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" -# LEDs -uci set system.led_wifi_led.dev="ra0" -uci set system.led_wlan2g.dev="ra0" - -uci commit system - -exit 0 diff --git a/custom-files/dir-819-a1/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/dir-819-a1/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index 06d0d709..00000000 --- a/custom-files/dir-819-a1/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/sh - -# -# WARNING! This file might be a symbolic link! Check your sources! -# - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh -. /lib/functions/system.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -LOWERMAC=$(get_mac | awk '{ print tolower($1) }') -LOWERMAC_5=$(macaddr_add "$LOWERMAC" 2) -SUFFIX_5="-5GHz" - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - touch /etc/config/wireless - - uci set wireless.radio0=wifi-device - # Disable the interface! - # MT7620 use a dat file, we only get the parameters from here - uci set wireless.@wifi-device[0].type="ralink" - uci set wireless.@wifi-device[0].txpower="100" - uci set wireless.@wifi-device[0].variant="mt7620" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].wifimode="9" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - uci set wireless.@wifi-device[0].ht_bsscoexist="0" - uci set wireless.@wifi-device[0].bw="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - fi - - uci set wireless.@wifi-device[0].disabled="1" - uci set wireless.default_radio0=wifi-iface - uci set wireless.@wifi-iface[0].ifname="ra0" - uci set wireless.@wifi-iface[0].mode="ap" - uci set wireless.@wifi-iface[0].network="lan" - uci set wireless.@wifi-iface[0].device="radio0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - # 5GHz - MT7610e - uci set wireless.radio1=wifi-device - # Disable the interface! - # MT7610e use a dat file, we only get the parameters from here - uci set wireless.@wifi-device[1].type="ralink" - uci set wireless.@wifi-device[1].txpower="100" - uci set wireless.@wifi-device[1].variant="mt7610e" - uci set wireless.@wifi-device[1].channel="$FLM_50_CHANNEL" - uci set wireless.@wifi-device[1].hwmode="11ac" - uci set wireless.@wifi-device[1].wifimode="15" - uci set wireless.@wifi-device[1].country="BR" - uci set wireless.@wifi-device[1].htmode="VHT80" - uci set wireless.@wifi-device[1].noscan="1" - uci set wireless.@wifi-device[1].ht_bsscoexist="0" - uci set wireless.@wifi-device[1].bw="2" - uci set wireless.@wifi-device[1].disabled="1" - uci set wireless.default_radio1=wifi-iface - uci set wireless.@wifi-iface[1].ifname="rai0" - uci set wireless.@wifi-iface[1].mode="ap" - uci set wireless.@wifi-iface[1].network="lan" - uci set wireless.@wifi-iface[1].device="radio1" - uci set wireless.@wifi-iface[1].ssid="$setssid$SUFFIX_5" - uci set wireless.@wifi-iface[1].encryption="psk2" - uci set wireless.@wifi-iface[1].key="$FLM_PASSWD" - - uci commit wireless -fi - -#Dump firmware of MT7620 -dd if=/dev/mtd0ro of=/lib/firmware/MT7620_AP_2T2R-4L_V15.BIN bs=1 skip=66080 count=512 - -/usr/bin/uci2dat -d radio0 -f /etc/Wireless/mt7620/mt7620.dat > /dev/null -printf "MacAddress=$LOWERMAC\n\n" >> /etc/Wireless/mt7620/mt7620.dat -insmod /lib/modules/`uname -r`/mt76x2ap.ko -echo "mt76x2ap" >> /etc/modules.d/50-mt76x2 - -# 5 GHz -/usr/bin/uci2dat -d radio1 -f /etc/Wireless/iNIC/iNIC_ap.dat > /dev/null -printf "MacAddress=$LOWERMAC_5\n\n" >> /etc/Wireless/iNIC/iNIC_ap.dat -insmod /lib/modules/`uname -r`/mt7610e.ko mac=$LOWERMAC_5 -echo "mt7610e mac=$LOWERMAC_5" >> /etc/modules.d/51-mt7610e - -[ -e /sbin/wifi ] && mv /sbin/wifi /sbin/wifi_legacy -cp /sbin/mtkwifi /sbin/wifi -# MT7620 driver needs to reload the first time it loads -/sbin/wifi reload - -exit 0 diff --git a/custom-files/dir-819-a1/usr/share/functions/device_functions.sh b/custom-files/dir-819-a1/usr/share/functions/device_functions.sh deleted file mode 100644 index e90b7153..00000000 --- a/custom-files/dir-819-a1/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,303 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless - /usr/bin/uci2dat -d radio0 -f /etc/Wireless/mt7620/mt7620.dat > /dev/null - /usr/bin/uci2dat -d radio1 -f /etc/Wireless/iNIC/iNIC_ap.dat > /dev/null -} - -is_5ghz_capable() { - # true - echo "1" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info="" - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - local _wifi_stats="" - local _ap_freq="2.4" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_num="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_num | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac > /dev/null - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx)" - break - fi - done - fi - - # 5 GHz search - _wifi_itf="rai0" - _dev_num="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_num | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac > /dev/null - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx)" - _ap_freq="5.0" - break - fi - done - fi - - if [ "$_dev_info" != "" ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="0.0" - local _dev_mode="$(echo "$_dev_info" | grep 'caps:' | \ - awk '{print $2}')" - local _dev_signal="$(echo "$_dev_info" | grep 'RSSI:' | \ - awk '{print $2}')" - local _dev_snr="$(echo "$_dev_info" | grep 'SNR:' | \ - awk '{print $2}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'TxBytes:' | \ - awk '{print $2}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'RxBytes:' | \ - awk '{print $2}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'TxPackets:' | \ - awk '{print $2}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'RxPackets:' | \ - awk '{print $2}')" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mode" == "VHT" ] - then - # AC - _wifi_stats="$_wifi_stats AC" - elif [ "$_dev_mode" == "HT" ] - then - # N - _wifi_stats="$_wifi_stats N" - else - # G - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_info | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - return 0 - fi - done - fi - - # 5 GHz search - _wifi_itf="rai0" - _dev_info="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_info | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - return 0 - fi - done - fi - - # Not found - return 1 - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - for system_led in /sys/class/leds/*system* - do - led_on "$system_led" - done - - # reset hardware lan ports if any - for lan_led in /sys/class/leds/*lan* - do - if [ -f "$lan_led"/enable_hw_mode ] - then - echo 1 > "$lan_led"/enable_hw_mode - fi - done - - # reset hardware wan port if any - for wan_led in /sys/class/leds/*wan* - do - if [ -f "$wan_led"/enable_hw_mode ] - then - echo 1 > "$wan_led"/enable_hw_mode - fi - done - - # reset atheros 5G led - if [ -f /sys/class/leds/ath9k-phy1/trigger ] - then - echo "phy1tpt" > /sys/class/leds/ath9k-phy1/trigger - fi -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - ledsoff=$(ls -d /sys/class/leds/*) - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - local _p0 - _p0=$(uci get network.wan_dev.macaddr | awk '{print toupper($1)}') - - if [ ! -z "$_p0" ] - then - _mac_address_tag=$_p0 - fi - - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch0 port 0 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch0 port 0 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="2" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/dl-dwr116-a3/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/dl-dwr116-a3/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index eb145de3..00000000 --- a/custom-files/dl-dwr116-a3/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/sh - -# -# WARNING! This file may be replaced depending on the selected target! -# - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - - uci set wireless.@wifi-device[0].type="mac80211" - uci set wireless.@wifi-device[0].txpower="17" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - fi - - uci set wireless.@wifi-device[0].disabled="0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -exit 0 diff --git a/custom-files/dl-dwr116-a3/usr/share/functions/device_functions.sh b/custom-files/dl-dwr116-a3/usr/share/functions/device_functions.sh deleted file mode 100644 index 7ec0d12b..00000000 --- a/custom-files/dl-dwr116-a3/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,203 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_info - local _wifi_stats="" - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - local _ap_freq="2.4" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="$(echo "$_dev_info" | grep 'rx bitrate:' | \ - awk '{print $3}')" - local _dev_mcs="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $5}')" - local _dev_signal="$(echo "$_dev_info" | grep 'signal:' | \ - awk '{print $2}' | awk -F. '{print $1}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'tx bytes:' | \ - awk '{print $3}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'rx bytes:' | \ - awk '{print $3}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'tx packets:' | \ - awk '{print $3}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'rx packets:' | \ - awk '{print $3}')" - - # Calculate SNR - local _dev_snr="$(($_dev_signal + 93))" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mcs" == "MCS" ] - then - # N or AC - _wifi_stats="$_wifi_stats N" - else - # G Mode - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - return 0 - else - return 1 - fi - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - led_on /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:status -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - ledsoff=$(ls -d /sys/class/leds/*) - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - local _p0 - _p0=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy0/macaddress) - - if [ ! -z "$_p0" ] - then - _mac_address_tag=$_p0 - fi - - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch0 port 4 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch0 port 4 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/dlink_covr-c1200-a1.sh b/custom-files/dlink_covr-c1200-a1.sh new file mode 100644 index 00000000..262c3a35 --- /dev/null +++ b/custom-files/dlink_covr-c1200-a1.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +get_custom_leds_blink() { + echo "$(ls -d /sys/class/leds/*yellow*)" +} + +# Enable/disable ethernet connection on LAN physical ports when in bridge mode +set_switch_bridge_mode() { + local _enable_bridge="$1" + local _disable_lan_ports="$2" + + if [ "$_enable_bridge" = "y" ] + then + if [ "$_disable_lan_ports" = "y" ] + then + uci set network.@switch_vlan[0].ports='1 0t' + uci set network.@switch_vlan[1].ports='' + else + uci set network.@switch_vlan[0].ports='1 2 0t' + uci set network.@switch_vlan[1].ports='' + fi + else + uci set network.@switch_vlan[0].ports='2 0t' + uci set network.@switch_vlan[1].ports='1 0t' + fi +} + +# Will not change ifnames if this variable is set when in bridge mode +keep_ifnames_in_bridge_mode() { + echo "1" +} diff --git a/custom-files/dlink_dl-dwr116-a3.sh b/custom-files/dlink_dl-dwr116-a3.sh new file mode 100644 index 00000000..b077518e --- /dev/null +++ b/custom-files/dlink_dl-dwr116-a3.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "DWR-116" +} + +get_custom_hardware_version() { + echo "A3" +} + +get_custom_mac() { + local _mac_address_tag="" + local _p0 + _p0=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy0/macaddress) + + if [ ! -z "$_p0" ] + then + _mac_address_tag=$_p0 + fi + + echo "$_mac_address_tag" +} diff --git a/custom-files/greatek_gwr1200-v1.sh b/custom-files/greatek_gwr1200-v1.sh new file mode 100644 index 00000000..77392c40 --- /dev/null +++ b/custom-files/greatek_gwr1200-v1.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +anlix_bootup_defaults() { + ifconfig wlan0 up + iwpriv wlan0 set_mib xcap=35 + iwpriv wlan0 set_mib ther=0 + iwpriv wlan0 set_mib pwrlevelCCK_A=2c2c2c2c2c2c2c2c2c2d2d2d2d2d + iwpriv wlan0 set_mib pwrlevelCCK_B=2929292b2b2b2b2b2b2b2b2b2b2b + iwpriv wlan0 set_mib pwrlevelHT40_1S_A=2828282828282828282929292929 + iwpriv wlan0 set_mib pwrlevelHT40_1S_B=2525252727272727272727272727 + ifconfig wlan0 down + + ifconfig wlan1 up + iwpriv wlan1 set_mib xcap=41 + iwpriv wlan1 set_mib ther=25 + iwpriv wlan1 set_mib pwrlevel5GHT40_1S_A=00000000000000000000000000000000000000000000000000000000000000000000002525252525252523232323232322222222222222222222232323232323242424242424242424242424242424242424242424242424242424242424242424242424242424242424222222222222232323232323232323232323232323232525252525252525252525252525252527272727272727272727272929292929292929292929292929292929292929292900000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrlevel5GHT40_1S_B=00000000000000000000000000000000000000000000000000000000000000000000002424242424242423232323232322222222222222222222222222222222252525252525252525252525252525252525252525252525252525252525252525252525252525252525232323232323232323232323232323232222222222222424242424242424242424242424242427272727272727272727272929292929292929292929292929292929292929292900000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_20BW1S_OFDM1T_A=00000000000000000000000000000000000000000000000000000000000000000000001313131313131313131313131313131313131313131313131313131313020202020202020202020202020202020202020202020202020202020202020202020202020202021313131313131313131313131313131313131313131313131313131313131313131313131313131302020202020202020224242424242424242424242424242424242424242424242400000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_20BW1S_OFDM1T_B=00000000000000000000000000000000000000000000000000000000000000000000002424242424242424242424242424242424242424242424242424242424131313131313131313131313131313131313131313131313131313131313131313131313131313130202020202020202020202020202020202020202020202020202020202020202020202020202020214141414141414141413131313131313131313131313131313131313131313131300000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_80BW1S_160BW1S_A=0000000000000000000000000000000000000000000000000000000000000000000000d0d0d0d0d0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e000000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_80BW1S_160BW1S_B=0000000000000000000000000000000000000000000000000000000000000000000000e0e0e0e0e0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d000000000000000000000000000000000000000 + ifconfig wlan1 down +} + +get_custom_mac() { + . /lib/functions/system.sh + local _mac_address_tag="" + local _p1 + + _p1=$(mtd_get_mac_binary config 19 | awk '{print toupper($1)}') + [ ! -z "$_p1" ] && _mac_address_tag=$_p1 + + echo "$_mac_address_tag" +} + +set_switch_bridge_mode_on_boot() { + local _disable_lan_ports="$1" + + if [ "$_disable_lan_ports" = "y" ] + then + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '0 6' + else + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '0 1 2 3 4 6' + fi +} + +custom_switch_ports() { + case $1 in + 1) echo "switch0" ;; + 2) echo "0" ;; + 3) echo "1 2 3 4" ;; + esac +} diff --git a/custom-files/greatek_gwr1200-v2.sh b/custom-files/greatek_gwr1200-v2.sh new file mode 100644 index 00000000..61f44fd3 --- /dev/null +++ b/custom-files/greatek_gwr1200-v2.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +anlix_bootup_defaults() { + ifconfig wlan0 up + iwpriv wlan0 set_mib xcap=30 + iwpriv wlan0 set_mib ther=32 + iwpriv wlan0 set_mib pwrlevelCCK_A=57555452504f4d4d4d4d4d4d4d4d + iwpriv wlan0 set_mib pwrlevelCCK_B=61616060605f5f5e5d5c5b5a5959 + iwpriv wlan0 set_mib pwrlevelHT40_1S_A=515151504e4d4d4d4c4c4c4c4c4c + iwpriv wlan0 set_mib pwrlevelHT40_1S_B=5f5f5f5e5d5c5b5b5a5a59595959 + iwpriv wlan0 set_mib pwrdiffHT40_2S=fdfdfdfdfdfdfdfdfdfdfdfdfdfd + iwpriv wlan0 set_mib pwrdiffHT20=00ffffff00011000110010000000 + iwpriv wlan0 set_mib pwrdiffOFDM=4433333344455444554454444444 + ifconfig wlan0 down + + ifconfig wlan1 up + iwpriv wlan1 set_mib xcap=71 + iwpriv wlan1 set_mib ther=34 + iwpriv wlan1 set_mib pwrlevel5GHT40_1S_A=00000000000000000000000000000000000000000000000000000000000000000000005f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5e5e5e5e5e5e5e5e5d5d5d5d5d5d5d5d5c5c5c5c5c5c5c5c5b5b5b5b5b5b5b5b5a5a5a5a5a5a5a5a595959595959595a5a5a5a5b5b5b5c5c5d5d5e5e5f5e5e5d5d5c5c5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a00000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrlevel5GHT40_1S_B=00000000000000000000000000000000000000000000000000000000000000000000005d5d5d5d5d5d5d5d5d5d5d5e5e5f5f60616162626262616161616161616161616060606060606060606060605f5f5f5f5f5f5f5f5f5f5f5f5e5e5e5e5e5e5e5e5e5e5e5e5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5e5e5f5f606161626261616060605f5f5f5f5f5f5f5f6060606060606060606060606161616161616160605f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f00000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_20BW1S_OFDM1T_A=00000000000000000000000000000000000000000000000000000000000000000000000202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020200000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_20BW1S_OFDM1T_B=00000000000000000000000000000000000000000000000000000000000000000000000202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020200000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_40BW2S_20BW2S_A=0000000000000000000000000000000000000000000000000000000000000000000000dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd00000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_40BW2S_20BW2S_B=0000000000000000000000000000000000000000000000000000000000000000000000dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd00000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_80BW1S_160BW1S_A=0000000000000000000000000000000000000000000000000000000000000000000000edededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededed00000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_80BW1S_160BW1S_B=0000000000000000000000000000000000000000000000000000000000000000000000edededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededededed00000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_80BW2S_160BW2S_A=0000000000000000000000000000000000000000000000000000000000000000000000dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd00000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_80BW2S_160BW2S_B=0000000000000000000000000000000000000000000000000000000000000000000000dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd00000000000000000000000000000000000000 + ifconfig wlan1 down +} + +get_custom_mac() { + . /lib/functions/system.sh + local _mac_address_tag="" + local _p1 + + _p1=$(mtd_get_mac_binary config 19 | awk '{print toupper($1)}') + [ ! -z "$_p1" ] && _mac_address_tag=$_p1 + + echo "$_mac_address_tag" +} + +set_switch_bridge_mode_on_boot() { + local _disable_lan_ports="$1" + + if [ "$_disable_lan_ports" = "y" ] + then + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '0 6' + else + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '0 1 2 3 4 6' + fi +} + +custom_switch_ports() { + case $1 in + 1) echo "switch0" ;; + 2) echo "0" ;; + 3) echo "1 2 3 4" ;; + esac +} diff --git a/custom-files/greatek_gwr300-v1.sh b/custom-files/greatek_gwr300-v1.sh new file mode 100644 index 00000000..de68b8a2 --- /dev/null +++ b/custom-files/greatek_gwr300-v1.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +anlix_bootup_defaults() { + ifconfig wlan0 up + iwpriv wlan0 set_mib xcap=38 + iwpriv wlan0 set_mib pwrlevelCCK_A=2c2c2c2c2c2c2c2c2c2c2c2c2c2c + iwpriv wlan0 set_mib pwrlevelCCK_B=2d2d2d2d2d2d2d2d2d2d2d2d2d2d + iwpriv wlan0 set_mib pwrlevelHT40_1S_A=2d2d2d2d2d2d2d2d2d2d2d2d2d2d + iwpriv wlan0 set_mib pwrlevelHT40_1S_B=2e2e2e2e2d2d2d2d2d2d2d2d2d2d + ifconfig wlan0 down + + echo 1 > /proc/sys/vm/panic_on_oom +} + +get_custom_mac() { + local _mac_address_tag="" + local _p1 + + _p1=$(awk '{print toupper($1)}' /sys/class/net/eth1/address) + [ ! -z "$_p1" ] && _mac_address_tag=$_p1 + + echo "$_mac_address_tag" +} + +set_switch_bridge_mode_on_boot() { + local _disable_lan_ports="$1" + + if [ "$_disable_lan_ports" = "y" ] + then + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '4 6' + else + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '0 1 2 3 4 6' + fi +} + +# Needs reboot to validate switch config +needs_reboot_bridge_mode() { + reboot +} + +#Force a memory cleanup to avoid processor usage in network +anlix_force_clean_memory() { + echo 3 > /proc/sys/vm/drop_caches +} + +custom_switch_ports() { + case $1 in + 1) echo "switch0" ;; + 2) echo "4" ;; + 3) echo "0 1 2 3" ;; + esac +} + +custom_wifi_24_txpower(){ + echo "22" +} diff --git a/custom-files/intelbras_gf1200-v1.sh b/custom-files/intelbras_gf1200-v1.sh new file mode 100644 index 00000000..4aa44a8f --- /dev/null +++ b/custom-files/intelbras_gf1200-v1.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +anlix_bootup_defaults() { + ifconfig wlan0 up + iwpriv wlan0 set_mib xcap=31 + iwpriv wlan0 set_mib ther=43 + iwpriv wlan0 set_mib pwrlevelCCK_A=2d2d2d2e2e2e2e2e2e3030303030 + iwpriv wlan0 set_mib pwrlevelCCK_B=2a2a2a2c2c2c2c2c2c2e2e2e2e2e + iwpriv wlan0 set_mib pwrlevelHT40_1S_A=2828282828282828282a2a2a2a2a + iwpriv wlan0 set_mib pwrlevelHT40_1S_B=2626262727272727272828282828 + iwpriv wlan0 set_mib pwrdiffHT20=1111111111111111111111111111 + iwpriv wlan0 set_mib pwrdiffOFDM=2222222222222222222222222222 + ifconfig wlan0 down + + ifconfig wlan1 up + iwpriv wlan1 set_mib xcap=59 + iwpriv wlan1 set_mib ther=28 + iwpriv wlan1 set_mib pwrlevel5GHT40_1S_A=00000000000000000000000000000000000000000000000000000000000000000000002323232323232322222222222222222222222222222222222222222222242424242424242424242424242424242424242424242424242424242424242424242424242424242424262626262626272727272727272727272222222222222121212121212121212121212121212127272727272727272727272a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a00000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrlevel5GHT40_1S_B=00000000000000000000000000000000000000000000000000000000000000000000002222222222222223232323232321212121212121212121202020202020232323232323232323232323232323232323232323232323232323232323232323232323232323232323252525252525272727272727272727272121212121211f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f25252525252525252525252929292929292929292929292929292929292929292900000000000000000000000000000000000000 + ifconfig wlan1 down +} + +get_custom_mac() { + . /lib/functions/system.sh + local _mac_address_tag="" + local _p1 + + _p1=$(mtd_get_mac_binary config 7 | awk '{print toupper($1)}') + [ ! -z "$_p1" ] && _mac_address_tag=$_p1 + + echo "$_mac_address_tag" +} + +set_switch_bridge_mode_on_boot() { + local _disable_lan_ports="$1" + + if [ "$_disable_lan_ports" = "y" ] + then + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '0 6' + else + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '1 2 3 6' + fi +} + +custom_switch_ports() { + case $1 in + 1) echo "switch0" ;; + 2) echo "0" ;; + 3) echo "1 2 3 4" ;; + esac +} + +get_custom_leds_blink() { + echo "$(ls -d /sys/class/leds/*blue*)" +} diff --git a/custom-files/intelbras_rf1200-v1.sh b/custom-files/intelbras_rf1200-v1.sh new file mode 100644 index 00000000..2e855aa0 --- /dev/null +++ b/custom-files/intelbras_rf1200-v1.sh @@ -0,0 +1,78 @@ +#!/bin/sh + +anlix_bootup_defaults() { + ifconfig wlan0 up + iwpriv wlan0 set_mib xcap=35 + iwpriv wlan0 set_mib ther=36 + iwpriv wlan0 set_mib pwrlevelCCK_A=2C2C2C2E2E2E2E2E2E2E2E2E2E2E + iwpriv wlan0 set_mib pwrlevelCCK_B=2E2E2E3030303030303030303030 + iwpriv wlan0 set_mib pwrlevelHT40_1S_A=2626262828282828282828282828 + iwpriv wlan0 set_mib pwrlevelHT40_1S_B=2929292929292929292A2A2A2A2A + iwpriv wlan0 set_mib pwrdiffHT40_2S=e0e0e0e0e0e0e0e0e0e0e0e0e0e0 + iwpriv wlan0 set_mib pwrdiffHT20=1111112222222222221111111111 + iwpriv wlan0 set_mib pwrdiffOFDM=2222222222222222222222222222 + ifconfig wlan0 down + + ifconfig wlan1 up + iwpriv wlan1 set_mib xcap=28 + iwpriv wlan1 set_mib ther=23 + iwpriv wlan1 set_mib pwrlevel5GHT40_1S_A=00000000000000000000000000000000000000000000000000000000000000000000002727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272727272725252525252525252526262626262626262626262626262626262626262626262600000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrlevel5GHT40_1S_B=00000000000000000000000000000000000000000000000000000000000000000000002828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282828282824242424242424242424242424242424242424242424242424242424242424242400000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_20BW1S_OFDM1T_A=2212121212121212121212121200 + iwpriv wlan1 set_mib pwrdiff_5G_20BW1S_OFDM1T_B=1212121212121212121212121200 + iwpriv wlan1 set_mib pwrdiff_5G_40BW2S_20BW2S_A=efefefefefefefefefefefefef00 + iwpriv wlan1 set_mib pwrdiff_5G_40BW2S_20BW2S_B=efefefefefefefefefefefefef00 + ifconfig wlan1 down +} + +get_custom_mac() { + . /lib/functions/system.sh + local _mac_address_tag="" + local _p1 + + _p1=$(mtd_get_mac_ascii boot HW_NIC0_ADDR | awk '{print toupper($1)}') + [ ! -z "$_p1" ] && _mac_address_tag=$_p1 + + echo "$_mac_address_tag" +} + +set_switch_bridge_mode_on_boot() { + local _disable_lan_ports="$1" + + if [ "$_disable_lan_ports" = "y" ] + then + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '0 6' + else + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '0 1 2 3 4 6' + fi +} + +custom_switch_ports() { + case $1 in + 1) echo "switch0" ;; + 2) echo "0" ;; + 3) echo "1 2 3 4" ;; + esac +} + +get_custom_leds_blink() { + echo "$(ls -d /sys/class/leds/*blue*)" +} + +custom_wifi_24_txpower(){ + echo "16" +} + +custom_wifi_50_txpower(){ + echo "14" +} + +custom_wifi_50_channels(){ + echo "40" +} diff --git a/custom-files/intelbras_rg1200-v1.sh b/custom-files/intelbras_rg1200-v1.sh new file mode 100644 index 00000000..e167d220 --- /dev/null +++ b/custom-files/intelbras_rg1200-v1.sh @@ -0,0 +1,74 @@ +#!/bin/sh + +anlix_bootup_defaults() { + ifconfig wlan0 up + iwpriv wlan0 set_mib xcap=32 + iwpriv wlan0 set_mib ther=34 + iwpriv wlan0 set_mib pwrlevelCCK_A=1616161919191919191B1B1B1B1B + iwpriv wlan0 set_mib pwrlevelCCK_B=1010101313131313131515151515 + iwpriv wlan0 set_mib pwrlevelHT40_1S_A=1919191A1A1A1A1A1A1C1C1C1C1C + iwpriv wlan0 set_mib pwrlevelHT40_1S_B=1414141515151515151616161616 + iwpriv wlan0 set_mib pwrdiffHT40_2S=0000000000000000000000000000 + iwpriv wlan0 set_mib pwrdiffHT20=0000001111111111112222222222 + iwpriv wlan0 set_mib pwrdiffOFDM=1111112222222222223333333333 + ifconfig wlan0 down + + ifconfig wlan1 up + iwpriv wlan1 set_mib xcap=37 + iwpriv wlan1 set_mib ther=28 + iwpriv wlan1 set_mib pwrlevel5GHT40_1S_A=00000000000000000000000000000000000000000000000000000000000000000000001D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D + iwpriv wlan1 set_mib pwrlevel5GHT40_1S_B=00000000000000000000000000000000000000000000000000000000000000000000001F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F + iwpriv wlan1 set_mib pwrdiff_5G_20BW1S_OFDM1T_A=1212121212121212121212121212 + iwpriv wlan1 set_mib pwrdiff_5G_20BW1S_OFDM1T_B=1212121212121212121212121212 + iwpriv wlan1 set_mib pwrdiff_5G_40BW2S_20BW2S_A=0101010101010101010101010101 + iwpriv wlan1 set_mib pwrdiff_5G_40BW2S_20BW2S_B=0101010101010101010101010101 + ifconfig wlan1 down +} + +get_custom_mac() { + . /lib/functions/system.sh + local _mac_address_tag="" + local _p1 + + _p1=$(mtd_get_mac_ascii boot HW_NIC0_ADDR | awk '{print toupper($1)}') + [ ! -z "$_p1" ] && _mac_address_tag=$_p1 + + echo "$_mac_address_tag" +} + +set_switch_bridge_mode_on_boot() { + local _disable_lan_ports="$1" + + if [ "$_disable_lan_ports" = "y" ] + then + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '3 4 6' + else + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '0 1 2 3 4 6' + fi +} + +custom_switch_ports() { + case $1 in + 1) echo "switch0" ;; + 2) echo "3" ;; + 3) echo "0 1 2" ;; + esac +} + +get_custom_leds_blink() { + echo "$(ls -d /sys/class/leds/*blue*)" +} + +custom_wifi_24_txpower(){ + echo "22" +} + +custom_wifi_50_channels(){ + echo "40" +} diff --git a/custom-files/intelbras_w51200f-v1.sh b/custom-files/intelbras_w51200f-v1.sh new file mode 100644 index 00000000..05d8f975 --- /dev/null +++ b/custom-files/intelbras_w51200f-v1.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +anlix_bootup_defaults() { + ifconfig wlan0 up + iwpriv wlan0 set_mib xcap=0 + iwpriv wlan0 set_mib ther=25 + iwpriv wlan0 set_mib pwrlevelCCK_A=5b5b5b5a5a5a5a5a5a5353535353 + iwpriv wlan0 set_mib pwrlevelCCK_B=4f4f4f4b4b4b4b4b4b4949494949 + iwpriv wlan0 set_mib pwrlevelHT40_1S_A=6464646464646464645e5e5e5e5e + iwpriv wlan0 set_mib pwrlevelHT40_1S_B=5c5c5c5858585858585454545454 + iwpriv wlan0 set_mib pwrdiffHT40_2S=0000000000000000000000000000 + iwpriv wlan0 set_mib pwrdiffHT20=dddddddddddddddddddddddddddd + iwpriv wlan0 set_mib pwrdiffOFDM=bcbcbcbcbcbcbcbcbcbcbcbcbcbc + iwpriv wlan0 set_mib pwrlevel_TSSIHT40_1S_A=2121211e1e1e1e1e1e2121212121 + iwpriv wlan0 set_mib pwrlevel_TSSIHT40_1S_B=1717171b1b1b1b1b1b1e1e1e1e1e + ifconfig wlan0 down + + ifconfig wlan1 up + iwpriv wlan1 set_mib xcap=69 + iwpriv wlan1 set_mib ther=28 + iwpriv wlan1 set_mib pwrlevel5GHT40_1S_A=00000000000000000000000000000000000000000000000000000000000000000000004343434343444444444444444444444444444444444444444444444444000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044444444444444444441414141414141414141414141414141414141414141414100000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrlevel5GHT40_1S_B=00000000000000000000000000000000000000000000000000000000000000000000004141414141434343434343434343434343434343434343434343434343000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000042424242424242424241414141414141414141414141414141414141414141414100000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_20BW1S_OFDM1T_A=00000000000000000000000000000000000000000000000000000000000000000000000e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f00000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_80BW1S_160BW1S_A=00000000000000000000000000000000000000000000000000000000000000000000001010101010101010101010101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020202020202020202020202020202020203030303030303030303030303030303000000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrdiff_5G_80BW1S_160BW1S_B=000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020202020202020202020202020202020202020202020202020202020202020202000000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrlevel_TSSI5GHT40_1S_A=000000000000000000000000000000000000000000000000000000000000000000000040404040403c3c3c3c3c3c3c3c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000036363636363636363639393939393939390000000000000000000000000000000000000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrlevel_TSSI5GHT40_1S_B=00000000000000000000000000000000000000000000000000000000000000000000003c3c3c3c3c373737373737373700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000036363636363636363636363636363636360000000000000000000000000000000000000000000000000000000000000000000000 + ifconfig wlan1 down +} + +get_custom_mac() { + . /lib/functions/system.sh + local _mac_address_tag="" + local _p1 + + _p1=$(mtd_get_mac_binary config 7 | awk '{print toupper($1)}') + [ ! -z "$_p1" ] && _mac_address_tag=$_p1 + + echo "$_mac_address_tag" +} + +set_switch_bridge_mode_on_boot() { + local _disable_lan_ports="$1" + + if [ "$_disable_lan_ports" = "y" ] + then + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '0 6' + else + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '0 1 2 3 6' + fi +} + +custom_switch_ports() { + case $1 in + 1) echo "switch0" ;; + 2) echo "0" ;; + 3) echo "1 2 3" ;; + esac +} + +custom_wifi_24_txpower(){ + echo "20" +} + +custom_wifi_50_txpower(){ + echo "20" +} diff --git a/custom-files/itlb-ncloud-v1/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/itlb-ncloud-v1/etc/uci-defaults/z005_flashbox-wireless.sh index 8592eada..713b7b01 100644 --- a/custom-files/itlb-ncloud-v1/etc/uci-defaults/z005_flashbox-wireless.sh +++ b/custom-files/itlb-ncloud-v1/etc/uci-defaults/z005_flashbox-wireless.sh @@ -41,7 +41,7 @@ then then uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" uci set wireless.@wifi-device[0].noscan="1" - elif [ "$_remote_htmode_24" = "HT20" ] + elif [ "$FLM_24_BAND" = "HT20" ] then uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" uci set wireless.@wifi-device[0].noscan="0" diff --git a/custom-files/itlb-ncloud-v1/usr/share/functions/device_functions.sh b/custom-files/itlb-ncloud-v1/usr/share/functions/device_functions.sh index 8af42612..f5f3c01e 100644 --- a/custom-files/itlb-ncloud-v1/usr/share/functions/device_functions.sh +++ b/custom-files/itlb-ncloud-v1/usr/share/functions/device_functions.sh @@ -237,3 +237,51 @@ get_lan_dev_negotiated_speed() { echo "$_speed" } + +store_enable_wifi() { + local _itf_num + # 0: 2.4GHz 1: 5.0GHz 2: Both + _itf_num=$1 + + wifi down + uci set wireless.@wifi-iface[0].disabled="0" + save_wifi_local_config + wifi up +} + +store_disable_wifi() { + local _itf_num + # 0: 2.4GHz 1: 5.0GHz 2: Both + _itf_num=$1 + + wifi down + uci set wireless.@wifi-iface[0].disabled="1" + save_wifi_local_config + wifi up +} + +get_wifi_state() { + local _itf_num + local _q + # 0: 2.4GHz 1: 5.0GHz + _itf_num=$1 + + if [ "$_itf_num" = "0" ] + then + _q=$(uci -q get wireless.@wifi-iface[0].disabled) + if [ "$_q" ] + then + if [ "$(uci get wireless.@wifi-iface[0].disabled)" = "1" ] + then + echo "0" + else + echo "1" + fi + else + echo "1" + fi + elif [ "$_itf_num" = "1" ] + then + echo "0" + fi +} diff --git a/custom-files/multilaser_re172-v1.sh b/custom-files/multilaser_re172-v1.sh new file mode 100644 index 00000000..9e1ce749 --- /dev/null +++ b/custom-files/multilaser_re172-v1.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +anlix_bootup_defaults() { + ifconfig wlan0 up + iwpriv wlan0 set_mib xcap=35 + iwpriv wlan0 set_mib pwrlevelCCK_A=2929292828282828282828282828 + iwpriv wlan0 set_mib pwrlevelCCK_B=2b2b2b2a2a2a2a2a2a2a2a2a2a2a + iwpriv wlan0 set_mib pwrlevelHT40_1S_A=2929292828282828282828282828 + iwpriv wlan0 set_mib pwrlevelHT40_1S_B=2b2b2b2a2a2a2a2a2a2a2a2a2a2a + ifconfig wlan0 down + + echo 1 > /proc/sys/vm/panic_on_oom +} + +get_custom_mac() { + local _mac_address_tag="" + local _p1 + + _p1=$(awk '{print toupper($1)}' /sys/class/net/eth1/address) + [ ! -z "$_p1" ] && _mac_address_tag=$_p1 + + echo "$_mac_address_tag" +} + +set_switch_bridge_mode_on_boot() { + local _disable_lan_ports="$1" + + if [ "$_disable_lan_ports" = "y" ] + then + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '4 6' + else + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '0 1 2 3 4 6' + fi +} + +# Needs reboot to validate switch config +needs_reboot_bridge_mode() { + reboot +} + +#Force a memory cleanup to avoid processor usage in network +anlix_force_clean_memory() { + echo 3 > /proc/sys/vm/drop_caches +} + +custom_switch_ports() { + case $1 in + 1) echo "switch0" ;; + 2) echo "4" ;; + 3) echo "0 1 2 3" ;; + esac +} + diff --git a/custom-files/multilaser_re708-v1.sh b/custom-files/multilaser_re708-v1.sh new file mode 100644 index 00000000..a25c9a4b --- /dev/null +++ b/custom-files/multilaser_re708-v1.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +anlix_bootup_defaults() { + ifconfig wlan0 up + iwpriv wlan0 set_mib xcap=35 + iwpriv wlan0 set_mib ther=0 + iwpriv wlan0 set_mib pwrlevelCCK_A=2c2c2c2c2c2c2c2c2c2d2d2d2d2d + iwpriv wlan0 set_mib pwrlevelCCK_B=2929292b2b2b2b2b2b2b2b2b2b2b + iwpriv wlan0 set_mib pwrlevelHT40_1S_A=2828282828282828282929292929 + iwpriv wlan0 set_mib pwrlevelHT40_1S_B=2525252727272727272727272727 + ifconfig wlan0 down + + ifconfig wlan1 up + iwpriv wlan1 set_mib xcap=30 + iwpriv wlan1 set_mib ther=0 + iwpriv wlan1 set_mib pwrlevel5GHT40_1S_A=00000000000000000000000000000000000000000000000000000000000000000000001d1d1d1d1d1c1c1c1c1c1c1c1c1b1b1b1b1b1b1b1b1919191919191919181818181818181818181818181818181818181818181818181818181818181818181818181818181717171717171717171717171717171716161616161616161717171717171717171717171717171712121212121212121210101010101010100b0b0b0b0b0b0b0b060606060606060600000000000000000000000000000000000000 + iwpriv wlan1 set_mib pwrlevel5GHT40_1S_B=00000000000000000000000000000000000000000000000000000000000000000000001c1c1c1c1c1b1b1b1b1b1b1b1b1a1a1a1a1a1a1a1a181818181818181817171717171717171717171717171717171717171717171717171717171717171717171717171717161616161616161616161616161616161515151515151515161616161616161616161616161616161010101010101010100e0e0e0e0e0e0e0e0909090909090909040404040404040400000000000000000000000000000000000000 + ifconfig wlan1 down +} + +get_custom_mac() { + . /lib/functions/system.sh + local _mac_address_tag="" + local _p1 + + _p1=$(mtd_get_mac_binary config 7 | awk '{print toupper($1)}') + [ ! -z "$_p1" ] && _mac_address_tag=$_p1 + + echo "$_mac_address_tag" +} + +set_switch_bridge_mode_on_boot() { + local _disable_lan_ports="$1" + + if [ "$_disable_lan_ports" = "y" ] + then + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '4 6' + else + # eth0 + swconfig dev switch0 vlan 9 set ports '' + # eth1 + swconfig dev switch0 vlan 8 set ports '0 1 2 3 4 6' + fi +} + +custom_switch_ports() { + case $1 in + 1) echo "switch0" ;; + 2) echo "4" ;; + 3) echo "0 1 2 3" ;; + esac +} diff --git a/custom-files/tbs.sh b/custom-files/tbs.sh new file mode 100644 index 00000000..84f117f2 --- /dev/null +++ b/custom-files/tbs.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +get_custom_leds_blink() { + local _leds=$(ls -d /sys/class/leds/*green*) + [ -e /sys/class/leds/mt76-phy0 ] && _leds="$_leds /sys/class/leds/mt76-phy0" + echo "$_leds" +} + +get_custom_mac() { + local _mac_address_tag="" + local _p1 + + _p1=$(uci get network.wan_eth0_2_dev.macaddr | awk '{print toupper($1)}') + [ ! -z "$_p1" ] && _mac_address_tag=$_p1 + + echo "$_mac_address_tag" +} diff --git a/custom-files/tl-wdr3500-v1/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wdr3500-v1/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 2968d8e5..00000000 --- a/custom-files/tl-wdr3500-v1/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wdr3500-v1/usr/share/functions/device_functions.sh b/custom-files/tl-wdr3500-v1/usr/share/functions/device_functions.sh deleted file mode 100644 index 2402feba..00000000 --- a/custom-files/tl-wdr3500-v1/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,232 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - # This model does not support AC options - if [ "$(uci -q get wireless.radio1.htmode)" != "HT40" ] || - [ "$(uci -q get wireless.radio1.htmode)" != "HT20" ] - then - uci set wireless.radio1.htmode="HT40" - fi - if [ "$(uci -q get wireless.radio1.hwmode)" != "11na" ] - then - uci set wireless.radio1.hwmode="11na" - fi - uci commit wireless -} - -is_5ghz_capable() { - # true - echo "1" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_info - local _wifi_stats="" - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - local _ap_freq="2.4" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -ne 0 ] - then - _wifi_itf="wlan1" - _ap_freq="5.0" - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - fi - - if [ $_retstatus -eq 0 ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="$(echo "$_dev_info" | grep 'rx bitrate:' | \ - awk '{print $3}')" - local _dev_mcs="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $5}')" - local _dev_signal="$(echo "$_dev_info" | grep 'signal:' | \ - awk '{print $2}' | awk -F. '{print $1}')" - local _ap_noise="$(iwinfo $_wifi_itf info | grep 'Noise:' | \ - awk '{print $5}' | awk -F. '{print $1}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'tx bytes:' | \ - awk '{print $3}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'rx bytes:' | \ - awk '{print $3}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'tx packets:' | \ - awk '{print $3}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'rx packets:' | \ - awk '{print $3}')" - - # Calculate SNR - local _dev_snr="$(($_dev_signal - $_ap_noise))" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mcs" == "MCS" ] - then - # N or AC - _wifi_stats="$_wifi_stats N" - else - # G Mode - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -ne 0 ] - then - _wifi_itf="wlan1" - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - fi - - if [ $_retstatus -eq 0 ] - then - return 0 - else - return 1 - fi - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - for system_led in /sys/class/leds/*system* - do - led_on "$system_led" - done - - # reset hardware lan ports if any - for lan_led in /sys/class/leds/*lan* - do - if [ -f "$lan_led"/enable_hw_mode ] - then - echo 1 > "$lan_led"/enable_hw_mode - fi - done - - # reset hardware wan port if any - for wan_led in /sys/class/leds/*wan* - do - if [ -f "$wan_led"/enable_hw_mode ] - then - echo 1 > "$wan_led"/enable_hw_mode - fi - done - - # reset atheros 5G led - if [ -f /sys/class/leds/ath9k-phy1/trigger ] - then - echo "phy1tpt" > /sys/class/leds/ath9k-phy1/trigger - fi -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - ledsoff=$(ls -d /sys/class/leds/*) - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - local _p0 - _p0=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy0/macaddress) - - if [ ! -z "$_p0" ] - then - _mac_address_tag=$_p0 - fi - - echo "$_mac_address_tag" -} - -# Possible values: 10 or 100 -get_wan_negotiated_speed() { - cat /sys/class/net/eth1/speed -} - -# Possible values: half or full -get_wan_negotiated_duplex() { - cat /sys/class/net/eth1/duplex -} - -get_lan_dev_negotiated_speed() { - local _mac="$1" - local _swport - local _speed - - _swport="$(swconfig dev switch0 show | grep $_mac | \ - awk -F: '{print $1}' | awk '{print $2}')" - _speed="$(swconfig dev switch0 port $_swport get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - echo "$_speed" -} diff --git a/custom-files/tl-wdr3600-v1/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wdr3600-v1/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 2968d8e5..00000000 --- a/custom-files/tl-wdr3600-v1/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wdr3600-v1/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wdr3600-v1/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index 636f6c8d..00000000 --- a/custom-files/tl-wdr3600-v1/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/sh - -# -# WARNING! This file may be replaced depending on the selected target! -# - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -SUFFIX_5="-5GHz" - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - - uci set wireless.@wifi-device[0].type="mac80211" - uci set wireless.@wifi-device[0].txpower="17" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - fi - - uci set wireless.@wifi-device[0].disabled="0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - uci set wireless.@wifi-iface[0].max_inactivity="3000" - - # 5GHz 802.11 a/n mode - if [ "$(uci -q get wireless.@wifi-iface[1])" ] - then - uci set wireless.@wifi-device[1].type="mac80211" - uci set wireless.@wifi-device[1].txpower="17" - uci set wireless.@wifi-device[1].channel="$FLM_50_CHANNEL" - uci set wireless.@wifi-device[1].hwmode="11na" - uci set wireless.@wifi-device[1].country="BR" - uci set wireless.@wifi-device[1].htmode="HT40" - uci set wireless.@wifi-device[1].noscan="1" - uci set wireless.@wifi-device[1].disabled="0" - uci set wireless.@wifi-iface[1].ssid="$setssid$SUFFIX_5" - uci set wireless.@wifi-iface[1].encryption="psk2" - uci set wireless.@wifi-iface[1].key="$FLM_PASSWD" - uci set wireless.@wifi-iface[1].max_inactivity="3000" - fi - uci commit wireless -fi - -exit 0 diff --git a/custom-files/tl-wdr3600-v1/usr/share/functions/device_functions.sh b/custom-files/tl-wdr3600-v1/usr/share/functions/device_functions.sh deleted file mode 100644 index 04eb63a3..00000000 --- a/custom-files/tl-wdr3600-v1/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,240 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - # This model does not support AC options - if [ "$(uci -q get wireless.radio1.htmode)" != "HT40" ] || - [ "$(uci -q get wireless.radio1.htmode)" != "HT20" ] - then - uci set wireless.radio1.htmode="HT40" - fi - if [ "$(uci -q get wireless.radio1.hwmode)" != "11na" ] - then - uci set wireless.radio1.hwmode="11na" - fi - uci commit wireless -} - -is_5ghz_capable() { - # true - echo "1" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_info - local _wifi_stats="" - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - local _ap_freq="2.4" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -ne 0 ] - then - _wifi_itf="wlan1" - _ap_freq="5.0" - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - fi - - if [ $_retstatus -eq 0 ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="$(echo "$_dev_info" | grep 'rx bitrate:' | \ - awk '{print $3}')" - local _dev_mcs="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $5}')" - local _dev_signal="$(echo "$_dev_info" | grep 'signal:' | \ - awk '{print $2}' | awk -F. '{print $1}')" - local _ap_noise="$(iwinfo $_wifi_itf info | grep 'Noise:' | \ - awk '{print $5}' | awk -F. '{print $1}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'tx bytes:' | \ - awk '{print $3}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'rx bytes:' | \ - awk '{print $3}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'tx packets:' | \ - awk '{print $3}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'rx packets:' | \ - awk '{print $3}')" - - # Calculate SNR - local _dev_snr="$(($_dev_signal - $_ap_noise))" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mcs" == "MCS" ] - then - # N or AC - _wifi_stats="$_wifi_stats N" - else - # G Mode - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -ne 0 ] - then - _wifi_itf="wlan1" - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - fi - - if [ $_retstatus -eq 0 ] - then - return 0 - else - return 1 - fi - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - for system_led in /sys/class/leds/*system* - do - led_on "$system_led" - done - - # reset hardware lan ports if any - for lan_led in /sys/class/leds/*lan* - do - if [ -f "$lan_led"/enable_hw_mode ] - then - echo 1 > "$lan_led"/enable_hw_mode - fi - done - - # reset hardware wan port if any - for wan_led in /sys/class/leds/*wan* - do - if [ -f "$wan_led"/enable_hw_mode ] - then - echo 1 > "$wan_led"/enable_hw_mode - fi - done - - # reset atheros 2.4G led - if [ -f /sys/class/leds/ath9k-phy0/trigger ] - then - echo "phy0tpt" > /sys/class/leds/ath9k-phy0/trigger - fi - # reset atheros 5G led - if [ -f /sys/class/leds/ath9k-phy1/trigger ] - then - echo "phy1tpt" > /sys/class/leds/ath9k-phy1/trigger - fi -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - ledsoff=$(ls -d /sys/class/leds/*) - for trigger_path in $ledsoff - do - led_off "$trigger_path" - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - local _p1 - - _p1=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy1/macaddress) - if [ ! -z "$_p1" ] - then - _mac_address_tag=$_p1 - fi - - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch0 port 1 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch0 port 1 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _mac="$1" - local _swport - local _speed - - _swport="$(swconfig dev switch0 show | grep $_mac | \ - awk -F: '{print $1}' | awk '{print $2}')" - _speed="$(swconfig dev switch0 port $_swport get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - echo "$_speed" -} diff --git a/custom-files/tl-wdr4300-v1/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wdr4300-v1/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 2968d8e5..00000000 --- a/custom-files/tl-wdr4300-v1/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wdr4300-v1/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wdr4300-v1/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index 636f6c8d..00000000 --- a/custom-files/tl-wdr4300-v1/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/sh - -# -# WARNING! This file may be replaced depending on the selected target! -# - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -SUFFIX_5="-5GHz" - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - - uci set wireless.@wifi-device[0].type="mac80211" - uci set wireless.@wifi-device[0].txpower="17" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - fi - - uci set wireless.@wifi-device[0].disabled="0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - uci set wireless.@wifi-iface[0].max_inactivity="3000" - - # 5GHz 802.11 a/n mode - if [ "$(uci -q get wireless.@wifi-iface[1])" ] - then - uci set wireless.@wifi-device[1].type="mac80211" - uci set wireless.@wifi-device[1].txpower="17" - uci set wireless.@wifi-device[1].channel="$FLM_50_CHANNEL" - uci set wireless.@wifi-device[1].hwmode="11na" - uci set wireless.@wifi-device[1].country="BR" - uci set wireless.@wifi-device[1].htmode="HT40" - uci set wireless.@wifi-device[1].noscan="1" - uci set wireless.@wifi-device[1].disabled="0" - uci set wireless.@wifi-iface[1].ssid="$setssid$SUFFIX_5" - uci set wireless.@wifi-iface[1].encryption="psk2" - uci set wireless.@wifi-iface[1].key="$FLM_PASSWD" - uci set wireless.@wifi-iface[1].max_inactivity="3000" - fi - uci commit wireless -fi - -exit 0 diff --git a/custom-files/tl-wdr4300-v1/usr/share/functions/device_functions.sh b/custom-files/tl-wdr4300-v1/usr/share/functions/device_functions.sh deleted file mode 100644 index 6d5c8f21..00000000 --- a/custom-files/tl-wdr4300-v1/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,246 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - # This model does not support AC options - if [ "$(uci -q get wireless.radio1.htmode)" != "HT40" ] || - [ "$(uci -q get wireless.radio1.htmode)" != "HT20" ] - then - uci set wireless.radio1.htmode="HT40" - fi - if [ "$(uci -q get wireless.radio1.hwmode)" != "11na" ] - then - uci set wireless.radio1.hwmode="11na" - fi - uci commit wireless -} - -is_5ghz_capable() { - # true - echo "1" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_info - local _wifi_stats="" - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - local _ap_freq="2.4" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -ne 0 ] - then - _wifi_itf="wlan1" - _ap_freq="5.0" - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - fi - - if [ $_retstatus -eq 0 ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="$(echo "$_dev_info" | grep 'rx bitrate:' | \ - awk '{print $3}')" - local _dev_mcs="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $5}')" - local _dev_signal="$(echo "$_dev_info" | grep 'signal:' | \ - awk '{print $2}' | awk -F. '{print $1}')" - local _ap_noise="$(iwinfo $_wifi_itf info | grep 'Noise:' | \ - awk '{print $5}' | awk -F. '{print $1}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'tx bytes:' | \ - awk '{print $3}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'rx bytes:' | \ - awk '{print $3}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'tx packets:' | \ - awk '{print $3}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'rx packets:' | \ - awk '{print $3}')" - - # Calculate SNR - local _dev_snr="$(($_dev_signal - $_ap_noise))" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mcs" == "MCS" ] - then - # N or AC - _wifi_stats="$_wifi_stats N" - else - # G Mode - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -ne 0 ] - then - _wifi_itf="wlan1" - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - fi - - if [ $_retstatus -eq 0 ] - then - return 0 - else - return 1 - fi - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - for system_led in /sys/class/leds/*system* - do - led_on "$system_led" - done - - # reset hardware lan ports if any - for lan_led in /sys/class/leds/*lan* - do - if [ -f "$lan_led"/enable_hw_mode ] - then - echo 1 > "$lan_led"/enable_hw_mode - fi - done - - # reset hardware wan port if any - for wan_led in /sys/class/leds/*wan* - do - if [ -f "$wan_led"/enable_hw_mode ] - then - echo 1 > "$wan_led"/enable_hw_mode - fi - done - - # reset atheros 5G led - if [ -f /sys/class/leds/ath9k-phy1/trigger ] - then - echo "phy1tpt" > /sys/class/leds/ath9k-phy1/trigger - fi -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - ledsoff=$(ls -d /sys/class/leds/*) - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - local _p1 - - _p1=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy1/macaddress) - if [ ! -z "$_p1" ] - then - _mac_address_tag=$_p1 - fi - - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch0 port 1 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch0 port 1 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _mac="$1" - local _swport - local _speed - - _swport="$(swconfig dev switch0 show | grep $_mac | \ - awk -F: '{print $1}' | awk '{print $2}')" - _speed="$(swconfig dev switch0 port $_swport get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - echo "$_speed" -} - -get_lan_dev_negotiated_speed() { - local _mac="$1" - local _swport - local _speed - - _swport="$(swconfig dev switch0 show | grep $_mac | \ - awk -F: '{print $1}' | awk '{print $2}')" - _speed="$(swconfig dev switch0 port $_swport get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - echo "$_speed" -} diff --git a/custom-files/tl-wr2543nd-v1/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr2543nd-v1/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 2968d8e5..00000000 --- a/custom-files/tl-wr2543nd-v1/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr2543nd-v1/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr2543nd-v1/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index 56063df1..00000000 --- a/custom-files/tl-wr2543nd-v1/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/sh - -# -# WARNING! This file may be replaced depending on the selected target! -# - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -SUFFIX_5="-5GHz" - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - - uci set wireless.@wifi-device[0].type="mac80211" - uci set wireless.@wifi-device[0].txpower="17" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - fi - - uci set wireless.@wifi-device[0].disabled="0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - # 5GHz 802.11 a/n mode - if [ "$(uci -q get wireless.@wifi-iface[1])" ] - then - uci set wireless.@wifi-device[1].type="mac80211" - uci set wireless.@wifi-device[1].txpower="17" - uci set wireless.@wifi-device[1].channel="$FLM_50_CHANNEL" - uci set wireless.@wifi-device[1].hwmode="11na" - uci set wireless.@wifi-device[1].country="BR" - uci set wireless.@wifi-device[1].htmode="HT40" - uci set wireless.@wifi-device[1].noscan="1" - uci set wireless.@wifi-device[1].disabled="0" - uci set wireless.@wifi-iface[1].ssid="$setssid$SUFFIX_5" - uci set wireless.@wifi-iface[1].encryption="psk2" - uci set wireless.@wifi-iface[1].key="$FLM_PASSWD" - fi - uci commit wireless -fi - -exit 0 diff --git a/custom-files/tl-wr2543nd-v1/usr/share/functions/device_functions.sh b/custom-files/tl-wr2543nd-v1/usr/share/functions/device_functions.sh deleted file mode 100644 index b6de36b5..00000000 --- a/custom-files/tl-wr2543nd-v1/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,234 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_info - local _wifi_stats="" - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - local _ap_freq="2.4" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -ne 0 ] - then - _wifi_itf="wlan1" - _ap_freq="5.0" - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - fi - - if [ $_retstatus -eq 0 ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="$(echo "$_dev_info" | grep 'rx bitrate:' | \ - awk '{print $3}')" - local _dev_mcs="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $5}')" - local _dev_signal="$(echo "$_dev_info" | grep 'signal:' | \ - awk '{print $2}' | awk -F. '{print $1}')" - local _ap_noise="$(iwinfo $_wifi_itf info | grep 'Noise:' | \ - awk '{print $5}' | awk -F. '{print $1}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'tx bytes:' | \ - awk '{print $3}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'rx bytes:' | \ - awk '{print $3}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'tx packets:' | \ - awk '{print $3}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'rx packets:' | \ - awk '{print $3}')" - - # Calculate SNR - local _dev_snr="$(($_dev_signal - $_ap_noise))" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mcs" == "MCS" ] - then - # N or AC - _wifi_stats="$_wifi_stats N" - else - # G Mode - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -ne 0 ] - then - _wifi_itf="wlan1" - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - fi - - if [ $_retstatus -eq 0 ] - then - return 0 - else - return 1 - fi - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - for system_led in /sys/class/leds/*system* - do - led_on "$system_led" - done - - # reset hardware lan ports if any - for lan_led in /sys/class/leds/*lan* - do - if [ -f "$lan_led"/enable_hw_mode ] - then - echo 1 > "$lan_led"/enable_hw_mode - fi - done - - # reset hardware wan port if any - for wan_led in /sys/class/leds/*wan* - do - if [ -f "$wan_led"/enable_hw_mode ] - then - echo 1 > "$wan_led"/enable_hw_mode - fi - done - - # reset atheros 5G led - if [ -f /sys/class/leds/ath9k-phy0/trigger ] - then - echo "phy0tpt" > /sys/class/leds/ath9k-phy0/trigger - fi -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - ledsoff=$(ls -d /sys/class/leds/*) - for trigger_path in $ledsoff - do - led_off "$trigger_path" - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - local _p0 - local _p1 - _p0=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy0/macaddress) - - if [ ! -d "/sys/class/ieee80211/phy1" ] - then - if [ ! -z "$_p0" ] - then - _mac_address_tag=$_p0 - fi - else - _p1=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy1/macaddress) - if [ ! -z "$_p1" ] - then - _mac_address_tag=$_p1 - fi - fi - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch0 port 0 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch0 port 0 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _mac="$1" - local _swport - local _speed - - _swport="$(swconfig dev switch0 show | grep $_mac | \ - awk -F: '{print $1}' | awk '{print $2}')" - _speed="$(swconfig dev switch0 port $_swport get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - echo "$_speed" -} diff --git a/custom-files/tl-wr741nd-v4/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr741nd-v4/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 2968d8e5..00000000 --- a/custom-files/tl-wr741nd-v4/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr741nd-v4/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr741nd-v4/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index eb145de3..00000000 --- a/custom-files/tl-wr741nd-v4/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/sh - -# -# WARNING! This file may be replaced depending on the selected target! -# - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - - uci set wireless.@wifi-device[0].type="mac80211" - uci set wireless.@wifi-device[0].txpower="17" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - fi - - uci set wireless.@wifi-device[0].disabled="0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -exit 0 diff --git a/custom-files/tl-wr741nd-v4/usr/share/functions/device_functions.sh b/custom-files/tl-wr741nd-v4/usr/share/functions/device_functions.sh deleted file mode 100644 index d0b2f05d..00000000 --- a/custom-files/tl-wr741nd-v4/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,231 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_info - local _wifi_stats="" - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - local _ap_freq="2.4" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="$(echo "$_dev_info" | grep 'rx bitrate:' | \ - awk '{print $3}')" - local _dev_mcs="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $5}')" - local _dev_signal="$(echo "$_dev_info" | grep 'signal:' | \ - awk '{print $2}' | awk -F. '{print $1}')" - local _ap_noise="$(iwinfo $_wifi_itf info | grep 'Noise:' | \ - awk '{print $5}' | awk -F. '{print $1}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'tx bytes:' | \ - awk '{print $3}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'rx bytes:' | \ - awk '{print $3}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'tx packets:' | \ - awk '{print $3}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'rx packets:' | \ - awk '{print $3}')" - - # Calculate SNR - local _dev_snr="$(($_dev_signal - $_ap_noise))" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mcs" == "MCS" ] - then - # N or AC - _wifi_stats="$_wifi_stats N" - else - # G Mode - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - return 0 - else - return 1 - fi - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - for system_led in /sys/class/leds/*system* - do - led_on "$system_led" - done - - # reset hardware lan ports if any - for lan_led in /sys/class/leds/*lan* - do - if [ -f "$lan_led"/enable_hw_mode ] - then - echo 1 > "$lan_led"/enable_hw_mode - fi - done - - # reset hardware wan port if any - for wan_led in /sys/class/leds/*wan* - do - if [ -f "$wan_led"/enable_hw_mode ] - then - echo 1 > "$wan_led"/enable_hw_mode - fi - done - - # reset atheros 5G led - if [ -f /sys/class/leds/ath9k-phy1/trigger ] - then - echo "phy1tpt" > /sys/class/leds/ath9k-phy1/trigger - fi -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - led_off /sys/class/leds/tp-link\:green\:system - ledsoff=$(ls -d /sys/class/leds/*) - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - local _p0 - _p0=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy0/macaddress) - - if [ ! -z "$_p0" ] - then - _mac_address_tag=$_p0 - fi - - echo "$_mac_address_tag" -} - -# Possible values: 10 or 100 -get_wan_negotiated_speed() { - cat /sys/class/net/eth1/speed -} - -# Possible values: half or full -get_wan_negotiated_duplex() { - cat /sys/class/net/eth1/duplex -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/tl-wr840n-v4/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr840n-v4/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 35712f2d..00000000 --- a/custom-files/tl-wr840n-v4/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" -# LEDs -uci set system.led_wifi_led.dev="ra0" -uci set system.led_wlan2g.dev="ra0" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr840n-v4/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr840n-v4/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index 82695cae..00000000 --- a/custom-files/tl-wr840n-v4/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -LOWERMAC=$(get_mac | awk '{ print tolower($1) }') - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - touch /etc/config/wireless - - uci set wireless.radio0=wifi-device - # Disable the interface! - # MT7628 use a dat file, we only get the parameters from here - uci set wireless.@wifi-device[0].type="ralink" - uci set wireless.@wifi-device[0].txpower="100" - uci set wireless.@wifi-device[0].variant="mt7628" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].wifimode="9" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - uci set wireless.@wifi-device[0].ht_bsscoexist="0" - uci set wireless.@wifi-device[0].bw="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - fi - - uci set wireless.@wifi-device[0].disabled="1" - uci set wireless.default_radio0=wifi-iface - uci set wireless.@wifi-iface[0].ifname="ra0" - uci set wireless.@wifi-iface[0].mode="ap" - uci set wireless.@wifi-iface[0].network="lan" - uci set wireless.@wifi-iface[0].device="radio0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -/usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -printf "MacAddress=$LOWERMAC\n\n" >> /etc/wireless/mt7628/mt7628.dat -insmod /lib/modules/`uname -r`/mt7628.ko mac=$LOWERMAC -echo "mt7628 mac=$LOWERMAC" >> /etc/modules.d/50-mt7628 - -[ -e /sbin/wifi ] && mv /sbin/wifi /sbin/wifi_legacy -cp /sbin/mtkwifi /sbin/wifi -# MT7628 driver needs to reload the first time it loads -/sbin/wifi reload - -exit 0 diff --git a/custom-files/tl-wr840n-v4/usr/share/functions/device_functions.sh b/custom-files/tl-wr840n-v4/usr/share/functions/device_functions.sh deleted file mode 100644 index 38c922c8..00000000 --- a/custom-files/tl-wr840n-v4/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,236 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless - /usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info="" - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - local _wifi_stats="" - local _ap_freq="2.4" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_num="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_num | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac > /dev/null - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx)" - break - fi - done - fi - - if [ "$_dev_info" != "" ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="0.0" - local _dev_mode="$(echo "$_dev_info" | grep 'caps:' | \ - awk '{print $2}')" - local _dev_signal="$(echo "$_dev_info" | grep 'RSSI:' | \ - awk '{print $2}')" - local _dev_snr="$(echo "$_dev_info" | grep 'SNR:' | \ - awk '{print $2}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'TxBytes:' | \ - awk '{print $2}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'RxBytes:' | \ - awk '{print $2}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'TxPackets:' | \ - awk '{print $2}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'RxPackets:' | \ - awk '{print $2}')" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mode" == "VHT" ] - then - # AC - _wifi_stats="$_wifi_stats AC" - elif [ "$_dev_mode" == "HT" ] - then - # N - _wifi_stats="$_wifi_stats N" - else - # G - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_info | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - return 0 - fi - done - fi - - # Not found - return 1 - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - led_on /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - # Need to turn power off to avoid out-of-sync blink - led_off /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power - ledsoff=$(ls -d /sys/class/leds/*) - - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - - if [ ! -z "$(awk '{ print toupper($1) }' /sys/class/net/eth0/address)" ] - then - _mac_address_tag=$(awk '{ print toupper($1) }' /sys/class/net/eth0/address) - fi - - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch0 port 0 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch0 port 0 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/tl-wr840n-v5/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr840n-v5/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 35712f2d..00000000 --- a/custom-files/tl-wr840n-v5/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" -# LEDs -uci set system.led_wifi_led.dev="ra0" -uci set system.led_wlan2g.dev="ra0" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr840n-v5/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr840n-v5/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index 82695cae..00000000 --- a/custom-files/tl-wr840n-v5/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -LOWERMAC=$(get_mac | awk '{ print tolower($1) }') - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - touch /etc/config/wireless - - uci set wireless.radio0=wifi-device - # Disable the interface! - # MT7628 use a dat file, we only get the parameters from here - uci set wireless.@wifi-device[0].type="ralink" - uci set wireless.@wifi-device[0].txpower="100" - uci set wireless.@wifi-device[0].variant="mt7628" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].wifimode="9" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - uci set wireless.@wifi-device[0].ht_bsscoexist="0" - uci set wireless.@wifi-device[0].bw="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - fi - - uci set wireless.@wifi-device[0].disabled="1" - uci set wireless.default_radio0=wifi-iface - uci set wireless.@wifi-iface[0].ifname="ra0" - uci set wireless.@wifi-iface[0].mode="ap" - uci set wireless.@wifi-iface[0].network="lan" - uci set wireless.@wifi-iface[0].device="radio0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -/usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -printf "MacAddress=$LOWERMAC\n\n" >> /etc/wireless/mt7628/mt7628.dat -insmod /lib/modules/`uname -r`/mt7628.ko mac=$LOWERMAC -echo "mt7628 mac=$LOWERMAC" >> /etc/modules.d/50-mt7628 - -[ -e /sbin/wifi ] && mv /sbin/wifi /sbin/wifi_legacy -cp /sbin/mtkwifi /sbin/wifi -# MT7628 driver needs to reload the first time it loads -/sbin/wifi reload - -exit 0 diff --git a/custom-files/tl-wr840n-v5/usr/share/functions/device_functions.sh b/custom-files/tl-wr840n-v5/usr/share/functions/device_functions.sh deleted file mode 100644 index f5294851..00000000 --- a/custom-files/tl-wr840n-v5/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,262 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless - /usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info="" - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - local _wifi_stats="" - local _ap_freq="2.4" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_num="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_num | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac > /dev/null - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx)" - break - fi - done - fi - - if [ "$_dev_info" != "" ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="0.0" - local _dev_mode="$(echo "$_dev_info" | grep 'caps:' | \ - awk '{print $2}')" - local _dev_signal="$(echo "$_dev_info" | grep 'RSSI:' | \ - awk '{print $2}')" - local _dev_snr="$(echo "$_dev_info" | grep 'SNR:' | \ - awk '{print $2}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'TxBytes:' | \ - awk '{print $2}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'RxBytes:' | \ - awk '{print $2}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'TxPackets:' | \ - awk '{print $2}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'RxPackets:' | \ - awk '{print $2}')" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mode" == "VHT" ] - then - # AC - _wifi_stats="$_wifi_stats AC" - elif [ "$_dev_mode" == "HT" ] - then - # N - _wifi_stats="$_wifi_stats N" - else - # G - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_info | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - return 0 - fi - done - fi - - # Not found - return 1 - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - for system_led in /sys/class/leds/*system* - do - led_on "$system_led" - done - - # reset hardware lan ports if any - for lan_led in /sys/class/leds/*lan* - do - if [ -f "$lan_led"/enable_hw_mode ] - then - echo 1 > "$lan_led"/enable_hw_mode - fi - done - - # reset hardware wan port if any - for wan_led in /sys/class/leds/*wan* - do - if [ -f "$wan_led"/enable_hw_mode ] - then - echo 1 > "$wan_led"/enable_hw_mode - fi - done - - # reset atheros 5G led - if [ -f /sys/class/leds/ath9k-phy1/trigger ] - then - echo "phy1tpt" > /sys/class/leds/ath9k-phy1/trigger - fi -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - led_off /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power - ledsoff=/sys/class/leds/$(cat /tmp/sysinfo/board_name)\:orange\:power - - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - - if [ ! -z "$(awk '{ print toupper($1) }' /sys/class/net/eth0/address)" ] - then - _mac_address_tag=$(awk '{ print toupper($1) }' /sys/class/net/eth0/address) - fi - - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch0 port 0 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch0 port 0 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/tl-wr840n-v5preset/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr840n-v5preset/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 35712f2d..00000000 --- a/custom-files/tl-wr840n-v5preset/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" -# LEDs -uci set system.led_wifi_led.dev="ra0" -uci set system.led_wlan2g.dev="ra0" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr840n-v5preset/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr840n-v5preset/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index 82695cae..00000000 --- a/custom-files/tl-wr840n-v5preset/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -LOWERMAC=$(get_mac | awk '{ print tolower($1) }') - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - touch /etc/config/wireless - - uci set wireless.radio0=wifi-device - # Disable the interface! - # MT7628 use a dat file, we only get the parameters from here - uci set wireless.@wifi-device[0].type="ralink" - uci set wireless.@wifi-device[0].txpower="100" - uci set wireless.@wifi-device[0].variant="mt7628" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].wifimode="9" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - uci set wireless.@wifi-device[0].ht_bsscoexist="0" - uci set wireless.@wifi-device[0].bw="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - fi - - uci set wireless.@wifi-device[0].disabled="1" - uci set wireless.default_radio0=wifi-iface - uci set wireless.@wifi-iface[0].ifname="ra0" - uci set wireless.@wifi-iface[0].mode="ap" - uci set wireless.@wifi-iface[0].network="lan" - uci set wireless.@wifi-iface[0].device="radio0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -/usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -printf "MacAddress=$LOWERMAC\n\n" >> /etc/wireless/mt7628/mt7628.dat -insmod /lib/modules/`uname -r`/mt7628.ko mac=$LOWERMAC -echo "mt7628 mac=$LOWERMAC" >> /etc/modules.d/50-mt7628 - -[ -e /sbin/wifi ] && mv /sbin/wifi /sbin/wifi_legacy -cp /sbin/mtkwifi /sbin/wifi -# MT7628 driver needs to reload the first time it loads -/sbin/wifi reload - -exit 0 diff --git a/custom-files/tl-wr840n-v5preset/usr/share/functions/device_functions.sh b/custom-files/tl-wr840n-v5preset/usr/share/functions/device_functions.sh deleted file mode 100644 index 38c922c8..00000000 --- a/custom-files/tl-wr840n-v5preset/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,236 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless - /usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info="" - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - local _wifi_stats="" - local _ap_freq="2.4" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_num="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_num | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac > /dev/null - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx)" - break - fi - done - fi - - if [ "$_dev_info" != "" ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="0.0" - local _dev_mode="$(echo "$_dev_info" | grep 'caps:' | \ - awk '{print $2}')" - local _dev_signal="$(echo "$_dev_info" | grep 'RSSI:' | \ - awk '{print $2}')" - local _dev_snr="$(echo "$_dev_info" | grep 'SNR:' | \ - awk '{print $2}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'TxBytes:' | \ - awk '{print $2}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'RxBytes:' | \ - awk '{print $2}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'TxPackets:' | \ - awk '{print $2}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'RxPackets:' | \ - awk '{print $2}')" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mode" == "VHT" ] - then - # AC - _wifi_stats="$_wifi_stats AC" - elif [ "$_dev_mode" == "HT" ] - then - # N - _wifi_stats="$_wifi_stats N" - else - # G - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_info | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - return 0 - fi - done - fi - - # Not found - return 1 - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - led_on /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - # Need to turn power off to avoid out-of-sync blink - led_off /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power - ledsoff=$(ls -d /sys/class/leds/*) - - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - - if [ ! -z "$(awk '{ print toupper($1) }' /sys/class/net/eth0/address)" ] - then - _mac_address_tag=$(awk '{ print toupper($1) }' /sys/class/net/eth0/address) - fi - - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch0 port 0 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch0 port 0 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/tl-wr840n-v6/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr840n-v6/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 35712f2d..00000000 --- a/custom-files/tl-wr840n-v6/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" -# LEDs -uci set system.led_wifi_led.dev="ra0" -uci set system.led_wlan2g.dev="ra0" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr840n-v6/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr840n-v6/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index 82695cae..00000000 --- a/custom-files/tl-wr840n-v6/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -LOWERMAC=$(get_mac | awk '{ print tolower($1) }') - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - touch /etc/config/wireless - - uci set wireless.radio0=wifi-device - # Disable the interface! - # MT7628 use a dat file, we only get the parameters from here - uci set wireless.@wifi-device[0].type="ralink" - uci set wireless.@wifi-device[0].txpower="100" - uci set wireless.@wifi-device[0].variant="mt7628" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].wifimode="9" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - uci set wireless.@wifi-device[0].ht_bsscoexist="0" - uci set wireless.@wifi-device[0].bw="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - fi - - uci set wireless.@wifi-device[0].disabled="1" - uci set wireless.default_radio0=wifi-iface - uci set wireless.@wifi-iface[0].ifname="ra0" - uci set wireless.@wifi-iface[0].mode="ap" - uci set wireless.@wifi-iface[0].network="lan" - uci set wireless.@wifi-iface[0].device="radio0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -/usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -printf "MacAddress=$LOWERMAC\n\n" >> /etc/wireless/mt7628/mt7628.dat -insmod /lib/modules/`uname -r`/mt7628.ko mac=$LOWERMAC -echo "mt7628 mac=$LOWERMAC" >> /etc/modules.d/50-mt7628 - -[ -e /sbin/wifi ] && mv /sbin/wifi /sbin/wifi_legacy -cp /sbin/mtkwifi /sbin/wifi -# MT7628 driver needs to reload the first time it loads -/sbin/wifi reload - -exit 0 diff --git a/custom-files/tl-wr840n-v6/usr/share/functions/device_functions.sh b/custom-files/tl-wr840n-v6/usr/share/functions/device_functions.sh deleted file mode 100644 index b3c05567..00000000 --- a/custom-files/tl-wr840n-v6/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,230 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless - /usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info="" - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - local _wifi_stats="" - local _ap_freq="2.4" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_num="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_num | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac > /dev/null - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx)" - break - fi - done - fi - - if [ "$_dev_info" != "" ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="0.0" - local _dev_mode="$(echo "$_dev_info" | grep 'caps:' | \ - awk '{print $2}')" - local _dev_signal="$(echo "$_dev_info" | grep 'RSSI:' | \ - awk '{print $2}')" - local _dev_snr="$(echo "$_dev_info" | grep 'SNR:' | \ - awk '{print $2}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'TxBytes:' | \ - awk '{print $2}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'RxBytes:' | \ - awk '{print $2}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'TxPackets:' | \ - awk '{print $2}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'RxPackets:' | \ - awk '{print $2}')" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mode" == "VHT" ] - then - # AC - _wifi_stats="$_wifi_stats AC" - elif [ "$_dev_mode" == "HT" ] - then - # N - _wifi_stats="$_wifi_stats N" - else - # G - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_info | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - return 0 - fi - done - fi - - # Not found - return 1 - else - return 1 - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -led_netdev() { - echo "netdev" > "$1"/trigger - echo "link tx rx" > "$1"/mode - echo "$2" > "$1"/device_name -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - led_netdev \ - /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power eth0.2 -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - led_off /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power - ledsoff=/sys/class/leds/$(cat /tmp/sysinfo/board_name)\:orange\:power - - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - - if [ ! -z "$(awk '{ print toupper($1) }' /sys/class/net/eth0/address)" ] - then - _mac_address_tag=$(awk '{ print toupper($1) }' /sys/class/net/eth0/address) - fi - - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch0 port 0 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch0 port 0 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/tl-wr840n-v6preset/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr840n-v6preset/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 35712f2d..00000000 --- a/custom-files/tl-wr840n-v6preset/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" -# LEDs -uci set system.led_wifi_led.dev="ra0" -uci set system.led_wlan2g.dev="ra0" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr840n-v6preset/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr840n-v6preset/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index 82695cae..00000000 --- a/custom-files/tl-wr840n-v6preset/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -LOWERMAC=$(get_mac | awk '{ print tolower($1) }') - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - touch /etc/config/wireless - - uci set wireless.radio0=wifi-device - # Disable the interface! - # MT7628 use a dat file, we only get the parameters from here - uci set wireless.@wifi-device[0].type="ralink" - uci set wireless.@wifi-device[0].txpower="100" - uci set wireless.@wifi-device[0].variant="mt7628" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].wifimode="9" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - uci set wireless.@wifi-device[0].ht_bsscoexist="0" - uci set wireless.@wifi-device[0].bw="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - fi - - uci set wireless.@wifi-device[0].disabled="1" - uci set wireless.default_radio0=wifi-iface - uci set wireless.@wifi-iface[0].ifname="ra0" - uci set wireless.@wifi-iface[0].mode="ap" - uci set wireless.@wifi-iface[0].network="lan" - uci set wireless.@wifi-iface[0].device="radio0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -/usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -printf "MacAddress=$LOWERMAC\n\n" >> /etc/wireless/mt7628/mt7628.dat -insmod /lib/modules/`uname -r`/mt7628.ko mac=$LOWERMAC -echo "mt7628 mac=$LOWERMAC" >> /etc/modules.d/50-mt7628 - -[ -e /sbin/wifi ] && mv /sbin/wifi /sbin/wifi_legacy -cp /sbin/mtkwifi /sbin/wifi -# MT7628 driver needs to reload the first time it loads -/sbin/wifi reload - -exit 0 diff --git a/custom-files/tl-wr840n-v6preset/usr/share/functions/device_functions.sh b/custom-files/tl-wr840n-v6preset/usr/share/functions/device_functions.sh deleted file mode 100644 index 38c922c8..00000000 --- a/custom-files/tl-wr840n-v6preset/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,236 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless - /usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info="" - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - local _wifi_stats="" - local _ap_freq="2.4" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_num="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_num | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac > /dev/null - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx)" - break - fi - done - fi - - if [ "$_dev_info" != "" ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="0.0" - local _dev_mode="$(echo "$_dev_info" | grep 'caps:' | \ - awk '{print $2}')" - local _dev_signal="$(echo "$_dev_info" | grep 'RSSI:' | \ - awk '{print $2}')" - local _dev_snr="$(echo "$_dev_info" | grep 'SNR:' | \ - awk '{print $2}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'TxBytes:' | \ - awk '{print $2}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'RxBytes:' | \ - awk '{print $2}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'TxPackets:' | \ - awk '{print $2}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'RxPackets:' | \ - awk '{print $2}')" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mode" == "VHT" ] - then - # AC - _wifi_stats="$_wifi_stats AC" - elif [ "$_dev_mode" == "HT" ] - then - # N - _wifi_stats="$_wifi_stats N" - else - # G - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_info | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - return 0 - fi - done - fi - - # Not found - return 1 - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - led_on /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - # Need to turn power off to avoid out-of-sync blink - led_off /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power - ledsoff=$(ls -d /sys/class/leds/*) - - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - - if [ ! -z "$(awk '{ print toupper($1) }' /sys/class/net/eth0/address)" ] - then - _mac_address_tag=$(awk '{ print toupper($1) }' /sys/class/net/eth0/address) - fi - - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch0 port 0 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch0 port 0 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/tl-wr841-v7/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr841-v7/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 2968d8e5..00000000 --- a/custom-files/tl-wr841-v7/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr841-v7/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr841-v7/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index eb145de3..00000000 --- a/custom-files/tl-wr841-v7/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/sh - -# -# WARNING! This file may be replaced depending on the selected target! -# - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - - uci set wireless.@wifi-device[0].type="mac80211" - uci set wireless.@wifi-device[0].txpower="17" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - fi - - uci set wireless.@wifi-device[0].disabled="0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -exit 0 diff --git a/custom-files/tl-wr841-v7/usr/share/functions/device_functions.sh b/custom-files/tl-wr841-v7/usr/share/functions/device_functions.sh deleted file mode 100644 index 52f728dd..00000000 --- a/custom-files/tl-wr841-v7/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,207 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_info - local _wifi_stats="" - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - local _ap_freq="2.4" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="$(echo "$_dev_info" | grep 'rx bitrate:' | \ - awk '{print $3}')" - local _dev_mcs="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $5}')" - local _dev_signal="$(echo "$_dev_info" | grep 'signal:' | \ - awk '{print $2}' | awk -F. '{print $1}')" - local _ap_noise="$(iwinfo $_wifi_itf info | grep 'Noise:' | \ - awk '{print $5}' | awk -F. '{print $1}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'tx bytes:' | \ - awk '{print $3}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'rx bytes:' | \ - awk '{print $3}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'tx packets:' | \ - awk '{print $3}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'rx packets:' | \ - awk '{print $3}')" - - # Calculate SNR - local _dev_snr="$(($_dev_signal - $_ap_noise))" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mcs" == "MCS" ] - then - # N or AC - _wifi_stats="$_wifi_stats N" - else - # G Mode - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - return 0 - else - return 1 - fi - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - led_on /sys/class/leds/tp-link\:green\:system - if [ -f /sys/class/leds/ath9k-phy0/trigger ] - then - echo "phy0tpt" > /sys/class/leds/ath9k-phy0/trigger - fi -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - ledsoff=$(ls -d /sys/class/leds/*) - for trigger_path in $ledsoff - do - led_off "$trigger_path" - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - local _p0 - _p0=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy0/macaddress) - - if [ ! -z "$_p0" ] - then - _mac_address_tag=$_p0 - fi - echo "$_mac_address_tag" -} - -# Possible values: 10 or 100 -get_wan_negotiated_speed() { - cat /sys/class/net/eth1/speed -} - -# Possible values: half or full -get_wan_negotiated_duplex() { - cat /sys/class/net/eth1/duplex -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/tl-wr841-v8/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr841-v8/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 2968d8e5..00000000 --- a/custom-files/tl-wr841-v8/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr841-v8/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr841-v8/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index eb145de3..00000000 --- a/custom-files/tl-wr841-v8/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/sh - -# -# WARNING! This file may be replaced depending on the selected target! -# - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - - uci set wireless.@wifi-device[0].type="mac80211" - uci set wireless.@wifi-device[0].txpower="17" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - fi - - uci set wireless.@wifi-device[0].disabled="0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -exit 0 diff --git a/custom-files/tl-wr842n-v3/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr842n-v3/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 2968d8e5..00000000 --- a/custom-files/tl-wr842n-v3/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr842n-v3/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr842n-v3/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index eb145de3..00000000 --- a/custom-files/tl-wr842n-v3/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/sh - -# -# WARNING! This file may be replaced depending on the selected target! -# - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - - uci set wireless.@wifi-device[0].type="mac80211" - uci set wireless.@wifi-device[0].txpower="17" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - fi - - uci set wireless.@wifi-device[0].disabled="0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -exit 0 diff --git a/custom-files/tl-wr842n-v3/usr/share/functions/device_functions.sh b/custom-files/tl-wr842n-v3/usr/share/functions/device_functions.sh deleted file mode 100644 index c7af02b3..00000000 --- a/custom-files/tl-wr842n-v3/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,231 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_info - local _wifi_stats="" - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - local _ap_freq="2.4" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="$(echo "$_dev_info" | grep 'rx bitrate:' | \ - awk '{print $3}')" - local _dev_mcs="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $5}')" - local _dev_signal="$(echo "$_dev_info" | grep 'signal:' | \ - awk '{print $2}' | awk -F. '{print $1}')" - local _ap_noise="$(iwinfo $_wifi_itf info | grep 'Noise:' | \ - awk '{print $5}' | awk -F. '{print $1}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'tx bytes:' | \ - awk '{print $3}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'rx bytes:' | \ - awk '{print $3}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'tx packets:' | \ - awk '{print $3}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'rx packets:' | \ - awk '{print $3}')" - - # Calculate SNR - local _dev_snr="$(($_dev_signal - $_ap_noise))" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mcs" == "MCS" ] - then - # N or AC - _wifi_stats="$_wifi_stats N" - else - # G Mode - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - return 0 - else - return 1 - fi - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - for system_led in /sys/class/leds/*system* - do - led_on "$system_led" - done - - # reset hardware lan ports if any - for lan_led in /sys/class/leds/*lan* - do - if [ -f "$lan_led"/enable_hw_mode ] - then - echo 1 > "$lan_led"/enable_hw_mode - fi - done - - # reset hardware wan port if any - if [ -f /sys/class/leds/tp-link:green:wan/enable_hw_mode ] - then - echo 1 > /sys/class/leds/tp-link:green:wan/enable_hw_mode - fi - - if [ -f /sys/class/leds/ath9k-phy0/trigger ] - then - echo "phy0tpt" > /sys/class/leds/ath9k-phy0/trigger - fi -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - ledsoff=$(ls -d /sys/class/leds/*) - for trigger_path in $ledsoff - do - led_off "$trigger_path" - # Skip orange LED - if [ "$trigger_path" = "/sys/class/leds/tp-link:red:wan" ] - then - continue - fi - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - local _p0 - _p0=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy0/macaddress) - - if [ ! -z "$_p0" ] - then - _mac_address_tag=$_p0 - fi - echo "$_mac_address_tag" -} - -# Possible values: 10 or 100 -get_wan_negotiated_speed() { - cat /sys/class/net/eth1/speed -} - -# Possible values: half or full -get_wan_negotiated_duplex() { - cat /sys/class/net/eth1/duplex -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/tl-wr845n-v3/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr845n-v3/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 35712f2d..00000000 --- a/custom-files/tl-wr845n-v3/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" -# LEDs -uci set system.led_wifi_led.dev="ra0" -uci set system.led_wlan2g.dev="ra0" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr845n-v3/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr845n-v3/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index 82695cae..00000000 --- a/custom-files/tl-wr845n-v3/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -LOWERMAC=$(get_mac | awk '{ print tolower($1) }') - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - touch /etc/config/wireless - - uci set wireless.radio0=wifi-device - # Disable the interface! - # MT7628 use a dat file, we only get the parameters from here - uci set wireless.@wifi-device[0].type="ralink" - uci set wireless.@wifi-device[0].txpower="100" - uci set wireless.@wifi-device[0].variant="mt7628" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].wifimode="9" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - uci set wireless.@wifi-device[0].ht_bsscoexist="0" - uci set wireless.@wifi-device[0].bw="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - fi - - uci set wireless.@wifi-device[0].disabled="1" - uci set wireless.default_radio0=wifi-iface - uci set wireless.@wifi-iface[0].ifname="ra0" - uci set wireless.@wifi-iface[0].mode="ap" - uci set wireless.@wifi-iface[0].network="lan" - uci set wireless.@wifi-iface[0].device="radio0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -/usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -printf "MacAddress=$LOWERMAC\n\n" >> /etc/wireless/mt7628/mt7628.dat -insmod /lib/modules/`uname -r`/mt7628.ko mac=$LOWERMAC -echo "mt7628 mac=$LOWERMAC" >> /etc/modules.d/50-mt7628 - -[ -e /sbin/wifi ] && mv /sbin/wifi /sbin/wifi_legacy -cp /sbin/mtkwifi /sbin/wifi -# MT7628 driver needs to reload the first time it loads -/sbin/wifi reload - -exit 0 diff --git a/custom-files/tl-wr845n-v3/usr/share/functions/device_functions.sh b/custom-files/tl-wr845n-v3/usr/share/functions/device_functions.sh deleted file mode 100644 index 1d57f5b8..00000000 --- a/custom-files/tl-wr845n-v3/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,236 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless - /usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info="" - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - local _wifi_stats="" - local _ap_freq="2.4" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_num="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_num | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac > /dev/null - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx)" - break - fi - done - fi - - if [ "$_dev_info" != "" ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="0.0" - local _dev_mode="$(echo "$_dev_info" | grep 'caps:' | \ - awk '{print $2}')" - local _dev_signal="$(echo "$_dev_info" | grep 'RSSI:' | \ - awk '{print $2}')" - local _dev_snr="$(echo "$_dev_info" | grep 'SNR:' | \ - awk '{print $2}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'TxBytes:' | \ - awk '{print $2}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'RxBytes:' | \ - awk '{print $2}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'TxPackets:' | \ - awk '{print $2}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'RxPackets:' | \ - awk '{print $2}')" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mode" == "VHT" ] - then - # AC - _wifi_stats="$_wifi_stats AC" - elif [ "$_dev_mode" == "HT" ] - then - # N - _wifi_stats="$_wifi_stats N" - else - # G - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_info | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - return 0 - fi - done - fi - - # Not found - return 1 - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - led_on /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - led_off /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power - # we cant turn on orange and blue at same time in this model - ledsoff=$(ls -d /sys/class/leds/*green*) - - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - - if [ ! -z "$(awk '{ print toupper($1) }' /sys/class/net/eth0/address)" ] - then - _mac_address_tag=$(awk '{ print toupper($1) }' /sys/class/net/eth0/address) - fi - - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch0 port 0 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch0 port 0 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/tl-wr845n-v4/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr845n-v4/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 35712f2d..00000000 --- a/custom-files/tl-wr845n-v4/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" -# LEDs -uci set system.led_wifi_led.dev="ra0" -uci set system.led_wlan2g.dev="ra0" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr845n-v4/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr845n-v4/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index 82695cae..00000000 --- a/custom-files/tl-wr845n-v4/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -LOWERMAC=$(get_mac | awk '{ print tolower($1) }') - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - touch /etc/config/wireless - - uci set wireless.radio0=wifi-device - # Disable the interface! - # MT7628 use a dat file, we only get the parameters from here - uci set wireless.@wifi-device[0].type="ralink" - uci set wireless.@wifi-device[0].txpower="100" - uci set wireless.@wifi-device[0].variant="mt7628" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].wifimode="9" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - uci set wireless.@wifi-device[0].ht_bsscoexist="0" - uci set wireless.@wifi-device[0].bw="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - fi - - uci set wireless.@wifi-device[0].disabled="1" - uci set wireless.default_radio0=wifi-iface - uci set wireless.@wifi-iface[0].ifname="ra0" - uci set wireless.@wifi-iface[0].mode="ap" - uci set wireless.@wifi-iface[0].network="lan" - uci set wireless.@wifi-iface[0].device="radio0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -/usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -printf "MacAddress=$LOWERMAC\n\n" >> /etc/wireless/mt7628/mt7628.dat -insmod /lib/modules/`uname -r`/mt7628.ko mac=$LOWERMAC -echo "mt7628 mac=$LOWERMAC" >> /etc/modules.d/50-mt7628 - -[ -e /sbin/wifi ] && mv /sbin/wifi /sbin/wifi_legacy -cp /sbin/mtkwifi /sbin/wifi -# MT7628 driver needs to reload the first time it loads -/sbin/wifi reload - -exit 0 diff --git a/custom-files/tl-wr845n-v4/usr/share/functions/device_functions.sh b/custom-files/tl-wr845n-v4/usr/share/functions/device_functions.sh deleted file mode 100644 index f2a6ee99..00000000 --- a/custom-files/tl-wr845n-v4/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,223 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless - /usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info="" - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - local _wifi_stats="" - local _ap_freq="2.4" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_num="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_num | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac > /dev/null - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx)" - break - fi - done - fi - - if [ "$_dev_info" != "" ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="0.0" - local _dev_mode="$(echo "$_dev_info" | grep 'caps:' | \ - awk '{print $2}')" - local _dev_signal="$(echo "$_dev_info" | grep 'RSSI:' | \ - awk '{print $2}')" - local _dev_snr="$(echo "$_dev_info" | grep 'SNR:' | \ - awk '{print $2}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'TxBytes:' | \ - awk '{print $2}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'RxBytes:' | \ - awk '{print $2}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'TxPackets:' | \ - awk '{print $2}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'RxPackets:' | \ - awk '{print $2}')" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mode" == "VHT" ] - then - # AC - _wifi_stats="$_wifi_stats AC" - elif [ "$_dev_mode" == "HT" ] - then - # N - _wifi_stats="$_wifi_stats N" - else - # G - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_info | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - return 0 - fi - done - fi - - # Not found - return 1 - else - return 1 - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -led_netdev() { - echo "netdev" > "$1"/trigger - echo "link tx rx" > "$1"/mode - echo "$2" > "$1"/device_name -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - /etc/init.d/led restart > /dev/null - led_netdev /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:wan eth0.2 -} - -blink_leds() { - local _do_restart=$1 - local _bname=$(cat /tmp/sysinfo/board_name) - if [ $_do_restart -eq 0 ] - then - led_off /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:wan - echo "timer" > /sys/class/leds/$_bname\:green\:wlan/trigger - echo "timer" > /sys/class/leds/$_bname\:orange\:wan/trigger - fi -} - -get_mac() { - local _mac_address_tag="" - - if [ ! -z "$(awk '{ print toupper($1) }' /sys/class/net/eth0/address)" ] - then - _mac_address_tag=$(awk '{ print toupper($1) }' /sys/class/net/eth0/address) - fi - - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch0 port 0 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch0 port 0 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/tl-wr849n-v4/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr849n-v4/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 35712f2d..00000000 --- a/custom-files/tl-wr849n-v4/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" -# LEDs -uci set system.led_wifi_led.dev="ra0" -uci set system.led_wlan2g.dev="ra0" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr849n-v4/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr849n-v4/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index 82695cae..00000000 --- a/custom-files/tl-wr849n-v4/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -LOWERMAC=$(get_mac | awk '{ print tolower($1) }') - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - touch /etc/config/wireless - - uci set wireless.radio0=wifi-device - # Disable the interface! - # MT7628 use a dat file, we only get the parameters from here - uci set wireless.@wifi-device[0].type="ralink" - uci set wireless.@wifi-device[0].txpower="100" - uci set wireless.@wifi-device[0].variant="mt7628" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].wifimode="9" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - uci set wireless.@wifi-device[0].ht_bsscoexist="0" - uci set wireless.@wifi-device[0].bw="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - fi - - uci set wireless.@wifi-device[0].disabled="1" - uci set wireless.default_radio0=wifi-iface - uci set wireless.@wifi-iface[0].ifname="ra0" - uci set wireless.@wifi-iface[0].mode="ap" - uci set wireless.@wifi-iface[0].network="lan" - uci set wireless.@wifi-iface[0].device="radio0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -/usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -printf "MacAddress=$LOWERMAC\n\n" >> /etc/wireless/mt7628/mt7628.dat -insmod /lib/modules/`uname -r`/mt7628.ko mac=$LOWERMAC -echo "mt7628 mac=$LOWERMAC" >> /etc/modules.d/50-mt7628 - -[ -e /sbin/wifi ] && mv /sbin/wifi /sbin/wifi_legacy -cp /sbin/mtkwifi /sbin/wifi -# MT7628 driver needs to reload the first time it loads -/sbin/wifi reload - -exit 0 diff --git a/custom-files/tl-wr849n-v4/usr/share/functions/device_functions.sh b/custom-files/tl-wr849n-v4/usr/share/functions/device_functions.sh deleted file mode 100644 index 3fbc4d5f..00000000 --- a/custom-files/tl-wr849n-v4/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,234 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless - /usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info="" - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - local _wifi_stats="" - local _ap_freq="2.4" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_num="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_num | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac > /dev/null - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx)" - break - fi - done - fi - - if [ "$_dev_info" != "" ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="0.0" - local _dev_mode="$(echo "$_dev_info" | grep 'caps:' | \ - awk '{print $2}')" - local _dev_signal="$(echo "$_dev_info" | grep 'RSSI:' | \ - awk '{print $2}')" - local _dev_snr="$(echo "$_dev_info" | grep 'SNR:' | \ - awk '{print $2}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'TxBytes:' | \ - awk '{print $2}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'RxBytes:' | \ - awk '{print $2}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'TxPackets:' | \ - awk '{print $2}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'RxPackets:' | \ - awk '{print $2}')" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mode" == "VHT" ] - then - # AC - _wifi_stats="$_wifi_stats AC" - elif [ "$_dev_mode" == "HT" ] - then - # N - _wifi_stats="$_wifi_stats N" - else - # G - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_info | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - return 0 - fi - done - fi - - # Not found - return 1 - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - led_on /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - ledsoff=$(ls -d /sys/class/leds/*) - - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - - if [ ! -z "$(awk '{ print toupper($1) }' /sys/class/net/eth0/address)" ] - then - _mac_address_tag=$(awk '{ print toupper($1) }' /sys/class/net/eth0/address) - fi - - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch0 port 0 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch0 port 0 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/tl-wr849n-v5/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr849n-v5/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 35712f2d..00000000 --- a/custom-files/tl-wr849n-v5/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" -# LEDs -uci set system.led_wifi_led.dev="ra0" -uci set system.led_wlan2g.dev="ra0" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr849n-v5/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr849n-v5/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index 82695cae..00000000 --- a/custom-files/tl-wr849n-v5/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -LOWERMAC=$(get_mac | awk '{ print tolower($1) }') - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - touch /etc/config/wireless - - uci set wireless.radio0=wifi-device - # Disable the interface! - # MT7628 use a dat file, we only get the parameters from here - uci set wireless.@wifi-device[0].type="ralink" - uci set wireless.@wifi-device[0].txpower="100" - uci set wireless.@wifi-device[0].variant="mt7628" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].wifimode="9" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - uci set wireless.@wifi-device[0].ht_bsscoexist="0" - uci set wireless.@wifi-device[0].bw="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - fi - - uci set wireless.@wifi-device[0].disabled="1" - uci set wireless.default_radio0=wifi-iface - uci set wireless.@wifi-iface[0].ifname="ra0" - uci set wireless.@wifi-iface[0].mode="ap" - uci set wireless.@wifi-iface[0].network="lan" - uci set wireless.@wifi-iface[0].device="radio0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -/usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -printf "MacAddress=$LOWERMAC\n\n" >> /etc/wireless/mt7628/mt7628.dat -insmod /lib/modules/`uname -r`/mt7628.ko mac=$LOWERMAC -echo "mt7628 mac=$LOWERMAC" >> /etc/modules.d/50-mt7628 - -[ -e /sbin/wifi ] && mv /sbin/wifi /sbin/wifi_legacy -cp /sbin/mtkwifi /sbin/wifi -# MT7628 driver needs to reload the first time it loads -/sbin/wifi reload - -exit 0 diff --git a/custom-files/tl-wr849n-v5/usr/share/functions/device_functions.sh b/custom-files/tl-wr849n-v5/usr/share/functions/device_functions.sh deleted file mode 100644 index b3c05567..00000000 --- a/custom-files/tl-wr849n-v5/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,230 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless - /usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info="" - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - local _wifi_stats="" - local _ap_freq="2.4" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_num="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_num | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac > /dev/null - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx)" - break - fi - done - fi - - if [ "$_dev_info" != "" ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="0.0" - local _dev_mode="$(echo "$_dev_info" | grep 'caps:' | \ - awk '{print $2}')" - local _dev_signal="$(echo "$_dev_info" | grep 'RSSI:' | \ - awk '{print $2}')" - local _dev_snr="$(echo "$_dev_info" | grep 'SNR:' | \ - awk '{print $2}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'TxBytes:' | \ - awk '{print $2}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'RxBytes:' | \ - awk '{print $2}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'TxPackets:' | \ - awk '{print $2}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'RxPackets:' | \ - awk '{print $2}')" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mode" == "VHT" ] - then - # AC - _wifi_stats="$_wifi_stats AC" - elif [ "$_dev_mode" == "HT" ] - then - # N - _wifi_stats="$_wifi_stats N" - else - # G - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_info | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - return 0 - fi - done - fi - - # Not found - return 1 - else - return 1 - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -led_netdev() { - echo "netdev" > "$1"/trigger - echo "link tx rx" > "$1"/mode - echo "$2" > "$1"/device_name -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - led_netdev \ - /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power eth0.2 -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - led_off /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power - ledsoff=/sys/class/leds/$(cat /tmp/sysinfo/board_name)\:orange\:power - - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - - if [ ! -z "$(awk '{ print toupper($1) }' /sys/class/net/eth0/address)" ] - then - _mac_address_tag=$(awk '{ print toupper($1) }' /sys/class/net/eth0/address) - fi - - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch0 port 0 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch0 port 0 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/tl-wr849n-v6/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr849n-v6/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 35712f2d..00000000 --- a/custom-files/tl-wr849n-v6/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" -# LEDs -uci set system.led_wifi_led.dev="ra0" -uci set system.led_wlan2g.dev="ra0" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr849n-v6/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr849n-v6/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index 82695cae..00000000 --- a/custom-files/tl-wr849n-v6/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -LOWERMAC=$(get_mac | awk '{ print tolower($1) }') - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - touch /etc/config/wireless - - uci set wireless.radio0=wifi-device - # Disable the interface! - # MT7628 use a dat file, we only get the parameters from here - uci set wireless.@wifi-device[0].type="ralink" - uci set wireless.@wifi-device[0].txpower="100" - uci set wireless.@wifi-device[0].variant="mt7628" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].wifimode="9" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - uci set wireless.@wifi-device[0].ht_bsscoexist="0" - uci set wireless.@wifi-device[0].bw="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - fi - - uci set wireless.@wifi-device[0].disabled="1" - uci set wireless.default_radio0=wifi-iface - uci set wireless.@wifi-iface[0].ifname="ra0" - uci set wireless.@wifi-iface[0].mode="ap" - uci set wireless.@wifi-iface[0].network="lan" - uci set wireless.@wifi-iface[0].device="radio0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -/usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -printf "MacAddress=$LOWERMAC\n\n" >> /etc/wireless/mt7628/mt7628.dat -insmod /lib/modules/`uname -r`/mt7628.ko mac=$LOWERMAC -echo "mt7628 mac=$LOWERMAC" >> /etc/modules.d/50-mt7628 - -[ -e /sbin/wifi ] && mv /sbin/wifi /sbin/wifi_legacy -cp /sbin/mtkwifi /sbin/wifi -# MT7628 driver needs to reload the first time it loads -/sbin/wifi reload - -exit 0 diff --git a/custom-files/tl-wr849n-v6/usr/share/functions/device_functions.sh b/custom-files/tl-wr849n-v6/usr/share/functions/device_functions.sh deleted file mode 100644 index b3c05567..00000000 --- a/custom-files/tl-wr849n-v6/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,230 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless - /usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info="" - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - local _wifi_stats="" - local _ap_freq="2.4" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_num="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_num | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac > /dev/null - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx)" - break - fi - done - fi - - if [ "$_dev_info" != "" ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="0.0" - local _dev_mode="$(echo "$_dev_info" | grep 'caps:' | \ - awk '{print $2}')" - local _dev_signal="$(echo "$_dev_info" | grep 'RSSI:' | \ - awk '{print $2}')" - local _dev_snr="$(echo "$_dev_info" | grep 'SNR:' | \ - awk '{print $2}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'TxBytes:' | \ - awk '{print $2}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'RxBytes:' | \ - awk '{print $2}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'TxPackets:' | \ - awk '{print $2}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'RxPackets:' | \ - awk '{print $2}')" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mode" == "VHT" ] - then - # AC - _wifi_stats="$_wifi_stats AC" - elif [ "$_dev_mode" == "HT" ] - then - # N - _wifi_stats="$_wifi_stats N" - else - # G - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_info | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - return 0 - fi - done - fi - - # Not found - return 1 - else - return 1 - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -led_netdev() { - echo "netdev" > "$1"/trigger - echo "link tx rx" > "$1"/mode - echo "$2" > "$1"/device_name -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - led_netdev \ - /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power eth0.2 -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - led_off /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:power - ledsoff=/sys/class/leds/$(cat /tmp/sysinfo/board_name)\:orange\:power - - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - - if [ ! -z "$(awk '{ print toupper($1) }' /sys/class/net/eth0/address)" ] - then - _mac_address_tag=$(awk '{ print toupper($1) }' /sys/class/net/eth0/address) - fi - - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch0 port 0 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch0 port 0 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/tl-wr849n-v62/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr849n-v62/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 35712f2d..00000000 --- a/custom-files/tl-wr849n-v62/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" -# LEDs -uci set system.led_wifi_led.dev="ra0" -uci set system.led_wlan2g.dev="ra0" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr849n-v62/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr849n-v62/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index 82695cae..00000000 --- a/custom-files/tl-wr849n-v62/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) -LOWERMAC=$(get_mac | awk '{ print tolower($1) }') - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - touch /etc/config/wireless - - uci set wireless.radio0=wifi-device - # Disable the interface! - # MT7628 use a dat file, we only get the parameters from here - uci set wireless.@wifi-device[0].type="ralink" - uci set wireless.@wifi-device[0].txpower="100" - uci set wireless.@wifi-device[0].variant="mt7628" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].wifimode="9" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - uci set wireless.@wifi-device[0].ht_bsscoexist="0" - uci set wireless.@wifi-device[0].bw="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - uci set wireless.@wifi-device[0].ht_bsscoexist="1" - uci set wireless.@wifi-device[0].bw="0" - fi - - uci set wireless.@wifi-device[0].disabled="1" - uci set wireless.default_radio0=wifi-iface - uci set wireless.@wifi-iface[0].ifname="ra0" - uci set wireless.@wifi-iface[0].mode="ap" - uci set wireless.@wifi-iface[0].network="lan" - uci set wireless.@wifi-iface[0].device="radio0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -/usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -printf "MacAddress=$LOWERMAC\n\n" >> /etc/wireless/mt7628/mt7628.dat -insmod /lib/modules/`uname -r`/mt7628.ko mac=$LOWERMAC -echo "mt7628 mac=$LOWERMAC" >> /etc/modules.d/50-mt7628 - -[ -e /sbin/wifi ] && mv /sbin/wifi /sbin/wifi_legacy -cp /sbin/mtkwifi /sbin/wifi -# MT7628 driver needs to reload the first time it loads -/sbin/wifi reload - -exit 0 diff --git a/custom-files/tl-wr849n-v62/usr/share/functions/device_functions.sh b/custom-files/tl-wr849n-v62/usr/share/functions/device_functions.sh deleted file mode 100644 index 0a92327f..00000000 --- a/custom-files/tl-wr849n-v62/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,233 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless - /usr/bin/uci2dat -d radio0 -f /etc/wireless/mt7628/mt7628.dat > /dev/null -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info="" - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - local _wifi_stats="" - local _ap_freq="2.4" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_num="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_num | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac > /dev/null - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx)" - break - fi - done - fi - - if [ "$_dev_info" != "" ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="0.0" - local _dev_mode="$(echo "$_dev_info" | grep 'caps:' | \ - awk '{print $2}')" - local _dev_signal="$(echo "$_dev_info" | grep 'RSSI:' | \ - awk '{print $2}')" - local _dev_snr="$(echo "$_dev_info" | grep 'SNR:' | \ - awk '{print $2}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'TxBytes:' | \ - awk '{print $2}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'RxBytes:' | \ - awk '{print $2}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'TxPackets:' | \ - awk '{print $2}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'RxPackets:' | \ - awk '{print $2}')" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mode" == "VHT" ] - then - # AC - _wifi_stats="$_wifi_stats AC" - elif [ "$_dev_mode" == "HT" ] - then - # N - _wifi_stats="$_wifi_stats N" - else - # G - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_num - local _idx - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="ra0" - - _cmd_res=$(command -v iwpriv) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iwpriv $_wifi_itf assoclist_num 2> /dev/null)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Interface returned successfully - _dev_num="$(echo $_dev_info | awk -F: '{print $2}')" - for _idx in $(seq 1 $_dev_num) - do - _dev_info="$(iwpriv $_wifi_itf assoclist $_idx | grep $_dev_mac)" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - return 0 - fi - done - fi - - # Not found - return 1 - else - return 1 - fi -} - -led_power_off() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - led_power_off /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:orange\:power - ledsoff=$(ls -d /sys/class/leds/$(cat /tmp/sysinfo/board_name)\:green\:*) - - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - - if [ ! -z "$(awk '{ print toupper($1) }' /sys/class/net/eth0/address)" ] - then - _mac_address_tag=$(awk '{ print toupper($1) }' /sys/class/net/eth0/address) - fi - - echo "$_mac_address_tag" -} - -# Possible values: empty, 10, 100 or 100 -get_wan_negotiated_speed() { - swconfig dev switch0 port 0 get link | \ - awk '{print $3}' | awk -F: '{print $2}' | awk -Fbase '{print $1}' -} - -# Possible values: empty, half or full -get_wan_negotiated_duplex() { - swconfig dev switch0 port 0 get link | \ - awk '{print $4}' | awk -F- '{print $1}' -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/tl-wr940n-v6/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr940n-v6/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 2968d8e5..00000000 --- a/custom-files/tl-wr940n-v6/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr940n-v6/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr940n-v6/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index eb145de3..00000000 --- a/custom-files/tl-wr940n-v6/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/sh - -# -# WARNING! This file may be replaced depending on the selected target! -# - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - - uci set wireless.@wifi-device[0].type="mac80211" - uci set wireless.@wifi-device[0].txpower="17" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - fi - - uci set wireless.@wifi-device[0].disabled="0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -exit 0 diff --git a/custom-files/tl-wr940n-v6/usr/share/functions/device_functions.sh b/custom-files/tl-wr940n-v6/usr/share/functions/device_functions.sh deleted file mode 100644 index 6323105f..00000000 --- a/custom-files/tl-wr940n-v6/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,231 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_info - local _wifi_stats="" - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - local _ap_freq="2.4" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="$(echo "$_dev_info" | grep 'rx bitrate:' | \ - awk '{print $3}')" - local _dev_mcs="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $5}')" - local _dev_signal="$(echo "$_dev_info" | grep 'signal:' | \ - awk '{print $2}' | awk -F. '{print $1}')" - local _ap_noise="$(iwinfo $_wifi_itf info | grep 'Noise:' | \ - awk '{print $5}' | awk -F. '{print $1}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'tx bytes:' | \ - awk '{print $3}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'rx bytes:' | \ - awk '{print $3}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'tx packets:' | \ - awk '{print $3}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'rx packets:' | \ - awk '{print $3}')" - - # Calculate SNR - local _dev_snr="$(($_dev_signal - $_ap_noise))" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mcs" == "MCS" ] - then - # N or AC - _wifi_stats="$_wifi_stats N" - else - # G Mode - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - return 0 - else - return 1 - fi - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - for system_led in /sys/class/leds/*system* - do - led_on "$system_led" - done - - # reset hardware lan ports if any - for lan_led in /sys/class/leds/*lan* - do - if [ -f "$lan_led"/enable_hw_mode ] - then - echo 1 > "$lan_led"/enable_hw_mode - fi - done - - # reset hardware wan port if any - for wan_led in /sys/class/leds/*wan* - do - if [ -f "$wan_led"/enable_hw_mode ] - then - echo 1 > "$wan_led"/enable_hw_mode - fi - done - - # reset atheros 5G led - if [ -f /sys/class/leds/ath9k-phy1/trigger ] - then - echo "phy1tpt" > /sys/class/leds/ath9k-phy1/trigger - fi -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - led_off /sys/class/leds/tp-link\:blue\:wan - ledsoff=/sys/class/leds/tp-link\:orange\:diag - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - local _p0 - _p0=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy0/macaddress) - - if [ ! -z "$_p0" ] - then - _mac_address_tag=$_p0 - fi - - echo "$_mac_address_tag" -} - -# Possible values: 10 or 100 -get_wan_negotiated_speed() { - cat /sys/class/net/eth0/speed -} - -# Possible values: half or full -get_wan_negotiated_duplex() { - cat /sys/class/net/eth0/duplex -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/tl-wr949n-v6/etc/uci-defaults/z001_flashbox-system.sh b/custom-files/tl-wr949n-v6/etc/uci-defaults/z001_flashbox-system.sh deleted file mode 100644 index 2968d8e5..00000000 --- a/custom-files/tl-wr949n-v6/etc/uci-defaults/z001_flashbox-system.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -HOSTNAME=$(get_mac | sed -e "s/:/-/g") - -uci set system.@system[-1].timezone="BRT3BRST,M10.3.0/0,M2.3.0/0" -uci set system.@system[-1].hostname="$HOSTNAME" -uci set system.@system[-1].cronloglevel="9" -uci set system.ntp.enabled="1" -uci set system.ntp.enable_server="0" -uci -q delete system.ntp.server -uci add_list system.ntp.server="$NTP_SVADDR" -uci add_list system.ntp.server="$NTP_SVADDR_2" -uci add_list system.ntp.server="$NTP_SVADDR_3" -uci add_list system.ntp.server="$NTP_SVADDR_4" - -uci commit system - -exit 0 diff --git a/custom-files/tl-wr949n-v6/etc/uci-defaults/z005_flashbox-wireless.sh b/custom-files/tl-wr949n-v6/etc/uci-defaults/z005_flashbox-wireless.sh deleted file mode 100644 index eb145de3..00000000 --- a/custom-files/tl-wr949n-v6/etc/uci-defaults/z005_flashbox-wireless.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/sh - -# -# WARNING! This file may be replaced depending on the selected target! -# - -. /usr/share/flashman_init.conf -. /usr/share/functions/device_functions.sh - -MAC_LAST_CHARS=$(get_mac | awk -F: '{ print $5$6 }') -SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) -ENCRYPTION_VALUE=$(uci -q get wireless.@wifi-iface[0].encryption) - -# Wireless password cannot be empty or have less than 8 chars -if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] -then - FLM_PASSWD=$(get_mac | sed -e "s/://g") -fi - -# Configure WiFi default SSID and password -if { [ "$SSID_VALUE" = "OpenWrt" ] || [ "$SSID_VALUE" = "LEDE" ] || \ - [ "$SSID_VALUE" = "" ]; } && [ "$ENCRYPTION_VALUE" != "psk2" ] -then - if [ "$FLM_SSID_SUFFIX" == "none" ] - then - #none - setssid="$FLM_SSID" - else - #lastmac - setssid="$FLM_SSID$MAC_LAST_CHARS" - fi - - uci set wireless.@wifi-device[0].type="mac80211" - uci set wireless.@wifi-device[0].txpower="17" - uci set wireless.@wifi-device[0].channel="$FLM_24_CHANNEL" - uci set wireless.@wifi-device[0].hwmode="11n" - uci set wireless.@wifi-device[0].country="BR" - - if [ "$FLM_24_BAND" = "HT40" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.@wifi-device[0].htmode="$FLM_24_BAND" - uci set wireless.@wifi-device[0].noscan="0" - else - uci set wireless.@wifi-device[0].htmode="HT20" - uci set wireless.@wifi-device[0].noscan="0" - fi - - uci set wireless.@wifi-device[0].disabled="0" - uci set wireless.@wifi-iface[0].ssid="$setssid" - uci set wireless.@wifi-iface[0].encryption="psk2" - uci set wireless.@wifi-iface[0].key="$FLM_PASSWD" - - uci commit wireless -fi - -exit 0 diff --git a/custom-files/tl-wr949n-v6/usr/share/functions/device_functions.sh b/custom-files/tl-wr949n-v6/usr/share/functions/device_functions.sh deleted file mode 100644 index 6323105f..00000000 --- a/custom-files/tl-wr949n-v6/usr/share/functions/device_functions.sh +++ /dev/null @@ -1,231 +0,0 @@ -#!/bin/sh - -save_wifi_local_config() { - uci commit wireless -} - -is_5ghz_capable() { - # false - echo "0" -} - -get_wifi_device_stats() { - local _dev_mac="$1" - local _dev_info - local _wifi_stats="" - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - local _ap_freq="2.4" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $3}')" - local _dev_rxbitrate="$(echo "$_dev_info" | grep 'rx bitrate:' | \ - awk '{print $3}')" - local _dev_mcs="$(echo "$_dev_info" | grep 'tx bitrate:' | \ - awk '{print $5}')" - local _dev_signal="$(echo "$_dev_info" | grep 'signal:' | \ - awk '{print $2}' | awk -F. '{print $1}')" - local _ap_noise="$(iwinfo $_wifi_itf info | grep 'Noise:' | \ - awk '{print $5}' | awk -F. '{print $1}')" - local _dev_txbytes="$(echo "$_dev_info" | grep 'tx bytes:' | \ - awk '{print $3}')" - local _dev_rxbytes="$(echo "$_dev_info" | grep 'rx bytes:' | \ - awk '{print $3}')" - local _dev_txpackets="$(echo "$_dev_info" | grep 'tx packets:' | \ - awk '{print $3}')" - local _dev_rxpackets="$(echo "$_dev_info" | grep 'rx packets:' | \ - awk '{print $3}')" - - # Calculate SNR - local _dev_snr="$(($_dev_signal - $_ap_noise))" - - _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" - _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" - - if [ "$_dev_mcs" == "MCS" ] - then - # N or AC - _wifi_stats="$_wifi_stats N" - else - # G Mode - _wifi_stats="$_wifi_stats G" - fi - # Traffic data - _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" - _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" - - echo "$_wifi_stats" - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi - else - echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0" - fi -} - -is_device_wireless() { - local _dev_mac="$1" - local _dev_info - local _retstatus - local _cmd_res - local _wifi_itf="wlan0" - - _cmd_res=$(command -v iw) - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - return 0 - else - return 1 - fi - else - return 1 - fi -} - -led_on() { - if [ -f "$1"/brightness ] - then - if [ -f "$1"/max_brightness ] - then - cat "$1"/max_brightness > "$1"/brightness - else - echo "255" > "$1"/brightness - fi - fi -} - -led_off() { - if [ -f "$1"/trigger ] - then - echo "none" > "$1"/trigger - echo "0" > "$1"/brightness - fi -} - -reset_leds() { - for trigger_path in $(ls -d /sys/class/leds/*) - do - led_off "$trigger_path" - done - - /etc/init.d/led restart > /dev/null - - for system_led in /sys/class/leds/*system* - do - led_on "$system_led" - done - - # reset hardware lan ports if any - for lan_led in /sys/class/leds/*lan* - do - if [ -f "$lan_led"/enable_hw_mode ] - then - echo 1 > "$lan_led"/enable_hw_mode - fi - done - - # reset hardware wan port if any - for wan_led in /sys/class/leds/*wan* - do - if [ -f "$wan_led"/enable_hw_mode ] - then - echo 1 > "$wan_led"/enable_hw_mode - fi - done - - # reset atheros 5G led - if [ -f /sys/class/leds/ath9k-phy1/trigger ] - then - echo "phy1tpt" > /sys/class/leds/ath9k-phy1/trigger - fi -} - -blink_leds() { - local _do_restart=$1 - - if [ $_do_restart -eq 0 ] - then - led_off /sys/class/leds/tp-link\:blue\:wan - ledsoff=/sys/class/leds/tp-link\:orange\:diag - for trigger_path in $ledsoff - do - echo "timer" > "$trigger_path"/trigger - done - fi -} - -get_mac() { - local _mac_address_tag="" - local _p0 - _p0=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy0/macaddress) - - if [ ! -z "$_p0" ] - then - _mac_address_tag=$_p0 - fi - - echo "$_mac_address_tag" -} - -# Possible values: 10 or 100 -get_wan_negotiated_speed() { - cat /sys/class/net/eth0/speed -} - -# Possible values: half or full -get_wan_negotiated_duplex() { - cat /sys/class/net/eth0/duplex -} - -get_lan_dev_negotiated_speed() { - local _speed="0" - local _switch="switch0" - local _vlan="1" - local _retstatus - - for _port in $(swconfig dev $_switch vlan $_vlan get ports) - do - # Check if it's not a bridge port - echo "$_port" | grep -q "t" - _retstatus=$? - if [ $_retstatus -eq 1 ] - then - local _speed_tmp="$(swconfig dev $_switch port $_port get link | \ - awk -F: '{print $4}' | awk -F 'baseT' '{print $1}')" - if [ "$_speed_tmp" != "" ] - then - if [ "$_speed" != "0" ] - then - if [ "$_speed" != "$_speed_tmp" ] - then - # Different values. Return 0 since we cannot know the correct value - _speed="0" - fi - else - # First assignment - _speed="$_speed_tmp" - fi - fi - fi - done - - echo "$_speed" -} diff --git a/custom-files/tplink_archer-c2-v1.sh b/custom-files/tplink_archer-c2-v1.sh new file mode 100644 index 00000000..18106001 --- /dev/null +++ b/custom-files/tplink_archer-c2-v1.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "ARCHERC2" +} + +get_custom_hardware_version() { + echo "V1" +} + +# Enable/disable ethernet connection on LAN physical ports when in bridge mode +set_switch_bridge_mode() { + local _enable_bridge="$1" + local _disable_lan_ports="$2" + + if [ "$_enable_bridge" = "y" ] + then + if [ "$_disable_lan_ports" = "y" ] + then + uci set network.@switch_vlan[0].ports='0 6t' + uci set network.@switch_vlan[1].ports='' + else + uci set network.@switch_vlan[0].ports='0 1 2 3 4 6t' + uci set network.@switch_vlan[1].ports='' + fi + else + uci set network.@switch_vlan[0].ports='1 2 3 4 6t' + uci set network.@switch_vlan[1].ports='0 6t' + fi +} + +# Will not change ifnames if this variable is set when in bridge mode +keep_ifnames_in_bridge_mode() { + echo "1" +} diff --git a/custom-files/tplink_archer-c20-v1.sh b/custom-files/tplink_archer-c20-v1.sh new file mode 100644 index 00000000..1494c0bd --- /dev/null +++ b/custom-files/tplink_archer-c20-v1.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "ARCHERC20" +} + +get_custom_hardware_version() { + echo "V1" +} + +get_custom_leds_blink() { + echo "$(ls -d /sys/class/leds/*blue*)" +} diff --git a/custom-files/tplink_archer-c20-v4.sh b/custom-files/tplink_archer-c20-v4.sh new file mode 100644 index 00000000..723a5d2d --- /dev/null +++ b/custom-files/tplink_archer-c20-v4.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "ARCHERC20" +} + +get_custom_hardware_version() { + echo "V4" +} diff --git a/custom-files/tplink_archer-c20-v5.sh b/custom-files/tplink_archer-c20-v5.sh new file mode 100644 index 00000000..b7dac5cc --- /dev/null +++ b/custom-files/tplink_archer-c20-v5.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "ARCHERC20" +} + +get_custom_hardware_version() { + echo "V5" +} diff --git a/custom-files/tplink_archer-c20-v5W.sh b/custom-files/tplink_archer-c20-v5W.sh new file mode 100644 index 00000000..1af352e1 --- /dev/null +++ b/custom-files/tplink_archer-c20-v5W.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "ARCHERC20" +} + +get_custom_hardware_version() { + echo "V5PRESET" +} diff --git a/custom-files/tplink_archer-c5-v4.sh b/custom-files/tplink_archer-c5-v4.sh new file mode 100644 index 00000000..9c92e6cc --- /dev/null +++ b/custom-files/tplink_archer-c5-v4.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "ARCHERC5" +} + +get_custom_hardware_version() { + echo "V4" +} + +# Enable/disable ethernet connection on LAN physical ports when in bridge mode +set_switch_bridge_mode() { + local _enable_bridge="$1" + local _disable_lan_ports="$2" + + if [ "$_enable_bridge" = "y" ] + then + if [ "$_disable_lan_ports" = "y" ] + then + uci set network.@switch_vlan[0].ports='4 5t' + uci set network.@switch_vlan[1].ports='' + else + uci set network.@switch_vlan[0].ports='0 1 2 3 4 5t' + uci set network.@switch_vlan[1].ports='' + fi + else + uci set network.@switch_vlan[0].ports='0 1 2 3 5t' + uci set network.@switch_vlan[1].ports='4 5t' + fi +} + +# Will not change ifnames if this variable is set when in bridge mode +keep_ifnames_in_bridge_mode() { + echo "1" +} diff --git a/custom-files/tplink_archer-c50-v3.sh b/custom-files/tplink_archer-c50-v3.sh new file mode 100644 index 00000000..8cf58aa7 --- /dev/null +++ b/custom-files/tplink_archer-c50-v3.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "ARCHERC50" +} + +get_custom_hardware_version() { + echo "V3" +} diff --git a/custom-files/tplink_archer-c50-v4.sh b/custom-files/tplink_archer-c50-v4.sh new file mode 100644 index 00000000..c5134868 --- /dev/null +++ b/custom-files/tplink_archer-c50-v4.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "ARCHERC50" +} + +get_custom_hardware_version() { + echo "V4" +} diff --git a/custom-files/tplink_archer-c6-v2US.sh b/custom-files/tplink_archer-c6-v2US.sh new file mode 100644 index 00000000..3ac169fb --- /dev/null +++ b/custom-files/tplink_archer-c6-v2US.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "ARCHERC6" +} + +get_custom_hardware_version() { + echo "V2US" +} + +# Enable/disable ethernet connection on LAN physical ports when in bridge mode +set_switch_bridge_mode() { + local _enable_bridge="$1" + local _disable_lan_ports="$2" + + if [ "$_enable_bridge" = "y" ] + then + if [ "$_disable_lan_ports" = "y" ] + then + uci set network.@switch_vlan[0].ports='1 0t' + uci set network.@switch_vlan[1].ports='' + else + uci set network.@switch_vlan[0].ports='1 2 3 4 5 0t' + uci set network.@switch_vlan[1].ports='' + fi + else + uci set network.@switch_vlan[0].ports='2 3 4 5 0t' + uci set network.@switch_vlan[1].ports='1 0t' + fi +} + +# Will not change ifnames if this variable is set when in bridge mode +keep_ifnames_in_bridge_mode() { + echo "1" +} diff --git a/custom-files/tplink_archer-c60-v2.sh b/custom-files/tplink_archer-c60-v2.sh new file mode 100644 index 00000000..04c90612 --- /dev/null +++ b/custom-files/tplink_archer-c60-v2.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "ARCHERC60" +} + +get_custom_hardware_version() { + echo "V2" +} diff --git a/custom-files/tplink_archer-c60-v3.sh b/custom-files/tplink_archer-c60-v3.sh new file mode 100644 index 00000000..66f1c22f --- /dev/null +++ b/custom-files/tplink_archer-c60-v3.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "ARCHERC60" +} + +get_custom_hardware_version() { + echo "V3" +} diff --git a/custom-files/tplink_archer-c7-v5.sh b/custom-files/tplink_archer-c7-v5.sh new file mode 100644 index 00000000..e3a9e0b4 --- /dev/null +++ b/custom-files/tplink_archer-c7-v5.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "ARCHERC7" +} + +get_custom_hardware_version() { + echo "V5" +} + +# Enable/disable ethernet connection on LAN physical ports when in bridge mode +set_switch_bridge_mode() { + local _enable_bridge="$1" + local _disable_lan_ports="$2" + + if [ "$_enable_bridge" = "y" ] + then + if [ "$_disable_lan_ports" = "y" ] + then + uci set network.@switch_vlan[0].ports='1 0t' + uci set network.@switch_vlan[1].ports='' + else + uci set network.@switch_vlan[0].ports='1 2 3 4 5 0t' + uci set network.@switch_vlan[1].ports='' + fi + else + uci set network.@switch_vlan[0].ports='2 3 4 5 0t' + uci set network.@switch_vlan[1].ports='1 0t' + fi +} + +# Will not change ifnames if this variable is set when in bridge mode +keep_ifnames_in_bridge_mode() { + echo "1" +} diff --git a/custom-files/tplink_tl-wdr3500.sh b/custom-files/tplink_tl-wdr3500.sh new file mode 100644 index 00000000..77b4a857 --- /dev/null +++ b/custom-files/tplink_tl-wdr3500.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +get_custom_mac() { + local _mac_address_tag="" + local _p1 + + _p1=$(awk '{print toupper($1)}' /sys/class/net/eth1/address) + [ ! -z "$_p1" ] && _mac_address_tag=$_p1 + + echo "$_mac_address_tag" +} diff --git a/custom-files/tplink_tl-wr2543nd.sh b/custom-files/tplink_tl-wr2543nd.sh new file mode 100644 index 00000000..957e59ce --- /dev/null +++ b/custom-files/tplink_tl-wr2543nd.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "TL-WR2543ND" +} diff --git a/custom-files/tplink_tl-wr740n.sh b/custom-files/tplink_tl-wr740n.sh new file mode 100644 index 00000000..475f7927 --- /dev/null +++ b/custom-files/tplink_tl-wr740n.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "TL-WR740ND" +} + +get_custom_mac() { + local _mac_address_tag="" + local _p0 + _p0=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy0/macaddress) + + if [ ! -z "$_p0" ] + then + _mac_address_tag=$_p0 + fi + echo "$_mac_address_tag" +} diff --git a/custom-files/tplink_tl-wr741n.sh b/custom-files/tplink_tl-wr741n.sh new file mode 100644 index 00000000..647486a9 --- /dev/null +++ b/custom-files/tplink_tl-wr741n.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "TL-WR741ND" +} + +get_custom_mac() { + local _mac_address_tag="" + local _p0 + _p0=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy0/macaddress) + + if [ ! -z "$_p0" ] + then + _mac_address_tag=$_p0 + fi + echo "$_mac_address_tag" +} diff --git a/custom-files/tplink_tl-wr841n.sh b/custom-files/tplink_tl-wr841n.sh new file mode 100644 index 00000000..7c377273 --- /dev/null +++ b/custom-files/tplink_tl-wr841n.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "TL-WR841ND" +} + +get_custom_mac() { + local _mac_address_tag="" + local _p0 + _p0=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy0/macaddress) + + if [ ! -z "$_p0" ] + then + _mac_address_tag=$_p0 + fi + echo "$_mac_address_tag" +} diff --git a/custom-files/tplink_tl-wr842n.sh b/custom-files/tplink_tl-wr842n.sh new file mode 100644 index 00000000..8b69cc6f --- /dev/null +++ b/custom-files/tplink_tl-wr842n.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +get_custom_hardware_model() { + echo "TL-WR842ND" +} + +get_custom_mac() { + local _mac_address_tag="" + local _p0 + _p0=$(awk '{print toupper($1)}' /sys/class/ieee80211/phy0/macaddress) + + if [ ! -z "$_p0" ] + then + _mac_address_tag=$_p0 + fi + echo "$_mac_address_tag" +} diff --git a/custom-files/tplink_tl-wr84Xn-v5-v6.sh b/custom-files/tplink_tl-wr84Xn-v5-v6.sh new file mode 100644 index 00000000..e54ba923 --- /dev/null +++ b/custom-files/tplink_tl-wr84Xn-v5-v6.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +get_custom_leds_blink() { + echo "$(ls -d /sys/class/leds/*orange*)" +} diff --git a/custom-files/tplink_tl-wr940n-v5.sh b/custom-files/tplink_tl-wr940n-v5.sh new file mode 100644 index 00000000..f41d5ea0 --- /dev/null +++ b/custom-files/tplink_tl-wr940n-v5.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +get_custom_leds_blink() { + echo "$(ls -d /sys/class/leds/*blue*)" +} + +#Force a memory cleanup to avoid processor usage in network +anlix_force_clean_memory() { + echo 3 > /proc/sys/vm/drop_caches +} + +anlix_upgrade_clean_memory() { + wifi down + sleep 3 + rmmod ath9k + rmmod ath9k_common + rmmod ath9k_hw + rmmod mac80211 + echo 3 > /proc/sys/vm/drop_caches +} + +anlix_upgrade_restore_memory() { + modprobe mac80211 + modprobe ath9k_hw + modprobe ath9k_common + modprobe ath9k + wifi up +} diff --git a/custom-files/tplink_tl-wr94Xn-v6.sh b/custom-files/tplink_tl-wr94Xn-v6.sh new file mode 100644 index 00000000..4c9fe264 --- /dev/null +++ b/custom-files/tplink_tl-wr94Xn-v6.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +get_custom_leds_blink() { + echo "$(ls -d /sys/class/leds/*orange*)" +} + +#Force a memory cleanup to avoid processor usage in network +anlix_force_clean_memory() { + echo 3 > /proc/sys/vm/drop_caches +} + +anlix_upgrade_clean_memory() { + wifi down + sleep 3 + rmmod ath9k + rmmod ath9k_common + rmmod ath9k_hw + rmmod mac80211 + echo 3 > /proc/sys/vm/drop_caches +} + +anlix_upgrade_restore_memory() { + modprobe mac80211 + modprobe ath9k_hw + modprobe ath9k_common + modprobe ath9k + wifi up +} diff --git a/files/etc/hotplug.d/dhcp/99-anlix-fingerprint.sh b/files/etc/hotplug.d/dhcp/99-anlix-fingerprint.sh new file mode 100644 index 00000000..b0d3906e --- /dev/null +++ b/files/etc/hotplug.d/dhcp/99-anlix-fingerprint.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +if [ ! -e /tmp/dhcpinfo ] +then + mkdir /tmp/dhcpinfo +fi + +if [ "$ACTION" = add ] && [ -n "$DNSMASQ_VENDOR_CLASS" ] +then + if [ "${DNSMASQ_VENDOR_CLASS:0:5}" == "ANLIX" ] + then + . /usr/share/libubox/jshn.sh + _mac="$(echo $DNSMASQ_SUPPLIED_HOSTNAME | sed 's/-/:/g')" + json_cleanup + json_init + json_add_string mac "$_mac" + [ "${DNSMASQ_VENDOR_CLASS#ANLIX}" == "02" ] && json_add_int status 0 || json_add_int status 1 + ubus call anlix_sapo notify_sapo "$(json_dump)" + json_close_object + fi +fi + +if [ "$ACTION" = add ] || [ "$ACTION" = update ] +then + if [ -n "$DNSMASQ_REQUESTED_OPTIONS" ] && [ -n "$MACADDR" ] + then + echo "$DNSMASQ_REQUESTED_OPTIONS $DNSMASQ_VENDOR_CLASS" > /tmp/dhcpinfo/$MACADDR + fi +elif [ "$ACTION" = remove ] +then + if [ -n "$MACADDR" ] + then + if [ -e /tmp/dhcpinfo/$MACADDR ] + then + rm /tmp/dhcpinfo/$MACADDR + fi + fi +fi diff --git a/files/etc/hotplug.d/iface/99-anlix b/files/etc/hotplug.d/iface/99-anlix index 82dd6acc..022f7c30 100644 --- a/files/etc/hotplug.d/iface/99-anlix +++ b/files/etc/hotplug.d/iface/99-anlix @@ -2,8 +2,98 @@ [ "$ACTION" = ifup ] || exit 0 +. /lib/functions/network.sh +. /usr/share/functions/network_functions.sh + +network_find_wan extiface +network_find_wan ext6iface + +update_lan_ip() { + local _lan_addr="" + while true + do + _lan_addr="$(ifstatus lan | jsonfilter -e '@["ipv4-address"][0]["address"]')" + valid_ip "$_lan_addr" + _retstatus=$? + if [ $_retstatus -eq 0 ] + then + break + fi + sleep 3 + done + # Replace LAN IP so Flash App can find the router + sed -i 's/.*anlixrouter/'"$_lan_addr"' anlixrouter/' /etc/hosts + /etc/init.d/uhttpd restart +} +[ "$INTERFACE" = "$extiface" ] && update_lan_ip + +set_dns_proxy_config() { + local _dns_sv_list + + if [ "$(uci get dhcp.@dnsmasq[0].noproxy)" == "1" ] + then + local _sv_list_opt="6" + # Check resolv conf + cat /tmp/resolv.conf.auto | grep -q "nameserver" + if [ $? -eq 0 ] + then + # Remove only the dns options + for i in $(uci get dhcp.lan.dhcp_option) + do + if [ "$i" != "${i#$_sv_list_opt}" ] + then + uci del_list dhcp.lan.dhcp_option=$i + fi + done + # Create DNS list. Only IPv4 + _dns_sv_list=$(cat /tmp/resolv.conf.auto | grep "nameserver" | grep "\." | awk '{print $2}') + for _dns_sv in $_dns_sv_list + do + valid_ip "$_dns_sv" + _retstatus=$? + if [ $_retstatus -eq 0 ] + then + _sv_list_opt="$_sv_list_opt,$_dns_sv" + fi + done + uci add_list dhcp.lan.dhcp_option="$_sv_list_opt" + + uci get dhcp.lan.dns > /dev/null 2>&1 + if [ $? -eq 0 ] + then + uci delete dhcp.lan.dns + fi + # Create DNS list. Only IPv6 + _dns_sv_list=$(cat /tmp/resolv.conf.auto | grep "nameserver" | grep "\:" | awk '{print $2}') + for _dns_sv in $_dns_sv_list + do + uci add_list dhcp.lan.dns="$_dns_sv" + done + + uci commit dhcp + fi + else + # Remove only the dns options + for i in $(uci get dhcp.lan.dhcp_option) + do + if [ "$i" != "${i#$_sv_list_opt}" ] + then + uci del_list dhcp.lan.dhcp_option=$i + fi + done + uci get dhcp.lan.dns > /dev/null 2>&1 + if [ $? -eq 0 ] + then + uci delete dhcp.lan.dns + fi + uci commit dhcp + fi +} +# Use proxy or give DNS addresses directly +set_dns_proxy_config + # Fix dnsmasq and iface race condition /etc/init.d/dnsmasq enabled && /etc/init.d/dnsmasq restart # Fix dhcp and iface wan6 race condition -[ "$INTERFACE" = "wan6" ] && /etc/init.d/odhcpd enabled && /etc/init.d/odhcpd restart +[ "$INTERFACE" = "$ext6iface" ] && /etc/init.d/odhcpd enabled && /etc/init.d/odhcpd restart diff --git a/files/etc/hotplug.d/net/99-anlix b/files/etc/hotplug.d/net/99-anlix new file mode 100644 index 00000000..978ef65b --- /dev/null +++ b/files/etc/hotplug.d/net/99-anlix @@ -0,0 +1,25 @@ +#!/bin/sh + +[ "$(type -t hostapd_cli)" ] || exit 0 + +if [ "$ACTION" = add ] +then + if [ "$INTERFACE" = wlan0 ] + then + /etc/init.d/hostapdstats_wlan0 start + elif [ "$INTERFACE" = wlan1 ] + then + /etc/init.d/hostapdstats_wlan1 start + fi +elif [ "$ACTION" = remove ] +then + if [ "$INTERFACE" = wlan0 ] + then + /etc/init.d/hostapdstats_wlan0 stop + elif [ "$INTERFACE" = wlan1 ] + then + /etc/init.d/hostapdstats_wlan1 stop + fi +else + exit 0 +fi diff --git a/files/etc/init.d/anlixboot b/files/etc/init.d/anlixboot new file mode 100755 index 00000000..54594f1e --- /dev/null +++ b/files/etc/init.d/anlixboot @@ -0,0 +1,30 @@ +#!/bin/sh /etc/rc.common + +. /usr/share/libubox/jshn.sh +if [ -e /usr/share/functions/custom_device.sh ] +then + . /usr/share/functions/custom_device.sh +else + . /usr/share/functions/device_functions.sh +fi + +START=17 + +boot() { + [ "$(type -t anlix_bootup_defaults)" ] && anlix_bootup_defaults + + if [ "$(type -t set_switch_bridge_mode_on_boot)" ] + then + local _bridge_mode="" + local _disable_lan_ports="" + + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _bridge_mode bridge_mode + json_get_var _disable_lan_ports bridge_disable_switch + json_close_object + + # ONLY RELEVANT TO TARGETS THAT SWITCH CONFIG BY UCI IS USELESS + [ "$_bridge_mode" = "y" ] && set_switch_bridge_mode_on_boot "$_disable_lan_ports" + fi +} diff --git a/files/etc/init.d/hostapdstats_wlan0 b/files/etc/init.d/hostapdstats_wlan0 new file mode 100755 index 00000000..f9c468ed --- /dev/null +++ b/files/etc/init.d/hostapdstats_wlan0 @@ -0,0 +1,17 @@ +#!/bin/sh /etc/rc.common + +USE_PROCD=1 +PROG="hostapd_cli -i wlan0 -a /usr/share/hostapdstats.sh" + +# THIS SERVICE DOES NOT START AUTOMATICALLY ON PURPOSE +# SEE HOTPLUG + +start_service() { + procd_open_instance + procd_set_param command ${PROG} + procd_set_param respawn 180 15 6 + procd_set_param stdout 1 # forward stdout of the command to logd + procd_set_param stderr 1 # same for stderr + procd_set_param pidfile /var/run/hostapdstats-wlan0.pid + procd_close_instance +} diff --git a/files/etc/init.d/hostapdstats_wlan1 b/files/etc/init.d/hostapdstats_wlan1 new file mode 100755 index 00000000..50a83485 --- /dev/null +++ b/files/etc/init.d/hostapdstats_wlan1 @@ -0,0 +1,17 @@ +#!/bin/sh /etc/rc.common + +USE_PROCD=1 +PROG="hostapd_cli -i wlan1 -a /usr/share/hostapdstats.sh" + +# THIS SERVICE DOES NOT START AUTOMATICALLY ON PURPOSE +# SEE HOTPLUG + +start_service() { + procd_open_instance + procd_set_param command ${PROG} + procd_set_param respawn 180 15 6 + procd_set_param stdout 1 # forward stdout of the command to logd + procd_set_param stderr 1 # same for stderr + procd_set_param pidfile /var/run/hostapdstats-wlan1.pid + procd_close_instance +} diff --git a/files/etc/init.d/minisapo b/files/etc/init.d/minisapo new file mode 100755 index 00000000..5f004411 --- /dev/null +++ b/files/etc/init.d/minisapo @@ -0,0 +1,74 @@ +#!/bin/sh /etc/rc.common + +. /usr/share/functions/device_functions.sh +. /usr/share/functions/network_functions.sh +. /usr/share/functions/wireless_functions.sh + +START=9F +STOP=1F + +USE_PROCD=1 + +param_list() { + + local _wifi_config="$(get_wifi_local_config)" + [ "$(echo "$_wifi_config" | jsonfilter -e '@["local_state_24"]')" == "1" ] && ubus -t 15 wait_for hostapd.wlan0 2>/dev/null + [ "$(is_5ghz_capable)" == "1" ] && [ "$(echo "$_wifi_config" | jsonfilter -e '@["local_state_50"]')" == "1" ] && ubus -t 15 wait_for hostapd.wlan1 2>/dev/null + + radios=$(ubus list | grep hostapd.wlan) + BRIDGE_IP_ADDR="" + while true + do + BRIDGE_IP_ADDR="$(get_lan_bridge_ipaddr)" + valid_ip "$BRIDGE_IP_ADDR" + _retstatus=$? + if [ $_retstatus -eq 0 ] + then + break + fi + sleep 5 + done + json_init + json_add_string "iface_ip" "$BRIDGE_IP_ADDR" + json_add_string "mac" "$(get_mac)" + json_add_string "ssid" "$(echo "$_wifi_config" | jsonfilter -e '@["local_ssid_24"]')" + json_add_string "ssid_5" "$(echo "$_wifi_config" | jsonfilter -e '@["local_ssid_50"]')" + [ "$(is_mesh_capable)" ] && json_add_int "mesh_support" "1" + json_add_int "mesh" "$(get_mesh_mode)" + [ "$(get_mesh_master)" ] && json_add_string "master" "$(get_mesh_master)" + for i in $radios + do + [ "${i: -1}" = "0" ] && tlan="2" || tlan="5" + json_add_string "mac_ssid$tlan" "$(ubus call $i rrm_nr_get_own | jsonfilter -e '$.value[0]')" + json_add_string "meshid$tlan" "$(ubus call $i rrm_nr_get_own | jsonfilter -e '$.value[2]')" + done + local _ifA="$(ifconfig mesh0 2>/dev/null)" + [ $? == 0 ] && json_add_string "mac_mesh0" "$(echo "$_ifA"| awk '/HWaddr/{print tolower($NF)}')" + _ifA="$(ifconfig mesh1 2>/dev/null)" + [ $? == 0 ] && json_add_string "mac_mesh1" "$(echo "$_ifA"| awk '/HWaddr/{print tolower($NF)}')" + _ifA="$(ifconfig br-lan 2>/dev/null)" + [ $? == 0 ] && json_add_string "mac_bridge" "$(echo "$_ifA"| awk '/HWaddr/{print tolower($NF)}')" + + echo "$(json_dump)" + json_cleanup +} + +start_service() { + procd_open_instance + procd_set_param command minisapo + procd_append_param command "$(param_list)" + procd_set_param respawn + procd_set_param stdout 1 # forward stdout of the command to logd + procd_set_param stderr 1 # same for stderr + procd_set_param pidfile /var/run/minisapo.pid + procd_close_instance +} + +reload_service() +{ + if service_running; then + ubus call anlix_sapo set_msg "$(param_list)" + else + start + fi +} diff --git a/files/etc/init.d/netstats b/files/etc/init.d/netstats new file mode 100755 index 00000000..f19307be --- /dev/null +++ b/files/etc/init.d/netstats @@ -0,0 +1,16 @@ +#!/bin/sh /etc/rc.common + +START=9D + +USE_PROCD=1 +PROG=/usr/share/netstats.sh + +start_service() { + procd_open_instance + procd_set_param command ${PROG} + procd_set_param respawn + procd_set_param stdout 1 # forward stdout of the command to logd + procd_set_param stderr 1 # same for stderr + procd_set_param pidfile /var/run/netstats.pid + procd_close_instance +} diff --git a/files/etc/odhcp6c.user b/files/etc/odhcp6c.user deleted file mode 100644 index 6f853526..00000000 --- a/files/etc/odhcp6c.user +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -[ -z "$2" ] && echo "Error: should be run by odhcpc6c" && exit 1 - -. /usr/share/functions/common_functions.sh - -case "$2" in - ra-updated) - [ -n "$ADDRESSES$RA_ADDRESSES$PREFIXES$USERPREFIX" ] && /etc/init.d/odhcpd reload - ;; - bound|rebound|informed|updated|stopped|unbound) - log "ODHCP6C" "ODHCP6C $2: RESTART" - /etc/init.d/odhcpd restart - ;; -esac -exit 0 diff --git a/files/etc/sysctl.d/12-iptv.conf b/files/etc/sysctl.d/12-iptv.conf new file mode 100644 index 00000000..2d8f3e54 --- /dev/null +++ b/files/etc/sysctl.d/12-iptv.conf @@ -0,0 +1,4 @@ +# Do not edit, changes to this file will be lost on upgrades +# /etc/sysctl.conf can be used to customize sysctl settings + +net.ipv4.igmp_max_msf=100 \ No newline at end of file diff --git a/files/etc/uci-defaults/z000_flashbox-reset-and-config.sh b/files/etc/uci-defaults/z000_flashbox-reset-and-config.sh index 12e67d97..f0d707a8 100644 --- a/files/etc/uci-defaults/z000_flashbox-reset-and-config.sh +++ b/files/etc/uci-defaults/z000_flashbox-reset-and-config.sh @@ -4,101 +4,118 @@ # Reset blockscan rule A=$(uci -X show firewall | grep "path='/etc/firewall.blockscan'" | \ - awk -F '.' '{ print "firewall."$2 }') + awk -F '.' '{ print "firewall."$2 }') if [ "$A" ] then - uci delete $A + uci delete $A fi # Reset ssh rule A=$(uci -X show firewall | \ - grep "firewall\..*\.name='\(anlix-ssh\|custom-ssh\)'" | \ - awk -F '.' '{ print "firewall."$2 }') + grep "firewall\..*\.name='\(anlix-ssh\|custom-ssh\)'" | \ + awk -F '.' '{ print "firewall."$2 }') if [ "$A" ] then - uci delete $A + uci delete $A fi # Migrate old multiple files into single JSON file # Files: /root/router_passwd, /root/mqtt_secret, -# /root/custom_connection_type, /root/upgrade_info, -# /root/custom_pppoe_user, /root/custom_pppoe_password +# /root/custom_connection_type, /root/upgrade_info, +# /root/custom_pppoe_user, /root/custom_pppoe_password if [ ! -f /root/flashbox_config.json ] then - _tmp_mqtt_secret="" - if [ -f /root/mqtt_secret ] - then - _tmp_mqtt_secret=$(cat /root/mqtt_secret) - rm /root/mqtt_secret - fi - _tmp_conn_type="" - if [ -f /root/custom_connection_type ] - then - _tmp_conn_type=$(cat /root/custom_connection_type) - rm /root/custom_connection_type - fi - _tmp_pppoe_user="" - if [ -f /root/custom_pppoe_user ] - then - _tmp_pppoe_user=$(cat /root/custom_pppoe_user) - rm /root/custom_pppoe_user - fi - _tmp_pppoe_pass="" - if [ -f /root/custom_pppoe_password ] - then - _tmp_pppoe_pass=$(cat /root/custom_pppoe_password) - rm /root/custom_pppoe_password - fi - _tmp_flashapp_pass="" - if [ -f /root/router_passwd ] - then - _tmp_flashapp_pass=$(cat /root/router_passwd) - rm /root/router_passwd - fi - _tmp_has_upgraded_version="0" - if [ -f /root/upgrade_info ] - then - _tmp_has_upgraded_version="1" - rm /root/upgrade_info - fi - _tmp_hard_reset_info="0" - if [ -f /root/hard_reset ] - then - _tmp_hard_reset_info="1" - rm /root/hard_reset - fi - # - # WARNING! No spaces or tabs inside the following string! - # - _flashbox_config_json="{\ -'mqtt_secret': '$_tmp_mqtt_secret',\ -'wan_conn_type': '$_tmp_conn_type',\ -'pppoe_user': '$_tmp_pppoe_user',\ -'pppoe_pass': '$_tmp_pppoe_pass',\ -'flashapp_pass': '$_tmp_flashapp_pass',\ -'zabbix_send_data': 'n',\ -'has_upgraded_version': '$_tmp_has_upgraded_version',\ -'hard_reset_info': '$_tmp_hard_reset_info'}" + _tmp_mqtt_secret="" + if [ -f /root/mqtt_secret ] + then + _tmp_mqtt_secret=$(cat /root/mqtt_secret) + rm /root/mqtt_secret + fi + _tmp_conn_type="" + if [ -f /root/custom_connection_type ] + then + _tmp_conn_type=$(cat /root/custom_connection_type) + rm /root/custom_connection_type + fi + _tmp_pppoe_user="" + if [ -f /root/custom_pppoe_user ] + then + _tmp_pppoe_user=$(cat /root/custom_pppoe_user) + rm /root/custom_pppoe_user + fi + _tmp_pppoe_pass="" + if [ -f /root/custom_pppoe_password ] + then + _tmp_pppoe_pass=$(cat /root/custom_pppoe_password) + rm /root/custom_pppoe_password + fi + _tmp_flashapp_pass="" + if [ -f /root/router_passwd ] + then + _tmp_flashapp_pass=$(cat /root/router_passwd) + rm /root/router_passwd + fi + _tmp_has_upgraded_version="0" + if [ -f /root/upgrade_info ] + then + _tmp_has_upgraded_version="1" + rm /root/upgrade_info + fi + _tmp_hard_reset_info="0" + if [ -f /root/hard_reset ] + then + _tmp_hard_reset_info="1" + rm /root/hard_reset + fi + json_cleanup + json_init + json_add_string "mqtt_secret" "$_tmp_mqtt_secret" + json_add_string "wan_conn_type" "$_tmp_conn_type" + json_add_string "pppoe_user" "$_tmp_pppoe_user" + json_add_string "pppoe_pass" "$_tmp_pppoe_pass" + json_add_string "flashapp_pass" "$_tmp_flashapp_pass" + json_add_string "zabbix_send_data" "n" + json_add_string "has_upgraded_version" "$_tmp_has_upgraded_version" + json_add_string "hard_reset_info" "$_tmp_hard_reset_info" + json_dump > /root/flashbox_config.json + json_close_object +fi - echo "$_flashbox_config_json" > /root/flashbox_config.json +#Migrate wireless +SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) +if [ "$SSID_VALUE" != "OpenWrt" ] && [ "$SSID_VALUE" != "LEDE" ] && [ -n "$SSID_VALUE" ] +then + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _ssid_24 ssid_24 + if [ -z "$_ssid_24" ] + then + json_add_string ssid_24 "$(uci -q get wireless.@wifi-iface[0].ssid)" + json_add_string password_24 "$(uci -q get wireless.@wifi-iface[0].key)" + json_add_string channel_24 "$(uci -q get wireless.@wifi-device[0].channel)" + json_add_string hwmode_24 "$(uci -q get wireless.@wifi-device[0].hwmode)" + json_add_string htmode_24 "$(uci -q get wireless.@wifi-device[0].htmode)" + json_add_string state_24 "1" + json_add_string txpower_24 "100" + json_add_string hidden_24 "0" - ## Migration below usefull for versions older than 0.13.0 + SSID_VALUE=$(uci -q get wireless.@wifi-iface[1].ssid) + if [ "$SSID_VALUE" != "OpenWrt" ] && [ "$SSID_VALUE" != "LEDE" ] && [ -n "$SSID_VALUE" ] + then + json_add_string ssid_50 "$(uci -q get wireless.@wifi-iface[1].ssid)" + json_add_string password_50 "$(uci -q get wireless.@wifi-iface[1].key)" + json_add_string channel_50 "$(uci -q get wireless.@wifi-device[1].channel)" + json_add_string hwmode_50 "$(uci -q get wireless.@wifi-device[1].hwmode)" + json_add_string htmode_50 "$(uci -q get wireless.@wifi-device[1].htmode)" + json_add_string state_50 "1" + json_add_string txpower_50 "100" + json_add_string hidden_50 "0" + fi + json_dump > /root/flashbox_config.json + fi + json_close_object - # In this migration we can also update some fixed wifi parameters - # that improves performance and were not present on older Flashbox versions - # This will be replaced on z005 if it's the first boot after factory firmware - uci set wireless.@wifi-device[0].wifimode="9" - uci set wireless.@wifi-device[0].noscan="1" - uci set wireless.@wifi-device[0].ht_bsscoexist="0" - uci set wireless.@wifi-device[0].bw="1" - # 5GHz - if [ "$(uci -q get wireless.@wifi-iface[1])" ] - then - uci set wireless.@wifi-device[1].wifimode="15" - uci set wireless.@wifi-device[1].noscan="1" - uci set wireless.@wifi-device[1].ht_bsscoexist="0" - uci set wireless.@wifi-device[1].bw="2" - uci set wireless.@wifi-device[1].country="BR" - fi - uci commit wireless + # reset /etc/config/wireless + rm /etc/config/wireless + wifi config fi # Create temporary file to differentiate between a boot after a upgrade diff --git a/custom-files/dl-dwr116-a3/etc/uci-defaults/z001_flashbox-system.sh b/files/etc/uci-defaults/z001_flashbox-system.sh similarity index 100% rename from custom-files/dl-dwr116-a3/etc/uci-defaults/z001_flashbox-system.sh rename to files/etc/uci-defaults/z001_flashbox-system.sh diff --git a/files/etc/uci-defaults/z002_flashbox-network.sh b/files/etc/uci-defaults/z002_flashbox-network.sh index 4cb660b2..0fb61cc2 100644 --- a/files/etc/uci-defaults/z002_flashbox-network.sh +++ b/files/etc/uci-defaults/z002_flashbox-network.sh @@ -3,29 +3,35 @@ . /usr/share/flashman_init.conf . /usr/share/libubox/jshn.sh . /usr/share/functions/network_functions.sh - -_wan_proto_value=$(uci get network.wan.proto) +. /usr/share/functions/device_functions.sh json_cleanup json_load_file /root/flashbox_config.json +json_get_var _bridge_mode bridge_mode +json_get_var _bridge_disable_switch bridge_disable_switch +json_get_var _bridge_fix_ip bridge_fix_ip +json_get_var _bridge_fix_gateway bridge_fix_gateway +json_get_var _bridge_fix_dns bridge_fix_dns json_get_var _wan_conn_type wan_conn_type json_get_var _pppoe_user pppoe_user json_get_var _pppoe_pass pppoe_pass json_get_var _lan_addr lan_addr json_get_var _lan_netmask lan_netmask json_get_var _lan_ipv6prefix lan_ipv6prefix +json_get_var _enable_ipv6 enable_ipv6 json_close_object +[ -z "$_enable_ipv6" ] && [ "$FLM_WAN_IPV6_ENABLED" = "y" ] && _enable_ipv6="1" || _enable_ipv6="0" if [ "$_lan_addr" = "" ] || [ "$_lan_netmask" = "" ] then - _lan_addr="$FLM_LAN_SUBNET" - _lan_netmask="$FLM_LAN_NETMASK" + _lan_addr="$FLM_LAN_SUBNET" + _lan_netmask="$FLM_LAN_NETMASK" fi if [ "$_lan_ipv6prefix" = "" ] then - _lan_ipv6prefix="$FLM_LAN_IPV6_PREFIX" + _lan_ipv6prefix="$FLM_LAN_IPV6_PREFIX" fi # Validate LAN gateway address @@ -33,26 +39,26 @@ valid_ip "$_lan_addr" _retstatus=$? if [ $_retstatus -eq 1 ] then - # Invalid. Use default 10.0.10.1 - _lan_addr="10.0.10.1" - _lan_netmask="24" + # Invalid. Use default 10.0.10.1 + _lan_addr="10.0.10.1" + _lan_netmask="24" else - _ipcalc_res="$(/bin/ipcalc.sh $_lan_addr $_lan_netmask 1)" - - _ipcalc_netmask=$(echo "$_ipcalc_res" | grep "PREFIX" | awk -F= '{print $2}') - # Accepted netmasks: 24 to 26 - if [ $_ipcalc_netmask -lt 24 ] || [ $_ipcalc_netmask -gt 26 ] - then - # Invalid netmask. Use default 24 - _lan_netmask="24" - _lan_addr="10.0.10.1" - else - # Valid netmask - _lan_netmask="$_ipcalc_netmask" - # Use first address available returned by ipcalc - _ipcalc_addr=$(echo "$_ipcalc_res" | grep "START" | awk -F= '{print $2}') - _lan_addr="$_ipcalc_addr" - fi + _ipcalc_res="$(/bin/ipcalc.sh $_lan_addr $_lan_netmask 1)" + + _ipcalc_netmask=$(echo "$_ipcalc_res" | grep "PREFIX" | awk -F= '{print $2}') + # Accepted netmasks: 24 to 26 + if [ $_ipcalc_netmask -lt 24 ] || [ $_ipcalc_netmask -gt 26 ] + then + # Invalid netmask. Use default 24 + _lan_netmask="24" + _lan_addr="10.0.10.1" + else + # Valid netmask + _lan_netmask="$_ipcalc_netmask" + # Use first address available returned by ipcalc + _ipcalc_addr=$(echo "$_ipcalc_res" | grep "START" | awk -F= '{print $2}') + _lan_addr="$_ipcalc_addr" + fi fi # Configure WAN @@ -64,6 +70,16 @@ uci set network.wan.keepalive="60 3" uci set network.lan.ipaddr="$_lan_addr" uci set network.lan.netmask="$_lan_netmask" uci set network.lan.ip6assign="$_lan_ipv6prefix" +uci set network.lan.igmp_snooping='1' + +if [ "$(is_mesh_capable)" ] +then + uci set network.wan.vendorid="ANLIX02" + uci set network.wan.reqopts="43" + uci set network.lan.stp='1' +else + uci set network.wan.vendorid="ANLIX01" +fi uci set network.dmz=interface uci set network.dmz.proto='static' @@ -75,28 +91,28 @@ uci set network.dmz.ipv6='0' # Check custom wan type if [ "$_wan_conn_type" = "pppoe" ] || [ "$_wan_conn_type" = "dhcp" ] then - uci set network.wan.proto="$_wan_conn_type" + uci set network.wan.proto="$_wan_conn_type" fi -if [ "$FLM_WAN_PROTO" = "pppoe" ] && [ "$_wan_proto_value" != "pppoe" ] && \ - [ "$_wan_conn_type" != "dhcp" ] +if { [ "$_wan_conn_type" = "" ] && [ "$FLM_WAN_PROTO" = "pppoe" ]; } || \ + [ "$_wan_conn_type" = "pppoe" ]; then - uci set network.wan.username="$FLM_WAN_PPPOE_USER" - uci set network.wan.password="$FLM_WAN_PPPOE_PASSWD" + uci set network.wan.username="$FLM_WAN_PPPOE_USER" + uci set network.wan.password="$FLM_WAN_PPPOE_PASSWD" fi # Check for custom pppoe credentials if [ "$_wan_conn_type" = "pppoe" ] && \ - [ "$_pppoe_user" != "" ] && [ "$_pppoe_pass" != "" ] + [ "$_pppoe_user" != "" ] && [ "$_pppoe_pass" != "" ] then - uci set network.wan.username="$_pppoe_user" - uci set network.wan.password="$_pppoe_pass" + uci set network.wan.username="$_pppoe_user" + uci set network.wan.password="$_pppoe_pass" fi # Check if IPv6 enabled -if [ "$FLM_WAN_IPV6_ENABLED" == "y" ] +if [ "$_enable_ipv6" = "1" ] then - uci set network.wan.ipv6="auto" + enable_ipv6 else - uci set network.wan.ipv6="0" + disable_ipv6 fi # Remove IPv6 ULA prefix to avoid phone issues @@ -107,7 +123,14 @@ uci commit network A=$(grep "$_lan_addr anlixrouter" /etc/hosts) if [ ! "$A" ] then - echo "$_lan_addr anlixrouter" >> /etc/hosts + echo "$_lan_addr anlixrouter" >> /etc/hosts +fi + +# Check if bridge mode should be enabled +if [ "$_bridge_mode" = "y" ] +then + enable_bridge_mode "n" "n" "$_bridge_disable_switch" "$_bridge_fix_ip" \ + "$_bridge_fix_gateway" "$_bridge_fix_dns" fi exit 0 diff --git a/files/etc/uci-defaults/z003_flashbox-firewall.sh b/files/etc/uci-defaults/z003_flashbox-firewall.sh index 9866117b..c6aff1d5 100644 --- a/files/etc/uci-defaults/z003_flashbox-firewall.sh +++ b/files/etc/uci-defaults/z003_flashbox-firewall.sh @@ -4,19 +4,22 @@ uci set firewall.@defaults[-1].input="ACCEPT" uci set firewall.@defaults[-1].output="ACCEPT" uci set firewall.@defaults[-1].forward="REJECT" +uci set firewall.@defaults[-1].flow_offloading="1" # Lan uci set firewall.@zone[0].input="ACCEPT" uci set firewall.@zone[0].output="ACCEPT" uci set firewall.@zone[0].forward="REJECT" +uci set firewall.@zone[0].mtu_fix="1" # Wan -uci set firewall.@zone[1].input="ACCEPT" +uci set firewall.@zone[1].input="REJECT" uci set firewall.@zone[1].output="ACCEPT" uci set firewall.@zone[1].forward="REJECT" +uci set firewall.@zone[1].mtu_fix="1" # Block port scan (stealth mode) if [ -f /etc/firewall.blockscan ] then - uci add firewall include - uci set firewall.@include[-1].path='/etc/firewall.blockscan' + uci add firewall include + uci set firewall.@include[-1].path='/etc/firewall.blockscan' fi # SSH access uci add firewall rule @@ -30,30 +33,30 @@ uci set firewall.@rule[-1].src="wan" A=$(uci show firewall | grep "@zone\[.\].name='dmz'") if [ -z "$A" ] then - uci -q add firewall zone - uci set firewall.@zone[-1].name="dmz" - uci set firewall.@zone[-1].input="REJECT" - uci set firewall.@zone[-1].output="ACCEPT" - uci set firewall.@zone[-1].forward="REJECT" - uci set firewall.@zone[-1].subnet="192.168.43.128/25" - uci -q add firewall forwarding - uci set firewall.@forwarding[-1].src='dmz' - uci set firewall.@forwarding[-1].dest='wan' - uci add firewall forwarding - uci set firewall.@forwarding[-1].src='lan' - uci set firewall.@forwarding[-1].dest='dmz' - uci -q add firewall rule - uci set firewall.@rule[-1].name="dmz-dns" - uci set firewall.@rule[-1].src='dmz' - uci set firewall.@rule[-1].proto='tcpudp' - uci set firewall.@rule[-1].dest_port='53' - uci set firewall.@rule[-1].target='ACCEPT' - uci -q add firewall rule - uci set firewall.@rule[-1].name="dmz-dhcp" - uci set firewall.@rule[-1].src='dmz' - uci set firewall.@rule[-1].proto='udp' - uci set firewall.@rule[-1].dest_port='67' - uci set firewall.@rule[-1].target='ACCEPT' + uci -q add firewall zone + uci set firewall.@zone[-1].name="dmz" + uci set firewall.@zone[-1].input="REJECT" + uci set firewall.@zone[-1].output="ACCEPT" + uci set firewall.@zone[-1].forward="REJECT" + uci set firewall.@zone[-1].subnet="192.168.43.128/25" + uci -q add firewall forwarding + uci set firewall.@forwarding[-1].src='dmz' + uci set firewall.@forwarding[-1].dest='wan' + uci add firewall forwarding + uci set firewall.@forwarding[-1].src='lan' + uci set firewall.@forwarding[-1].dest='dmz' + uci -q add firewall rule + uci set firewall.@rule[-1].name="dmz-dns" + uci set firewall.@rule[-1].src='dmz' + uci set firewall.@rule[-1].proto='tcpudp' + uci set firewall.@rule[-1].dest_port='53' + uci set firewall.@rule[-1].target='ACCEPT' + uci -q add firewall rule + uci set firewall.@rule[-1].name="dmz-dhcp" + uci set firewall.@rule[-1].src='dmz' + uci set firewall.@rule[-1].proto='udp' + uci set firewall.@rule[-1].dest_port='67' + uci set firewall.@rule[-1].target='ACCEPT' fi uci commit firewall diff --git a/files/etc/uci-defaults/z005_flashbox-wireless.sh b/files/etc/uci-defaults/z005_flashbox-wireless.sh new file mode 100755 index 00000000..df664faf --- /dev/null +++ b/files/etc/uci-defaults/z005_flashbox-wireless.sh @@ -0,0 +1,158 @@ +#!/bin/sh +# WARNING! This file may be replaced depending on the selected target! + +. /usr/share/libubox/jshn.sh +. /usr/share/flashman_init.conf +. /lib/functions/system.sh +. /usr/share/functions/device_functions.sh +. /usr/share/functions/wireless_functions.sh + +MAC_ADDR="$(get_mac)" +MAC_LAST_CHARS=$(echo $MAC_ADDR | awk -F: '{ print $5$6 }') +SSID_VALUE=$(uci -q get wireless.@wifi-iface[0].ssid) +SUFFIX_5="-5GHz" +IS_REALTEK="$(lsmod | grep rtl8192cd)" + +json_cleanup +json_load_file /root/flashbox_config.json +json_get_var _mesh_mode mesh_mode +json_get_var _mesh_master mesh_master +json_get_var _ssid_24 ssid_24 +json_get_var _password_24 password_24 +json_get_var _channel_24 channel_24 +json_get_var _htmode_24 htmode_24 +json_get_var _state_24 state_24 +json_get_var _txpower_24 txpower_24 "100" +json_get_var _hidden_24 hidden_24 "0" +if [ "$(is_5ghz_capable)" == "1" ] +then + json_get_var _ssid_50 ssid_50 + json_get_var _password_50 password_50 + json_get_var _channel_50 channel_50 + json_get_var _htmode_50 htmode_50 + json_get_var _state_50 state_50 + json_get_var _txpower_50 txpower_50 "100" + json_get_var _hidden_50 hidden_50 "0" +fi +json_close_object + +[ ! "$_mesh_mode" ] && _mesh_mode="0" + +if [ -z "$_ssid24" ] +then + #use defaults + [ "$FLM_SSID_SUFFIX" == "none" ] && setssid="$FLM_SSID" || setssid="$FLM_SSID$MAC_LAST_CHARS" + # Wireless password cannot be empty or have less than 8 chars + if [ "$FLM_PASSWD" == "" ] || [ $(echo "$FLM_PASSWD" | wc -m) -lt 9 ] + then + FLM_PASSWD=$(echo $MAC_ADDR | sed -e "s/://g") + fi + + _ssid_24=$setssid + _password_24="$FLM_PASSWD" + _channel_24="$FLM_24_CHANNEL" + _htmode_24="$([ "$FLM_24_BAND" = "HT40" ] && echo "HT40" || echo "HT20")" + _state_24="1" + _txpower_24="100" + _hidden_24="0" + + _ssid_50="$setssid$SUFFIX_5" + _password_50="$FLM_PASSWD" + _channel_50="$FLM_50_CHANNEL" + _htmode_50="$([ "$(is_5ghz_vht)" ] && echo "VHT80" || echo "HT40")" + _state_50="1" + _txpower_50="100" + _hidden_50="0" +fi + +DEFAULT_24_CHANNELS="1 6 11 3 9 2 4 5 7 8 10" +DEFAULT_50_CHANNELS="36 40 44 153 157 161" + +if [ "$(type -t custom_wifi_24_channels)" ] +then + DEFAULT_24_CHANNELS="$(custom_wifi_24_channels)" + [ "$(echo $DEFAULT_24_CHANNELS|grep -c ' ')" = 0 ] && _channel_24=$DEFAULT_24_CHANNELS +fi + +if [ "$(type -t custom_wifi_50_channels)" ] +then + DEFAULT_50_CHANNELS="$(custom_wifi_50_channels)" + [ "$(echo $DEFAULT_50_CHANNELS|grep -c ' ')" = 0 ] && _channel_50=$DEFAULT_50_CHANNELS +fi + +_phy0=$(get_radio_phy "0") +if [ "$(get_phy_type $_phy0)" -eq "2" ] +then + # 2.4 Radio is always first radio + uci rename wireless.radio0=radiotmp + uci rename wireless.radio1=radio0 + uci rename wireless.radiotmp=radio1 + uci rename wireless.default_radio0=default_radiotmp + uci rename wireless.default_radio1=default_radio0 + uci rename wireless.default_radiotmp=default_radio1 + uci set wireless.default_radio0.device='radio0' + uci set wireless.default_radio1.device='radio1' + uci reorder wireless.radio0=0 + uci reorder wireless.default_radio0=1 + uci reorder wireless.radio1=2 + uci reorder wireless.default_radio1=3 +fi + +uci set wireless.radio0.txpower="$(convert_txpower "24" "$_channel_24" "$_txpower_24")" +uci set wireless.radio0.htmode="$_htmode_24" +uci set wireless.radio0.noscan="0" +[ "$_htmode_24" = "HT40" ] && uci set wireless.radio0.noscan="1" +uci set wireless.radio0.country="BR" +uci set wireless.radio0.channel="$_channel_24" +uci set wireless.radio0.channels="$DEFAULT_24_CHANNELS" +uci set wireless.radio0.disabled='0' +uci set wireless.default_radio0.disabled="$([ "$_state_24" = "1" ] && echo "0" || echo "1")" +uci set wireless.default_radio0.ifname='wlan0' +uci set wireless.default_radio0.ssid="$_ssid_24" +uci set wireless.default_radio0.encryption="$([ "$(grep RTL8196E /proc/cpuinfo)" ] && echo "psk2+tkip+ccmp" || echo "psk2")" +uci set wireless.default_radio0.key="$_password_24" +uci set wireless.default_radio0.hidden="$_hidden_24" +[ "$(type -t hostapd_cli)" ] && change_wps_state "0" "1" +[ "$IS_REALTEK" ] && uci set wireless.default_radio0.macaddr="$(macaddr_add $MAC_ADDR -1)" + +if [ "$(is_5ghz_capable)" == "1" ] +then + uci set wireless.radio1.txpower="$(convert_txpower "50" "$_channel_50" "$_txpower_50")" + uci set wireless.radio1.channel="$_channel_50" + uci set wireless.radio1.channels="$DEFAULT_50_CHANNELS" + uci set wireless.radio1.country="BR" + uci set wireless.radio1.htmode="$_htmode_50" + uci set wireless.radio1.noscan="1" + uci set wireless.radio1.disabled='0' + uci set wireless.default_radio1.disabled="$([ "$_state_50" = "1" ] && echo "0" || echo "1")" + uci set wireless.default_radio1.ifname='wlan1' + uci set wireless.default_radio1.ssid="$_ssid_50" + uci set wireless.default_radio1.encryption="psk2" + uci set wireless.default_radio1.key="$_password_50" + uci set wireless.default_radio1.hidden="$_hidden_50" + [ "$(type -t hostapd_cli)" ] && change_wps_state "1" "1" + [ "$IS_REALTEK" ] && uci set wireless.default_radio1.macaddr="$(macaddr_add $MAC_ADDR -2)" +fi + +if [ "$_mesh_mode" -gt "0" ] +then + if [ -z "$_mesh_master" ] + then + set_mesh_master_mode "$_mesh_mode" + else + set_mesh_slave_mode "$_mesh_mode" "$_mesh_master" + fi + + # Enable Fast Transition + change_fast_transition "0" "1" + if [ "$(is_5ghz_capable)" = "1" ] + then + change_fast_transition "1" "1" + fi + + enable_mesh_routing "$_mesh_mode" +fi + +uci commit wireless + +exit 0 diff --git a/files/etc/uci-defaults/z006_flashbox-dhcp.sh b/files/etc/uci-defaults/z006_flashbox-dhcp.sh index 7d6f55f5..e872609f 100644 --- a/files/etc/uci-defaults/z006_flashbox-dhcp.sh +++ b/files/etc/uci-defaults/z006_flashbox-dhcp.sh @@ -1,11 +1,12 @@ #!/bin/sh +. /usr/share/flashman_init.conf . /usr/share/functions/network_functions.sh A=$(uci get dhcp.@dnsmasq[0].interface) if [ "$A" ] then - uci delete dhcp.@dnsmasq[0].interface + uci delete dhcp.@dnsmasq[0].interface fi uci add_list dhcp.@dnsmasq[0].interface='lan' @@ -28,6 +29,13 @@ uci set dhcp.dmz.dynamicdhcp='0' uci set dhcp.dmz.leasetime='1h' uci set dhcp.dmz.force='1' +if [ "$FLM_DHCP_NOPROXY" == "1" ] +then + uci set dhcp.@dnsmasq[0].noproxy='1' +else + uci set dhcp.@dnsmasq[0].noproxy='0' +fi + uci commit dhcp exit 0 diff --git a/files/etc/uci-defaults/z008_flashbox-zabbix.sh b/files/etc/uci-defaults/z008_flashbox-zabbix.sh index ae435da5..9738f46c 100644 --- a/files/etc/uci-defaults/z008_flashbox-zabbix.sh +++ b/files/etc/uci-defaults/z008_flashbox-zabbix.sh @@ -9,12 +9,12 @@ json_get_var _zabbix_fqdn zabbix_fqdn json_close_object if [ "$_zabbix_psk" != "" ] then - echo -n $_zabbix_psk > /etc/zabbix_agentd.psk + echo -n $_zabbix_psk > /etc/zabbix_agentd.psk fi if [ "$_zabbix_fqdn" != "" ] then - sed -i 's/Server=.*/Server='"$_zabbix_fqdn"'/' /etc/zabbix_agentd.conf - sed -i 's/ServerActive=.*/ServerActive='"$_zabbix_fqdn"':80/' /etc/zabbix_agentd.conf + sed -i 's/Server=.*/Server='"$_zabbix_fqdn"'/' /etc/zabbix_agentd.conf + sed -i 's/ServerActive=.*/ServerActive='"$_zabbix_fqdn"':80/' /etc/zabbix_agentd.conf fi exit 0 diff --git a/files/etc/udhcpc.user b/files/etc/udhcpc.user new file mode 100644 index 00000000..b540a7b4 --- /dev/null +++ b/files/etc/udhcpc.user @@ -0,0 +1,28 @@ +#!/bin/sh +[ -z "$opt43" ] && exit 1 + +. /usr/share/functions/common_functions.sh +. /usr/share/functions/network_functions.sh +. /usr/share/functions/device_functions.sh + +#format is "43 FF" +if [ "${opt43:0: -4}" == "2b01" ] +then + [ ! "$(is_mesh_capable)" ] && exit 1 + + #get the mesh mode + _mesh_mode="${opt43:5: -2}" + if [ "$_mesh_mode" != "0" ] + then + #Enable bridge and let sapo do the rest + if [ "$(get_bridge_mode_status)" != "y" ] + then + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string did_change_wan_local "y" + json_dump > /root/flashbox_config.json + json_close_object + enable_bridge_mode y n n "" "" "" + fi + fi +fi diff --git a/files/usr/lib/lua/json.lua b/files/usr/lib/lua/json.lua index 12ba4e66..711ef786 100644 --- a/files/usr/lib/lua/json.lua +++ b/files/usr/lib/lua/json.lua @@ -1,13 +1,28 @@ -- -- json.lua -- --- Copyright (c) 2015 rxi +-- Copyright (c) 2020 rxi -- --- This library is free software; you can redistribute it and/or modify it --- under the terms of the MIT license. See LICENSE for details. +-- Permission is hereby granted, free of charge, to any person obtaining a copy of +-- this software and associated documentation files (the "Software"), to deal in +-- the Software without restriction, including without limitation the rights to +-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +-- of the Software, and to permit persons to whom the Software is furnished to do +-- so, subject to the following conditions: +-- +-- The above copyright notice and this permission notice shall be included in all +-- copies or substantial portions of the Software. +-- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +-- SOFTWARE. -- -local json = { _version = "0.1.0" } +local json = { _version = "0.1.2" } ------------------------------------------------------------------------------- -- Encode @@ -16,29 +31,29 @@ local json = { _version = "0.1.0" } local encode local escape_char_map = { - [ "\\" ] = "\\\\", - [ "\"" ] = "\\\"", - [ "\b" ] = "\\b", - [ "\f" ] = "\\f", - [ "\n" ] = "\\n", - [ "\r" ] = "\\r", - [ "\t" ] = "\\t", + [ "\\" ] = "\\", + [ "\"" ] = "\"", + [ "\b" ] = "b", + [ "\f" ] = "f", + [ "\n" ] = "n", + [ "\r" ] = "r", + [ "\t" ] = "t", } -local escape_char_map_inv = { [ "\\/" ] = "/" } +local escape_char_map_inv = { [ "/" ] = "/" } for k, v in pairs(escape_char_map) do escape_char_map_inv[v] = k end local function escape_char(c) - return escape_char_map[c] or string.format("\\u%04x", c:byte()) + return "\\" .. (escape_char_map[c] or string.format("u%04x", c:byte())) end local function encode_nil(val) return "null" -end +end local function encode_table(val, stack) @@ -50,7 +65,7 @@ local function encode_table(val, stack) stack[val] = true - if val[1] ~= nil or next(val) == nil then + if rawget(val, 1) ~= nil or next(val) == nil then -- Treat as array -- check keys are valid and it is not sparse local n = 0 for k in pairs(val) do @@ -127,7 +142,7 @@ end local parse -local function create_set(...) +local function create_set(...) local res = {} for i = 1, select("#", ...) do res[ select(i, ...) ] = true @@ -189,9 +204,9 @@ end local function parse_unicode_escape(s) - local n1 = tonumber( s:sub(3, 6), 16 ) - local n2 = tonumber( s:sub(9, 12), 16 ) - -- Surrogate pair? + local n1 = tonumber( s:sub(1, 4), 16 ) + local n2 = tonumber( s:sub(7, 10), 16 ) + -- Surrogate pair? if n2 then return codepoint_to_utf8((n1 - 0xd800) * 0x400 + (n2 - 0xdc00) + 0x10000) else @@ -201,54 +216,42 @@ end local function parse_string(str, i) - local has_unicode_escape = false - local has_surrogate_escape = false - local has_escape = false - local last - for j = i + 1, #str do + local res = "" + local j = i + 1 + local k = j + + while j <= #str do local x = str:byte(j) if x < 32 then decode_error(str, j, "control character in string") - end - if last == 92 then -- "\\" (escape char) - if x == 117 then -- "u" (unicode escape sequence) - local hex = str:sub(j + 1, j + 5) - if not hex:find("%x%x%x%x") then - decode_error(str, j, "invalid unicode escape in string") - end - if hex:find("^[dD][89aAbB]") then - has_surrogate_escape = true - else - has_unicode_escape = true - end + elseif x == 92 then -- `\`: Escape + res = res .. str:sub(k, j - 1) + j = j + 1 + local c = str:sub(j, j) + if c == "u" then + local hex = str:match("^[dD][89aAbB]%x%x\\u%x%x%x%x", j + 1) + or str:match("^%x%x%x%x", j + 1) + or decode_error(str, j - 1, "invalid unicode escape in string") + res = res .. parse_unicode_escape(hex) + j = j + #hex else - local c = string.char(x) if not escape_chars[c] then - decode_error(str, j, "invalid escape char '" .. c .. "' in string") + decode_error(str, j - 1, "invalid escape char '" .. c .. "' in string") end - has_escape = true + res = res .. escape_char_map_inv[c] end - last = nil + k = j + 1 - elseif x == 34 then -- '"' (end of string) - local s = str:sub(i + 1, j - 1) - if has_surrogate_escape then - s = s:gsub("\\u[dD][89aAbB]..\\u....", parse_unicode_escape) - end - if has_unicode_escape then - s = s:gsub("\\u....", parse_unicode_escape) - end - if has_escape then - s = s:gsub("\\.", escape_char_map_inv) - end - return s, j + 1 - - else - last = x + elseif x == 34 then -- `"`: End of string + res = res .. str:sub(k, j - 1) + return res, j + 1 end + + j = j + 1 end + decode_error(str, i, "expected closing quote for string") end @@ -282,7 +285,7 @@ local function parse_array(str, i) local x i = next_char(str, i, space_chars, true) -- Empty / end of array? - if str:sub(i, i) == "]" then + if str:sub(i, i) == "]" then i = i + 1 break end @@ -290,7 +293,7 @@ local function parse_array(str, i) x, i = parse(str, i) res[n] = x n = n + 1 - -- Next token + -- Next token i = next_char(str, i, space_chars, true) local chr = str:sub(i, i) i = i + 1 @@ -308,7 +311,7 @@ local function parse_object(str, i) local key, val i = next_char(str, i, space_chars, true) -- Empty / end of object? - if str:sub(i, i) == "}" then + if str:sub(i, i) == "}" then i = i + 1 break end @@ -373,9 +376,13 @@ function json.decode(str) if type(str) ~= "string" then error("expected argument of type string, got " .. type(str)) end - return ( parse(str, next_char(str, 1, space_chars, true)) ) + local res, idx = parse(str, next_char(str, 1, space_chars, true)) + idx = next_char(str, idx, space_chars, true) + if idx <= #str then + decode_error(str, idx, "trailing garbage") + end + return res end return json - diff --git a/files/usr/share/anlix/index.lua b/files/usr/share/anlix/index.lua index 554f2509..5b38d957 100644 --- a/files/usr/share/anlix/index.lua +++ b/files/usr/share/anlix/index.lua @@ -1,473 +1,327 @@ require("uci") +require("lib") json = require("json") - -local function run_process(proc) - local handle = io.popen(proc) - local result = handle:read("*a") - handle:close() - return result -end - -local function get_router_id() - local result = run_process("sh -c \". /usr/share/functions/device_functions.sh; get_mac\"") - -- remove \n - return result:sub(1,-2) -end - -local function get_mac_from_ip(ip) - local result = run_process("sh -c \". /usr/share/functions/dhcp_functions.sh; get_device_mac_from_ip " .. ip .. "\"") - -- remove \n - return result:sub(1,-2) -end - -local function is_authenticated() - local result = run_process("sh -c \". /usr/share/functions/common_functions.sh; if is_authenticated; then echo 1; else echo 0; fi\"") - -- remove \n - result = result:sub(1,-2) - - if result == "1" then - return true - else - return false - end -end - -local function get_router_secret() - local result = run_process(". /usr/share/flashman_init.conf; echo $FLM_CLIENT_SECRET") - -- remove \n - return result:sub(1,-2) -end - -local function get_flashman_server() - local result = run_process(". /usr/share/flashman_init.conf; echo $FLM_SVADDR") - -- remove \n - return result:sub(1,-2) -end - -local function check_file(path) - local file = io.open(path, "rb") - if not file then - return false - else - file:close() - return true - end -end - -local function read_file(path) - local file = io.open(path, "rb") - if not file then return nil end - local content = file:read "*all" - file:close() - return content -end - -local function read_lines(path) - if not check_file(path) then return nil end - local file = io.lines(path) - local content = {} - for line in file do - table.insert(content, line) - end - return content -end - -local function trim_file(path) - if not check_file(path) then return end - local file = io.lines(path) - local content = {} - local line_count = 0 - for line in file do - table.insert(content, line) - line_count = line_count + 1 - end - file = io.open(path, "wb") - for index, line in ipairs(content) do - if (index > 1 or line_count <= 5) then - file:write(line .. "\n") - end - end -end - -local function append_to_file(path, content) - local file = io.open(path, "ab") - if not file then return false end - file:write(content) - file:close() - return true -end - -local function remove_from_file(path, data) - if not check_file(path) then return false end - local file = io.lines(path) - local ret = false - local content = {} - for line in file do - if not line:match(data) then - table.insert(content, line) - else - ret = true - end - end - file = io.open(path, "wb") - for index, line in ipairs(content) do - file:write(line .. "\n") - end - file:close() - return ret -end - -local function touch_file(path) - local file = io.open(path, "wb") - if not file then return false end - local content = file:write "tmp" - file:close() - return true -end +flashman = require("flashman") +web = require("webHandle") +auth_provider = require("auth") +require("config") local function write_firewall_file(blacklist_path) - local lines = read_lines(blacklist_path) - local firewall_file = io.open("/etc/firewall.user", "wb") - for index, line in ipairs(lines) do - local mac = line:match("%x%x:%x%x:%x%x:%x%x:%x%x:%x%x") - local rule = "iptables -I FORWARD -m mac --mac-source " .. mac .. " -j DROP" - firewall_file:write(rule .. "\n") - end -end - -local function flashman_update(remote_addr, app_id, app_secret) - local flashman_addr = get_flashman_server() - -- Add App to the flashman base - auth = {} - auth["id"]=get_router_id() - auth["secret"]=get_router_secret() - auth["app_id"]=app_id - auth["app_secret"]=app_secret - auth["app_mac"]=get_mac_from_ip(remote_addr) - post_data = json.encode(auth) - - post_data = post_data:gsub("\"","\\\"") - cmd_curl = "curl -s --tlsv1.2 -X POST -H \"Content-Type:application/json\" -d \"".. post_data .."\" https://".. flashman_addr .."/deviceinfo/app/add?api=1" - - local result = run_process(cmd_curl) - - local jres = json.decode(result) - - if jres["is_registered"] == 1 then - return true - else - return false - end -end - -local function save_router_passwd_flashman(passwd, app_id, app_secret) - local flashman_addr = get_flashman_server() - auth = {} - auth["id"]=get_router_id() - auth["secret"]=get_router_secret() - auth["app_id"]=app_id - auth["app_secret"]=app_secret - auth["router_passwd"]=passwd - post_data = json.encode(auth) - - post_data = post_data:gsub("\"","\\\"") - cmd_curl = "curl -s --tlsv1.2 -X POST -H \"Content-Type:application/json\" -d \"".. post_data .."\" https://".. flashman_addr .."/deviceinfo/app/addpass?api=1" - - local result = run_process(cmd_curl) - local jres = json.decode(result) - - if jres["is_registered"] == 1 then - return true - elseif jres["is_registered"] == nil then - -- Legacy flashman doesn't have the url, can't set password on flashman - return true - else - return false - end + local lines = read_lines(blacklist_path) + local firewall_file = io.open("/etc/firewall.user", "wb") + for index, line in ipairs(lines) do + local mac = line:match("%x%x:%x%x:%x%x:%x%x:%x%x:%x%x") + local rule = "iptables -I FORWARD -m mac --mac-source " .. mac .. " -j DROP" + firewall_file:write(rule .. "\n") + end end local function get_key(id) - return read_file("/tmp/" .. id) + return read_file("/tmp/" .. id) end local function gen_app_key(id) - local file = io.open("/tmp/" .. id, "wb") - if not file then return nil end - local secret = run_process("head -c 128 /dev/urandom | tr -dc 'a-zA-Z0-9'") - file:write(secret) - file:close() - return secret -end - -local function get_router_passwd() - local result = run_process("sh -c \". /usr/share/functions/api_functions.sh; get_flashapp_pass\"") - -- remove \n - result = result:sub(1,-2) - if result == nil or result == "" then - result = nil - end - return result -end - -local function save_router_passwd(pass) - run_process("sh -c \". /usr/share/functions/api_functions.sh; set_flashapp_pass ".. pass .."\"") - return true + local file = io.open("/tmp/" .. id, "wb") + if not file then return nil end + local secret = run_process("head -c 128 /dev/urandom | tr -dc 'a-zA-Z0-9'") + file:write(secret) + file:close() + return secret end local function leases_to_json(leases) - local result = {} - for index, value in ipairs(leases) do - local info = {} - local values = {} - for word in value:gmatch("%S+") do table.insert(values, word) end - info["expire"] = values[1] - info["mac"] = values[2] - info["ip"] = values[3] - info["id"] = values[4] - table.insert(result, info) - end - return json.encode(result) + local result = {} + for index, value in ipairs(leases) do + local info = {} + local values = {} + for word in value:gmatch("%S+") do table.insert(values, word) end + info["expire"] = values[1] + info["mac"] = values[2] + info["ip"] = values[3] + info["id"] = values[4] + table.insert(result, info) + end + return json.encode(result) end local function separate_fields(devices) - local result = {} - for index, info in ipairs(devices) do - local device = {} - device.mac = info:match("%x%x:%x%x:%x%x:%x%x:%x%x:%x%x") - device.id = info:match("|.+"):sub(2) - table.insert(result, device) - end - return result + local result = {} + for index, info in ipairs(devices) do + local device = {} + device.mac = info:match("%x%x:%x%x:%x%x:%x%x:%x%x:%x%x") + device.id = info:match("|.+"):sub(2) + table.insert(result, device) + end + return result end local function separate_keys(devices) - local result = {} - for index, info in ipairs(devices) do - local mac = info:match("%x%x:%x%x:%x%x:%x%x:%x%x:%x%x") - local name = info:match("|.+"):sub(2) - result[mac] = name - end - return result -end - -local function error_handle(errid, errinfo, auth) - resp = {} - err = {} - err["errno"] = errid - err["errstr"] = errinfo - if auth ~= nil then resp["auth"] = auth end - resp["Error"] = err - - uhttpd.send("Status: 500 Internal Server Error\r\n") - uhttpd.send("Content-Type: text/json\r\n\r\n") - uhttpd.send(json.encode(resp)) + local result = {} + for index, info in ipairs(devices) do + local mac = info:match("%x%x:%x%x:%x%x:%x%x:%x%x:%x%x") + local name = info:match("|.+"):sub(2) + result[mac] = name + end + return result end function handle_request(env) - local command = string.sub(env.PATH_INFO, 2) - - if env.REQUEST_METHOD == "POST" then - local rlen, post_data = uhttpd.recv(8192) -- Max 8K in the post data! - local data = json.decode(post_data) - local app_protocol_ver = data.version - local app_id = data.app_id - local blacklist_path = "/tmp/blacklist_mac" - - if app_protocol_ver == nil then return end - if app_id == nil then return end - - if tonumber(app_protocol_ver) > 2 then - error_handle(1, "Invalid Protocol Version", nil) - return - end - - if command == "ping" then - local passwd = get_router_passwd() - -- no need to authenticate ping command - uhttpd.send("Status: 200 OK\r\n") - uhttpd.send("Content-Type: text/json\r\n\r\n") - - system_model = read_file("/tmp/sysinfo/model") - if(system_model == nil) then system_model = "INVALID MODEL" end - info = {} - info["anlix_model"] = system_model - info["protocol_version"] = 2.0 - if passwd ~= nil then - info["router_has_passwd"] = 1 - else - info["router_has_passwd"] = 0 - end - uhttpd.send(json.encode(info)) - return - end - - if tonumber(app_protocol_ver) == 1 then - error_handle(1, "Invalid Protocol Version", nil) - return - end - - if not check_file("/tmp/anlix_authorized") then - if is_authenticated then - touch_file("/tmp/anlix_authorized") - else - error_handle(10, "Authorization Fail", nil) - return - end - end - - local secret = get_key(app_id) - local app_secret = data.app_secret - - if app_secret == nil or secret == nil then - -- the app do not provide a secret, generate and send to flashman - secret = gen_app_key(app_id) - if secret == nil then - -- error generating key, report to app - error_handle(2, "Error generating secret for app", nil) - return - end - if not flashman_update(env.REMOTE_ADDR, app_id, secret) then - error_handle(7, "Error updating flashman", nil) - return - end - else - -- we have key, compare secrets - if app_secret ~= secret then - error_handle(8, "Secret not match", nil) - return - end - end - - -- authenticated successfully - local resp = {} - - auth = {} - auth["version"] = "1.0" - auth["id_router"] = get_router_id() - auth["app_secret"] = secret - auth["flashman_addr"] = get_flashman_server() - - -- verify passwd - local passwd = get_router_passwd() - local router_passwd = data.router_passwd - if passwd ~= nil then - if router_passwd ~= passwd then - error_handle(5, "Password not match", auth) - return - end - end - - resp["auth"] = auth - - -- exec command - if command == "change_passwd" then - local new_passwd = data.new_passwd - if new_passwd == nil then - error_handle(3, "Invalid Parameters", auth) - return - end - - if passwd == nil then - if not save_router_passwd_flashman(new_passwd, app_id, secret) then - error_handle(4, "Error saving password", auth) - return - end - end - - if not save_router_passwd(new_passwd) then - error_handle(4, "Error saving password", auth) - return - else - uhttpd.send("Status: 200 OK\r\n") - uhttpd.send("Content-Type: text/json\r\n\r\n") - resp["password_changed"] = 1 - uhttpd.send(json.encode(resp)) - end - elseif command == "info" then - uhttpd.send("Status: 200 OK\r\n") - uhttpd.send("Content-Type: text/json\r\n\r\n") - - system_model = read_file("/tmp/sysinfo/model") - if(system_model == nil) then system_model = "INVALID MODEL" end - info = {} - info["anlix_model"] = system_model - resp["info"] = info - uhttpd.send(json.encode(resp)) - elseif command == "wifi" then - u = uci.cursor() - wifi = u.get_all("wireless") - - uhttpd.send("Status: 200 OK\r\n") - uhttpd.send("Content-Type: text/json\r\n\r\n") - resp["wireless"] = wifi - uhttpd.send(json.encode(resp)) - elseif command == "devices" then - local leases = read_lines("/tmp/dhcp.leases") - local result = leases_to_json(leases) - local blacklist = {} - local named_devices = {} - if check_file(blacklist_path) then - blacklist = read_lines(blacklist_path) - end - if check_file("/tmp/named_devices") then - named_devices = read_lines("/tmp/named_devices") - end - local blacklist_info = separate_fields(blacklist) - local named_devices_info = separate_keys(named_devices) - resp["leases"] = result - resp["blacklist"] = json.encode(blacklist_info) - resp["named_devices"] = json.encode(named_devices_info) - resp["origin"] = env.REMOTE_ADDR - uhttpd.send("Status: 200 OK\r\n") - uhttpd.send("Content-Type: text/json\r\n\r\n") - uhttpd.send(json.encode(resp)) - elseif command == "blacklist" then - local mac = data.blacklist_mac - local id = data.blacklist_id - if mac == nil or not mac:match("%x%x:%x%x:%x%x:%x%x:%x%x:%x%x") then - error_handle(11, "Error reading mac address") - return - end - append_to_file(blacklist_path, mac .. "|" .. id .. "\n") - write_firewall_file(blacklist_path) - run_process("/etc/init.d/firewall restart") - resp["blacklisted"] = 1 - uhttpd.send("Status: 200 OK\r\n") - uhttpd.send("Content-Type: text/json\r\n\r\n") - uhttpd.send(json.encode(resp)) - elseif command == "whitelist" then - local mac = data.whitelist_mac - if mac == nil or not mac:match("") then - error_handle(11, "Error reading mac address") - return - end - remove_from_file(blacklist_path, mac) - write_firewall_file(blacklist_path) - run_process("/etc/init.d/firewall restart") - resp["whitelisted"] = 1 - uhttpd.send("Status: 200 OK\r\n") - uhttpd.send("Content-Type: text/json\r\n\r\n") - uhttpd.send(json.encode(resp)) - elseif command == "setHashCommand" then - local hash = data.command_hash - local timeout = data.command_timeout - local epoch_timeout = os.time() + timeout - 1 - append_to_file("/root/to_do_hashes", hash .. " " .. epoch_timeout .. "\n") - trim_file("/root/to_do_hashes") - trim_file("/root/done_hashes") - resp["is_set"] = 1 - uhttpd.send("Status: 200 OK\r\n") - uhttpd.send("Content-Type: text/json\r\n\r\n") - uhttpd.send(json.encode(resp)) - elseif command == "getHashCommand" then - local hash = data.command_hash - local is_done = remove_from_file("/root/done_hashes", hash) - resp["command_done"] = is_done - uhttpd.send("Status: 200 OK\r\n") - uhttpd.send("Content-Type: text/json\r\n\r\n") - uhttpd.send(json.encode(resp)) - else - error_handle(6, "Command not implemented", auth) - end - end + logger("Connection from " .. env.REMOTE_ADDR) + + if env.PATH_INFO == nil then + web.error_handle(web.ERROR_URL, nil) + return + end + + if not (env.REQUEST_METHOD == "POST") then + web.error_handle(web.ERROR_URL, nil) + return + end + + local subcompos = string.find(env.PATH_INFO, "/", 2) + local command = nil + local subcommand = nil + if subcompos == nil then + command = string.sub(env.PATH_INFO, 2) + else + command = string.sub(env.PATH_INFO, 2, subcompos-1) + subcommand = string.sub(env.PATH_INFO, subcompos+1) + end + + local rlen, post_data = uhttpd.recv(8192) -- Max 8K in the post data! + if not post_data then + web.error_handle(web.ERROR_DATA, nil) + return + end + + local status, data = pcall(function() return json.decode(post_data) end) + if not status then + web.error_handle(web.ERROR_DATA, nil) + logger(data) + return + end + + local app_protocol_ver = data.version + local app_id = data.app_id + + if app_protocol_ver == nil or app_id == nil then + web.error_handle(web.ERROR_DATA, nil) + return + end + + if tonumber(app_protocol_ver) > 2 then + web.error_handle(web.ERROR_PROT_VER, nil) + return + end + + local auth_data = data.auth_provider + if not (auth_data == nil) then + if auth_provider.authenticate(auth_data) then + logger("Provider Authorized as " .. auth_provider.get_user()) + else + web.error_handle(web.ERROR_AUTH_PROVIDER, nil) + return + end + end + + if command == "config" then + if auth_provider.is_authorized() then + handle_config(subcommand, data) + return + else + web.error_handle(web.ERROR_COMM_AUTH_PROVIDER, nil) + return + end + end + + local blacklist_path = "/tmp/blacklist_mac" + + if command == "ping" then + local passwd = flashman.get_router_passwd() + -- no need to authenticate ping command + system_model = read_file("/tmp/sysinfo/model") + if(system_model == nil) then system_model = "INVALID MODEL" end + info = {} + info["anlix_model"] = system_model + info["protocol_version"] = 3.0 + info["diag_protocol_version"] = 1.0 + if passwd ~= nil then + info["router_has_passwd"] = 1 + else + info["router_has_passwd"] = 0 + end + web.send_json(info) + return + elseif command == "getMulticastCache" then + local cache = ubus("anlix_sapo", "get_cache") + local resp = {} + resp["ok"] = true + if(cache ~= nil and next(cache) ~= nil) then + resp["multicast_cache"] = cache + end + web.send_json(resp) + return + elseif command == "getLoginInfo" then + local data = {} + data["mac"] = flashman.get_router_id() + data["ssid"] = flashman.get_router_ssid() + data["mesh_master"] = flashman.get_mesh_master() + local resp = {} + resp["data"] = data + web.send_json(resp) + return + end + + if tonumber(app_protocol_ver) == 1 then + web.error_handle(web.ERROR_DATA, nil) + return + end + + if not check_file("/tmp/anlix_authorized") then + if flashman.is_authenticated() then + touch_file("/tmp/anlix_authorized") + else + web.error_handle(web.ERROR_AUTH_FAIL, nil) + return + end + end + + local secret = get_key(app_id) + local app_secret = data.app_secret + + if app_secret == nil or secret == nil then + -- the app do not provide a secret, generate and send to flashman + secret = gen_app_key(app_id) + if secret == nil then + web.error_handle(web.ERROR_GEN_SECRET, nil) + return + end + if not flashman.update(env.REMOTE_ADDR, app_id, secret) then + web.error_handle(web.ERROR_FLASHMAN_UPDATE, nil) + return + end + else + -- we have key, compare secrets + if app_secret ~= secret then + web.error_handle(web.ERROR_SECRET_MATCH, nil) + return + end + end + + -- authenticated successfully + local resp = {} + + auth = {} + auth["version"] = "1.0" + auth["id_router"] = flashman.get_router_id() + auth["app_secret"] = secret + auth["flashman_addr"] = flashman.get_server() + + -- verify passwd + local passwd = flashman.get_router_passwd() + local router_passwd = data.router_passwd + if passwd ~= nil then + if router_passwd ~= passwd then + web.error_handle(web.ERROR_ROUTER_PASSWD, nil) + return + end + end + + resp["auth"] = auth + + -- exec command + if command == "change_passwd" then + local new_passwd = data.new_passwd + if new_passwd == nil then + web.error_handle(web.ERROR_PARAMETERS, auth) + return + end + + if passwd == nil then + if not flashman.save_router_passwd_flashman(new_passwd, app_id, secret) then + web.error_handle(web.ERROR_PASSWD_SAVE, auth) + return + end + end + + if not flashman.save_router_passwd_local(new_passwd) then + web.error_handle(web.ERROR_PASSWD_SAVE, auth) + return + else + resp["password_changed"] = 1 + web.send_json(resp) + end + elseif command == "info" then + system_model = read_file("/tmp/sysinfo/model") + if(system_model == nil) then system_model = "INVALID MODEL" end + info = {} + info["anlix_model"] = system_model + resp["info"] = info + web.send_json(resp) + elseif command == "wifi" then + u = uci.cursor() + wifi = u.get_all("wireless") + resp["wireless"] = wifi + web.send_json(resp) + elseif command == "devices" then + local leases = {} + if check_file("/tmp/dhcp.leases") then + leases = read_lines("/tmp/dhcp.leases") + end + local result = leases_to_json(leases) + local blacklist = {} + local named_devices = {} + if check_file(blacklist_path) then + blacklist = read_lines(blacklist_path) + end + if check_file("/tmp/named_devices") then + named_devices = read_lines("/tmp/named_devices") + end + local blacklist_info = separate_fields(blacklist) + local named_devices_info = separate_keys(named_devices) + resp["leases"] = result + resp["blacklist"] = json.encode(blacklist_info) + resp["named_devices"] = json.encode(named_devices_info) + resp["origin"] = env.REMOTE_ADDR + web.send_json(resp) + elseif command == "blacklist" then + local mac = data.blacklist_mac + local id = data.blacklist_id + if mac == nil or not mac:match("%x%x:%x%x:%x%x:%x%x:%x%x:%x%x") then + web.error_handle(web.ERROR_READ_MAC, auth) + return + end + append_to_file(blacklist_path, mac .. "|" .. id .. "\n") + write_firewall_file(blacklist_path) + run_process("/etc/init.d/firewall restart") + resp["blacklisted"] = 1 + web.send_json(resp) + elseif command == "whitelist" then + local mac = data.whitelist_mac + if mac == nil or not mac:match("") then + web.error_handle(web.ERROR_READ_MAC, auth) + return + end + remove_from_file(blacklist_path, mac) + write_firewall_file(blacklist_path) + run_process("/etc/init.d/firewall restart") + resp["whitelisted"] = 1 + web.send_json(resp) + elseif command == "setHashCommand" then + local hash = data.command_hash + local timeout = data.command_timeout + local epoch_timeout = os.time() + timeout - 1 + append_to_file("/root/to_do_hashes", hash .. " " .. epoch_timeout .. "\n") + trim_file("/root/to_do_hashes") + trim_file("/root/done_hashes") + resp["is_set"] = 1 + web.send_json(resp) + elseif command == "getHashCommand" then + local hash = data.command_hash + local is_done = remove_from_file("/root/done_hashes", hash) + resp["command_done"] = is_done + web.send_json(resp) + else + web.error_handle(web.ERROR_CMD_UNKNOWN, auth) + end end diff --git a/files/usr/share/check_cable_wan.sh b/files/usr/share/check_cable_wan.sh index c5411ee7..755d732c 100755 --- a/files/usr/share/check_cable_wan.sh +++ b/files/usr/share/check_cable_wan.sh @@ -2,74 +2,49 @@ . /usr/share/functions/common_functions.sh . /usr/share/functions/device_functions.sh +. /usr/share/functions/network_functions.sh +. /usr/share/functions/api_functions.sh -DO_RESTART=0 +DO_RESTART=1 -check_connectivity_internet() -{ - _addrs="www.google.com.br"$'\n'"www.facebook.com"$'\n'"www.globo.com" - for _addr in $_addrs - do - if ping -q -c 1 -w 2 "$_addr" > /dev/null 2>&1 - then - # true - echo 0 - return - fi - done - # No successfull pings - - # false - echo 1 - return +write_access_start_time() { + local _start_time="$1" + # Reset external access start time + json_init + if [ -f /tmp/ext_access_time.json ] + then + json_load_file /tmp/ext_access_time.json + fi + json_add_string "starttime" "$_start_time" + json_dump > "/tmp/ext_access_time.json" + json_cleanup } +# Bootstrap reset_leds +blink_leds "0" +write_access_start_time 0 + while true do - wan_itf_name=$(uci get network.wan.ifname) - if [ -f /sys/class/net/$wan_itf_name/carrier ] - then - is_cable_conn=$(cat /sys/class/net/$wan_itf_name/carrier) - - if [ $is_cable_conn -eq 1 ] - then - # We have layer 2 connectivity, now check external access - if [ ! "$(check_connectivity_internet)" -eq 0 ] - then - # No external access - if [ $DO_RESTART -ne 1 ] - then - log "CHECK_WAN" "No external access..." - blink_leds "$DO_RESTART" - DO_RESTART=1 - fi - else - # The device has external access. Cancel notifications - if [ $DO_RESTART -ne 0 ] - then - log "CHECK_WAN" "External access restored..." - reset_leds - DO_RESTART=0 - fi - fi - else - # Cable is not connected - if [ $DO_RESTART -ne 2 ] - then - log "CHECK_WAN" "Cable not connected..." - blink_leds "$DO_RESTART" - DO_RESTART=2 - fi - fi - else - # WAN interface not created yet - if [ $DO_RESTART -ne 3 ] - then - log "CHECK_WAN" "No WAN interface..." - blink_leds "$DO_RESTART" - DO_RESTART=3 - fi - fi - sleep 2 + # We have layer 2 connectivity, now check external access + if [ ! "$(check_connectivity_internet)" -eq 0 ] + then + # No external access + log "CHECK_WAN" "No external access..." + blink_leds "$DO_RESTART" + DO_RESTART=1 + write_access_start_time 0 + else + # The device has external access. Cancel notifications + if [ $DO_RESTART -ne 0 ] + then + log "CHECK_WAN" "External access restored..." + reset_leds + DO_RESTART=0 + # Reset external access start time + write_access_start_time "$(sys_uptime)" + fi + fi + sleep 2 done diff --git a/files/usr/share/flash_image.sh b/files/usr/share/flash_image.sh index fda74b92..ac2a084c 100755 --- a/files/usr/share/flash_image.sh +++ b/files/usr/share/flash_image.sh @@ -7,141 +7,156 @@ . /usr/share/functions/network_functions.sh clean_memory() { - rm -r /tmp/opkg-lists/ - echo 3 > /proc/sys/vm/drop_caches + [ -d /tmp/opkg-lists/ ] && rm -r /tmp/opkg-lists/ + echo 3 > /proc/sys/vm/drop_caches } -download_file() { - local _dfile="$2" - local _uri="$1/$_dfile" - local _dest_dir="$3" +lupg() { + log "FLASHBOX UPGRADE" "$1" +} - if [ "$#" -eq 3 ] - then - mkdir -p "$_dest_dir" +download_file() { + local _dfile="$2" + local _uri="$1/$_dfile" + local _dest_dir="$3" - local _md5_remote_hash=`curl -I -s -w "%{http_code}" \ - -u routersync:landufrj123 \ - --tlsv1.2 --connect-timeout 5 --retry 3 "$_uri" \ - | grep "X-Checksum-Md5" | awk '{ print $2 }'` + if [ "$#" -eq 3 ] + then + mkdir -p "$_dest_dir" - local _curl_code=`curl -s -w "%{http_code}" -u routersync:landufrj123 \ - --tlsv1.2 --connect-timeout 5 --retry 3 \ - -o "/tmp/$_dfile" "$_uri"` + local _md5_remote_hash=`curl -I -s -w "%{http_code}" \ + -u routersync:landufrj123 \ + --tlsv1.2 --connect-timeout 5 --retry 3 "$_uri" \ + | grep "X-Checksum-Md5" | awk '{ print $2 }'` + if [ ! -f $_dest_dir/$_dfile ] + then + local _curl_code=`curl -s -w "%{http_code}" -u routersync:landufrj123 \ + --tlsv1.2 --connect-timeout 5 --retry 3 \ + -o "$_dest_dir/$_dfile" "$_uri"` + if [ "$_curl_code" != "200" ] + then + lupg "FAIL: Download error on $_uri" + if [ "$_curl_code" != "304" ] + then + rm "$_dest_dir/$_dfile" + return 1 + fi + fi + fi - if [ "$_curl_code" = "200" ] - then - local _md5_local_hash=$(md5sum /tmp/$_dfile | awk '{ print $1 }') - if [ "$_md5_remote_hash" != "$_md5_local_hash" ] - then - log "FLASHBOX UPGRADE" "No match on MD5 hash" - rm "/tmp/$_dfile" - return 1 - fi - mv "/tmp/$_dfile" "$_dest_dir/$_dfile" - log "FLASHBOX UPGRADE" "Downloaded file on $_uri" - return 0 - else - log "FLASHBOX UPGRADE" "Download error on $_uri" - if [ "$_curl_code" != "304" ] - then - rm "/tmp/$_dfile" - return 1 - else - return 0 - fi - fi - else - log "FLASHBOX UPGRADE" "Wrong number of arguments" - return 1 - fi + local _md5_local_hash=$(md5sum $_dest_dir/$_dfile | awk '{ print $1 }') + if [ "$_md5_remote_hash" != "$_md5_local_hash" ] + then + lupg "FAIL: No match on MD5 hash" + rm "$_dest_dir/$_dfile" + return 1 + fi + lupg "Downloaded file on $_uri" + return 0 + else + lupg "FAIL: Wrong number of arguments in download" + return 1 + fi } # Downloads correct image based on current model get_image() { - if [ "$#" -eq 5 ] - then - local _sv_address=$1 - local _release_id=$2 - local _vendor=$3 - local _model=$4 - local _ver=$5 - local _retstatus - download_file "https://$_sv_address/firmwares" \ - $_vendor"_"$_model"_"$_ver"_"$_release_id".bin" "/tmp" - _retstatus=$? + if [ "$#" -eq 4 ] + then + local _release_id=$1 + local _vendor=$2 + local _model=$3 + local _ver=$4 + local _retstatus + download_file "https://$FLM_SVADDR/firmwares" \ + $_vendor"_"$_model"_"$_ver"_"$_release_id".bin" "/tmp" + _retstatus=$? - if [ $_retstatus -eq 1 ] - then - log "FLASHBOX UPGRADE" "Image download failed" - return 1 - fi - else - log "FLASHBOX UPGRADE" "Error in number of args" - return 1 - fi - return 0 + if [ $_retstatus -eq 1 ] + then + lupg "FAIL: Image download failed" + return 1 + fi + else + lupg "FAIL: Error in number of args for get_image" + return 1 + fi + return 0 } run_reflash() { - if [ "$#" -eq 2 ] - then - log "FLASHBOX UPGRADE" "Init image reflash" - local _sv_address=$1 - local _release_id=$2 - local _vendor - local _model - local _ver - local _pppoe_user_local - local _pppoe_password_local - local _connection_type - _vendor=$(cat /tmp/sysinfo/model | awk '{ print toupper($1) }') - _model=$(get_hardware_model | \ - awk -F "/" '{ if($2 != "") { print $1"D"; } else { print $1 } }') - _ver=$(get_hardware_version) - _pppoe_user_local=$(uci -q get network.wan.username) - _pppoe_password_local=$(uci -q get network.wan.password) - _connection_type=$(get_wan_type) + if [ "$#" -eq 1 ] + then + lupg "Init image reflash" + local _release_id=$1 + local _vendor + local _model + local _ver + local _res + local _pppoe_user_local + local _pppoe_password_local + local _connection_type + _vendor=$(cat /tmp/sysinfo/model | awk '{ print toupper($1) }') + _model=$(get_hardware_model | \ + awk -F "/" '{ if($2 != "") { print $1"D"; } else { print $1 } }') + _ver=$(get_hardware_version) + _pppoe_user_local=$(uci -q get network.wan.username) + _pppoe_password_local=$(uci -q get network.wan.password) + _connection_type=$(get_wan_type) + + if ! lock -n /tmp/lock_firmware 2> /dev/null + then + lupg "FAIL: Firmware locked!" + return 1 + fi + + clean_memory + [ "$(type -t anlix_upgrade_clean_memory)" ] && anlix_upgrade_clean_memory + if get_image "$_release_id" "$_vendor" "$_model" "$_ver" + then + _res=$(rest_flashman "deviceinfo/ack/" "id=$(get_mac)&status=1") + if [ "$(jsonfilter -s "$_res" -e '@.proceed')" = "1" ] + then + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string has_upgraded_version "1" + if [ "$(get_bridge_mode_status)" != "y" ] + then + # Do not write "none" in case of bridge + json_add_string wan_conn_type "$_connection_type" + fi + json_add_string pppoe_user "$_pppoe_user_local" + json_add_string pppoe_pass "$_pppoe_password_local" + json_dump > /root/flashbox_config.json + tar -zcf /tmp/config.tar.gz /root/flashbox_config.json + json_add_string has_upgraded_version "0" + json_dump > /root/flashbox_config.json + json_close_object - clean_memory - if get_image "$_sv_address" "$_release_id" "$_vendor" "$_model" "$_ver" - then - json_cleanup - json_load_file /root/flashbox_config.json - json_add_string has_upgraded_version "1" - json_add_string wan_conn_type "$_connection_type" - json_add_string pppoe_user "$_pppoe_user_local" - json_add_string pppoe_pass "$_pppoe_password_local" - json_dump > /root/flashbox_config.json - tar -zcf /tmp/config.tar.gz \ - /etc/config/wireless /root/flashbox_config.json - json_add_string has_upgraded_version "0" - json_dump > /root/flashbox_config.json - json_close_object - if sysupgrade -T "/tmp/"$_vendor"_"$_model"_"$_ver"_"$_release_id".bin" - then - curl -s -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" \ - --tlsv1.2 --connect-timeout 5 --retry 0 \ - --data "id=$(get_mac)&status=1" \ - "https://$_sv_address/deviceinfo/ack/" - sysupgrade -f /tmp/config.tar.gz \ - "/tmp/"$_vendor"_"$_model"_"$_ver"_"$_release_id".bin" - else - curl -s -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" \ - --tlsv1.2 --connect-timeout 5 --retry 0 \ - --data "id=$(get_mac)&status=0" \ - "https://$_sv_address/deviceinfo/ack/" - log "FLASHBOX UPGRADE" "Image check failed" - return 1 - fi - else - curl -s -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" \ - --tlsv1.2 --connect-timeout 5 --retry 0 \ - --data "id=$(get_mac)&status=2" \ - "https://$_sv_address/deviceinfo/ack/" - fi - else - log "FLASHBOX UPGRADE" "Error in number of args" - return 1 - fi + /etc/init.d/check_cable_wan stop + /etc/init.d/keepalive stop + /etc/init.d/flashman stop + /etc/init.d/netstats stop + /etc/init.d/minisapo stop + /etc/init.d/miniupnpd stop + /etc/init.d/uhttpd stop + wifi down + /etc/init.d/network stop + clean_memory + sysupgrade --force -f /tmp/config.tar.gz \ + "/tmp/"$_vendor"_"$_model"_"$_ver"_"$_release_id".bin" + else + lock -u /tmp/lock_firmware + lupg "CANCEL: Cancel by flashman" + rm "/tmp/"$_vendor"_"$_model"_"$_ver"_"$_release_id".bin" + fi + else + lock -u /tmp/lock_firmware + _res=$(rest_flashman "deviceinfo/ack/" "id=$(get_mac)&status=2") + fi + [ "$(type -t anlix_upgrade_restore_memory)" ] && anlix_upgrade_restore_memory + else + lupg "FAIL: Error in number of args" + return 1 + fi } diff --git a/files/usr/share/flashman_update.sh b/files/usr/share/flashman_update.sh index 09bd760a..562abb90 100755 --- a/files/usr/share/flashman_update.sh +++ b/files/usr/share/flashman_update.sh @@ -12,70 +12,123 @@ . /usr/share/functions/api_functions.sh . /usr/share/functions/zabbix_functions.sh +lock /tmp/lock_updater + # If a command hash is provided, check if it should still be done COMMANDHASH="" if [ "$1" != "" ] then - if [ -f /root/to_do_hashes ] && [ "$(grep $1 /root/to_do_hashes)" != "" ] - then - TIMEOUT="$(grep $1 /root/to_do_hashes | tail -n 1)" - COMMANDHASH="$(echo $TIMEOUT | cut -d " " -f 1)" - TIMEOUT="$(echo $TIMEOUT | cut -d " " -f 2)" - if [ "$(date +%s)" -gt "$TIMEOUT" ] - then - log "FLASHMAN UPDATER" "Provided hash received after command timeout" - log "FLASHMAN UPDATER" "Done" - exit 0 - fi - else - log "FLASHMAN UPDATER" "Provided hash is not in the to do file" - log "FLASHMAN UPDATER" "Done" - exit 0 - fi + if [ -f /root/to_do_hashes ] && [ "$(grep $1 /root/to_do_hashes)" != "" ] + then + TIMEOUT="$(grep $1 /root/to_do_hashes | tail -n 1)" + COMMANDHASH="$(echo $TIMEOUT | cut -d " " -f 1)" + TIMEOUT="$(echo $TIMEOUT | cut -d " " -f 2)" + if [ "$(date +%s)" -gt "$TIMEOUT" ] + then + log "FLASHMAN UPDATER" "Provided hash received after command timeout" + log "FLASHMAN UPDATER" "Done" + lock -u /tmp/lock_updater + exit 0 + fi + else + log "FLASHMAN UPDATER" "Provided hash is not in the to do file" + log "FLASHMAN UPDATER" "Done" + lock -u /tmp/lock_updater + exit 0 + fi fi log "FLASHMAN UPDATER" "Start ..." if is_authenticated then - log "FLASHMAN UPDATER" "Authenticated ..." - - # Get WiFi data - json_cleanup - json_load "$(get_wifi_local_config)" - json_get_var _local_ssid_24 local_ssid_24 - json_get_var _local_password_24 local_password_24 - json_get_var _local_channel_24 local_channel_24 - json_get_var _local_hwmode_24 local_hwmode_24 - json_get_var _local_htmode_24 local_htmode_24 - json_get_var _local_5ghz_capable local_5ghz_capable - json_get_var _local_ssid_50 local_ssid_50 - json_get_var _local_password_50 local_password_50 - json_get_var _local_channel_50 local_channel_50 - json_get_var _local_hwmode_50 local_hwmode_50 - json_get_var _local_htmode_50 local_htmode_50 - json_close_object - # Get config data - json_cleanup - json_load_file /root/flashbox_config.json - json_get_var _has_upgraded_version has_upgraded_version - json_get_var _hard_reset_info hard_reset_info - json_close_object - - # Report if a hard reset has occured - if [ "_hard_reset_info" = "1" ] - then - log "FLASHMAN UPDATER" "Sending HARD RESET Information to server" - if [ -e /sysupgrade.tgz ] - then - rm /sysupgrade.tgz - fi - fi - - # - # WARNING! No spaces or tabs inside the following string! - # - _data="id=$(get_mac)&\ + log "FLASHMAN UPDATER" "Authenticated ..." + + # Get WiFi data + json_cleanup + json_load "$(get_wifi_local_config)" + json_get_var _local_ssid_24 local_ssid_24 + json_get_var _local_password_24 local_password_24 + json_get_var _local_channel_24 local_channel_24 + json_get_var _local_hwmode_24 local_hwmode_24 + json_get_var _local_htmode_24 local_htmode_24 + json_get_var _local_state_24 local_state_24 + json_get_var _local_txpower_24 local_txpower_24 + json_get_var _local_hidden_24 local_hidden_24 + json_get_var _local_5ghz_capable local_5ghz_capable + json_get_var _local_ssid_50 local_ssid_50 + json_get_var _local_password_50 local_password_50 + json_get_var _local_channel_50 local_channel_50 + json_get_var _local_hwmode_50 local_hwmode_50 + json_get_var _local_htmode_50 local_htmode_50 + json_get_var _local_state_50 local_state_50 + json_get_var _local_txpower_50 local_txpower_50 + json_get_var _local_hidden_50 local_hidden_50 + json_close_object + # Get config data + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _has_upgraded_version has_upgraded_version + json_get_var _hard_reset_info hard_reset_info + json_get_var _local_bridge_enabled bridge_mode + json_get_var _local_bridge_switch_disable bridge_disable_switch + json_get_var _local_bridge_fix_ip bridge_fix_ip + json_get_var _local_bridge_fix_gateway bridge_fix_gateway + json_get_var _local_bridge_fix_dns bridge_fix_dns + json_get_var _local_bridge_did_reset bridge_did_reset + json_get_var _local_did_change_wan did_change_wan_local + json_get_var _local_mesh_mode mesh_mode + json_close_object + + # Get WPS state if exists + _local_wps_state="0" + if [ -f "/tmp/wps_state.json" ] + then + json_cleanup + json_load_file /tmp/wps_state.json + json_get_var _local_wps_state wps_content + json_close_object + fi + + [ ! "$_local_mesh_mode" ] && _local_mesh_mode="0" + + # If bridge is active, we cannot use get_wan_type, use flashman_init.conf + _local_wan_type="$(get_wan_type)" + if [ "$_local_bridge_enabled" = "y" ] + then + _local_wan_type="$FLM_WAN_PROTO" + fi + + # Translate some variables from y/n to 1/0 + if [ "$_local_bridge_enabled" = "y" ] + then + _local_bridge_enabled=1 + else + _local_bridge_enabled=0 + fi + if [ "$_local_bridge_switch_disable" = "y" ] + then + _local_bridge_switch_disable=1 + else + _local_bridge_switch_disable=0 + fi + + _local_enabled_ipv6="$(get_ipv6_enabled)" + + # Report if a hard reset has occured + if [ "$_hard_reset_info" = "1" ] + then + log "FLASHMAN UPDATER" "Sending HARD RESET Information to server" + if [ -e /sysupgrade.tgz ] + then + rm /sysupgrade.tgz + fi + fi + + # + # WARNING! No spaces or tabs inside the following string! + # + _data="id=$(get_mac)&\ flm_updater=1&\ version=$(get_flashbox_version)&\ model=$(get_hardware_model)&\ @@ -86,180 +139,325 @@ pppoe_password=$(uci -q get network.wan.password)&\ wan_ip=$(get_wan_ip)&\ wan_negociated_speed=$(get_wan_negotiated_speed)&\ wan_negociated_duplex=$(get_wan_negotiated_duplex)&\ -lan_addr=$(get_lan_subnet)&\ +lan_addr=$(get_lan_ipaddr)&\ lan_netmask=$(get_lan_netmask)&\ +lan_no_dns_proxy=$(get_use_dns_proxy)&\ +ipv6_enabled=$_local_enabled_ipv6&\ wifi_ssid=$_local_ssid_24&\ wifi_password=$_local_password_24&\ wifi_channel=$_local_channel_24&\ wifi_band=$_local_htmode_24&\ wifi_mode=$_local_hwmode_24&\ +wifi_state=$_local_state_24&\ +wifi_power=$_local_txpower_24&\ +wifi_hidden=$_local_hidden_24&\ wifi_5ghz_capable=$_local_5ghz_capable&\ wifi_ssid_5ghz=$_local_ssid_50&\ wifi_password_5ghz=$_local_password_50&\ wifi_channel_5ghz=$_local_channel_50&\ wifi_band_5ghz=$_local_htmode_50&\ wifi_mode_5ghz=$_local_hwmode_50&\ -connection_type=$(get_wan_type)&\ +wifi_state_5ghz=$_local_state_50&\ +wifi_power_5ghz=$_local_txpower_50&\ +wifi_hidden_5ghz=$_local_hidden_50&\ +connection_type=$_local_wan_type&\ ntp=$(ntp_anlix)&\ hardreset=$_hard_reset_info&\ -upgfirm=$_has_upgraded_version" - _url="deviceinfo/syn/" - _res=$(rest_flashman "$_url" "$_data") - - if [ "$?" -eq 1 ] - then - log "FLASHMAN UPDATER" "Fail in Rest Flashman! Aborting..." - else - json_cleanup - json_load "$_res" - json_get_var _do_update do_update - json_get_var _do_newprobe do_newprobe - json_get_var _release_id release_id - json_get_var _connection_type connection_type - json_get_var _pppoe_user pppoe_user - json_get_var _pppoe_password pppoe_password - json_get_var _lan_addr lan_addr - json_get_var _lan_netmask lan_netmask - json_get_var _wifi_ssid_24 wifi_ssid - json_get_var _wifi_password_24 wifi_password - json_get_var _wifi_channel_24 wifi_channel - json_get_var _wifi_htmode_24 wifi_band - json_get_var _wifi_hwmode_24 wifi_mode - json_get_var _wifi_ssid_50 wifi_ssid_5ghz - json_get_var _wifi_password_50 wifi_password_5ghz - json_get_var _wifi_channel_50 wifi_channel_5ghz - json_get_var _wifi_htmode_50 wifi_band_5ghz - json_get_var _wifi_hwmode_50 wifi_mode_5ghz - json_get_var _app_password app_password - json_get_var _forward_index forward_index - json_get_var _blocked_devices_index blocked_devices_index - json_get_var _zabbix_psk zabbix_psk - json_get_var _zabbix_fqdn zabbix_fqdn - json_get_var _zabbix_active zabbix_active - - _blocked_macs="" - _blocked_devices="" - json_select blocked_devices - INDEX="1" # Json library starts indexing at 1 - while json_get_type TYPE $INDEX && [ "$TYPE" = string ]; do - json_get_var _device "$((INDEX++))" - _blocked_devices="$_blocked_devices""$_device"$'\n' - _mac_addr=$(echo "$_device" | head -c 17) - _blocked_macs="$_mac_addr $_blocked_macs" - done - _named_devices="" - json_select .. - json_select named_devices - INDEX="1" # Json library starts indexing at 1 - while json_get_type TYPE $INDEX && [ "$TYPE" = string ]; do - json_get_var _device "$((INDEX++))" - _named_devices="$_named_devices""$_device"$'\n' - done - # Remove trailing newline / space - _blocked_macs=${_blocked_macs::-1} - _blocked_devices=${_blocked_devices::-1} - _named_devices=${_named_devices::-1} - json_close_object - - if [ "$_hard_reset_info" = "1" ] - then - json_cleanup - json_load_file /root/flashbox_config.json - json_add_string hard_reset_info "0" - json_dump > /root/flashbox_config.json - json_close_object - fi - - if [ "$_has_upgraded_version" = "1" ] - then - json_cleanup - json_load_file /root/flashbox_config.json - json_add_string has_upgraded_version "0" - json_dump > /root/flashbox_config.json - json_close_object - fi - - if [ "$_do_newprobe" = "1" ] - then - log "FLASHMAN UPDATER" "Router Registered in Flashman Successfully!" - # On a new probe, force a new registry in mqtt secret - reset_mqtt_secret > /dev/null - fi - - # Send boot log information if boot is completed and probe is registered! - if [ ! -e /tmp/boot_completed ] - then - log "FLASHMAN UPDATER" "Sending BOOT log" - send_boot_log "boot" - echo "0" > /tmp/boot_completed - fi - - # WAN connection type update - set_wan_type "$_connection_type" "$_pppoe_user" "$_pppoe_password" - - # PPPoE update - set_pppoe_credentials "$_pppoe_user" "$_pppoe_password" - - # LAN connection subnet update - set_lan_subnet "$_lan_addr" "$_lan_netmask" - # If LAN has changed then reload port forward mapping - if [ $? -eq 0 ] - then - update_port_forward - fi - - # WiFi update - log "FLASHMAN UPDATER" "Updating Wireless ..." - set_wifi_local_config "$_wifi_ssid_24" "$_wifi_password_24" \ - "$_wifi_channel_24" "$_wifi_hwmode_24" \ - "$_wifi_htmode_24" \ - "$_wifi_ssid_50" "$_wifi_password_50" \ - "$_wifi_channel_50" "$_wifi_hwmode_50" \ - "$_wifi_htmode_50" - # Flash App password update - if [ "$_app_password" == "" ] - then - log "FLASHMAN UPDATER" "Removing app access password ..." - reset_flashapp_pass - elif [ "$_app_password" != "$(get_flashapp_pass)" ] - then - log "FLASHMAN UPDATER" "Updating app access password ..." - set_flashapp_pass "$_app_password" - fi - - # Named devices file update - always do this to avoid file diff logic - log "FLASHMAN UPDATER" "Writing named devices file..." - echo -n "$_named_devices" > /tmp/named_devices - - # Check for updates in blocked devices - _local_dindex=$(get_forward_indexes "blocked_devices_index") - if [ "$_local_dindex" != "$_blocked_devices_index" ] - then - update_blocked_devices "$_blocked_devices" "$_blocked_macs" \ - "$_blocked_devices_index" - fi - - # Update zabbix parameters as necessary - set_zabbix_params "$_zabbix_psk" "$_zabbix_fqdn" "$_zabbix_active" - - # Check for updates in port forward mapping - _local_findex=$(get_forward_indexes "forward_index") - [ "$_local_findex" != "$_forward_index" ] && update_port_forward - - # Store completed command hash if one was provided - if [ "$COMMANDHASH" != "" ] - then - echo "$COMMANDHASH" >> /root/done_hashes - fi - - if [ "$_do_update" == "1" ] - then - log "FLASHMAN UPDATER" "Reflashing ..." - # Execute firmware update - run_reflash $FLM_SVADDR $_release_id - fi - fi +upgfirm=$_has_upgraded_version&\ +sysuptime=$(sys_uptime)&\ +wanuptime=$(wan_uptime)&\ +wpsstate=$_local_wps_state" + if [ "$_local_bridge_did_reset" = "y" ] || [ "$_local_did_change_wan" = "y" ] + then + _data="$_data&\ +bridge_enabled=$_local_bridge_enabled&\ +bridge_switch_disable=$_local_bridge_switch_disable&\ +bridge_fix_ip=$_local_bridge_fix_ip&\ +bridge_fix_gateway=$_local_bridge_fix_gateway&\ +bridge_fix_dns=$_local_bridge_fix_dns" + fi + if [ "$_local_did_change_wan" = "y" ] + then + _data="$_data&local_change_wan=1" + fi + _url="deviceinfo/syn/" + _res=$(rest_flashman "$_url" "$_data") + + if [ "$?" -eq 1 ] + then + log "FLASHMAN UPDATER" "Fail in Rest Flashman! Aborting..." + lock -u /tmp/lock_updater + exit 0 + else + json_cleanup + json_load "$_res" + json_get_var _do_update do_update + json_get_var _do_newprobe do_newprobe + json_get_var _release_id release_id + json_get_var _connection_type connection_type + json_get_var _pppoe_user pppoe_user + json_get_var _pppoe_password pppoe_password + json_get_var _lan_addr lan_addr + json_get_var _lan_netmask lan_netmask + json_get_var _lan_no_dns_proxy lan_no_dns_proxy + json_get_var _ipv6_enabled ipv6_enabled + json_get_var _wifi_ssid_24 wifi_ssid + json_get_var _wifi_password_24 wifi_password + json_get_var _wifi_channel_24 wifi_channel + json_get_var _wifi_htmode_24 wifi_band + json_get_var _wifi_hwmode_24 wifi_mode + json_get_var _wifi_txpower_24 wifi_power + json_get_var _wifi_hidden_24 wifi_hidden + json_get_var _wifi_state wifi_state + json_get_var _wifi_ssid_50 wifi_ssid_5ghz + json_get_var _wifi_password_50 wifi_password_5ghz + json_get_var _wifi_channel_50 wifi_channel_5ghz + json_get_var _wifi_htmode_50 wifi_band_5ghz + json_get_var _wifi_hwmode_50 wifi_mode_5ghz + json_get_var _wifi_state_50 wifi_state_5ghz + json_get_var _wifi_txpower_50 wifi_power_5ghz + json_get_var _wifi_hidden_50 wifi_hidden_5ghz + json_get_var _app_password app_password + json_get_var _forward_index forward_index + json_get_var _blocked_devices_index blocked_devices_index + json_get_var _upnp_devices_index upnp_devices_index + json_get_var _zabbix_psk zabbix_psk + json_get_var _zabbix_fqdn zabbix_fqdn + json_get_var _zabbix_active zabbix_active + json_get_var _bridge_mode_enabled bridge_mode_enabled + json_get_var _bridge_mode_switch_disable bridge_mode_switch_disable + json_get_var _bridge_mode_ip bridge_mode_ip + json_get_var _bridge_mode_gateway bridge_mode_gateway + json_get_var _bridge_mode_dns bridge_mode_dns + json_get_var _mesh_mode mesh_mode + json_get_var _mesh_master mesh_master + json_get_var _mesh_id mesh_id + json_get_var _mesh_key mesh_key + + _local_bridge_enabled=$(get_bridge_mode_status) + + _blocked_macs="" + _blocked_devices="" + if json_get_type TYPE blocked_devices && [ "$TYPE" == array ] + then + json_select blocked_devices + INDEX="1" # Json library starts indexing at 1 + while json_get_type TYPE $INDEX && [ "$TYPE" = string ]; do + json_get_var _device "$((INDEX++))" + _blocked_devices="$_blocked_devices""$_device"$'\n' + _mac_addr=$(echo "$_device" | head -c 17) + _blocked_macs="$_mac_addr $_blocked_macs" + done + json_select .. + fi + _named_devices="" + if json_get_type TYPE named_devices && [ "$TYPE" == array ] + then + json_select named_devices + INDEX="1" # Json library starts indexing at 1 + while json_get_type TYPE $INDEX && [ "$TYPE" = string ]; do + json_get_var _device "$((INDEX++))" + _named_devices="$_named_devices""$_device"$'\n' + done + json_select .. + fi + # Remove trailing newline / space + _blocked_macs=${_blocked_macs::-1} + _blocked_devices=${_blocked_devices::-1} + _named_devices=${_named_devices::-1} + json_close_object + + if [ "$_do_update" == "1" ] + then + log "FLASHMAN UPDATER" "Reflashing ..." + run_reflash $_release_id + lock -u /tmp/lock_updater + exit 1 + fi + + # Reset the reset flags when we receive syn reply + if [ "$_local_bridge_did_reset" = "y" ] + then + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string bridge_did_reset "n" + json_dump > /root/flashbox_config.json + json_close_object + fi + if [ "$_local_did_change_wan" = "y" ] + then + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string did_change_wan_local "n" + json_dump > /root/flashbox_config.json + json_close_object + fi + + if [ "$_hard_reset_info" = "1" ] + then + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string hard_reset_info "0" + json_dump > /root/flashbox_config.json + json_close_object + fi + + if [ "$_has_upgraded_version" = "1" ] + then + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string has_upgraded_version "0" + json_dump > /root/flashbox_config.json + json_close_object + fi + + if [ "$_do_newprobe" = "1" ] + then + log "FLASHMAN UPDATER" "Router Registered in Flashman Successfully!" + # On a new probe, force a new registry in mqtt secret + reset_mqtt_secret > /dev/null + fi + + # Send boot log information if boot is completed and probe is registered! + if [ ! -e /tmp/boot_completed ] + then + log "FLASHMAN UPDATER" "Sending BOOT log" + send_boot_log "boot" + echo "0" > /tmp/boot_completed + fi + + if [ "$_ipv6_enabled" ] && [ "$_local_enabled_ipv6" != "$_ipv6_enabled" ] + then + if [ "$_ipv6_enabled" = "1" ] + then + enable_ipv6 + else + disable_ipv6 + fi + /etc/init.d/network restart + /etc/init.d/miniupnpd reload + fi + + # Ignore changes if in bridge mode + if [ "$_local_bridge_enabled" != "y" ] + then + # WAN connection type update + set_wan_type "$_connection_type" "$_pppoe_user" "$_pppoe_password" + + # PPPoE update + set_pppoe_credentials "$_pppoe_user" "$_pppoe_password" + + # LAN connection subnet update + set_lan_subnet "$_lan_addr" "$_lan_netmask" + # If LAN has changed then reload port forward mapping + if [ $? -eq 0 ] + then + update_port_forward + fi + + # Change use of local router DNS proxy + set_use_dns_proxy "$_lan_no_dns_proxy" + fi + + # WiFi update + log "FLASHMAN UPDATER" "Updating Wireless ..." + _need_wifi_reload=0 + if [ "$_mesh_mode" ] && [ "$_mesh_mode" != "$_local_mesh_mode" ] + then + if [ -z "$_mesh_master" ] + then + set_mesh_master_mode "$_mesh_mode" + else + set_mesh_slave_mode "$_mesh_mode" "$_mesh_master" + fi + enable_mesh_routing "$_mesh_mode" "$_mesh_id" "$_mesh_key" && _need_wifi_reload=1 + /etc/init.d/minisapo restart + fi + + set_wifi_local_config "$_wifi_ssid_24" "$_wifi_password_24" \ + "$_wifi_channel_24" "$_wifi_hwmode_24" \ + "$_wifi_htmode_24" "$_wifi_state" \ + "$_wifi_txpower_24" "$_wifi_hidden_24" \ + "$_wifi_ssid_50" "$_wifi_password_50" \ + "$_wifi_channel_50" "$_wifi_hwmode_50" \ + "$_wifi_htmode_50" "$_wifi_state_50" \ + "$_wifi_txpower_50" "$_wifi_hidden_50" \ + "$_mesh_mode" && _need_wifi_reload=1 + [ $_need_wifi_reload -eq 1 ] && wifi reload && /etc/init.d/minisapo reload + + # Flash App password update + if [ "$_app_password" == "" ] + then + log "FLASHMAN UPDATER" "Removing app access password ..." + reset_flashapp_pass + elif [ "$_app_password" != "$(get_flashapp_pass)" ] + then + log "FLASHMAN UPDATER" "Updating app access password ..." + set_flashapp_pass "$_app_password" + fi + + # Named devices file update - always do this to avoid file diff logic + log "FLASHMAN UPDATER" "Writing named devices file..." + echo -n "$_named_devices" > /tmp/named_devices + + # Check for updates in blocked devices + # Ignore changes if in bridge mode + if [ "$_local_bridge_enabled" != "y" ] + then + _local_dindex=$(get_forward_indexes "blocked_devices_index") + if [ "$_local_dindex" != "$_blocked_devices_index" ] + then + update_blocked_devices "$_blocked_devices" "$_blocked_macs" \ + "$_blocked_devices_index" + fi + fi + + # Update zabbix parameters as necessary + if [ "$ZBX_SUPPORT" == "y" ] + then + set_zabbix_params "$_zabbix_psk" "$_zabbix_fqdn" "$_zabbix_active" + fi + + # Check for updates in port forward mapping + # Ignore changes if in bridge mode + if [ "$_local_bridge_enabled" != "y" ] + then + _local_findex=$(get_forward_indexes "forward_index") + [ "$_local_findex" != "$_forward_index" ] && update_port_forward + + # Check for updates in upnp allowed devices mapping + _local_uindex=$(get_forward_indexes "upnp_devices_index") + [ "$_local_uindex" != "$_upnp_devices_index" ] && update_upnp_devices + fi + + # Store completed command hash if one was provided + if [ "$COMMANDHASH" != "" ] + then + echo "$COMMANDHASH" >> /root/done_hashes + fi + + # Update bridge mode information + if [ "$_bridge_mode_enabled" = "y" ] && [ "$_local_bridge_enabled" != "y" ] + then + log "FLASHMAN UPDATER" "Enabling bridge mode..." + enable_bridge_mode "y" "n" "$_bridge_mode_switch_disable" "$_bridge_mode_ip" \ + "$_bridge_mode_gateway" "$_bridge_mode_dns" + elif [ "$_bridge_mode_enabled" = "y" ] && [ "$_local_bridge_enabled" = "y" ] + then + log "FLASHMAN UPDATER" "Updating bridge mode parameters..." + update_bridge_mode "n" "$_bridge_mode_switch_disable" "$_bridge_mode_ip" \ + "$_bridge_mode_gateway" "$_bridge_mode_dns" + elif [ "$_bridge_mode_enabled" = "n" ] && [ "$_local_bridge_enabled" = "y" ] + then + log "FLASHMAN UPDATER" "Disabling bridge mode..." + disable_bridge_mode + fi + fi else - log "FLASHMAN UPDATER" "Fail Authenticating device!" + log "FLASHMAN UPDATER" "Fail Authenticating device!" + lock -u /tmp/lock_updater + exit 0 fi log "FLASHMAN UPDATER" "Done" +lock -u /tmp/lock_updater +exit 1 diff --git a/files/usr/share/functions/api_functions.sh b/files/usr/share/functions/api_functions.sh index 6143b841..883da220 100644 --- a/files/usr/share/functions/api_functions.sh +++ b/files/usr/share/functions/api_functions.sh @@ -2,191 +2,344 @@ . /usr/share/flashman_init.conf . /usr/share/libubox/jshn.sh +. /usr/share/functions/common_functions.sh . /usr/share/functions/device_functions.sh . /usr/share/functions/common_functions.sh +. /usr/share/functions/firewall_functions.sh +. /usr/share/functions/network_functions.sh send_boot_log() { - local _res - local _header="X-ANLIX-LOGS: NONE" - - if [ "$1" = "boot" ] - then - if [ -e /tmp/clean_boot ] - then - _header="X-ANLIX-LOGS: FIRST" - else - _header="X-ANLIX-LOGS: BOOT" - fi - fi - if [ "$1" = "live" ] - then - _header="X-ANLIX-LOGS: LIVE" - fi - - _res=$(logread | gzip | curl -s --tlsv1.2 --connect-timeout 5 \ - --retry 1 \ - -H "Content-Type: application/octet-stream" \ - -H "X-ANLIX-ID: $(get_mac)" -H "X-ANLIX-SEC: $FLM_CLIENT_SECRET" \ - -H "$_header" --data-binary @- "https://$FLM_SVADDR/deviceinfo/logs") - - json_cleanup - json_load "$_res" - json_get_var _processed processed - json_close_object - - return $_processed + local _res + local _header="X-ANLIX-LOGS: NONE" + + if [ "$1" = "boot" ] + then + if [ -e /tmp/clean_boot ] + then + _header="X-ANLIX-LOGS: FIRST" + else + _header="X-ANLIX-LOGS: BOOT" + fi + fi + if [ "$1" = "live" ] + then + _header="X-ANLIX-LOGS: LIVE" + fi + + _res=$(logread | gzip | curl -s --tlsv1.2 --connect-timeout 5 \ + --retry 1 \ + -H "Content-Type: application/octet-stream" \ + -H "X-ANLIX-ID: $(get_mac)" -H "X-ANLIX-SEC: $FLM_CLIENT_SECRET" \ + -H "$_header" --data-binary @- "https://$FLM_SVADDR/deviceinfo/logs") + + json_cleanup + json_load "$_res" + json_get_var _processed processed + json_close_object + + return $_processed } reset_flashapp_pass() { - json_cleanup - json_load_file /root/flashbox_config.json - json_get_var _flashapp_pass flashapp_pass + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _flashapp_pass flashapp_pass - if [ "$_flashapp_pass" != "" ] - then - json_add_string flashapp_pass "" - json_dump > /root/flashbox_config.json - fi + if [ "$_flashapp_pass" != "" ] + then + json_add_string flashapp_pass "" + json_dump > /root/flashbox_config.json + fi - json_close_object + json_close_object } get_flashapp_pass() { - json_cleanup - json_load_file /root/flashbox_config.json - json_get_var _flashapp_pass flashapp_pass - json_close_object + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _flashapp_pass flashapp_pass + json_close_object - echo "$_flashapp_pass" + echo "$_flashapp_pass" } set_flashapp_pass() { - json_cleanup - json_load_file /root/flashbox_config.json - json_add_string flashapp_pass "$1" - json_dump > /root/flashbox_config.json - json_close_object + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string flashapp_pass "$1" + json_dump > /root/flashbox_config.json + json_close_object } flashbox_ping() { - local _host="$1" - local _type="$2" - local _out="$3" - local _result=$(ping -q -i 0.01 -c 100 "$_host") - local _latval=$(echo "$_result" | awk -F= 'NR==5 { print $2 }' | \ - awk -F/ '{ print $2 }') - local _lossval=$(echo "$_result" | awk -F, 'NR==4 { print $3 }' | \ - awk '{ print $1 }' | awk -F% '{ print $1 }') - - if [ "$_type" = "lat" ] - then - if [ "$_out" = "json" ] - then - json_add_object "$_host" - json_add_string "lat" "$_latval" - json_close_object - else - echo "$_latval" - fi - elif [ "$_type" = "loss" ] - then - if [ "$_out" = "json" ] - then - json_add_object "$_host" - json_add_string "loss" "$_lossval" - json_close_object - else - echo "$_lossval" - fi - else - if [ "$_out" = "json" ] - then - json_add_object "$_host" - json_add_string "lat" "$_latval" - json_add_string "loss" "$_lossval" - json_close_object - else - echo "$_latval $_lossval" - fi - fi + local _host="$1" + local _type="$2" + local _out="$3" + local _result=$(ping -q -i 0.01 -c 100 "$_host") + local _latval=$(echo "$_result" | awk -F= 'NR==5 { print $2 }' | \ + awk -F/ '{ print $2 }') + local _lossval=$(echo "$_result" | awk -F, 'NR==4 { print $3 }' | \ + awk '{ print $1 }' | awk -F% '{ print $1 }') + + if [ "$_type" = "lat" ] + then + if [ "$_out" = "json" ] + then + json_add_object "$_host" + json_add_string "lat" "$_latval" + json_close_object + else + echo "$_latval" + fi + elif [ "$_type" = "loss" ] + then + if [ "$_out" = "json" ] + then + json_add_object "$_host" + json_add_string "loss" "$_lossval" + json_close_object + else + echo "$_lossval" + fi + else + if [ "$_out" = "json" ] + then + json_add_object "$_host" + json_add_string "lat" "$_latval" + json_add_string "loss" "$_lossval" + json_close_object + else + echo "$_latval $_lossval" + fi + fi } flashbox_multi_ping() { - local _hosts_file=$1 - local _hosts="" - local _out=$2 - local _type=$3 - local _result="" - local _lossval="" - local _latval="" - - json_cleanup - json_load_file "$_hosts_file" - json_select "hosts" - if [ "$?" -eq 1 ] - then - return - fi - local _idx="1" - while json_get_type type "$_idx" && [ "$type" = string ] - do - json_get_var _hostaddr "$((_idx++))" - _hosts="$_hostaddr"$'\n'"$_hosts" - done - json_select ".." - json_close_object - - json_init - json_add_object "results" - # Don't put double quotes on _hosts variable! - for _host in $_hosts - do - flashbox_ping "$_host" "$_type" "json" - done - json_close_object - json_dump > "$_out" - json_cleanup + local _hosts_file=$1 + local _hosts="" + local _out=$2 + local _type=$3 + local _result="" + local _lossval="" + local _latval="" + + json_cleanup + json_load_file "$_hosts_file" + json_select "hosts" + if [ "$?" -eq 1 ] + then + return + fi + local _idx="1" + while json_get_type type "$_idx" && [ "$type" = string ] + do + json_get_var _hostaddr "$((_idx++))" + _hosts="$_hostaddr"$'\n'"$_hosts" + done + json_select ".." + json_close_object + + json_init + json_add_object "results" + # Don't put double quotes on _hosts variable! + for _host in $_hosts + do + flashbox_ping "$_host" "$_type" "json" + done + json_close_object + json_dump > "$_out" + json_cleanup } run_ping_ondemand_test() { - local _hosts_file="/tmp/hosts_file.json" - local _out_file="/tmp/ping_result.json" - local _data="id=$(get_mac)" - local _url="deviceinfo/get/pinghosts" - local _res - local _retstatus - _res=$(rest_flashman "$_url" "$_data") - _retstatus=$? + local _hosts_file="/tmp/hosts_file.json" + local _out_file="/tmp/ping_result.json" + local _data="id=$(get_mac)" + local _url="deviceinfo/get/pinghosts" + local _res + local _retstatus + _res=$(rest_flashman "$_url" "$_data") + _retstatus=$? + + if [ $_retstatus -eq 0 ] + then + json_cleanup + json_load "$_res" + json_dump > "$_hosts_file" + json_close_object + json_cleanup + + flashbox_multi_ping "$_hosts_file" "$_out_file" "all" + if [ -f "$_out_file" ] + then + _res="" + _res=$(cat "$_out_file" | curl -s --tlsv1.2 --connect-timeout 5 \ + --retry 1 -H "Content-Type: application/json" \ + -H "X-ANLIX-ID: $(get_mac)" -H "X-ANLIX-SEC: $FLM_CLIENT_SECRET" \ + --data @- "https://$FLM_SVADDR/deviceinfo/receive/pingresult") + + json_load "$_res" + json_get_var _processed processed + json_close_object + + rm "$_out_file" + + return $_processed + else + return 0 + fi + fi + return 0 +} - if [ $_retstatus -eq 0 ] - then - json_cleanup - json_load "$_res" - json_dump > "$_hosts_file" - json_close_object - json_cleanup +sys_uptime() { + echo "$(awk -F. '{print $1}' /proc/uptime)" +} - flashbox_multi_ping "$_hosts_file" "$_out_file" "all" - if [ -f "$_out_file" ] - then - _res="" - _res=$(cat "$_out_file" | curl -s --tlsv1.2 --connect-timeout 5 \ - --retry 1 -H "Content-Type: application/json" \ - -H "X-ANLIX-ID: $(get_mac)" -H "X-ANLIX-SEC: $FLM_CLIENT_SECRET" \ - --data @- "https://$FLM_SVADDR/deviceinfo/receive/pingresult") +wan_uptime() { + local _wan_uptime=0 + local _start_time - json_load "$_res" - json_get_var _processed processed - json_close_object + json_cleanup + if [ -f /tmp/ext_access_time.json ] + then + json_load_file /tmp/ext_access_time.json + json_get_var _start_time starttime + json_close_object + [ -n "$_start_time" ] && _wan_uptime=$(($(sys_uptime)-$_start_time)) + fi - rm "$_out_file" + echo "$_wan_uptime" +} - return $_processed - else - return 0 - fi - fi - return 0 +router_status() { + local _res + local _processed + local _sys_uptime + local _wan_uptime + local _out_file="/tmp/router_status.json" + + _sys_uptime="$(sys_uptime)" + _wan_uptime="$(wan_uptime)" + + json_init + if [ -f /tmp/wanbytes.json ] + then + json_load_file /tmp/wanbytes.json + fi + json_add_string "sysuptime" "$_sys_uptime" + json_add_string "wanuptime" "$_wan_uptime" + json_dump > "$_out_file" + json_cleanup + + if [ -f "$_out_file" ] + then + _res="" + _res=$(cat "$_out_file" | curl -s --tlsv1.2 --connect-timeout 5 \ + --retry 1 -H "Content-Type: application/json" \ + -H "X-ANLIX-ID: $(get_mac)" -H "X-ANLIX-SEC: $FLM_CLIENT_SECRET" \ + --data @- "https://$FLM_SVADDR/deviceinfo/receive/routerstatus") + + json_load "$_res" + json_get_var _processed processed + json_close_object + + rm "$_out_file" + + return $_processed + else + return 0 + fi +} + +run_speed_ondemand_test() { + local _sv_ip_addr="$1" + local _username="$2" + local _connections="$3" + local _timeout="$4" + local _url="http://$_sv_ip_addr/measure" + local _urllist="" + local _result + local _retstatus + local _reply + for i in $(seq 1 "$_connections") + do + _urllist="$_urllist $_url/file$i.bin" + done + log "SPEEDTEST" "Dropping traffic on firewall..." + drop_all_forward_traffic + _result="$(flash-measure "$_timeout" "$_connections" $_urllist)" + _retstatus=$? + log "SPEEDTEST" "Restoring firewall to normal..." + undrop_all_forward_traffic + _reply='{"downSpeed":"'"$_result"'","user":"'"$_username"'"}' + curl -s --tlsv1.2 --connect-timeout 5 --retry 1 -H "Content-Type: application/json" \ + -H "X-ANLIX-ID: $(get_mac)" -H "X-ANLIX-SEC: $FLM_CLIENT_SECRET" --data "$_reply" \ + "https://$FLM_SVADDR/deviceinfo/receive/speedtestresult" + return 0 +} + +run_diagnostics_test() { + local _wan_status + local _ipv4_status + local _ipv6_status + local _dns_status + local _license_status + local _result + _wan_status="$(diagnose_wan_connectivity)" + _ipv4_status="$(check_connectivity_ipv4)" + _ipv6_status="$(check_connectivity_ipv6)" + _dns_status="$(check_connectivity_internet)" + _flashman_status="$(check_connectivity_flashman)" + is_authenticated + _license_status="$?" + json_cleanup + json_load "{}" + json_add_string "wan" "$_wan_status" + json_add_string "ipv4" "$_ipv4_status" + json_add_string "ipv6" "$_ipv6_status" + json_add_string "dns" "$_dns_status" + json_add_string "license" "$_license_status" + json_add_string "flashman" "$_flashman_status" + echo "$(json_dump)" + json_close_object +} + +send_wps_status() { + local _res + local _processed + local _wps_inform="$1" + local _wps_content="$2" + local _out_file="/tmp/wps_info.json" + if [ "$_wps_inform" == "0" ] + then + _out_file="/tmp/wps_state.json" + fi + + json_init + json_add_string "wps_inform" "$_wps_inform" + json_add_string "wps_content" "$_wps_content" + json_dump > "$_out_file" + json_cleanup + + if [ -f "$_out_file" ] + then + log "WPS" "Sending $_wps_inform and $_wps_content to Flashman..." + + _res="" + _res=$(cat "$_out_file" | curl -s --tlsv1.2 --connect-timeout 5 \ + --retry 1 -H "Content-Type: application/json" \ + -H "X-ANLIX-ID: $(get_mac)" -H "X-ANLIX-SEC: $FLM_CLIENT_SECRET" \ + --data @- "https://$FLM_SVADDR/deviceinfo/receive/wps") + json_load "$_res" + json_get_var _processed processed + json_close_object + + return $_processed + else + log "WPS" "Status file not created" + return 0 + fi } download_binary() { diff --git a/files/usr/share/functions/common_functions.sh b/files/usr/share/functions/common_functions.sh index 428012f6..32814880 100644 --- a/files/usr/share/functions/common_functions.sh +++ b/files/usr/share/functions/common_functions.sh @@ -5,126 +5,227 @@ . /usr/share/functions/device_functions.sh log() { - logger -t "$1 " "$2" + logger -t "$1 " "$2" +} + +sh_timeout() { + cmd="$1" + timeout="$2" + ( + eval "$cmd" & + child=$! + trap -- "" SIGTERM + ( + sleep "$timeout" + kill $child 2> /dev/null + ) & + wait $child + ) } get_flashbox_version() { - echo "$(cat /etc/anlix_version)" + echo "$(cat /etc/anlix_version)" +} + +get_flashbox_release() { + echo "$FLM_RELID" } get_hardware_model() { - echo "$(cat /tmp/sysinfo/model | awk '{ print toupper($2) }')" + if [ "$(type -t get_custom_hardware_model)" ] + then + get_custom_hardware_model + else + echo "$(cat /tmp/sysinfo/model | awk '{ print toupper($2) }')" + fi } get_hardware_version() { - echo "$(cat /tmp/sysinfo/model | awk '{ print toupper($3) }')" + if [ "$(type -t get_custom_hardware_version)" ] + then + get_custom_hardware_version + else + echo "$(cat /tmp/sysinfo/model | awk '{ print toupper($3) }')" + fi } set_mqtt_secret() { - json_cleanup - json_load_file /root/flashbox_config.json - json_get_var _mqtt_secret mqtt_secret - json_close_object - - if [ "$_mqtt_secret" != "" ] - then - echo "$_mqtt_secret" - else - local _rand=$(head /dev/urandom | tr -dc A-Z-a-z-0-9) - local _mqttsec=${_rand:0:32} - local _data="id=$(get_mac)&mqttsecret=$_mqttsec" - local _url="deviceinfo/mqtt/add" - local _res=$(rest_flashman "$_url" "$_data") - - json_cleanup - json_load "$_res" - json_get_var _is_registered is_registered - json_close_object - - if [ "$_is_registered" = "1" ] - then - json_cleanup - json_load_file /root/flashbox_config.json - json_add_string mqtt_secret $_mqttsec - json_dump > /root/flashbox_config.json - json_get_var _mqtt_secret mqtt_secret - json_close_object - echo "$_mqtt_secret" - fi - fi + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _mqtt_secret mqtt_secret + json_close_object + + if [ "$_mqtt_secret" != "" ] + then + echo "$_mqtt_secret" + else + local _rand=$(head /dev/urandom | tr -dc A-Z-a-z-0-9) + local _mqttsec=${_rand:0:32} + local _data="id=$(get_mac)&mqttsecret=$_mqttsec" + local _url="deviceinfo/mqtt/add" + local _res=$(rest_flashman "$_url" "$_data") + + _retstatus=$? + if [ $_retstatus -eq 0 ] + then + json_cleanup + json_load "$_res" + json_get_var _is_registered is_registered + json_close_object + + if [ "$_is_registered" = "1" ] + then + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string mqtt_secret $_mqttsec + json_dump > /root/flashbox_config.json + json_get_var _mqtt_secret mqtt_secret + json_close_object + echo "$_mqtt_secret" + fi + fi + fi } reset_mqtt_secret() { - json_cleanup - json_load_file /root/flashbox_config.json - json_get_var _mqtt_secret mqtt_secret - - if [ "$_mqtt_secret" != "" ] - then - json_add_string mqtt_secret "" - json_dump > /root/flashbox_config.json - fi - - json_close_object - set_mqtt_secret + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _mqtt_secret mqtt_secret + + if [ "$_mqtt_secret" != "" ] + then + json_add_string mqtt_secret "" + json_dump > /root/flashbox_config.json + fi + + json_close_object + set_mqtt_secret } # send data to flashman using rest api rest_flashman() { - local _url=$1 - local _data=$2 - local _res - local _curl_out - _res=$(curl -s \ - -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" \ - --tlsv1.2 --connect-timeout 5 --retry 1 \ - --data "$_data&secret=$FLM_CLIENT_SECRET" \ - "https://$FLM_SVADDR/$_url") - _curl_out=$? - - if [ "$_curl_out" -eq 0 ] - then - echo "$_res" - return 0 - elif [ "$_curl_out" -eq 51 ] - then - # curl code 51 is bad certificate - return 2 - else - # other curl errors - return 1 - fi + local _url=$1 + local _data=$2 + local _res + local _curl_out + _res=$(curl -s \ + -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" \ + --tlsv1.2 --connect-timeout 5 --retry 1 \ + --data "$_data&secret=$FLM_CLIENT_SECRET" \ + "https://$FLM_SVADDR/$_url") + _curl_out=$? + + if [ "$_curl_out" -eq 0 ] + then + echo "$_res" + return 0 + elif [ "$_curl_out" -eq 51 ] + then + # curl code 51 is bad certificate + return 2 + else + log "REST FLASHMAN" "Error connecting to server ($_curl_out)" + # other curl errors + return 1 + fi +} + +is_mesh_slave() { + local _mesh_mode="" + local _mesh_master="" + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _mesh_mode mesh_mode + json_get_var _mesh_master mesh_master + json_close_object + + [ -n "$_mesh_mode" ] && [ "$_mesh_mode" != "0" ] && [ -n "$_mesh_master" ] && echo "1" || echo "0" } is_authenticated() { - local _res - local _is_authenticated=1 - - if [ "$FLM_USE_AUTH_SVADDR" == "y" ] - then - # - # WARNING! No spaces or tabs inside the following string! - # - local _data - _data="id=$(get_mac)&\ + local _res + local _is_authenticated=1 + + if [ "$FLM_USE_AUTH_SVADDR" == "y" ] + then + # + # WARNING! No spaces or tabs inside the following string! + # + local _data + _data="id=$(get_mac)&\ organization=$FLM_CLIENT_ORG&\ secret=$FLM_CLIENT_SECRET&\ model=$(get_hardware_model)&\ -model_ver=$(get_hardware_version)" - - _res=$(curl -s \ - -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" \ - --tlsv1.2 --connect-timeout 5 --retry 1 \ - --data "$_data" \ - "https://$FLM_AUTH_SVADDR/api/device/auth") - - json_cleanup - json_load "$_res" - json_get_var _is_authenticated is_authenticated - json_close_object - else - _is_authenticated=0 - fi - - return $_is_authenticated +model_ver=$(get_hardware_version)&\ +is_mesh_active=$(is_mesh_slave)" + + _res=$(curl -s \ + -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" \ + --tlsv1.2 --connect-timeout 5 --retry 1 \ + --data "$_data" \ + "https://$FLM_AUTH_SVADDR/api/device/auth") + + local _curl_res=$? + if [ $_curl_res -eq 0 ] + then + json_cleanup + json_load "$_res" 2>/dev/null + if [ $? == 0 ] + then + json_get_var _is_authenticated is_authenticated + json_close_object + else + log "AUTHENTICATOR" "Invalid answer from controler" + fi + else + log "AUTHENTICATOR" "Error connecting to controler ($_curl_res)" + fi + else + _is_authenticated=0 + fi + + return $_is_authenticated +} + +is_mesh_license_available() { + local _res + local _slave_mac=$1 + local _is_available=1 + + if [ "$FLM_USE_AUTH_SVADDR" == "y" ] + then + # + # WARNING! No spaces or tabs inside the following string! + # + local _data + _data="organization=$FLM_CLIENT_ORG&\ +mac=$_slave_mac&\ +secret=$FLM_CLIENT_SECRET" + + _res=$(curl -s \ + -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" \ + --tlsv1.2 --connect-timeout 5 --retry 1 \ + --data "$_data" \ + "https://$FLM_AUTH_SVADDR/api/device/mesh/available") + + local _curl_res=$? + if [ $_curl_res -eq 0 ] + then + json_cleanup + json_load "$_res" 2>/dev/null + if [ $? == 0 ] + then + json_get_var _is_available is_available + json_close_object + else + log "AUTHENTICATOR" "Invalid answer from controler" + fi + else + log "AUTHENTICATOR" "Error connecting to controler ($_curl_res)" + fi + else + _is_available=0 + fi + + return $_is_available } diff --git a/files/usr/share/functions/device_functions.sh b/files/usr/share/functions/device_functions.sh new file mode 100644 index 00000000..bf94fd02 --- /dev/null +++ b/files/usr/share/functions/device_functions.sh @@ -0,0 +1,322 @@ +#!/bin/sh +# WARNING! This file may be replaced depending on the selected target! +[ -e /usr/share/functions/custom_device.sh ] && . /usr/share/functions/custom_device.sh +. /lib/functions.sh +. /lib/functions/leds.sh + +get_radio_phy() { + echo "$(ls /sys/devices/$(uci get wireless.radio$1.path)/ieee80211)" +} + +get_phy_type() { + #1: 2.4 2: 5GHz + echo "$(iw phy $1 channels|grep Band|tail -1|cut -c6)" +} + +get_24ghz_phy() { + for i in /sys/class/ieee80211/* + do + iface=`basename $i` + [ "$(get_phy_type $iface)" -eq "1" ] && echo $iface + done +} + +get_5ghz_phy() { + for i in /sys/class/ieee80211/* + do + iface=`basename $i` + [ "$(get_phy_type $iface)" -eq "2" ] && echo $iface + done +} + +is_5ghz_vht() { + local _5iface=$(get_5ghz_phy) + [ "$_5iface" ] && [ "$(iw phy $_5iface info|grep "VHT")" ] && echo "1" +} + +is_5ghz_capable() { + [ "$(get_5ghz_phy)" ] && echo "1" || echo "0" +} + +is_mesh_routing_capable() { + local _ret=0 + local _ret5=0 + local _24iface=$(get_24ghz_phy) + local _5iface=$(get_5ghz_phy) + [ "$_24iface" ] && [ "$(iw phy $_24iface info|grep "mesh point")" ] && _ret=1 + [ "$_5iface" ] && [ "$(iw phy $_5iface info|grep "mesh point")" ] && _ret5=1 + if [ "$_ret5" -eq "1" ] + then + [ "$_ret" -eq "1" ] && echo "3" || echo "2" + else + echo "$_ret" + fi +} + +is_mesh_capable() { + [ -f /usr/sbin/wpad ] && [ "$(is_mesh_routing_capable)" != "0" ] && echo "1" +} + +get_wifi_device_stats() { + local _dev_mac="$1" + local _dev_info + local _wifi_stats="" + local _retstatus + local _cmd_res + local _wifi_itf="wlan0" + local _ap_freq="2.4" + local _base_noise="-92" + + _cmd_res=$(command -v iw) + _retstatus=$? + + if [ $_retstatus -eq 0 ] + then + _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" + _retstatus=$? + + if [ $_retstatus -ne 0 ] + then + _wifi_itf="wlan1" + _ap_freq="5.0" + _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" + _retstatus=$? + fi + + if [ $_retstatus -eq 0 ] + then + local _dev_txbitrate="$(echo "$_dev_info" | grep 'tx bitrate:' | awk '{print $3}')" + local _dev_rxbitrate="$(echo "$_dev_info" | grep 'rx bitrate:' | awk '{print $3}')" + local _dev_mcs="$(echo "$_dev_info" | grep 'tx bitrate:' | awk '{print $5}')" + local _dev_signal="$(echo "$_dev_info" | grep -m1 'signal:' | awk '{print $2}' | awk -F. '{print $1}')" + local _ap_noise="$(iwinfo $_wifi_itf info | grep 'Noise:' | awk '{print $5}' | awk -F. '{print $1}')" + local _dev_txbytes="$(echo "$_dev_info" | grep 'tx bytes:' | awk '{print $3}')" + local _dev_rxbytes="$(echo "$_dev_info" | grep 'rx bytes:' | awk '{print $3}')" + local _dev_txpackets="$(echo "$_dev_info" | grep 'tx packets:' | awk '{print $3}')" + local _dev_rxpackets="$(echo "$_dev_info" | grep 'rx packets:' | awk '{print $3}')" + local _dev_conntime="$(echo "$_dev_info" | grep 'connected time:' | awk '{print $3}')" + + _ap_noise=$([ "$_ap_noise" == "unknown" ] && echo "$_base_noise" || echo "$_ap_noise") + if [ "$_ap_noise" -lt "$_base_noise" ] + then + _ap_noise="$_base_noise" + fi + + # Calculate SNR + local _dev_snr="$(($_dev_signal - $_ap_noise))" + + _wifi_stats="$_dev_txbitrate $_dev_rxbitrate $_dev_signal" + _wifi_stats="$_wifi_stats $_dev_snr $_ap_freq" + + [ "$_dev_mcs" == "VHT-MCS" ] && _wifi_stats="$_wifi_stats AC" || _wifi_stats="$_wifi_stats N" + # Traffic data + _wifi_stats="$_wifi_stats $_dev_txbytes $_dev_rxbytes" + _wifi_stats="$_wifi_stats $_dev_txpackets $_dev_rxpackets" + _wifi_stats="$_wifi_stats $_dev_conntime" + echo "$_wifi_stats" + else + echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0 0" + fi + else + echo "0.0 0.0 0.0 0.0 0 Z 0 0 0 0 0" + fi +} + +is_device_wireless() { + local _dev_mac="$1" + local _dev_info + local _retstatus + local _cmd_res + local _wifi_itf="wlan0" + + _cmd_res=$(command -v iw) + _retstatus=$? + + if [ $_retstatus -eq 0 ] + then + _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" + _retstatus=$? + + if [ $_retstatus -ne 0 ] + then + _wifi_itf="wlan1" + _dev_info="$(iw dev $_wifi_itf station get $_dev_mac 2> /dev/null)" + _retstatus=$? + fi + + [ $_retstatus -eq 0 ] && return 0 || return 1 + else + return 1 + fi +} + +leds_off() { + for trigger_path in $(ls -d /sys/class/leds/*) + do + led_off "$(basename "$trigger_path")" + done +} + +reset_leds() { + leds_off + /etc/init.d/led restart > /dev/null + led_on "$(get_dt_led running)" +} + +blink_leds() { + if [ $1 -eq 0 ] + then + local led_blink="$([ "$(type -t get_custom_leds_blink)" ] && get_custom_leds_blink || ls -d /sys/class/leds/*green*)" + leds_off + for trigger_path in $led_blink; do + led_timer "$(basename "$trigger_path")" 500 500 + done + fi +} + +get_mac() { + if [ "$(type -t get_custom_mac)" ] + then + get_custom_mac + else + local _mac_address_tag="" + local _p1 + + _p1=$(awk '{print toupper($1)}' /sys/class/net/eth0/address) + [ ! -z "$_p1" ] && _mac_address_tag=$_p1 + + echo "$_mac_address_tag" + fi +} + +get_vlan_device() { + parse_get_switch() { + config_get device $2 device + config_get vlan $2 vlan + [ $vlan -eq $1 ] && echo "${device}" + } + config_load network + swt=$(config_foreach "parse_get_switch $1" switch_vlan) + echo "$swt" +} + +get_vlan_ports() { + local _switch="$(get_vlan_device $1)" + local _port=$(swconfig dev $_switch vlan $1 get ports) + echo "$(for i in $_port; do [ "${i:1}" != "t" ] && echo $i; done)" +} + +get_wan_device() { + ubus call network.interface.wan status|jsonfilter -e "@.device" +} + +get_switch_device() { + local _switch + for i in $(swconfig list) + do + [ -z "${i%switch*}" ] && _switch="$i" + done + echo "$_switch" +} + +is_device_vlan() { + local _iface=$1 + [ "${_iface:4:1}" == "." ] && echo "1" +} + +get_device_vlan() { + local _iface=$1 + echo "${_iface:5:1}" +} + +get_wan_negotiated_speed() { + local _wan=$(get_wan_device) + if [ "$(type -t custom_switch_ports)" ] || [ "$(is_device_vlan $_wan)" ] + then + local _switch + local _port + if [ "$(type -t custom_switch_ports)" ] + then + _switch="$(custom_switch_ports 1)" + _port="$(custom_switch_ports 2)" + else + local _vport=$(get_device_vlan $_wan) + _switch="$(get_vlan_device $_vport)" + _port="$(get_vlan_ports $_vport)" + fi + echo "$(swconfig dev $_switch port $_port get link|sed -ne 's/.*speed:\([0-9]*\)*.*/\1/p')" + else + cat /sys/class/net/$_wan/speed + fi +} + +get_wan_negotiated_duplex() { + local _wan=$(get_wan_device) + if [ "$(type -t custom_switch_ports)" ] || [ "$(is_device_vlan $_wan)" ] + then + local _switch + local _port + if [ "$(type -t custom_switch_ports)" ] + then + _switch="$(custom_switch_ports 1)" + _port="$(custom_switch_ports 2)" + else + local _vport=$(get_device_vlan $_wan) + _switch="$(get_vlan_device $_vport)" + _port="$(get_vlan_ports $_vport)" + fi + echo "$(swconfig dev $_switch port $_port get link|sed -ne 's/.* \([a-z]*\)-duplex*.*/\1/p')" + else + cat /sys/class/net/$_wan/duplex + fi +} + +get_lan_dev_negotiated_speed() { + local _speed="0" + local _switch="$(get_vlan_device 1)" + [ -z "$_switch" ] && _switch="$(get_switch_device)" + [ -z "$_switch" ] && ( + log "get_lan_dev_speed" "Cant get lan switch device!" + return + ) + + local _switch_ports + if [ "$(type -t custom_switch_ports)" ] + then + _switch_ports="$(custom_switch_ports 3)" + else + _switch_ports="$(get_vlan_ports 1)" + fi + [ -z "$_switch_ports" ] && ( + log "get_lan_dev_speed" "Cant get lan switch ports!" + return + ) + + for _port in $_switch_ports; do + local _speed_tmp="$(swconfig dev $_switch port $_port get link|sed -ne 's/.*speed:\([0-9]*\)*.*/\1/p')" + if [ "$_speed_tmp" != "" ] + then + if [ "$_speed" != "0" ] + then + [ "$_speed" != "$_speed_tmp" ] && _speed="0" + else + # First assignment + _speed="$_speed_tmp" + fi + fi + done + + echo "$_speed" +} + +get_wifi_device_signature() { + local _dev_mac="$1" + local _q="" + _q="$(ubus -S call hostapd.wlan0 get_clients | jsonfilter -e '@.clients["'"$_dev_mac"'"].signature')" + [ -z "$_q" ] && [ "$(is_5ghz_capable)" -eq "1" ] && _q="$(ubus -S call hostapd.wlan1 get_clients | jsonfilter -e '@.clients["'"$_dev_mac"'"].signature')" + echo "$_q" +} + +needs_reboot_bridge_mode() { + reboot +} diff --git a/files/usr/share/functions/dhcp_functions.sh b/files/usr/share/functions/dhcp_functions.sh index c1a751cc..195d651c 100644 --- a/files/usr/share/functions/dhcp_functions.sh +++ b/files/usr/share/functions/dhcp_functions.sh @@ -4,229 +4,357 @@ . /usr/share/functions/device_functions.sh get_device_mac_from_ip() { - local _ip=$1 - local _arp_mac=$(cat /proc/net/arp | grep "$_ip" | awk '{ print $4 }') - echo "$_arp_mac" + local _ip=$1 + local _arp_mac=$(cat /proc/net/arp | grep "$_ip" | awk '{ print $4 }') + echo "$_arp_mac" } get_device_conn_type() { - local _mac=$1 - local _online=$2 - local _retstatus - - is_device_wireless "$_mac" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - # Wireless - echo "1" - else - if [ $_online -eq 1 ] - then - # Wired - echo "0" - return - fi - local _state=$(ip neigh | grep "$_mac" | awk '{print $NF}') - for i in $_state - do - if [ "$i" = "STALE" ] || [ "$i" = "REACHABLE" ] - then - # Wired - echo "0" - return - fi - done - # Not connected - echo "2" - fi + local _mac=$1 + local _online=$2 + local _retstatus + + is_device_wireless "$_mac" + _retstatus=$? + if [ $_retstatus -eq 0 ] + then + # Wireless + echo "1" + else + if [ "$_online" == "1" ] + then + # Wired + echo "0" + return + fi + local _state=$(ip neigh | grep "$_mac" | awk '{print $NF}') + for i in $_state + do + if [ "$i" == "REACHABLE" ] + then + # Wired + echo "0" + return + fi + done + # Not connected + echo "2" + fi } # IPV6 dhcp are uid not mac # Send a probe to search for mac in ip neigh get_ipv6_dhcp() { - json_init - local DHCP=$(ubus -v call dhcp ipv6leases) - json_load "$DHCP" - json_select "device" - if json_get_type type "br-lan" && [ "$type" = object ]; then - json_select "br-lan" - if json_get_type type "leases" && [ "$type" = array ]; then - json_select "leases" - local Index="1" - while json_get_type type $Index && [ "$type" = object ]; do - json_select "$((Index++))" - json_get_var duid "duid" - json_select "ipv6-addr" - local Index_Addr="1" - while json_get_type type $Index_Addr && [ "$type" = object ]; do - json_select "$((Index_Addr++))" - json_get_var addrv6 "address" - - #we need to "wake up" the ip to get the mac from ip neigh - ping6 -I br-lan -q -c 1 -w 1 "$addrv6" > /dev/null 2>&1 - local _macaddr=$(ip -6 neigh | grep "$addrv6" | awk '{ if($4 == "lladdr") print $5 }') - if [ ! -z $_macaddr ]; then - echo $duid $_macaddr $addrv6 - fi - - json_select ".." - done - json_select ".." - json_select ".." - done - fi - fi + json_init + local DHCP=$(ubus -v call dhcp ipv6leases) + json_load "$DHCP" + json_select "device" + if json_get_type type "br-lan" && [ "$type" = object ]; then + json_select "br-lan" + if json_get_type type "leases" && [ "$type" = array ]; then + json_select "leases" + local Index="1" + while json_get_type type $Index && [ "$type" = object ]; do + json_select "$((Index++))" + json_get_var duid "duid" + json_select "ipv6-addr" + local Index_Addr="1" + while json_get_type type $Index_Addr && [ "$type" = object ]; do + json_select "$((Index_Addr++))" + json_get_var addrv6 "address" + + # We need to "wake up" the ip to get the mac from ip neigh + ping6 -I br-lan -q -c 1 -w 1 "$addrv6" > /dev/null 2>&1 + local _macaddr=$(ip -6 neigh | grep "$addrv6" | awk '{ if($4 == "lladdr") print $5 }') + if [ ! -z $_macaddr ]; then + echo $duid $_macaddr $addrv6 + fi + + json_select ".." + done + json_select ".." + json_select ".." + done + fi + fi +} + +check_dev_online_status() { + local _mac="$1" + local _ipv4_neigh="$2" + local _ipv6_neigh="$3" + local _ipv4="$(echo "$_ipv4_neigh" | grep "$_mac" | awk '{ print $2 }')" + local _ipv6="$(echo "$_ipv6_neigh" | grep "$_mac" | awk '{ print $2 }')" + local _res + + # check online in ipv4 + _res="$(ping -q -c 1 -w 1 "$i" 2>/dev/null)" + if [ $? -eq 0 ] + then + mv "/tmp/onlinedevscheck/$_mac.wait" "/tmp/onlinedevscheck/$_mac.on" + echo "$(echo $_res|sed -ne 's/.* = \([0-9\.]*\)*.*/\1/p')" > "/tmp/onlinedevscheck/$_mac.on" + return + fi + + for i in $_ipv6 + do + _res=$(ping6 -I br-lan -q -c 1 -w 1 "$i" 2>/dev/null) + if [ $? -eq 0 ] + then + mv "/tmp/onlinedevscheck/$_mac.wait" "/tmp/onlinedevscheck/$_mac.on" + echo "$(echo $_res|sed -ne 's/.* = \([0-9\.]*\)*.*/\1/p')" > "/tmp/onlinedevscheck/$_mac.on" + return + fi + done + + # if cant connect, check arp table + local _count=0 + local _state=$(ip neigh | grep "$_mac" | awk '{print $NF}') + local _ctrl=$(echo "$_state" | grep "DELAY") + while [ ! -z "$_ctrl" ] || [ $_count -eq 2 ] + do + sleep 2 + _state=$(ip neigh | grep "$_mac" | awk '{print $NF}') + _ctrl=$(echo "$_state" | grep "DELAY") + _count=$((_count+1)) + done + + for s in $_state + do + if [ "$s" == "REACHABLE" ] + then + mv "/tmp/onlinedevscheck/$_mac.wait" "/tmp/onlinedevscheck/$_mac.on" + return + fi + done + + mv "/tmp/onlinedevscheck/$_mac.wait" "/tmp/onlinedevscheck/$_mac.off" + return } get_online_devices() { - local _dhcp_ipv6=$(get_ipv6_dhcp) - local _arp_neigh=$(ip neigh | grep lladdr | awk '{ if($3 == "br-lan") print $5, $1 }') - local _arp_macs=$(awk 'NR>1 { if($6 == "br-lan") print $4, $1 }' /proc/net/arp) - local _arp_macs_all=$(printf %s\\n%s "$_arp_neigh" "$_arp_macs" | sort | uniq) - local _arp_macs=$(echo "$_arp_macs_all" | awk '{ print $1 }' | uniq) - - json_init - json_add_object "Devices" - local _idx=1 - for _mac in $_arp_macs - do - local _ipv4="$(echo "$_arp_macs_all" | grep "$_mac" | awk '{ print $2 }' | grep \\.)" - local _ipv6="$(echo "$_arp_macs_all" | grep "$_mac" | awk '{ print $2 }' | grep :)" - - # check online in ipv4 - local _online=0 - for i in $_ipv4 - do - ping -q -c 1 -w 1 "$i" > /dev/null 2>&1 - if [ $? -eq 0 ] - then - _online=1 - fi - done - - # check online in ipv6 - if [ $_online -eq 0 ] - then - for i in $_ipv6 - do - ping6 -I br-lan -q -c 1 -w 1 "$i" > /dev/null 2>&1 - if [ $? -eq 0 ] - then - _online=1 - fi - done - fi - - # if cant connect, check arp table - if [ $_online -eq 0 ] - then - local _count=0 - local _state=$(ip neigh | grep "$_mac" | awk '{print $NF}') - local _ctrl=$(echo "$_state" | grep "DELAY") - while [ ! -z "$_ctrl" ] || [ $_count -eq 2 ] - do - sleep 2 - _state=$(ip neigh | grep "$_mac" | awk '{print $NF}') - _ctrl=$(echo "$_state" | grep "DELAY") - _count=$((_count+1)) - done - - for s in $_state - do - if [ "$s" = "STALE" ] || [ "$s" = "REACHABLE" ] - then - _online=1 - fi - done - fi - - # if still offline, give up - if [ $_online -eq 0 ] - then - # Not connected get next device - _idx=$((_idx+1)) - continue - fi - - local _hostname="$(cat /tmp/dhcp.leases | grep $_mac | \ - awk '{ if ($4=="*") print "!"; else print $4 }')" - local _conn_type="$(get_device_conn_type $_mac $_online)" - local _conn_speed="" - local _dev_signal="" - local _dev_snr="" - local _dev_freq="" - local _dev_mode="" - - if [ "$_conn_type" == "0" ] - then - # Get speed from LAN ports - _conn_speed=$(get_lan_dev_negotiated_speed $_mac) - elif [ "$_conn_type" == "1" ] - then - local _wifi_stats="$(get_wifi_device_stats $_mac)" - # Get wireless bitrate - _conn_speed=$(echo $_wifi_stats | awk '{print $1}') - _dev_signal=$(echo $_wifi_stats | awk '{print $3}') - _dev_snr=$(echo $_wifi_stats | awk '{print $4}') - _dev_freq=$(echo $_wifi_stats | awk '{print $5}') - _dev_mode=$(echo $_wifi_stats | awk '{print $6}') - fi - - json_add_object "$_mac" - json_add_string "ip" "$_ipv4" - json_add_array "ipv6" - for _i6 in $_ipv6 - do - json_add_string "" "$_i6" - done - json_close_array - json_add_array "dhcpv6" - for _i6 in $(echo "$_dhcp_ipv6" | grep $_mac | awk '{print $3}') - do - json_add_string "" "$_i6" - done - json_close_array - json_add_string "hostname" "$_hostname" - json_add_string "conn_type" "$_conn_type" - json_add_string "conn_speed" "$_conn_speed" - json_add_string "wifi_signal" "$_dev_signal" - json_add_string "wifi_snr" "$_dev_snr" - json_add_string "wifi_freq" "$_dev_freq" - json_add_string "wifi_mode" "$_dev_mode" - json_close_object - _idx=$((_idx+1)) - done - json_close_object - json_dump + local _dhcp_ipv6="" + [ "$(get_ipv6_enabled)" != "0" ] && _dhcp_ipv6=$(get_ipv6_dhcp) + local _ipv4_neigh="$(ip -4 neigh | grep lladdr | awk '{ if($3 == "br-lan") print $5, $1}')" + local _ipv6_neigh="" + [ "$(get_ipv6_enabled)" != "0" ] &&_ipv6_neigh="$(ip -6 neigh | grep lladdr | awk '{ if($3 == "br-lan") print $5, $1}')" + local _macs_v4="$(echo "$_ipv4_neigh" | awk '{ print $1 }')" + local _macs_v6="$(echo "$_ipv6_neigh" | awk '{ print $1 }')" + local _macs="$(printf %s\\n%s "$_macs_v4" "$_macs_v6" | sort | uniq)" + local _local_itf_macs="$(ifconfig | grep HWaddr | awk '{ print tolower($NF) }' | sort | uniq)" + local _mesh_routers="$(ubus call anlix_sapo get_routers_mac | jsonfilter -e '@.routers[@].mac' | awk '{ print tolower($NF) }' | sort | uniq)" + + # Remove MACs related to the router itself and mesh neighbors + local _local_mac_duplicates="$(printf %s\\n%s\\n%s "$_macs" "$_local_itf_macs" "$_mesh_routers" | sort | uniq -d)" + for _mac in $_local_mac_duplicates + do + _macs="$(printf %s\\n%s "$_macs" | sed "/$_mac/d")" + done + + # Create control dir with device status + [ -d /tmp/onlinedevscheck ] && rm -rf /tmp/onlinedevscheck + mkdir /tmp/onlinedevscheck + for _mac in $_macs + do + touch "/tmp/onlinedevscheck/$_mac.wait" + done + # Dispatch pings and arp checks for each device + for _mac in $_macs + do + (check_dev_online_status "$_mac" "$_ipv4_neigh" "$_ipv6_neigh" & ) + done + # Wait pings and arp checks completion + local _wait_complete=1 + while [ $_wait_complete -eq 1 ] + do + ls /tmp/onlinedevscheck | grep -q "wait" + if [ $? -eq 0 ] + then + sleep 1 + else + break + fi + done + # Filter only online devs + _macs=$(ls /tmp/onlinedevscheck | grep ".on" | awk -F. '{print $1}') + # Create JSON with online devices + json_add_object "Devices" + for _mac in $_macs + do + local _ipv4="$(echo "$_ipv4_neigh" | grep "$_mac" | awk '{ print $2 }')" + + local _ipv6="" + [ "$(get_ipv6_enabled)" != "0" ] && _ipv6="$(echo "$_ipv6_neigh" | grep "$_mac" | awk '{ print $2 }')" + + local _hostname="" + local _conn_type="$(get_device_conn_type $_mac $_online)" + local _conn_speed="" + local _dev_signal="" + local _dev_snr="" + local _dev_freq="" + local _dev_mode="" + local _dev_ping="" + local _dev_rx="" + local _dev_tx="" + local _dev_conntime="" + local _dev_signature="" + local _dhcp_signature="" + local _dhcp_vendor_class="" + + if [ -f /tmp/dhcp.leases ] + then + _hostname="$(cat /tmp/dhcp.leases | grep $_mac | awk '{ if ($4=="*") print "!"; else print $4 }')" + fi + + if [ "$_conn_type" == "0" ] + then + # Get speed from LAN ports + _conn_speed=$(get_lan_dev_negotiated_speed $_mac) + elif [ "$_conn_type" == "1" ] + then + local _wifi_stats="$(get_wifi_device_stats $_mac)" + # Get wireless bitrate + _conn_speed=$(echo $_wifi_stats | awk '{print $1}') + _dev_signal=$(echo $_wifi_stats | awk '{print $3}') + _dev_snr=$(echo $_wifi_stats | awk '{print $4}') + _dev_freq=$(echo $_wifi_stats | awk '{print $5}') + _dev_mode=$(echo $_wifi_stats | awk '{print $6}') + _dev_tx=$(echo $_wifi_stats | awk '{print $7}') + _dev_rx=$(echo $_wifi_stats | awk '{print $8}') + _dev_conntime=$(echo $_wifi_stats | awk '{print $11}') + + if [ "$(type -t get_wifi_device_signature)" ] + then + _dev_signature="$(get_wifi_device_signature $_mac)" + fi + fi + _dev_ping=$([ -s "/tmp/onlinedevscheck/$_mac.on" ] && cat "/tmp/onlinedevscheck/$_mac.on") + + if [ -e "/tmp/dhcpinfo/$_mac" ] + then + _dhcp_signature="$(cat /tmp/dhcpinfo/"$_mac" | awk '{print $1}')" + _dhcp_vendor_class="$(cat /tmp/dhcpinfo/"$_mac" | awk '{print $2}')" + fi + + json_add_object "$_mac" + json_add_string "ip" "$_ipv4" + json_add_array "ipv6" + for _i6 in $_ipv6 + do + json_add_string "" "$_i6" + done + json_close_array + json_add_array "dhcpv6" + if [ "$(get_ipv6_enabled)" != "0" ] + then + for _i6 in $(echo "$_dhcp_ipv6" | grep $_mac | awk '{print $3}') + do + json_add_string "" "$_i6" + done + fi + json_close_array + json_add_string "hostname" "$_hostname" + json_add_string "conn_type" "$_conn_type" + json_add_string "conn_speed" "$_conn_speed" + json_add_string "wifi_signal" "$_dev_signal" + json_add_string "wifi_snr" "$_dev_snr" + json_add_string "wifi_freq" "$_dev_freq" + json_add_string "wifi_mode" "$_dev_mode" + json_add_string "ping" "$_dev_ping" + json_add_string "tx_bytes" "$_dev_tx" + json_add_string "rx_bytes" "$_dev_rx" + json_add_string "conn_time" "$_dev_conntime" + json_add_string "wifi_signature" "$_dev_signature" + json_add_string "dhcp_signature" "$_dhcp_signature" + json_add_string "dhcp_vendor_class" "$_dhcp_vendor_class" + json_close_object + done + json_close_object +} + +get_online_mesh_routers() { + local _routers="" + local _stations="" + local _r + if [ -e /sys/class/net/mesh0 ] + then + _routers="$(iw dev mesh0 mpath dump | awk '/mesh0/{print $1}')" + _stations="$(iw dev mesh0 station dump)" + fi + if [ -e /sys/class/net/mesh1 ] + then + if [ "$_routers" ] + then + _routers="$_routers $(iw dev mesh1 mpath dump | awk '/mesh1/{print $1}')" + else + _routers="$(iw dev mesh1 mpath dump | awk '/mesh1/{print $1}')" + fi + if [ "$_stations" ] + then + _stations="$_stations $(iw dev mesh1 station dump)" + else + _stations="$(iw dev mesh1 station dump)" + fi + fi + + local _mac + json_add_object "mesh_routers" + while [ "$(echo "$_stations"|xargs)" ] + do + _r=${_stations##*Station} + _stations=${_stations%Station *} + _mac="$(echo ${_r%% (*}|xargs)" + case "$_routers" in *"$_mac"*) + json_add_object "$_mac" + json_add_string "signal" "$(echo "$_r"|awk '/signal:/{print $2}')" + json_add_string "conn_time" "$(echo "$_r"|awk '/connected time:/{print $3}')" + json_add_string "rx_bytes" "$(echo "$_r"|awk '/rx bytes:/{print $3}')" + json_add_string "tx_bytes" "$(echo "$_r"|awk '/tx bytes:/{print $3}')" + json_add_string "rx_bit" "$(echo "$_r"|awk '/rx bitrate:/{print $3}')" + json_add_string "tx_bit" "$(echo "$_r"|awk '/tx bitrate:/{print $3}')" + json_add_string "iface" "$(echo "$_r"| awk '/\(on /{print substr($3, 1, 5)}')" + json_close_object + ;; + esac + done + + json_close_object } send_online_devices() { - local _res - _res=$(get_online_devices | curl -s --tlsv1.2 --connect-timeout 5 \ - --retry 1 -H "Content-Type: application/json" \ - -H "X-ANLIX-ID: $(get_mac)" \ - -H "X-ANLIX-SEC: $FLM_CLIENT_SECRET" \ - --data @- "https://$FLM_SVADDR/deviceinfo/receive/devices") - json_cleanup - json_load "$_res" - json_get_var _processed processed - json_close_object - - return $_processed + local _res + local _mesh_mode=$(cat /root/flashbox_config.json | jsonfilter -e '@.mesh_mode') + + json_init + get_online_devices + [ "$_mesh_mode" -gt 1 ] && get_online_mesh_routers + + _res=$(json_dump | curl -s --tlsv1.2 --connect-timeout 5 \ + --retry 1 -H "Content-Type: application/json" \ + -H "X-ANLIX-ID: $(get_mac)" \ + -H "X-ANLIX-SEC: $FLM_CLIENT_SECRET" \ + --data @- "https://$FLM_SVADDR/deviceinfo/receive/devices") + json_cleanup + json_load "$_res" + json_get_var _processed processed + json_close_object + + return $_processed } get_active_device_leases() { - local _devarraystr="{\"data\":[" - local _devlist=$(cat /tmp/dhcp.leases | awk '{ print $2 }') - local _hostname - local _dev - for _dev in $_devlist - do - _hostname=$(cat /tmp/dhcp.leases | grep "$_dev" | awk '{ print $4 }') - _devarraystr="$_devarraystr\ + local _devarraystr="{\"data\":[" + local _devlist + [ -f /tmp/dhcp.leases ] && _devlist=$(cat /tmp/dhcp.leases | awk '{ print $2 }') + local _hostname + local _dev + for _dev in $_devlist + do + _hostname="" + _hostname=$(cat /tmp/dhcp.leases | grep "$_dev" | awk '{ print $4 }') + _devarraystr="$_devarraystr\ {\"{#MAC}\":\"$_dev\", \"{#DEVHOSTNAME}\":\"$_hostname\"}," - done - _devarraystr=$_devarraystr"]}" - echo $_devarraystr | sed 's/\(.*\),/\1/' + done + _devarraystr=$_devarraystr"]}" + echo $_devarraystr | sed 's/\(.*\),/\1/' } diff --git a/files/usr/share/functions/firewall_functions.sh b/files/usr/share/functions/firewall_functions.sh index 38cb23a3..395d09f0 100644 --- a/files/usr/share/functions/firewall_functions.sh +++ b/files/usr/share/functions/firewall_functions.sh @@ -6,166 +6,296 @@ . /usr/share/libubox/jshn.sh json_update_index() { - _index=$1 - _json_var=$2 - - json_init - [ -f /etc/anlix_indexes ] && json_load_file /etc/anlix_indexes - json_add_string "$_json_var" "$_index" - json_close_object - json_dump > /etc/anlix_indexes + _index=$1 + _json_var=$2 + + json_init + [ -f /etc/anlix_indexes ] && json_load_file /etc/anlix_indexes + json_add_string "$_json_var" "$_index" + json_close_object + json_dump > /etc/anlix_indexes } get_forward_indexes() { - local _index=$1 - local _idx_val="" - - if [ -f /etc/anlix_indexes ] - then - json_cleanup - json_load_file /etc/anlix_indexes - json_get_var _idx_val "$_index" - json_close_object - fi - echo "$_idx_val" + local _index=$1 + local _idx_val="" + + if [ -f /etc/anlix_indexes ] + then + json_cleanup + json_load_file /etc/anlix_indexes + json_get_var _idx_val "$_index" + json_close_object + fi + echo "$_idx_val" } update_port_forward() { - log "PORT FORWARD" "Requesting Flashman ..." - local _data="id=$(get_mac)" - local _url="deviceinfo/get/portforward/" - local _res - local _retstatus - _res=$(rest_flashman "$_url" "$_data") - _retstatus=$? - - if [ $_retstatus -eq 0 ] - then - json_cleanup - json_load "$_res" - json_get_var _flash_idx forward_index - - [ -f /etc/ethers ] && rm /etc/ethers - - # Remove old forward rules - local _old_rules=$(uci -X show firewall | grep ".name='anlix_forward_.*'") - for rule in $_old_rules - do - local _old_rule=$(echo "$rule" | awk -F '.' '{ print "firewall."$2}') - uci delete "$_old_rule" - done - - json_select forward_rules - local _rule_idx="1" - local _forward_idx=1 - while json_get_type _rule_type $_rule_idx && [ "$_rule_type" = object ] - do - json_select "$((_rule_idx++))" - json_get_var _mac mac - json_get_var _dmz dmz - local _static_ip=$(add_static_ip "$_mac" "$_dmz") - local _static_ipv6=$(add_static_ipv6 "$_mac") - - local has_router_port=0 - json_get_type _router_port_type router_port - if [ "$_router_port_type" == "array" ] - then - json_select router_port - local _router_port_idx=1 - while json_get_type _router_port_type $_router_port_idx && [ "$_router_port_type" = int ] - do - has_router_port=1 - json_get_var _router_port "$_router_port_idx" - eval _router_port_$_router_port_idx=$_router_port - _router_port_idx=$((_router_port_idx+1)) - done - json_select ".." - fi - - json_select port - local _port_idx=1 - while json_get_type _port_type $_port_idx && [ "$_port_type" = int ] - do - local _act_idx="$((_port_idx++))" - json_get_var _port $_act_idx - - #IPV4 - uci add firewall redirect > /dev/null - uci set firewall.@redirect[-1].src='wan' - - if [ $has_router_port -eq 1 ] - then - eval _src_port=\$_router_port_$_act_idx - if [ $_src_port -eq $_port ] - then - uci set firewall.@redirect[-1].src_dport="$_port" - else - uci set firewall.@redirect[-1].src_dport="$_src_port" - uci set firewall.@redirect[-1].dest_port="$_port" - fi - else - uci set firewall.@redirect[-1].src_dport="$_port" - fi - - uci set firewall.@redirect[-1].proto='tcpudp' - if [ "$_dmz" = 1 ] - then - uci set firewall.@redirect[-1].dest='dmz' - else - uci set firewall.@redirect[-1].dest='lan' - fi - uci set firewall.@redirect[-1].dest_ip="$_static_ip" - uci set firewall.@redirect[-1].target="DNAT" - uci set firewall.@redirect[-1].name="anlix_forward_$((_forward_idx++))" - - #IPV6 - if [ ! -z "$_static_ipv6" ] - then - uci add firewall rule > /dev/null - uci set firewall.@rule[-1].src='wan' - uci set firewall.@rule[-1].proto='tcpudp' - uci set firewall.@rule[-1].dest='lan' - uci set firewall.@rule[-1].dest_ip="::$_static_ipv6/::ffff" - uci set firewall.@rule[-1].dest_port="$_port" - uci set firewall.@rule[-1].family='ipv6' - uci set firewall.@rule[-1].target='ACCEPT' - uci set firewall.@rule[-1].name="anlix_forward_$((_forward_idx++))" - fi - - done - json_select ".." - json_select ".." - done - json_close_object - uci commit firewall - /etc/init.d/dnsmasq reload - /etc/init.d/firewall reload - - # Save index - json_update_index "$_flash_idx" "forward_index" - fi + log "PORT FORWARD" "Requesting Flashman ..." + local _data="id=$(get_mac)" + local _url="deviceinfo/get/portforward/" + local _res + local _retstatus + _res=$(rest_flashman "$_url" "$_data") + _retstatus=$? + + if [ $_retstatus -eq 0 ] + then + json_cleanup + json_load "$_res" + json_get_var _flash_idx forward_index + + [ -f /etc/ethers ] && rm /etc/ethers + [ -f /etc/ethers_port_forward ] && rm /etc/ethers_port_forward + + # Remove old forward rules + local _old_rules=$(uci -X show firewall | grep ".name='anlix_forward_.*'") + for rule in $_old_rules + do + local _old_rule=$(echo "$rule" | awk -F '.' '{ print "firewall."$2}') + uci delete "$_old_rule" + done + + json_select forward_rules + local _rule_idx="1" + local _forward_idx=1 + while json_get_type _rule_type $_rule_idx && [ "$_rule_type" = object ] + do + json_select "$((_rule_idx++))" + json_get_var _mac mac + json_get_var _dmz dmz + local _static_ip + # Check if device has already a fixed ip due to upnp + grep -q -i "$_mac" /etc/ethers_upnp_devices 2>/dev/null + _retstatus=$? + if [ ! $_retstatus -eq 0 ] + then + _static_ip=$(add_static_ip "$_mac" "$_dmz" "ethers_port_forward") + else + local _line=$(grep -i "$_mac" /etc/ethers_upnp_devices) + _static_ip=$(echo "$_line" | awk '{print $2}') + echo "$_line" >> /etc/ethers_port_forward + fi + local _static_ipv6=$(add_static_ipv6 "$_mac") + + local has_router_port=0 + json_get_type _router_port_type router_port + if [ "$_router_port_type" == "array" ] + then + json_select router_port + local _router_port_idx=1 + while json_get_type _router_port_type $_router_port_idx && [ "$_router_port_type" = int ] + do + has_router_port=1 + json_get_var _router_port "$_router_port_idx" + eval _router_port_$_router_port_idx=$_router_port + _router_port_idx=$((_router_port_idx+1)) + done + json_select ".." + fi + + json_select port + local _port_idx=1 + while json_get_type _port_type $_port_idx && [ "$_port_type" = int ] + do + local _act_idx="$((_port_idx++))" + json_get_var _port $_act_idx + + #IPV4 + uci add firewall redirect > /dev/null + uci set firewall.@redirect[-1].src='wan' + + if [ $has_router_port -eq 1 ] + then + eval _src_port=\$_router_port_$_act_idx + if [ $_src_port -eq $_port ] + then + uci set firewall.@redirect[-1].src_dport="$_port" + else + uci set firewall.@redirect[-1].src_dport="$_src_port" + uci set firewall.@redirect[-1].dest_port="$_port" + fi + else + uci set firewall.@redirect[-1].src_dport="$_port" + fi + + uci set firewall.@redirect[-1].proto='tcpudp' + if [ "$_dmz" = 1 ] + then + uci set firewall.@redirect[-1].dest='dmz' + else + uci set firewall.@redirect[-1].dest='lan' + fi + uci set firewall.@redirect[-1].dest_ip="$_static_ip" + uci set firewall.@redirect[-1].target="DNAT" + uci set firewall.@redirect[-1].name="anlix_forward_$((_forward_idx++))" + + #IPV6 + if [ ! -z "$_static_ipv6" ] + then + uci add firewall rule > /dev/null + uci set firewall.@rule[-1].src='wan' + uci set firewall.@rule[-1].proto='tcpudp' + uci set firewall.@rule[-1].dest='lan' + uci set firewall.@rule[-1].dest_ip="::$_static_ipv6/::ffff" + uci set firewall.@rule[-1].dest_port="$_port" + uci set firewall.@rule[-1].family='ipv6' + uci set firewall.@rule[-1].target='ACCEPT' + uci set firewall.@rule[-1].name="anlix_forward_$((_forward_idx++))" + fi + + done + json_select ".." + json_select ".." + done + json_close_object + + touch /etc/ethers + # Restore ethers file + if [ -f /etc/ethers_port_forward ] + then + cat /etc/ethers_port_forward >> /etc/ethers + fi + if [ -f /etc/ethers_upnp_devices ] + then + while read _fixed_line + do + _fixed_mac="$(echo "$_fixed_line" | awk '{print $1}')" + grep -q -i "$_fixed_mac" /etc/ethers + _retstatus=$? + if [ ! $_retstatus -eq 0 ] + then + echo "$_fixed_line" >> /etc/ethers + fi + done < /etc/ethers_upnp_devices + fi + + uci commit firewall + /etc/init.d/dnsmasq reload + /etc/init.d/firewall reload + + # Save index + json_update_index "$_flash_idx" "forward_index" + fi } update_blocked_devices() { - local _blocked_devices="$1" - local _blocked_macs="$2" - local _blocked_devices_index="$3" - - # Blocked devices firewall update - always do this to avoid file diff logic - log "FLASHMAN UPDATER" "Rewriting user firewall rules ..." - rm /etc/firewall.user - touch /etc/firewall.user - echo -n "$_blocked_devices" > /tmp/blacklist_mac - for mac in $_blocked_macs - do - echo "iptables -I FORWARD -m mac --mac-source $mac -j DROP" >> \ - /etc/firewall.user - echo "ip6tables -I FORWARD -m mac --mac-source $mac -j DROP" >> \ - /etc/firewall.user - done - /etc/init.d/firewall restart - /etc/init.d/odhcpd restart # Must restart to fix IPv6 leasing - - # Save index - json_update_index "$_blocked_devices_index" "blocked_devices_index" + local _blocked_devices="$1" + local _blocked_macs="$2" + local _blocked_devices_index="$3" + + # Blocked devices firewall update - always do this to avoid file diff logic + log "FLASHMAN UPDATER" "Rewriting user firewall rules ..." + rm /etc/firewall.user + touch /etc/firewall.user + echo -n "$_blocked_devices" > /tmp/blacklist_mac + for mac in $_blocked_macs + do + echo "iptables -I FORWARD -m mac --mac-source $mac -j DROP" >> \ + /etc/firewall.user + echo "ip6tables -I FORWARD -m mac --mac-source $mac -j DROP" >> \ + /etc/firewall.user + done + /etc/init.d/firewall restart + [ "$(get_ipv6_enabled)" != "0" ] && /etc/init.d/odhcpd restart # Must restart to fix IPv6 leasing + + # Save index + json_update_index "$_blocked_devices_index" "blocked_devices_index" +} + +update_upnp_devices() { + log "UPNP SERVICE" "Requesting Flashman ..." + local _data="id=$(get_mac)" + local _url="deviceinfo/get/upnpdevices/" + local _res + local _retstatus + _res=$(rest_flashman "$_url" "$_data") + _retstatus=$? + + if [ $_retstatus -eq 0 ] + then + json_cleanup + json_load "$_res" + json_get_var _upnp_idx upnp_devices_index + + [ -f /etc/ethers ] && rm /etc/ethers + [ -f /etc/ethers_upnp_devices ] && rm /etc/ethers_upnp_devices + [ -f /etc/enabled_upnp_devices ] && rm /etc/enabled_upnp_devices + # Reset IGP and NAT-PMP permissions + cp /rom/etc/config/upnpd /etc/config/upnpd + + json_select upnp_devices + local _rule_idx="1" + while json_get_type _rule_type $_rule_idx && [ "$_rule_type" = object ] + do + json_select "$((_rule_idx++))" + json_get_var _mac mac + json_get_var _dmz dmz + json_get_var _upnp upnp + if [ "$_upnp" = "accept" ] + then + local _static_ip + # Check if device has already a fixed ip due to port forward + grep -q -i "$_mac" /etc/ethers_port_forward 2>/dev/null + _retstatus=$? + if [ ! $_retstatus -eq 0 ] + then + _static_ip=$(add_static_ip "$_mac" "$_dmz" "ethers_upnp_devices") + else + local _line=$(grep -i "$_mac" /etc/ethers_port_forward) + _static_ip=$(echo "$_line" | awk '{print $2}') + echo "$_line" >> /etc/ethers_upnp_devices + fi + # Include upnp condition of selected device + echo "$_mac,$_static_ip" >> /etc/enabled_upnp_devices + # Allow IGP for device + uci add upnpd perm_rule > /dev/null + uci set upnpd.@perm_rule[-1].action='allow' + uci set upnpd.@perm_rule[-1].ext_ports='0-65535' + uci set upnpd.@perm_rule[-1].int_ports='0-65535' + uci set upnpd.@perm_rule[-1].int_addr="$_static_ip/32" + uci reorder upnpd.@perm_rule[-1]=1 + uci commit upnpd + fi + + json_select ".." + done + json_close_object + + touch /etc/ethers + # Restore ethers file + if [ -f /etc/ethers_upnp_devices ] + then + cat /etc/ethers_upnp_devices >> /etc/ethers + fi + if [ -f /etc/ethers_port_forward ] + then + while read _fixed_line + do + _fixed_mac="$(echo "$_fixed_line" | awk '{print $1}')" + grep -q -i "$_fixed_mac" /etc/ethers + _retstatus=$? + if [ ! $_retstatus -eq 0 ] + then + echo "$_fixed_line" >> /etc/ethers + fi + done < /etc/ethers_port_forward + fi + + /etc/init.d/dnsmasq reload + /etc/init.d/miniupnpd restart + + # Save index + json_update_index "$_upnp_idx" "upnp_devices_index" + fi +} + +drop_all_forward_traffic() { + iptables -I FORWARD -j DROP + ip6tables -I FORWARD -j DROP +} + +undrop_all_forward_traffic() { + iptables -D FORWARD -j DROP + ip6tables -D FORWARD -j DROP } diff --git a/files/usr/share/functions/network_functions.sh b/files/usr/share/functions/network_functions.sh index 1c2beef0..1130482b 100644 --- a/files/usr/share/functions/network_functions.sh +++ b/files/usr/share/functions/network_functions.sh @@ -5,400 +5,1159 @@ . /usr/share/functions/dhcp_functions.sh . /usr/share/libubox/jshn.sh . /lib/functions/network.sh +. /usr/share/functions/device_functions.sh + +get_ipv6_enabled() { + local _ipv6_enabled=1 + if [ "$(get_bridge_mode_status)" != "y" ] + then + [ "$(uci -q get network.wan.ipv6)" = "0" ] && _ipv6_enabled=0 + else + [ "$(uci -q get network.lan.ipv6)" = "0" ] && _ipv6_enabled=0 + fi + echo "$_ipv6_enabled" +} + +enable_ipv6() { + if [ "$(get_bridge_mode_status)" != "y" ] + then + uci set network.wan.ipv6="auto" + uci set network.wan6.proto="dhcpv6" + [ "$(uci -q get network.lan.ipv6)" ] && uci delete network.lan.ipv6 + [ "$(uci -q get network.lan6)" ] && uci delete network.lan6 + else + uci set network.wan.ipv6="auto" + uci set network.wan6.proto="none" + uci set network.lan.ipv6="auto" + if [ -z "$(uci -q get network.lan6)" ] + then + uci set network.lan6=interface + uci set network.lan6.ifname='@lan' + fi + uci set network.lan6.proto='dhcpv6' + fi + uci commit network + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string enable_ipv6 "1" + json_dump > /root/flashbox_config.json + json_close_object +} + +disable_ipv6() { + uci set network.wan.ipv6="0" + uci set network.wan6.proto='none' + uci set network.lan.ipv6="0" + [ "$(uci -q get network.lan6)" ] && uci delete network.lan6 + uci commit network + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string enable_ipv6 "0" + json_dump > /root/flashbox_config.json + json_close_object +} + + +diagnose_wan_connectivity() { + local _status="" + local _ip="" + local _gateway="" + local _hasconn="" + if [ "$(get_bridge_mode_status)" != "y" ] + then + # Not in bridge mode, WAN must be configured + _status="$(ifstatus wan)" + else + # Bridge mode enabled, WAN is not configured, so we use the LAN as a base + _status="$(ifstatus lan)" + fi + _ip="$(echo "$_status" | jsonfilter -e '@["ipv4-address"][0].address')" + _gateway="$(echo "$_status" | jsonfilter -e '@["route"][0].nexthop')" + if [ "$_ip" = "" ] + then + echo 1 + return + fi + if [ "$_gateway" = "" ] + then + echo 2 + return + fi + _hasconn="$(check_connectivity_internet $_gateway)" + if [ "$_hasconn" != "0" ] + then + echo 3 + return + fi + echo 0 + return +} + +check_connectivity_ipv4() { + local _addrs="8.8.8.8"$'\n'"200.132.0.132" + check_connectivity_internet "$_addrs" +} + +check_connectivity_ipv6() { + local _ip="2001:4860:4860::8888" + local _ipv6_connectivity=1 + + if [ "$(get_ipv6_enabled)" != "0" ] + then + if ping6 -q -c 1 -w 2 "$_ip" > /dev/null 2>&1 + then + _ipv6_connectivity=0 + fi + fi + echo $_ipv6_connectivity +} + +check_connectivity_flashman() { + _addrs="$FLM_SVADDR" + check_connectivity_internet "$_addrs" +} + +check_connectivity_internet() { + _addrs="www.google.com.br"$'\n'"www.facebook.com"$'\n'"www.globo.com" + if [ "$1" != "" ] + then + _addrs="$1" + fi + for _addr in $_addrs + do + if ping -q -c 1 -w 2 "$_addr" > /dev/null 2>&1 + then + # true + echo 0 + return + fi + done + # No successfull pings + + # false + echo 1 + return +} + +renew_dhcp() { + local _iface="wan" + [ "$(get_bridge_mode_status)" = "y" ] && _iface="lan" + local _proto="$(ifstatus $_iface | jsonfilter -e '@.proto')" + [ "$_proto" = "dhcp" ] && ubus call "network.interface.$_iface" renew +} get_wan_ip() { - local _ip="" - network_get_ipaddr _ip wan - echo "$_ip" + local _ip="" + if [ "$(get_bridge_mode_status)" != "y" ] + then + network_get_ipaddr _ip wan + else + # Do not write "none" in case of bridge + _ip="$(get_lan_bridge_ipaddr)" + fi + echo "$_ip" } get_wan_type() { - echo "$(uci get network.wan.proto | awk '{ print tolower($1) }')" + echo "$(uci get network.wan.proto | awk '{ print tolower($1) }')" } set_wan_type() { - local _wan_type=$(get_wan_type) - local _wan_type_remote=$1 - local _pppoe_user_remote=$2 - local _pppoe_password_remote=$3 + local _wan_type=$(get_wan_type) + local _wan_type_remote=$1 + local _pppoe_user_remote=$2 + local _pppoe_password_remote=$3 + local _wait_uhttpd_reply=$4 # TODO: Find a better way to solve this + local _did_change_bridge="n" - if [ "$_wan_type_remote" != "$_wan_type" ] - then - if [ "$_wan_type_remote" = "dhcp" ] - then - log "FLASHMAN UPDATER" "Updating connection type to DHCP ..." - uci set network.wan.proto="dhcp" - uci set network.wan.username="" - uci set network.wan.password="" - uci set network.wan.service="" - uci commit network - - /etc/init.d/network restart - /etc/init.d/odhcpd restart # Must restart to fix IPv6 leasing - - # This will persist connection type between firmware upgrades - json_cleanup - json_load_file /root/flashbox_config.json - json_add_string wan_conn_type "dhcp" - json_add_string pppoe_user "" - json_add_string pppoe_pass "" - json_dump > /root/flashbox_config.json - json_close_object - elif [ "$_wan_type_remote" = "pppoe" ] - then - if [ "$_pppoe_user_remote" != "" ] && [ "$_pppoe_password_remote" != "" ] - then - log "FLASHMAN UPDATER" "Updating connection type to PPPOE ..." - uci set network.wan.proto="pppoe" - uci set network.wan.username="$_pppoe_user_remote" - uci set network.wan.password="$_pppoe_password_remote" - uci set network.wan.service="$FLM_WAN_PPPOE_SERVICE" - uci set network.wan.keepalive="60 3" - uci commit network - - /etc/init.d/network restart - /etc/init.d/odhcpd restart # Must restart to fix IPv6 leasing - - # This will persist connection type between firmware upgrades - json_cleanup - json_load_file /root/flashbox_config.json - json_add_string wan_conn_type "pppoe" - json_add_string pppoe_user "$_pppoe_user_remote" - json_add_string pppoe_pass "$_pppoe_password_remote" - json_dump > /root/flashbox_config.json - json_close_object - fi - fi - # Don't put anything outside here. _content_type may be corrupted - fi + if [ "$_wait_uhttpd_reply" = "y" ] + then + sleep 3 + fi + + if [ "$_wan_type" = "none" ] + then + # Must disable bridge mode before changing wan configuration + log "FLASHMAN UPDATER" "Disabling bridge mode to change WAN config ..." + disable_bridge_mode "y" + _did_change_bridge="y" + fi + + if [ "$_wan_type_remote" != "$_wan_type" ] + then + if [ "$_wan_type_remote" = "dhcp" ] + then + log "FLASHMAN UPDATER" "Updating connection type to DHCP ..." + uci set network.wan.proto="dhcp" + uci set network.wan.username="" + uci set network.wan.password="" + uci set network.wan.service="" + uci commit network + + /etc/init.d/network restart + [ "$(get_ipv6_enabled)" != "0" ] && /etc/init.d/odhcpd restart # Must restart to fix IPv6 leasing + + # This will persist connection type between firmware upgrades + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string wan_conn_type "dhcp" + json_add_string pppoe_user "" + json_add_string pppoe_pass "" + json_dump > /root/flashbox_config.json + json_close_object + + # If we changed bridge and router needs reboot, we do so here + if [ "$_did_change_bridge" = "y" ] && [ "$(type -t needs_reboot_bridge_mode)" ] + then + needs_reboot_bridge_mode + fi + + elif [ "$_wan_type_remote" = "pppoe" ] + then + if [ "$_pppoe_user_remote" != "" ] && [ "$_pppoe_password_remote" != "" ] + then + log "FLASHMAN UPDATER" "Updating connection type to PPPOE ..." + uci set network.wan.proto="pppoe" + uci set network.wan.username="$_pppoe_user_remote" + uci set network.wan.password="$_pppoe_password_remote" + uci set network.wan.service="$FLM_WAN_PPPOE_SERVICE" + uci set network.wan.keepalive="60 3" + uci commit network + + /etc/init.d/network restart + [ "$(get_ipv6_enabled)" != "0" ] && /etc/init.d/odhcpd restart # Must restart to fix IPv6 leasing + + # This will persist connection type between firmware upgrades + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string wan_conn_type "pppoe" + json_add_string pppoe_user "$_pppoe_user_remote" + json_add_string pppoe_pass "$_pppoe_password_remote" + json_dump > /root/flashbox_config.json + json_close_object + + # If we changed bridge and router needs reboot, we do so here + if [ "$_did_change_bridge" = "y" ] && [ "$(type -t needs_reboot_bridge_mode)" ] + then + needs_reboot_bridge_mode + fi + + fi + fi + # Don't put anything outside here. _content_type may be corrupted + fi } set_pppoe_credentials() { - local _wan_type=$(get_wan_type) - local _pppoe_user_remote=$1 - local _pppoe_password_remote=$2 - local _pppoe_user_local=$(uci -q get network.wan.username) - local _pppoe_password_local=$(uci -q get network.wan.password) + local _wan_type=$(get_wan_type) + local _pppoe_user_remote=$1 + local _pppoe_password_remote=$2 + local _wait_uhttpd_reply=$3 # TODO: Find a better way to solve this + local _pppoe_user_local=$(uci -q get network.wan.username) + local _pppoe_password_local=$(uci -q get network.wan.password) - if [ "$_wan_type" = "pppoe" ] - then - if [ "$_pppoe_user_remote" != "" ] && [ "$_pppoe_password_remote" != "" ] - then - if [ "$_pppoe_user_remote" != "$_pppoe_user_local" ] || \ - [ "$_pppoe_password_remote" != "$_pppoe_password_local" ] - then - log "FLASHMAN UPDATER" "Updating PPPoE ..." - uci set network.wan.username="$_pppoe_user_remote" - uci set network.wan.password="$_pppoe_password_remote" - uci commit network - - /etc/init.d/network restart - /etc/init.d/odhcpd restart # Must restart to fix IPv6 leasing - - # This will persist connection type between firmware upgrades - json_cleanup - json_load_file /root/flashbox_config.json - json_add_string wan_conn_type "pppoe" - json_add_string pppoe_user "$_pppoe_user_remote" - json_add_string pppoe_pass "$_pppoe_password_remote" - json_dump > /root/flashbox_config.json - json_close_object - fi - fi - fi + if [ "$_wait_uhttpd_reply" = "y" ] + then + sleep 3 + fi + + if [ "$_wan_type" = "pppoe" ] + then + if [ "$_pppoe_user_remote" != "" ] && [ "$_pppoe_password_remote" != "" ] + then + if [ "$_pppoe_user_remote" != "$_pppoe_user_local" ] || \ + [ "$_pppoe_password_remote" != "$_pppoe_password_local" ] + then + log "FLASHMAN UPDATER" "Updating PPPoE ..." + uci set network.wan.username="$_pppoe_user_remote" + uci set network.wan.password="$_pppoe_password_remote" + uci commit network + + /etc/init.d/network restart + [ "$(get_ipv6_enabled)" != "0" ] && /etc/init.d/odhcpd restart # Must restart to fix IPv6 leasing + + # This will persist connection type between firmware upgrades + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string wan_conn_type "pppoe" + json_add_string pppoe_user "$_pppoe_user_remote" + json_add_string pppoe_pass "$_pppoe_password_remote" + json_dump > /root/flashbox_config.json + json_close_object + fi + fi + fi } valid_ip() { - local ip=$1 - local filtered_ip - local stat=1 - local b1 - local b2 - local b3 - local b4 - - filtered_ip=$(printf "%s\n" "$ip" | - grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$') - - if [ "$filtered_ip" != "" ] - then - b1="$(echo $ip | awk -F. '{print $1}')" - b2="$(echo $ip | awk -F. '{print $2}')" - b3="$(echo $ip | awk -F. '{print $3}')" - b4="$(echo $ip | awk -F. '{print $4}')" + local ip=$1 + local filtered_ip + local stat=1 + local b1 + local b2 + local b3 + local b4 - [[ $b1 -le 255 && $b2 -le 255 && $b3 -le 255 && $b4 -le 255 ]] - stat=$? - fi - return $stat + filtered_ip=$(printf "%s\n" "$ip" | + grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$') + + if [ "$filtered_ip" != "" ] + then + b1="$(echo $ip | awk -F. '{print $1}')" + b2="$(echo $ip | awk -F. '{print $2}')" + b3="$(echo $ip | awk -F. '{print $3}')" + b4="$(echo $ip | awk -F. '{print $4}')" + + [[ $b1 -le 255 && $b2 -le 255 && $b3 -le 255 && $b4 -le 255 ]] + stat=$? + fi + return $stat } get_lan_subnet() { - local _ipcalc_res - local _uci_lan_ipaddr - local _uci_lan_netmask - local _lan_addr - _uci_lan_ipaddr=$(uci get network.lan.ipaddr) - _uci_lan_netmask=$(uci get network.lan.netmask) - _ipcalc_res="$(/bin/ipcalc.sh $_uci_lan_ipaddr $_uci_lan_netmask)" - _lan_addr="$(echo "$_ipcalc_res" | grep "NETWORK" | awk -F= '{print $2}')" + local _ipcalc_res + local _uci_lan_ipaddr + local _uci_lan_netmask + local _lan_addr + _uci_lan_ipaddr=$(uci get network.lan.ipaddr) + _uci_lan_netmask=$(uci get network.lan.netmask) + _ipcalc_res="$(/bin/ipcalc.sh $_uci_lan_ipaddr $_uci_lan_netmask)" + _lan_addr="$(echo "$_ipcalc_res" | grep "NETWORK" | awk -F= '{print $2}')" + + echo "$_lan_addr" +} + +get_lan_bridge_ipaddr() { + echo "$(ifstatus lan | jsonfilter -e '@["ipv4-address"][0]["address"]')" +} - echo "$_lan_addr" +get_lan_ipaddr() { + local _uci_lan_ipaddr + _uci_lan_ipaddr=$(uci get network.lan.ipaddr) + echo "$_uci_lan_ipaddr" } get_lan_netmask() { - local _ipcalc_res - local _uci_lan_ipaddr - local _uci_lan_netmask - local _lan_netmask - _uci_lan_ipaddr=$(uci get network.lan.ipaddr) - _uci_lan_netmask=$(uci get network.lan.netmask) - _ipcalc_res="$(/bin/ipcalc.sh $_uci_lan_ipaddr $_uci_lan_netmask)" - _lan_netmask="$(echo "$_ipcalc_res" | grep "PREFIX" | awk -F= '{print $2}')" + local _ipcalc_res + local _uci_lan_ipaddr + local _uci_lan_netmask + local _lan_netmask + _uci_lan_ipaddr=$(uci get network.lan.ipaddr) + _uci_lan_netmask=$(uci get network.lan.netmask) + _ipcalc_res="$(/bin/ipcalc.sh $_uci_lan_ipaddr $_uci_lan_netmask)" + _lan_netmask="$(echo "$_ipcalc_res" | grep "PREFIX" | awk -F= '{print $2}')" - echo "$_lan_netmask" + echo "$_lan_netmask" } set_lan_subnet() { - local _lan_addr - local _lan_netmask - local _lan_net - local _retstatus - local _ipcalc_res - local _ipcalc_netmask - local _ipcalc_addr - local _current_lan_net=$(get_lan_subnet) - _lan_addr=$1 - _lan_netmask=$2 - - # Validate LAN gateway address - valid_ip "$_lan_addr" - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _ipcalc_res="$(/bin/ipcalc.sh $_lan_addr $_lan_netmask 1 255)" - - _ipcalc_netmask=$(echo "$_ipcalc_res" | grep "PREFIX" | \ - awk -F= '{print $2}') - # Accepted netmasks: 24 to 26 - if [ $_ipcalc_netmask -ge 24 ] && [ $_ipcalc_netmask -le 26 ] - then - # Valid netmask - _lan_netmask="$_ipcalc_netmask" - # Use first address available returned by ipcalc - _ipcalc_addr=$(echo "$_ipcalc_res" | grep "START" | awk -F= '{print $2}') - _lan_addr="$_ipcalc_addr" - _lan_net=$(echo "$_ipcalc_res" | grep "NETWORK" | awk -F= '{print $2}') - # Calculate DHCP start and limit - _addr_net=$(echo "$_ipcalc_res" | grep "NETWORK" | awk -F. '{print $4}') - _addr_end=$(echo "$_ipcalc_res" | grep "END" | awk -F. '{print $4}') - _addr_limit=$(( (_addr_end - _addr_net) / 2 )) - _addr_start=$(( _addr_end - _addr_limit )) - - # DMZ lan is forbidden - local _dmzprefix="$(echo $_lan_net | awk -F. '{print $1$2$3}')" - if [ "$_dmzprefix" = "19216843" ] - then - # Error. DMZ is forbidden - return 1 - fi - - # Only change LAN if its not the same - if [ "$_lan_net" != "$_current_lan_net" ] - then - uci set network.lan.ipaddr="$_lan_addr" - uci set network.lan.netmask="$_lan_netmask" - uci commit network - uci set dhcp.lan.start="$_addr_start" - uci set dhcp.lan.limit="$_addr_limit" - uci commit dhcp - - # Replace IP so Flash App can find the router - sed -i 's/.*anlixrouter/'"$_lan_addr"' anlixrouter/' /etc/hosts - - /etc/init.d/network restart - /etc/init.d/odhcpd restart # Must restart to fix IPv6 leasing - /etc/init.d/dnsmasq reload - /etc/init.d/uhttpd restart # Must restart to update Flash App API - - # Save LAN config - json_cleanup - json_load_file /root/flashbox_config.json - json_add_string lan_addr "$_lan_net" - json_add_string lan_netmask "$_lan_netmask" - json_dump > /root/flashbox_config.json - json_close_object - - return 0 - else - # No change - return 1 - fi - else - # Parse error - return 1 - fi - else - # Parse error - return 1 - fi + local _lan_addr + local _lan_netmask + local _lan_net + local _retstatus + local _ipcalc_res + local _ipcalc_netmask + local _ipcalc_addr + local _current_lan_ipaddr=$(get_lan_ipaddr) + _lan_addr=$1 + _lan_netmask=$2 + + # Validate LAN gateway address + valid_ip "$_lan_addr" + _retstatus=$? + if [ $_retstatus -eq 0 ] + then + _ipcalc_res="$(/bin/ipcalc.sh $_lan_addr $_lan_netmask 1 255)" + + _ipcalc_netmask=$(echo "$_ipcalc_res" | grep "PREFIX" | \ + awk -F= '{print $2}') + # Accepted netmasks: 24 to 26 + if [ $_ipcalc_netmask -ge 24 ] && [ $_ipcalc_netmask -le 26 ] + then + # Valid netmask + _lan_netmask="$_ipcalc_netmask" + # Use first address available returned by ipcalc + _ipcalc_addr=$(echo "$_ipcalc_res" | grep "IP" | awk -F= '{print $2}') + _lan_net=$(echo "$_ipcalc_res" | grep "NETWORK" | awk -F= '{print $2}') + # Avoid placing subnet IP by mistake + if [ "$_lan_net" = "$_ipcalc_addr" ] + then + _ipcalc_addr=$(echo "$_ipcalc_res" | grep "START" | awk -F= '{print $2}') + fi + # Assign LAN router ip + _lan_addr="$_ipcalc_addr" + # Calculate DHCP start and limit + _addr_net=$(echo "$_ipcalc_res" | grep "NETWORK" | awk -F. '{print $4}') + _addr_end=$(echo "$_ipcalc_res" | grep "END" | awk -F. '{print $4}') + _addr_limit=$(( (_addr_end - _addr_net) / 2 )) + _addr_start=$(( _addr_end - _addr_limit )) + + # DMZ lan is forbidden + local _dmzprefix="$(echo $_lan_net | awk -F. '{print $1$2$3}')" + if [ "$_dmzprefix" = "19216843" ] + then + # Error. DMZ is forbidden + return 1 + fi + + # Only change LAN if its not the same + if [ "$_lan_addr" != "$_current_lan_ipaddr" ] + then + uci set network.lan.ipaddr="$_lan_addr" + uci set network.lan.netmask="$_lan_netmask" + uci commit network + uci set dhcp.lan.start="$_addr_start" + uci set dhcp.lan.limit="$_addr_limit" + uci commit dhcp + + # Replace IP so Flash App can find the router + sed -i 's/.*anlixrouter/'"$_lan_addr"' anlixrouter/' /etc/hosts + + /etc/init.d/network restart + [ "$(get_ipv6_enabled)" != "0" ] && /etc/init.d/odhcpd restart # Must restart to fix IPv6 leasing + /etc/init.d/dnsmasq reload + /etc/init.d/uhttpd restart # Must restart to update Flash App API + /etc/init.d/minisapo reload + /etc/init.d/miniupnpd reload + + # Save LAN config + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string lan_addr "$_lan_net" + json_add_string lan_netmask "$_lan_netmask" + json_dump > /root/flashbox_config.json + json_close_object + + return 0 + else + # No change + return 1 + fi + else + # Parse error + return 1 + fi + else + # Parse error + return 1 + fi } # Arg 1: IP address to check, Arg 2: LAN subnet, Arg 3: LAN netmask is_ip_in_lan() { - local _device_ip - local _lan_subnet - local _lan_netmask - local _ipcalc_res - local _ipcalc_addr + local _device_ip + local _lan_subnet + local _lan_netmask + local _ipcalc_res + local _ipcalc_addr - if [ $# -eq 3 ] && [ "$1" ] - then - _device_ip=$1 - _lan_subnet=$2 - _lan_netmask=$3 - _ipcalc_res="$(/bin/ipcalc.sh $_lan_subnet $_lan_netmask $_device_ip)" - _ipcalc_addr=$(echo "$_ipcalc_res" | grep "START" | awk -F= '{print $2}') - if [ "$_ipcalc_addr" = "$_device_ip" ] - then - # IP belongs to LAN subnet - return 0 - else - # No match - return 1 - fi - else - # Error - return 1 - fi + if [ $# -eq 3 ] && [ "$1" ] + then + _device_ip=$1 + _lan_subnet=$2 + _lan_netmask=$3 + _ipcalc_res="$(/bin/ipcalc.sh $_lan_subnet $_lan_netmask $_device_ip)" + _ipcalc_addr=$(echo "$_ipcalc_res" | grep "START" | awk -F= '{print $2}') + if [ "$_ipcalc_addr" = "$_device_ip" ] + then + # IP belongs to LAN subnet + return 0 + else + # No match + return 1 + fi + else + # Error + return 1 + fi } add_static_ipv6() { - local _mac=$1 - - # do not create new entry - local i=0 - local _idtmp=$(uci -q get dhcp.@host[$i].mac) - while [ $? -eq 0 ]; do - if [ "$_idtmp" = "$_mac" ] - then - local _addr=$(uci -q get dhcp.@host[$i].hostid) - if [ ! -z "$_addr" ] - then - echo "$_addr" - return - fi - fi - i=$((i+1)) - _idtmp=$(uci -q get dhcp.@host[$i].mac) - done - - # no entry found, create new - local _dhcp_ipv6=$(get_ipv6_dhcp | grep "$_mac") - if [ ! -z "$_dhcp_ipv6" ] - then - for _i6 in "$_dhcp_ipv6" - do - local _duid=$(echo $_i6 | awk '{print $1}') - local _addr=$(echo $_i6 | awk '{print $3}') - - uci -q add dhcp host > /dev/null - uci -q set dhcp.@host[-1].mac="$_mac" - uci -q set dhcp.@host[-1].duid="$_duid" - uci -q set dhcp.@host[-1].hostid="${_addr#*::}" - uci -q commit dhcp - - #return just the first - echo "${_addr#*::}" - return - done - fi + local _mac=$1 + + # do not create new entry + local i=0 + local _idtmp=$(uci -q get dhcp.@host[$i].mac) + while [ $? -eq 0 ]; do + if [ "$_idtmp" = "$_mac" ] + then + local _addr=$(uci -q get dhcp.@host[$i].hostid) + if [ ! -z "$_addr" ] + then + echo "$_addr" + return + fi + fi + i=$((i+1)) + _idtmp=$(uci -q get dhcp.@host[$i].mac) + done + + # no entry found, create new + local _dhcp_ipv6=$(get_ipv6_dhcp | grep "$_mac") + if [ -n "$_dhcp_ipv6" ] + then + local _duid=$(echo "$_dhcp_ipv6" | awk '{print $1}') + local _addr=$(echo "$_dhcp_ipv6" | awk '{print $3}') + + uci -q add dhcp host > /dev/null + uci -q set dhcp.@host[-1].mac="$_mac" + uci -q set dhcp.@host[-1].duid="$_duid" + uci -q set dhcp.@host[-1].hostid="${_addr#*::}" + uci -q commit dhcp + + #return just the first + echo "${_addr#*::}" + fi } add_static_ip() { - local _mac=$1 - local _dmz=$2 - local _device_ip=$(grep "$_mac" /tmp/dhcp.leases | awk '{print $3}') - local _lan_subnet=$(get_lan_subnet) - local _lan_netmask=$(get_lan_netmask) - local _dmz_subnet="192.168.43.0" - local _dmz_netmask="24" - local _device_on_lan - local _device_on_dmz - local _fixed_ip - local _ipcalc_res - local _next_addr="" - - is_ip_in_lan "$_device_ip" "$_lan_subnet" "$_lan_netmask" - _device_on_lan=$? - is_ip_in_lan "$_device_ip" "$_dmz_subnet" "$_dmz_netmask" - _device_on_dmz=$? - - # Device is online. Use the same ip address - if [ "$_device_ip" ] - then - if { [ "$_dmz" = "1" ] && [ $_device_on_dmz -eq 0 ]; } || \ - { [ "$_dmz" = "0" ] && [ $_device_on_lan -eq 0 ]; } - then - echo "$_mac $_device_ip" >> /etc/ethers - echo "$_device_ip" - return - fi - fi + local _mac=$1 + local _dmz=$2 + local _ethers_file="$3" + local _ipv4_neigh="$(ip -4 neigh | grep lladdr | awk '{ if($3 == "br-lan") print $5, $1}')" + local _device_ip="$(echo "$_ipv4_neigh" | grep "$_mac" | awk '{ print $2 }')" + local _lan_subnet=$(get_lan_subnet) + local _lan_netmask=$(get_lan_netmask) + local _dmz_subnet="192.168.43.0" + local _dmz_netmask="24" + local _device_on_lan + local _device_on_dmz + local _fixed_ip + local _ipcalc_res + local _next_addr="" + + is_ip_in_lan "$_device_ip" "$_lan_subnet" "$_lan_netmask" + _device_on_lan=$? + is_ip_in_lan "$_device_ip" "$_dmz_subnet" "$_dmz_netmask" + _device_on_dmz=$? + + # Device is online. Use the same ip address + if [ "$_device_ip" ] + then + if { [ "$_dmz" = "1" ] && [ $_device_on_dmz -eq 0 ]; } || \ + { [ "$_dmz" = "0" ] && [ $_device_on_lan -eq 0 ]; } + then + echo "$_mac $_device_ip" >> /etc/$_ethers_file + echo "$_device_ip" + return + fi + fi + + # Device is offline. Choose an ip address + if [ "$_dmz" = "1" ] + then + if [ -f /etc/$_ethers_file ] + then + while read _fixed_ip + do + _fixed_ip="$(echo "$_fixed_ip" | awk '{print $2}')" + is_ip_in_lan "$_fixed_ip" "$_dmz_subnet" "$_dmz_netmask" + if [ $? -eq 0 ] + then + _ipcalc_res="$(/bin/ipcalc.sh $_dmz_subnet \ + $_dmz_netmask $_fixed_ip 1)" + _next_addr="$(echo "$_ipcalc_res" | grep "END" | \ + awk -F= '{print $2}')" + fi + done < /etc/$_ethers_file + if [ "$_next_addr" = "" ] + then + # It must start at 130 to isolate routes + _ipcalc_res="$(/bin/ipcalc.sh $_dmz_subnet $_dmz_netmask 1 129)" + _next_addr="$(echo "$_ipcalc_res" | grep "END" | awk -F= '{print $2}')" + fi + else + # It must start at 130 to isolate routes + _ipcalc_res="$(/bin/ipcalc.sh $_dmz_subnet $_dmz_netmask 1 129)" + _next_addr="$(echo "$_ipcalc_res" | grep "END" | awk -F= '{print $2}')" + fi + else + if [ -f /etc/$_ethers_file ] + then + while read _fixed_ip + do + _fixed_ip="$(echo "$_fixed_ip" | awk '{print $2}')" + is_ip_in_lan "$_fixed_ip" "$_lan_subnet" "$_lan_netmask" + if [ $? -eq 0 ] + then + _ipcalc_res="$(/bin/ipcalc.sh $_lan_subnet \ + $_lan_netmask $_fixed_ip 1)" + _next_addr="$(echo "$_ipcalc_res" | grep "END" | \ + awk -F= '{print $2}')" + fi + done < /etc/$_ethers_file + if [ "$_next_addr" = "" ] + then + _ipcalc_res="$(/bin/ipcalc.sh $_lan_subnet $_lan_netmask 1 1)" + _next_addr="$(echo "$_ipcalc_res" | grep "END" | awk -F= '{print $2}')" + fi + else + _ipcalc_res="$(/bin/ipcalc.sh $_lan_subnet $_lan_netmask 1 1)" + _next_addr="$(echo "$_ipcalc_res" | grep "END" | awk -F= '{print $2}')" + fi + fi + echo "$_mac $_next_addr" >> /etc/$_ethers_file + echo "$_next_addr" +} + +get_use_dns_proxy() { + local _current_dnsproxy + + _current_dnsproxy="$(uci get dhcp.@dnsmasq[0].noproxy)" + if [ $? -eq 0 ] + then + echo "$_current_dnsproxy" + else + # If not set than use default + echo "$FLM_DHCP_NOPROXY" + fi +} + +set_use_dns_proxy() { + local _no_dnsproxy + local _current_dnsproxy + + _no_dnsproxy=$1 + if [ "$_no_dnsproxy" != "1" ] && [ "$_no_dnsproxy" != "0" ] + then + # Invalid value + return + fi + + _current_dnsproxy="$(uci get dhcp.@dnsmasq[0].noproxy)" + if [ $? -eq 0 ] + then + if [ "$_current_dnsproxy" != "$_no_dnsproxy" ] + then + if [ "$_no_dnsproxy" == "1" ] + then + uci set dhcp.@dnsmasq[0].noproxy='1' + else + uci set dhcp.@dnsmasq[0].noproxy='0' + fi + uci commit dhcp + /etc/init.d/dnsmasq reload + [ "$(get_ipv6_enabled)" != "0" ] && /etc/init.d/odhcpd reload + fi + fi + + return +} + +store_wan_bytes() { + local _wan_itf + _wan_itf=$(uci get network.wan.ifname) + + if [ $? -eq 0 ] + then + local _epoch=$(date +%s) + local _wan_rx=$(cat /sys/class/net/$_wan_itf/statistics/rx_bytes) + local _wan_tx=$(cat /sys/class/net/$_wan_itf/statistics/tx_bytes) + + json_init + + if [ -f /tmp/wanbytes.json ] + then + local _size=$(ls -l /tmp/wanbytes.json | awk '{print $5}') + if [ $_size -lt 8196 ] + then + json_load_file /tmp/wanbytes.json + json_select "wanbytes" + else + json_add_object "wanbytes" + fi + else + json_add_object "wanbytes" + fi + + json_add_array "$_epoch" + json_add_int "" "$_wan_rx" + json_add_int "" "$_wan_tx" + json_close_array + json_close_object + json_dump > /tmp/wanbytes.json + json_cleanup + fi +} + +get_bridge_mode_status() { + local _status="" + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _status bridge_mode + json_close_object + echo "$_status" +} + +enable_bridge_mode() { + local _do_network_restart=$1 + local _wait_uhttpd_reply=$2 # TODO: Find a better way to solve this + local _disable_lan_ports=$3 + local _fixed_ip=$4 + local _fixed_gateway=$5 + local _fixed_dns=$6 + + if [ "$_wait_uhttpd_reply" = "y" ] + then + sleep 3 + fi + + # Get ifnames to bridge them together + local _lan_ip="$(uci get network.lan.ipaddr)" + local _lan_ifnames="$(uci get network.lan.ifname)" + local _wan_ifnames="$(uci get network.wan.ifname)" + local _lan_ifnames_wifi="" + # Write bridge mode to config.json so it persists between flashes + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _enable_ipv6 enable_ipv6 + json_add_string bridge_mode "y" + json_add_string bridge_lan_backup "$_lan_ifnames" + json_add_string bridge_lan_ip_backup "$_lan_ip" + json_add_string bridge_disable_switch "$_disable_lan_ports" + json_add_string bridge_fix_ip "$_fixed_ip" + json_add_string bridge_fix_gateway "$_fixed_gateway" + json_add_string bridge_fix_dns "$_fixed_dns" + json_dump > /root/flashbox_config.json + json_close_object + # Disable wan and bridge interfaces in lan + uci set network.wan.proto="none" + uci set network.wan6.proto="none" + + if [ "$_enable_ipv6" = "1" ] + then + uci set network.lan.ipv6="auto" + if [ -z "$(uci -q get network.lan6)" ] + then + uci set network.lan6=interface + uci set network.lan6.ifname='@lan' + fi + uci set network.lan6.proto='dhcpv6' + else + uci set network.lan.ipv6="0" + [ "$(uci -q get network.lan6)" ] && uci delete network.lan6 + fi + + if [ "$_fixed_ip" != "" ] + then + uci set network.lan.ipaddr="$_fixed_ip" + uci set network.lan.gateway="$_fixed_gateway" + uci set network.lan.dns="$_fixed_dns" + # Replace LAN IP so Flash App can find the router + sed -i 's/.*anlixrouter/'"$_fixed_ip"' anlixrouter/' /etc/hosts + else + # LAN IP on etc/hosts will be replaced by hotplug + uci set network.lan.proto="dhcp" + fi + # Separate non-wifi interfaces to back them up + for iface in $_lan_ifnames + do + if [ "$(echo $iface | grep ra)" != "" ] + then + _lan_ifnames_wifi="$iface $_lan_ifnames_wifi" + fi + done + if [ "$(type -t keep_ifnames_in_bridge_mode)" == "" ] + then + # Enable/disable ethernet connection on LAN physical ports + if [ "$_disable_lan_ports" = "y" ] + then + uci set network.lan.ifname="$_lan_ifnames_wifi $_wan_ifnames" + else + # DO NOT PLACE WAN IFNAME BEFORE LAN IFNAME OR SOME ROUTERS WILL CRASH + uci set network.lan.ifname="$_lan_ifnames $_wan_ifnames" + fi + fi + # Some routers need to change port mapping on software switch + if [ "$(type -t set_switch_bridge_mode)" ] + then + set_switch_bridge_mode "y" "$_disable_lan_ports" + fi - # Device is offline. Choose an ip address - if [ "$_dmz" = "1" ] + # Disable dns, dhcp and dhcp6 + /etc/init.d/miniupnpd disable + /etc/init.d/miniupnpd stop + /etc/init.d/firewall disable + /etc/init.d/firewall stop + /etc/init.d/dnsmasq disable + /etc/init.d/dnsmasq stop + /etc/init.d/odhcpd disable + /etc/init.d/odhcpd stop + # Save changes and reboot network + uci commit network + if [ "$_do_network_restart" = "y" ] + then + if [ "$_fixed_ip" != "" ] + then + /etc/init.d/network restart + # Wait for network to configure itself and check connectivity + sleep 5 + _accessOK="$(check_connectivity_internet)" + if [ "$_accessOK" = "1" ] + then + # No connectivity - remove fixed ip config from bridge + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string bridge_did_reset "y" + json_add_string bridge_fix_ip "" + json_add_string bridge_fix_gateway "" + json_add_string bridge_fix_dns "" + json_dump > /root/flashbox_config.json + json_close_object + uci set network.lan.proto="dhcp" + uci set network.lan.ipaddr="" + uci set network.lan.gateway="" + uci set network.lan.dns="" + uci commit network + fi + fi + # Some targets need to reboot the whole router after changing mode + if [ "$(type -t needs_reboot_bridge_mode)" ] + then + needs_reboot_bridge_mode + else + /etc/init.d/network restart + /etc/init.d/uhttpd restart + /etc/init.d/minisapo reaload + fi + fi +} + +update_bridge_mode() { + local _wait_uhttpd_reply=$1 # TODO: Find a better way to solve this + local _disable_lan_ports=$2 + local _fixed_ip=$3 + local _fixed_gateway=$4 + local _fixed_dns=$5 + + if [ "$_wait_uhttpd_reply" = "y" ] + then + sleep 3 + fi + + local _current_switch="" + local _current_ip="" + local _current_gateway="" + local _current_dns="" + local _lan_ifnames="" + local _lan_ifnames_wifi="" + local _reset_network="n" + local _check_reboot="n" + local _wan_ifnames="$(uci get network.wan.ifname)" + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _current_switch bridge_disable_switch + json_get_var _current_ip bridge_fix_ip + json_get_var _current_gateway bridge_fix_gateway + json_get_var _current_dns bridge_fix_dns + # Update ip, gateway, dns if needed + if [ "$_current_ip" != "$_fixed_ip" ] + then + _reset_network="y" + if [ "$_fixed_ip" != "" ] + then + uci set network.lan.proto="static" + uci set network.lan.ipaddr="$_fixed_ip" + else + uci set network.lan.proto="dhcp" + fi + json_add_string bridge_fix_ip "$_fixed_ip" + fi + if [ "$_current_gateway" != "$_fixed_gateway" ] + then + uci set network.lan.gateway="$_fixed_gateway" + json_add_string bridge_fix_gateway "$_fixed_gateway" + _reset_network="y" + fi + if [ "$_current_dns" != "$_fixed_dns" ] + then + uci set network.lan.dns="$_fixed_dns" + json_add_string bridge_fix_dns "$_fixed_dns" + _reset_network="y" + fi + # Update switch disable flag if needed + if [ "$_current_switch" != "$_disable_lan_ports" ] + then + json_add_string bridge_disable_switch "$_disable_lan_ports" + json_get_var _lan_ifnames bridge_lan_backup + _reset_network="y" + _check_reboot="y" + # Separate non-wifi interfaces to back them up + for iface in $_lan_ifnames + do + if [ "$(echo $iface | grep ra)" != "" ] + then + _lan_ifnames_wifi="$iface $_lan_ifnames_wifi" + fi + done + # Enable/disable ethernet connection on LAN physical ports + if [ "$(type -t keep_ifnames_in_bridge_mode)" == "" ] + then + # Enable/disable ethernet connection on LAN physical ports + if [ "$_disable_lan_ports" = "y" ] + then + uci set network.lan.ifname="$_lan_ifnames_wifi $_wan_ifnames" + else + # DO NOT PLACE WAN IFNAME BEFORE LAN IFNAME OR SOME ROUTERS WILL CRASH + uci set network.lan.ifname="$_lan_ifnames $_wan_ifnames" + fi + fi + # Some routers need to change port mapping on software switch + if [ "$(type -t set_switch_bridge_mode)" ] + then + set_switch_bridge_mode "y" "$_disable_lan_ports" + fi + fi + json_dump > /root/flashbox_config.json + json_close_object + if [ "$_reset_network" = "y" ] + then + log "FLASHMAN UPDATER" "Updated parameters, restarting network..." + uci commit network + /etc/init.d/network restart + if [ "$_fixed_ip" != "" ] + then + /etc/init.d/uhttpd restart + # Wait for network to configure itself and check connectivity + sleep 5 + _accessOK="$(check_connectivity_internet)" + if [ "$_accessOK" = "1" ] + then + # No connectivity - remove fixed ip config from bridge + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string bridge_did_reset "y" + json_dump > /root/flashbox_config.json + json_close_object + update_bridge_mode "n" "$2" "" "" "" + fi + fi + # Some targets need to reboot the whole router after changes on switch + if [ "$(type -t needs_reboot_bridge_mode)" ] && [ "$_check_reboot" == "y" ] + then + needs_reboot_bridge_mode + fi + /etc/init.d/minisapo reload + else + log "FLASHMAN UPDATER" "No changes in bridge parameters..." + fi +} + +disable_bridge_mode() { + local _wan_conn_type="" + local _lan_ifnames="" + local _lan_ip="" + local _skip_network_restart="$1" + local _wait_uhttpd_reply="$2" # TODO: Find a better way to solve this + + if [ "$_wait_uhttpd_reply" = "y" ] + then + sleep 3 + fi + + # Clear bridge mode from config.json so it doesn't persist between flashes + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _enable_ipv6 enable_ipv6 + json_get_var _wan_conn_type wan_conn_type + json_get_var _lan_ifnames bridge_lan_backup + json_get_var _lan_ip bridge_lan_ip_backup + json_add_string bridge_mode "n" + json_dump > /root/flashbox_config.json + json_close_object + # Test for empty wan_conn_type to avoid bugs after hard reset + if [ "$_wan_conn_type" = "" ] + then + _wan_conn_type="$FLM_WAN_PROTO" + fi + if [ "$(type -t keep_ifnames_in_bridge_mode)" == "" ] + then + # Get ifname to remove from the bridge + uci set network.lan.ifname="$_lan_ifnames" + fi + # Some routers need to change back port mapping on software switch + if [ "$(type -t set_switch_bridge_mode)" ] then - if [ -f /etc/ethers ] - then - while read _fixed_ip - do - _fixed_ip="$(echo "$_fixed_ip" | awk '{print $2}')" - is_ip_in_lan "$_fixed_ip" "$_dmz_subnet" "$_dmz_netmask" - if [ $? -eq 0 ] - then - _ipcalc_res="$(/bin/ipcalc.sh $_dmz_subnet \ - $_dmz_netmask $_fixed_ip 1)" - _next_addr="$(echo "$_ipcalc_res" | grep "END" | \ - awk -F= '{print $2}')" - fi - done < /etc/ethers - if [ "$_next_addr" = "" ] - then - # It must start at 130 to isolate routes - _ipcalc_res="$(/bin/ipcalc.sh $_dmz_subnet $_dmz_netmask 1 129)" - _next_addr="$(echo "$_ipcalc_res" | grep "END" | awk -F= '{print $2}')" - fi - else - # It must start at 130 to isolate routes - _ipcalc_res="$(/bin/ipcalc.sh $_dmz_subnet $_dmz_netmask 1 129)" - _next_addr="$(echo "$_ipcalc_res" | grep "END" | awk -F= '{print $2}')" - fi - else - if [ -f /etc/ethers ] - then - while read _fixed_ip - do - _fixed_ip="$(echo "$_fixed_ip" | awk '{print $2}')" - is_ip_in_lan "$_fixed_ip" "$_lan_subnet" "$_lan_netmask" - if [ $? -eq 0 ] - then - _ipcalc_res="$(/bin/ipcalc.sh $_lan_subnet \ - $_lan_netmask $_fixed_ip 1)" - _next_addr="$(echo "$_ipcalc_res" | grep "END" | \ - awk -F= '{print $2}')" - fi - done < /etc/ethers - if [ "$_next_addr" = "" ] - then - _ipcalc_res="$(/bin/ipcalc.sh $_lan_subnet $_lan_netmask 1 1)" - _next_addr="$(echo "$_ipcalc_res" | grep "END" | awk -F= '{print $2}')" - fi - else - _ipcalc_res="$(/bin/ipcalc.sh $_lan_subnet $_lan_netmask 1 1)" - _next_addr="$(echo "$_ipcalc_res" | grep "END" | awk -F= '{print $2}')" - fi + set_switch_bridge_mode "n" "$_disable_lan_ports" fi - echo "$_mac $_next_addr" >> /etc/ethers - echo "$_next_addr" + uci set network.lan.proto="static" + uci set network.lan.ipaddr="$_lan_ip" + # Set wan and lan back to proper values + uci set network.wan.proto="$_wan_conn_type" + + if [ "$_enable_ipv6" = "1" ] + then + uci set network.wan.ipv6="auto" + uci set network.wan6.proto="dhcpv6" + [ "$(uci -q get network.lan.ipv6)" ] && uci delete network.lan.ipv6 + else + uci set network.wan.ipv6="0" + uci set network.wan6.proto='none' + uci set network.lan.ipv6="0" + fi + [ "$(uci -q get network.lan6)" ] && uci delete network.lan6 + + uci set network.lan.proto="static" + uci delete network.lan.gateway + uci delete network.lan.dns + uci commit network + /etc/init.d/miniupnpd enable + /etc/init.d/miniupnpd start + /etc/init.d/firewall enable + /etc/init.d/firewall start + /etc/init.d/dnsmasq enable + /etc/init.d/dnsmasq start + if [ "$_enable_ipv6" = "1" ] + then + /etc/init.d/odhcpd enable + /etc/init.d/odhcpd start + fi + if [ "$_skip_network_restart" != "y" ] + then + # Some targets need to reboot the whole router after changing mode + if [ "$(type -t needs_reboot_bridge_mode)" ] + then + needs_reboot_bridge_mode + else + /etc/init.d/network restart + [ "$(get_ipv6_enabled)" = "1" ] && /etc/init.d/odhcpd restart + fi + fi +} + +get_mesh_mode() { + local _mesh_mode="" + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _mesh_mode mesh_mode + json_close_object + [ -z "$_mesh_mode" ] && echo "0" || echo "$_mesh_mode" +} + +get_mesh_master() { + local _mesh_master="" + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _mesh_master mesh_master + json_close_object + echo "$_mesh_master" +} + +is_mesh_master() { + local _mesh_mode="" + local _mesh_master="" + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _mesh_mode mesh_mode + json_get_var _mesh_master mesh_master + json_close_object + [ -n "$_mesh_mode" ] && [ "$_mesh_mode" != "0" ] && [ -z "$_mesh_master" ] && echo "1" || echo "0" +} + +is_mesh_connected() { + local _mesh_mode="$(get_mesh_mode)" + local conn="" + if [ "$_mesh_mode" -eq "2" ] || [ "$_mesh_mode" -eq "4" ] + then + iw dev mesh0 info 1>/dev/null 2> /dev/null && [ "$(iw mesh0 station dump | grep ESTAB)" ] && conn="1" + fi + if [ "$_mesh_mode" -eq "3" ] || [ "$_mesh_mode" -eq "4" ] + then + iw dev mesh1 info 1>/dev/null 2> /dev/null && [ "$(iw mesh1 station dump | grep ESTAB)" ] && conn="1" + fi + echo "$conn" +} + +set_mesh_master_mode() { + local _mesh_mode="$1" + local _local_mesh_mode=$(get_mesh_mode) + + for i in $(uci -q get dhcp.lan.dhcp_option) + do + if [ "$i" != "${i#"vendor:ANLIX02,43"}" ] + then + uci del_list dhcp.lan.dhcp_option=$i + fi + done + + if [ "$_mesh_mode" != "0" ] + then + log "MESH" "Enabling mesh mode $_mesh_mode" + uci add_list dhcp.lan.dhcp_option="vendor:ANLIX02,43,$_mesh_mode" + else + log "MESH" "Mesh mode disabled" + fi + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string mesh_mode "$_mesh_mode" + json_add_string mesh_master "" + json_dump > /root/flashbox_config.json + json_close_object + + uci commit dhcp + if [ "$(get_bridge_mode_status)" != "y" ] + then + /etc/init.d/dnsmasq reload + fi +} + +set_mesh_slave_mode() { + local _mesh_mode="$1" + local _mesh_master="$2" + + log "MESH" "Enabling mesh slave mode $_mesh_mode from master $_mesh_master" + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string mesh_mode "$_mesh_mode" + json_add_string mesh_master "$_mesh_master" + json_dump > /root/flashbox_config.json + json_close_object +} + +set_mesh_slaves() { + local _mesh_slave="$1" + if [ "$(is_mesh_master)" = "1" ] + then + # Check license availability before proceeding + if is_mesh_license_available $_mesh_slave + then + local _retstatus + local _status=20 + local _data="id=$(get_mac)&slave=$_mesh_slave" + local _url="deviceinfo/mesh/add" + local _res=$(rest_flashman "$_url" "$_data") + + _retstatus=$? + if [ $_retstatus -eq 0 ] + then + json_cleanup + json_load "$_res" + json_get_var _is_registered is_registered + json_close_object + # value 2 is already registred. No need to do anything + if [ "$_is_registered" = "1" ] + then + log "MESH" "Slave router $_mesh_slave registered successfull" + fi + if [ "$_is_registered" = "0" ] + then + log "MESH" "Error registering slave router $_mesh_slave" + _status=21 + fi + else + log "MESH" "Error communicating with server for registration" + _status=21 + fi + else + log "MESH" "No license available" + _status=22 + fi + + json_cleanup + json_init + json_add_string mac "$_mesh_slave" + json_add_int status $_status + ubus call anlix_sapo notify_sapo "$(json_dump)" + json_close_object + fi } diff --git a/files/usr/share/functions/system_functions.sh b/files/usr/share/functions/system_functions.sh index 14102df8..09b0ac44 100644 --- a/files/usr/share/functions/system_functions.sh +++ b/files/usr/share/functions/system_functions.sh @@ -6,45 +6,45 @@ # Verify ntp ntp_anlix() { - if [ -f /tmp/anlixntp ] - then - cat /tmp/anlixntp - else - echo "unsync" - fi + if [ -f /tmp/anlixntp ] + then + cat /tmp/anlixntp + else + echo "unsync" + fi } resync_ntp() { - local _curdate=$(date +%s) - local _data="id=$(get_mac)&ntp=$(ntp_anlix)&date=$_curdate" - local _url="https://$FLM_SVADDR/deviceinfo/ntp" + local _curdate=$(date +%s) + local _data="id=$(get_mac)&ntp=$(ntp_anlix)&date=$_curdate" + local _url="https://$FLM_SVADDR/deviceinfo/ntp" - # Date sync with Flashman is done insecurely - local _res - local _retstatus - _res=$(curl -k -s \ - -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" \ - --tlsv1.2 --connect-timeout 5 --retry 1 --data "$_data" \ - "$_url") - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - json_cleanup - json_load "$_res" - json_get_var _need_update need_update - json_get_var _new_date new_date - json_close_object + # Date sync with Flashman is done insecurely + local _res + local _retstatus + _res=$(curl -k -s \ + -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" \ + --tlsv1.2 --connect-timeout 5 --retry 1 --data "$_data" \ + "$_url") + _retstatus=$? + if [ $_retstatus -eq 0 ] + then + json_cleanup + json_load "$_res" + json_get_var _need_update need_update + json_get_var _new_date new_date + json_close_object - if [ "$_need_update" = "1" ] - then - log "NTP_FLASHMAN" "Change date to $_new_date" - date +%s -s "@$_new_date" - echo "flash_sync" > /tmp/anlixntp - else - log "NTP_FLASHMAN" "No need to change date (Server clock $_new_date)" - echo "flash_sync" > /tmp/anlixntp - fi - else - log "NTP_FLASHMAN" "Error in CURL: $_retstatus" - fi + if [ "$_need_update" = "1" ] + then + log "NTP_FLASHMAN" "Change date to $_new_date" + date "@$_new_date" > /dev/null + echo "flash_sync" > /tmp/anlixntp + else + log "NTP_FLASHMAN" "No need to change date (Server clock $_new_date)" + echo "flash_sync" > /tmp/anlixntp + fi + else + log "NTP_FLASHMAN" "Error in CURL: $_retstatus" + fi } diff --git a/files/usr/share/functions/wireless_functions.sh b/files/usr/share/functions/wireless_functions.sh index c2f83edc..dc5baefd 100644 --- a/files/usr/share/functions/wireless_functions.sh +++ b/files/usr/share/functions/wireless_functions.sh @@ -1,198 +1,709 @@ #!/bin/sh . /usr/share/libubox/jshn.sh +. /usr/share/functions/common_functions.sh . /usr/share/functions/device_functions.sh +. /usr/share/functions/network_functions.sh + +get_hwmode_24() { + local _htmode_24="$(uci -q get wireless.radio0.htmode)" + [ "$_htmode_24" = "NOHT" ] && echo "11g" || echo "11n" +} + +get_htmode_24() { + local _htmode_24="$(uci -q get wireless.radio0.htmode)" + [ "$_htmode_24" = "NOHT" ] && echo "HT20" || echo "$_htmode_24" +} + +get_wifi_state() { + local _q=$(uci -q get wireless.default_radio$1.disabled) + [ "$_q" ] && [ "$_q" = "1" ] && echo "0" || echo "1" +} + +auto_channel_selection() { + local _iface=$1 + case "$_iface" in + wlan0) + echo "6" + ;; + wlan1) + echo "40" + ;; + esac +} + +convert_txpower() { + local _freq="$1" + local _channel="$2" + local _txprct="$3" + local _maxpwr + + if [ "$_freq" = "24" ] + then + _maxpwr=20 + [ "$(type -t custom_wifi_24_txpower)" ] && _maxpwr="$(custom_wifi_24_txpower)" + else + _maxpwr=30 + [ "$(type -t custom_wifi_50_txpower)" ] && _maxpwr="$(custom_wifi_50_txpower)" + fi + + if [ "$_channel" = "auto" ] + then + echo "$_maxpwr" + return + fi + + local _phy + local _reload=0 + if [ "$_freq" = "24" ] + then + _phy=$(get_24ghz_phy) + [ ! "$(type -t custom_wifi_24_txpower)" ] && _reload=1 + else + _phy=$(get_5ghz_phy) + [ ! "$(type -t custom_wifi_50_txpower)" ] && _reload=1 + fi + [ $_reload = 1 ] && _maxpwr=$(iw $_phy info | awk '/\['$_channel'\]/{ print substr($5,2,2) }') + + echo $(( ((_maxpwr * _txprct)+50) / 100 )) +} + +get_txpower() { + local _freq="$1" + local _txpower="$(uci -q get wireless.radio$_freq.txpower)" + local _channel="$(uci -q get wireless.radio$_freq.channel)" + + if [ "$_channel" = "auto" ] + then + echo "100" + return + fi + + local _phy + local _maxpwr="0" + if [ "$_freq" = "0" ] + then + _phy=$(get_24ghz_phy) + [ "$(type -t custom_wifi_24_txpower)" ] && _maxpwr="$(custom_wifi_24_txpower)" + else + _phy=$(get_5ghz_phy) + [ "$(type -t custom_wifi_50_txpower)" ] && _maxpwr="$(custom_wifi_50_txpower)" + fi + [ "$_maxpwr" = "0" ] && _maxpwr=$(iw $_phy info | awk '/\['$_channel'\]/{ print substr($5,2,2) }') + + local _txprct="$(( (_txpower * 100) / _maxpwr ))" + if [ $_txprct -ge 100 ]; then echo "100" + elif [ $_txprct -ge 75 ]; then echo "75" + elif [ $_txprct -ge 50 ]; then echo "50" + else echo "25" + fi +} + +change_fast_transition() { + local _radio="$1" + local _enabled="$2" + if [ "$_enabled" = "1" ] + then + # Enable Fast Transition + uci set wireless.default_radio$_radio.ieee80211r="1" + uci set wireless.default_radio$_radio.ieee80211v="1" + uci set wireless.default_radio$_radio.bss_transition="1" + uci set wireless.default_radio$_radio.ieee80211k="1" + else + uci delete wireless.default_radio$_radio.ieee80211r + uci delete wireless.default_radio$_radio.ieee80211v + uci delete wireless.default_radio$_radio.bss_transition + uci delete wireless.default_radio$_radio.ieee80211k + fi +} + +change_wps_state() { + local _radio="$1" + local _enabled="$2" + if [ "$_enabled" = "1" ] + then + uci set wireless.default_radio$_radio.wps_pushbutton='1' + uci set wireless.default_radio$_radio.wps_manufacturer='FlashBox AP' + uci set wireless.default_radio$_radio.wps_device_name='anlix.io' + fi +} get_wifi_local_config() { - local _ssid_24="$(uci -q get wireless.@wifi-iface[0].ssid)" - local _password_24="$(uci -q get wireless.@wifi-iface[0].key)" - local _channel_24="$(uci -q get wireless.radio0.channel)" - local _hwmode_24="$(uci -q get wireless.radio0.hwmode)" - local _htmode_24="$(uci -q get wireless.radio0.htmode)" - - local _is_5ghz_capable="$(is_5ghz_capable)" - local _ssid_50="$(uci -q get wireless.@wifi-iface[1].ssid)" - local _password_50="$(uci -q get wireless.@wifi-iface[1].key)" - local _channel_50="$(uci -q get wireless.radio1.channel)" - local _hwmode_50="$(uci -q get wireless.radio1.hwmode)" - local _htmode_50="$(uci -q get wireless.radio1.htmode)" - - # - # WARNING! No spaces or tabs inside the following string! - # - local _wifi_json="{\ -'local_ssid_24':'$_ssid_24',\ -'local_password_24':'$_password_24',\ -'local_channel_24':'$_channel_24',\ -'local_hwmode_24':'$_hwmode_24',\ -'local_htmode_24':'$_htmode_24',\ -'local_5ghz_capable':'$_is_5ghz_capable',\ -'local_ssid_50':'$_ssid_50',\ -'local_password_50':'$_password_50',\ -'local_channel_50':'$_channel_50',\ -'local_hwmode_50':'$_hwmode_50',\ -'local_htmode_50':'$_htmode_50'}" - - echo "$_wifi_json" + local _ssid_24="$(uci -q get wireless.default_radio0.ssid)" + local _password_24="$(uci -q get wireless.default_radio0.key)" + local _channel_24="$(uci -q get wireless.radio0.channel)" + local _hwmode_24="$(get_hwmode_24)" + local _htmode_24="$(get_htmode_24)" + local _state_24="$(get_wifi_state '0')" + local _txpower_24="$(get_txpower 0)" + local _ft_24="$(uci -q get wireless.default_radio0.ieee80211r)" + local _hidden_24="$(uci -q get wireless.default_radio0.hidden)" + + local _is_5ghz_capable="$(is_5ghz_capable)" + local _ssid_50="" + local _password_50="" + local _channel_50="" + local _hwmode_50="" + local _htmode_50="" + local _state_50="" + local _txpower_50="" + local _ft_50="" + local _hidden_50="" + if [ "$_is_5ghz_capable" = "1" ] + then + _ssid_50="$(uci -q get wireless.default_radio1.ssid)" + _password_50="$(uci -q get wireless.default_radio1.key)" + _channel_50="$(uci -q get wireless.radio1.channel)" + _hwmode_50="$(uci -q get wireless.radio1.hwmode)" + _htmode_50="$(uci -q get wireless.radio1.htmode)" + _state_50="$(get_wifi_state '1')" + _txpower_50="$(get_txpower 1)" + _ft_50="$(uci -q get wireless.default_radio1.ieee80211r)" + _hidden_50="$(uci -q get wireless.default_radio1.hidden)" + fi + + json_cleanup + json_init + json_add_string "local_ssid_24" "$_ssid_24" + json_add_string "local_password_24" "$_password_24" + json_add_string "local_channel_24" "$_channel_24" + json_add_string "local_hwmode_24" "$_hwmode_24" + json_add_string "local_htmode_24" "$_htmode_24" + json_add_string "local_ft_24" "$_ft_24" + json_add_string "local_state_24" "$_state_24" + json_add_string "local_txpower_24" "$_txpower_24" + json_add_string "local_hidden_24" "$_hidden_24" + json_add_string "local_5ghz_capable" "$_is_5ghz_capable" + json_add_string "local_ssid_50" "$_ssid_50" + json_add_string "local_password_50" "$_password_50" + json_add_string "local_channel_50" "$_channel_50" + json_add_string "local_hwmode_50" "$_hwmode_50" + json_add_string "local_htmode_50" "$_htmode_50" + json_add_string "local_ft_50" "$_ft_50" + json_add_string "local_state_50" "$_state_50" + json_add_string "local_txpower_50" "$_txpower_50" + json_add_string "local_hidden_50" "$_hidden_50" + json_dump + json_close_object +} + +save_wifi_parameters() { + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string ssid_24 "$(uci -q get wireless.default_radio0.ssid)" + json_add_string password_24 "$(uci -q get wireless.default_radio0.key)" + json_add_string channel_24 "$(uci -q get wireless.radio0.channel)" + json_add_string hwmode_24 "$(uci -q get wireless.radio0.hwmode)" + json_add_string htmode_24 "$(uci -q get wireless.radio0.htmode)" + json_add_string state_24 "$(get_wifi_state '0')" + json_add_string txpower_24 "$(get_txpower 0)" + json_add_string hidden_24 "$(uci -q get wireless.default_radio0.hidden)" + + if [ "$(is_5ghz_capable)" == "1" ] + then + json_add_string ssid_50 "$(uci -q get wireless.default_radio1.ssid)" + json_add_string password_50 "$(uci -q get wireless.default_radio1.key)" + json_add_string channel_50 "$(uci -q get wireless.radio1.channel)" + json_add_string hwmode_50 "$(uci -q get wireless.radio1.hwmode)" + json_add_string htmode_50 "$(uci -q get wireless.radio1.htmode)" + json_add_string state_50 "$(get_wifi_state '1')" + json_add_string txpower_50 "$(get_txpower 1)" + json_add_string hidden_50 "$(uci -q get wireless.default_radio1.hidden)" + fi + json_dump > /root/flashbox_config.json + json_close_object } set_wifi_local_config() { - local _do_reload=0 - - local _remote_ssid_24="$1" - local _remote_password_24="$2" - local _remote_channel_24="$3" - local _remote_hwmode_24="$4" - local _remote_htmode_24="$5" - - local _remote_ssid_50="$6" - local _remote_password_50="$7" - local _remote_channel_50="$8" - local _remote_hwmode_50="$9" - local _remote_htmode_50="$10" - - json_cleanup - json_load "$(get_wifi_local_config)" - json_get_var _local_ssid_24 local_ssid_24 - json_get_var _local_password_24 local_password_24 - json_get_var _local_channel_24 local_channel_24 - json_get_var _local_hwmode_24 local_hwmode_24 - json_get_var _local_htmode_24 local_htmode_24 - - json_get_var _local_ssid_50 local_ssid_50 - json_get_var _local_password_50 local_password_50 - json_get_var _local_channel_50 local_channel_50 - json_get_var _local_hwmode_50 local_hwmode_50 - json_get_var _local_htmode_50 local_htmode_50 - json_close_object - - if [ "$_remote_ssid_24" != "" ] && \ - [ "$_remote_ssid_24" != "$_local_ssid_24" ] - then - uci set wireless.@wifi-iface[0].ssid="$_remote_ssid_24" - _do_reload=1 - fi - if [ "$_remote_password_24" != "" ] && \ - [ "$_remote_password_24" != "$_local_password_24" ] - then - uci set wireless.@wifi-iface[0].key="$_remote_password_24" - _do_reload=1 - fi - if [ "$_remote_channel_24" != "" ] && \ - [ "$_remote_channel_24" != "$_local_channel_24" ] - then - uci set wireless.radio0.channel="$_remote_channel_24" - _do_reload=1 - fi - if [ "$_remote_hwmode_24" != "" ] && \ - [ "$_remote_hwmode_24" != "$_local_hwmode_24" ] - then - if [ "$_remote_hwmode_24" = "11n" ] - then - uci set wireless.radio0.hwmode="$_remote_hwmode_24" - uci set wireless.radio0.wifimode="9" - elif [ "$_remote_hwmode_24" = "11g" ] - then - uci set wireless.radio0.hwmode="$_remote_hwmode_24" - uci set wireless.radio0.wifimode="4" - fi - _do_reload=1 - fi - if [ "$_remote_htmode_24" != "" ] && \ - [ "$_remote_htmode_24" != "$_local_htmode_24" ] - then - if [ "$_remote_htmode_24" = "HT40" ] - then - uci set wireless.radio0.htmode="$_remote_htmode_24" - uci set wireless.radio0.noscan="1" - uci set wireless.radio0.ht_bsscoexist="0" - uci set wireless.radio0.bw="1" - elif [ "$_remote_htmode_24" = "HT20" ] - then - uci set wireless.radio0.htmode="$_remote_htmode_24" - uci set wireless.radio0.noscan="0" - uci set wireless.radio0.ht_bsscoexist="1" - uci set wireless.radio0.bw="0" - fi - _do_reload=1 - fi - - # 5GHz - if [ "$(uci -q get wireless.@wifi-iface[1])" ] - then - if [ "$_remote_ssid_50" != "" ] && \ - [ "$_remote_ssid_50" != "$_local_ssid_50" ] - then - uci set wireless.@wifi-iface[1].ssid="$_remote_ssid_50" - _do_reload=1 - fi - if [ "$_remote_password_50" != "" ] && \ - [ "$_remote_password_50" != "$_local_password_50" ] - then - uci set wireless.@wifi-iface[1].key="$_remote_password_50" - _do_reload=1 - fi - if [ "$_remote_channel_50" != "" ] && \ - [ "$_remote_channel_50" != "$_local_channel_50" ] - then - uci set wireless.radio1.channel="$_remote_channel_50" - _do_reload=1 - fi - if [ "$_remote_hwmode_50" != "" ] && \ - [ "$_remote_hwmode_50" != "$_local_hwmode_50" ] - then - if [ "$_remote_hwmode_50" = "11ac" ] - then - uci set wireless.radio1.hwmode="$_remote_hwmode_50" - uci set wireless.radio1.wifimode="15" - elif [ "$_remote_hwmode_50" = "11na" ] - then - uci set wireless.radio1.hwmode="$_remote_hwmode_50" - uci set wireless.radio1.wifimode="11" - fi - _do_reload=1 - fi - if [ "$_remote_htmode_50" != "" ] && \ - [ "$_remote_htmode_50" != "$_local_htmode_50" ] - then - if [ "$_remote_htmode_50" = "VHT80" ] - then - uci set wireless.radio1.htmode="$_remote_htmode_50" - uci set wireless.radio1.noscan="1" - uci set wireless.radio1.ht_bsscoexist="0" - uci set wireless.radio1.bw="2" - elif [ "$_remote_htmode_50" = "VHT40" ] - then - uci set wireless.radio1.htmode="$_remote_htmode_50" - uci set wireless.radio1.noscan="1" - uci set wireless.radio1.ht_bsscoexist="0" - uci set wireless.radio1.bw="1" - elif [ "$_remote_htmode_50" = "HT40" ] - then - uci set wireless.radio1.htmode="$_remote_htmode_50" - uci set wireless.radio1.noscan="1" - uci set wireless.radio1.ht_bsscoexist="0" - uci set wireless.radio1.bw="1" - elif [ "$_remote_htmode_50" = "VHT20" ] - then - uci set wireless.radio1.htmode="$_remote_htmode_50" - uci set wireless.radio1.noscan="0" - uci set wireless.radio1.ht_bsscoexist="1" - uci set wireless.radio1.bw="0" - elif [ "$_remote_htmode_50" = "HT20" ] - then - uci set wireless.radio1.htmode="$_remote_htmode_50" - uci set wireless.radio1.noscan="0" - uci set wireless.radio1.ht_bsscoexist="1" - uci set wireless.radio1.bw="0" - fi - _do_reload=1 - fi - fi - - if [ $_do_reload -eq 1 ] - then - save_wifi_local_config - wifi reload - fi + local _do_reload=0 + + local _remote_ssid_24="$1" + local _remote_password_24="$2" + local _remote_channel_24="$3" + local _remote_hwmode_24="$4" + local _remote_htmode_24="$5" + local _remote_state_24="$6" + local _remote_txpower_24="$7" + local _remote_hidden_24="$8" + + local _remote_ssid_50="$9" + local _remote_password_50="${10}" + local _remote_channel_50="${11}" + local _remote_hwmode_50="${12}" + local _remote_htmode_50="${13}" + local _remote_state_50="${14}" + local _remote_txpower_50="${15}" + local _remote_hidden_50="${16}" + + local _mesh_mode="${17}" + + json_cleanup + json_load "$(get_wifi_local_config)" + json_get_var _local_ssid_24 local_ssid_24 + json_get_var _local_password_24 local_password_24 + json_get_var _local_channel_24 local_channel_24 + json_get_var _local_hwmode_24 local_hwmode_24 + json_get_var _local_htmode_24 local_htmode_24 + json_get_var _local_ft_24 local_ft_24 + json_get_var _local_state_24 local_state_24 + json_get_var _local_txpower_24 local_txpower_24 + json_get_var _local_hidden_24 local_hidden_24 + + json_get_var _local_ssid_50 local_ssid_50 + json_get_var _local_password_50 local_password_50 + json_get_var _local_channel_50 local_channel_50 + json_get_var _local_hwmode_50 local_hwmode_50 + json_get_var _local_htmode_50 local_htmode_50 + json_get_var _local_ft_50 local_ft_50 + json_get_var _local_state_50 local_state_50 + json_get_var _local_txpower_50 local_txpower_50 + json_get_var _local_hidden_50 local_hidden_50 + json_close_object + + if [ "$_remote_ssid_24" != "" ] && \ + [ "$_remote_ssid_24" != "$_local_ssid_24" ] + then + uci set wireless.default_radio0.ssid="$_remote_ssid_24" + _do_reload=1 + fi + if [ "$_remote_password_24" != "" ] && \ + [ "$_remote_password_24" != "$_local_password_24" ] + then + uci set wireless.default_radio0.key="$_remote_password_24" + _do_reload=1 + fi + if [ "$_remote_channel_24" != "" ] && \ + [ "$_remote_channel_24" != "$_local_channel_24" ] + then + local _newchan="$_remote_channel_24" + if [ "$(type -t custom_wifi_24_channels)" ] && \ + [ "$(custom_wifi_24_channels|grep -c ' ')" = 0 ] && \ + [ "$_newchan" = "auto" ] + then + _newchan="$(custom_wifi_24_channels)" + fi + + if [ "$_newchan" != "$_local_channel_24" ] + then + uci set wireless.radio0.channel="$_newchan" + _do_reload=1 + fi + fi + if [ "$_remote_hwmode_24" != "" ] && \ + [ "$_remote_hwmode_24" != "$_local_hwmode_24" ] + then + # hostapd use only 11g (11n is defined in htmode) + [ "$_remote_hwmode_24" = "11g" ] && uci set wireless.radio0.htmode="NOHT" + [ "$_remote_hwmode_24" = "11n" ] && uci set wireless.radio0.htmode="HT20" + _do_reload=1 + fi + if [ "$_remote_htmode_24" != "" ] && \ + [ "$_remote_htmode_24" != "$_local_htmode_24" ] + then + local _newht=$(uci -q get wireless.radio0.htmode) + if [ "$_newht" != "NOHT" ] + then + uci set wireless.radio0.htmode="$_remote_htmode_24" + [ "$_remote_htmode_24" = "HT40" ] && uci set wireless.radio0.noscan="1" + [ "$_remote_htmode_24" = "HT20" ] && uci set wireless.radio0.noscan="0" + _do_reload=1 + fi + fi + + if [ -n "$_mesh_mode" ] + then + local _new_channel="$([ "$_remote_channel_24" != "" ] && echo "$_remote_channel_24" || echo $_local_channel_24)" + if [ "$_mesh_mode" -eq "2" ] || [ "$_mesh_mode" -eq "4" ] && [ "$_new_channel" = "auto" ] + then + #MESH cant run auto! + _new_channel="$(auto_channel_selection wlan0)" + uci set wireless.radio0.channel="$_new_channel" + _do_reload=1 + fi + + # Enable Fast Transition + if [ "$_mesh_mode" != "0" ] && \ + [ "$_local_ft_24" != "1" ] + then + change_fast_transition "0" "1" + _do_reload=1 + fi + + #Disable Fast Transition + if [ "$_mesh_mode" == "0" ] && \ + [ "$_local_ft_24" == "1" ] + then + change_fast_transition "0" "0" + _do_reload=1 + fi + fi + + if [ "$_remote_state_24" != "" ] + then + if [ "$_remote_state_24" = "0" ] && [ "$_local_state_24" = "1" ] + then + uci set wireless.default_radio0.disabled="1" + _do_reload=1 + elif [ "$_remote_state_24" = "1" ] && [ "$_local_state_24" = "0" ] + then + uci set wireless.default_radio0.disabled="0" + _do_reload=1 + fi + fi + if [ "$_remote_txpower_24" != "" ] && [ "$_remote_txpower_24" != "$_local_txpower_24" ] + then + _conv_channel=$([ "$_remote_channel_24" ] && echo "$_remote_channel_24" || echo "$_local_channel_24") + uci set wireless.radio0.txpower="$(convert_txpower "24" "$_conv_channel" "$_remote_txpower_24")" + _do_reload=1 + fi + if [ "$_remote_hidden_24" != "" ] && [ "$_remote_hidden_24" != "$_local_hidden_24" ] + then + uci set wireless.default_radio0.hidden="$_remote_hidden_24" + _do_reload=1 + fi + + # 5GHz + if [ "$(is_5ghz_capable)" == "1" ] + then + if [ "$_remote_ssid_50" != "" ] && \ + [ "$_remote_ssid_50" != "$_local_ssid_50" ] + then + uci set wireless.default_radio1.ssid="$_remote_ssid_50" + _do_reload=1 + fi + if [ "$_remote_password_50" != "" ] && \ + [ "$_remote_password_50" != "$_local_password_50" ] + then + uci set wireless.default_radio1.key="$_remote_password_50" + _do_reload=1 + fi + if [ "$_remote_channel_50" != "" ] && \ + [ "$_remote_channel_50" != "$_local_channel_50" ] + then + local _newchan="$_remote_channel_50" + if [ "$(type -t custom_wifi_50_channels)" ] && \ + [ "$(custom_wifi_50_channels|grep -c ' ')" = 0 ] && \ + [ "$_newchan" = "auto" ] + then + _newchan="$(custom_wifi_50_channels)" + fi + + if [ "$_newchan" != "$_local_channel_50" ] + then + uci set wireless.radio1.channel="$_newchan" + _do_reload=1 + fi + fi + + if [ "$_remote_htmode_50" != "" ] && \ + [ "$_remote_htmode_50" != "$_local_htmode_50" ] + then + uci set wireless.radio1.htmode="$_remote_htmode_50" + if [ ! "$(is_5ghz_vht)" ] + then + if [ "$_remote_htmode_50" != "HT40" ] && + [ "$_remote_htmode_50" != "HT20" ] + then + uci set wireless.radio1.htmode="HT40" + fi + fi + _do_reload=1 + fi + + if [ -n "$_mesh_mode" ] + then + local _new_channel="$([ "$_remote_channel_50" != "" ] && echo "$_remote_channel_50" || echo $_local_channel_50)" + if [ "$_mesh_mode" -eq "3" ] || [ "$_mesh_mode" -eq "4" ] && [ "$_new_channel" = "auto" ] + then + #MESH cant run auto! + _new_channel="$(auto_channel_selection wlan1)" + uci set wireless.radio1.channel="$_new_channel" + _do_reload=1 + fi + + # Enable Fast Transition + if [ "$_mesh_mode" != "0" ] && \ + [ "$_local_ft_50" != "1" ] + then + change_fast_transition "1" "1" + _do_reload=1 + fi + + #Disable Fast Transition + if [ "$_mesh_mode" == "0" ] && \ + [ "$_local_ft_50" == "1" ] + then + change_fast_transition "1" "0" + _do_reload=1 + fi + fi + + if [ "$_remote_state_50" != "" ] + then + if [ "$_remote_state_50" = "0" ] && [ "$_local_state_50" = "1" ] + then + uci set wireless.default_radio1.disabled="1" + _do_reload=1 + elif [ "$_remote_state_50" = "1" ] && [ "$_local_state_50" = "0" ] + then + uci set wireless.default_radio1.disabled="0" + _do_reload=1 + fi + fi + if [ "$_remote_txpower_50" != "" ] && [ "$_remote_txpower_50" != "$_local_txpower_50" ] + then + + _conv_channel=$([ "$_remote_channel_50" ] && echo "$_remote_channel_50" || echo "$_local_channel_50") + uci set wireless.radio1.txpower="$(convert_txpower "50" "$_conv_channel" "$_remote_txpower_50")" + _do_reload=1 + fi + if [ "$_remote_hidden_50" != "" ] && [ "$_remote_hidden_50" != "$_local_hidden_50" ] + then + uci set wireless.default_radio1.hidden="$_remote_hidden_50" + _do_reload=1 + fi + fi + + if [ $_do_reload -eq 1 ] + then + uci commit wireless + save_wifi_parameters + return 0 + fi + return 1 +} + +get_mesh_id() { + local _mesh_id="" + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _mesh_id mesh_id + json_close_object + [ "$_mesh_id" ] && echo "$_mesh_id" || echo "anlix" +} + +get_mesh_key() { + local _mesh_key="" + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _mesh_key mesh_key + json_close_object + [ "$_mesh_key" ] && echo "$_mesh_key" || echo "tempkey1234" +} + +enable_mesh_routing() { + local _new_mesh_id + local _new_mesh_key + local _mesh_mode=$1 + local _do_save=0 + local _local_mesh_id="$(get_mesh_id)" + if [ "$#" -eq 3 ] + then + _new_mesh_id="$2" + _new_mesh_key="$3" + else + _new_mesh_id="$(get_mesh_id)" + _new_mesh_key="$(get_mesh_key)" + fi + + if [ "$_local_mesh_id" != "$_new_mesh_id" ] + then + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string mesh_id "$_new_mesh_id" + json_add_string mesh_key "$_new_mesh_key" + json_dump > /root/flashbox_config.json + json_close_object + fi + + if [ "$(type -t is_mesh_routing_capable)" ] + then + local _mrc=$(is_mesh_routing_capable) + if [ "$_mrc" -gt "0" ] + then + if [ "$_mesh_mode" -eq "2" ] || [ "$_mesh_mode" -eq "4" ] + then + if [ "$_mrc" -eq "1" ] || [ "$_mrc" -eq "3" ] + then + uci set wireless.mesh2=wifi-iface + uci set wireless.mesh2.device='radio0' + uci set wireless.mesh2.ifname='mesh0' + uci set wireless.mesh2.network='lan' + uci set wireless.mesh2.mode='mesh' + uci set wireless.mesh2.mesh_id="$_new_mesh_id" + uci set wireless.mesh2.encryption='psk2' + uci set wireless.mesh2.key="$_new_mesh_key" + _do_save=1 + fi + else + if [ "$(uci -q get wireless.mesh2)" ] + then + uci delete wireless.mesh2 + _do_save=1 + fi + fi + if [ "$_mesh_mode" -eq "3" ] || [ "$_mesh_mode" -eq "4" ] + then + if [ "$_mrc" -eq "2" ] || [ "$_mrc" -eq "3" ] + then + uci set wireless.mesh5=wifi-iface + uci set wireless.mesh5.device='radio1' + uci set wireless.mesh5.ifname='mesh1' + uci set wireless.mesh5.network='lan' + uci set wireless.mesh5.mode='mesh' + uci set wireless.mesh5.mesh_id="$_new_mesh_id" + uci set wireless.mesh5.encryption='psk2' + uci set wireless.mesh5.key="$_new_mesh_key" + _do_save=1 + fi + else + if [ "$(uci -q get wireless.mesh5)" ] + then + uci delete wireless.mesh5 + _do_save=1 + fi + fi + fi + + if [ $_do_save -eq 1 ] + then + uci commit wireless + return 0 + fi + fi + return 1 } + +change_wifi_state() { + local _state + local _itf_num + local _wifi_state + local _wifi_state_50 + + _state=$1 + _itf_num=$2 + + if [ "$_state" = "0" ] + then + _wifi_state="0" + _wifi_state_50="0" + else + _wifi_state="1" + _wifi_state_50="1" + fi + [ "$_itf_num" = "0" ] && _wifi_state_50="" + [ "$_itf_num" = "1" ] && _wifi_state="" + set_wifi_local_config "" "" "" "" "" "$_wifi_state" "" "" \ + "" "" "" "" "" "$_wifi_state_50" "" "" \ + "" && wifi reload && /etc/init.d/minisapo reload +} + +auto_change_mesh_slave_channel() { + scan_channel(){ + local _new_NCh="" + local _iface="$1" + local _mesh_id="$2" + A=$(iw dev $_iface scan -u); + while [ "$A" ] + do + AP=${A##*BSS } + A=${A%BSS *} + case "$AP" in + *"MESH ID: $_mesh_id"*) + _new_NCh="$(echo "$AP"|awk 'BEGIN{CH=""}/primary channel/{CH=$4}END{print CH}')" + ;; + esac + done + echo "$_new_NCh" + } + + local _mesh_mode="$(get_mesh_mode)" + local _mesh_id="$(get_mesh_id)" + local _NCh2="" + local _NCh5="" + if [ "$_mesh_mode" -eq "2" ] || [ "$_mesh_mode" -eq "4" ] + then + log "AUTOCHANNEL" "Scanning MESH channel for mesh0..." + iw dev mesh0 info 1>/dev/null 2> /dev/null && _NCh2=$(sh_timeout "scan_channel mesh0 $_mesh_id" 10) + fi + if [ "$_mesh_mode" -eq "3" ] || [ "$_mesh_mode" -eq "4" ] + then + log "AUTOCHANNEL" "Scanning MESH channel for mesh1..." + iw dev mesh1 info 1>/dev/null 2> /dev/null && _NCh5=$(sh_timeout "scan_channel mesh1 $_mesh_id" 10) + fi + + if [ "$_NCh2" ] || [ "$_NCh5" ] + then + if set_wifi_local_config "" "" "$_NCh2" "" "" "" "" "" \ + "" "" "$_NCh5" "" "" "" "" "" "$_mesh_mode" + then + log "AUTOCHANNEL" "MESH Channel change ($_NCh2) ($_NCh5)" + wifi reload + else + log "AUTOCHANNEL" "No need to change MESH channel" + fi + else + log "AUTOCHANNEL" "No MESH signal found" + fi +} + +set_mesh_rrm() { + local _need_change=0 + [ "$(get_wifi_state 0)" = "1" ] && ubus -t 15 wait_for hostapd.wlan0 2>/dev/null && _need_change=1 + [ "$(is_5ghz_capable)" = "1" ] && [ "$(get_wifi_state 1)" = "1" ] && \ + ubus -t 15 wait_for hostapd.wlan1 2>/dev/null && _need_change=1 + + if [ $_need_change -eq 1 ] + then + local rrm_list + local radios=$(ubus list | grep hostapd.wlan) + A=$'\n'$(ubus call anlix_sapo get_meshids | jsonfilter -e "@.list[*]") + while [ "$A" ] + do + B=${A##*$'\n'} + A=${A%$'\n'*} + rrm_list=$rrm_list",$B" + done + for value in ${radios} + do + rrm_list=${rrm_list}",$(ubus call ${value} rrm_nr_get_own | jsonfilter -e '$.value')" + done + for value in ${radios} + do + ubus call ${value} bss_mgmt_enable '{"neighbor_report": true}' + eval "ubus call ${value} rrm_nr_set '{ \"list\": [ ${rrm_list:1} ] }'" + done + fi +} + +set_wps_push_button() { + local _state + + _state=$1 + + if [ ! "$(type -t hostapd_cli)" ] + then + return 1 + fi + + if [ "$_state" = "1" ] + then + # Push button will last 2 min active or until first conn succeeds + hostapd_cli -i wlan0 wps_pbc + + if [ "$(is_5ghz_capable)" == "1" ] + then + hostapd_cli -i wlan1 wps_pbc + fi + return 0 + else + hostapd_cli -i wlan0 wps_cancel + + if [ "$(is_5ghz_capable)" == "1" ] + then + hostapd_cli -i wlan1 wps_cancel + fi + return 0 + fi +} + diff --git a/files/usr/share/functions/zabbix_functions.sh b/files/usr/share/functions/zabbix_functions.sh index a5285092..e8dad70f 100644 --- a/files/usr/share/functions/zabbix_functions.sh +++ b/files/usr/share/functions/zabbix_functions.sh @@ -5,152 +5,152 @@ . /usr/share/functions/common_functions.sh get_zabbix_send_data() { - local _send - json_cleanup - json_load_file /root/flashbox_config.json - json_get_var _send zabbix_send_data - json_close_object + local _send + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _send zabbix_send_data + json_close_object - echo "$_send" + echo "$_send" } get_zabbix_psk() { - local _psk - json_cleanup - json_load_file /root/flashbox_config.json - json_get_var _psk zabbix_psk - json_close_object + local _psk + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _psk zabbix_psk + json_close_object - echo "$_psk" + echo "$_psk" } get_zabbix_fqdn() { - local _fqdn - json_cleanup - json_load_file /root/flashbox_config.json - json_get_var _fqdn zabbix_fqdn - json_close_object + local _fqdn + json_cleanup + json_load_file /root/flashbox_config.json + json_get_var _fqdn zabbix_fqdn + json_close_object - echo "$_fqdn" + echo "$_fqdn" } # $1 - psk / $2 - fqdn / $3 - send_data set_zabbix_params() { - local _changed_params=0 - local _psk="$(get_zabbix_psk)" - local _fqdn="$(get_zabbix_fqdn)" - local _send_data="$(get_zabbix_send_data)" - json_cleanup - json_load_file /root/flashbox_config.json - # Check if psk changed - if [ "$1" != "" ] && [ "$1" != "$_psk" ] - then - log "ZABBIX" "Updating zabbix PSK parameter" - _psk="$1" - json_add_string zabbix_psk "$1" - echo -n "$1" > /etc/zabbix_agentd.psk - _changed_params=1 - fi - # Check if zabbix fqdn changed - if [ "$2" != "" ] && [ "$2" != "$_fqdn" ] - then - log "ZABBIX" "Updating zabbix FQDN parameter" - _fqdn="$2" - json_add_string zabbix_fqdn "$2" - sed -i 's/Server=.*/Server='"$2"'/' /etc/zabbix_agentd.conf - sed -i 's/ServerActive=.*/ServerActive='"$2"':80/' /etc/zabbix_agentd.conf - _changed_params=1 - fi - if [ "$3" = "1" ] && { [ "$_send_data" != "y" ] || [ "$_changed_params" = "1" ]; } - then - # Properly restart zabbix service if was active and anything changed - # or if was inactive and new values are valid - if [ "$_psk" != "" ] && [ "$_fqdn" != "" ] - then - log "ZABBIX" "Starting zabbix agent" - json_add_string zabbix_send_data "y" - /etc/init.d/zabbix_agentd stop - /etc/init.d/zabbix_agentd start - else - log "ZABBIX" "Stopping zabbix agent" - /etc/init.d/zabbix_agentd stop - json_add_string zabbix_send_data "n" - fi - elif [ "$3" = "0" ] - then - # Properly kill zabbix service - log "ZABBIX" "Stopping zabbix agent" - /etc/init.d/zabbix_agentd stop - json_add_string zabbix_send_data "n" - else - log "ZABBIX" "No changes in zabbix service" - fi - json_dump > /root/flashbox_config.json - json_close_object + local _changed_params=0 + local _psk="$(get_zabbix_psk)" + local _fqdn="$(get_zabbix_fqdn)" + local _send_data="$(get_zabbix_send_data)" + json_cleanup + json_load_file /root/flashbox_config.json + # Check if psk changed + if [ "$1" != "" ] && [ "$1" != "$_psk" ] + then + log "ZABBIX" "Updating zabbix PSK parameter" + _psk="$1" + json_add_string zabbix_psk "$1" + echo -n "$1" > /etc/zabbix_agentd.psk + _changed_params=1 + fi + # Check if zabbix fqdn changed + if [ "$2" != "" ] && [ "$2" != "$_fqdn" ] + then + log "ZABBIX" "Updating zabbix FQDN parameter" + _fqdn="$2" + json_add_string zabbix_fqdn "$2" + sed -i 's/Server=.*/Server='"$2"'/' /etc/zabbix_agentd.conf + sed -i 's/ServerActive=.*/ServerActive='"$2"':80/' /etc/zabbix_agentd.conf + _changed_params=1 + fi + if [ "$3" = "1" ] && { [ "$_send_data" != "y" ] || [ "$_changed_params" = "1" ]; } + then + # Properly restart zabbix service if was active and anything changed + # or if was inactive and new values are valid + if [ "$_psk" != "" ] && [ "$_fqdn" != "" ] + then + log "ZABBIX" "Starting zabbix agent" + json_add_string zabbix_send_data "y" + /etc/init.d/zabbix_agentd stop + /etc/init.d/zabbix_agentd start + else + log "ZABBIX" "Stopping zabbix agent" + /etc/init.d/zabbix_agentd stop + json_add_string zabbix_send_data "n" + fi + elif [ "$3" = "0" ] + then + # Properly kill zabbix service + log "ZABBIX" "Stopping zabbix agent" + /etc/init.d/zabbix_agentd stop + json_add_string zabbix_send_data "n" + else + log "ZABBIX" "No changes in zabbix service" + fi + json_dump > /root/flashbox_config.json + json_close_object } check_zabbix_startup() { - local _do_restart - _do_restart="$1" + local _do_restart + _do_restart="$1" - if [ "$(get_zabbix_send_data)" = "y" ] && [ -f /etc/zabbix_agentd.psk ] - then - # Enable Zabbix - /etc/init.d/zabbix_agentd enable - if [ "$_do_restart" = "true" ] - then - /etc/init.d/zabbix_agentd restart - else - /etc/init.d/zabbix_agentd start - fi - log "ZABBIX" "Zabbix Enabled" - else - # Disable Zabbix - /etc/init.d/zabbix_agentd stop - /etc/init.d/zabbix_agentd disable - log "ZABBIX" "Zabbix Disabled" - fi + if [ "$(get_zabbix_send_data)" = "y" ] && [ -f /etc/zabbix_agentd.psk ] + then + # Enable Zabbix + /etc/init.d/zabbix_agentd enable + if [ "$_do_restart" = "true" ] + then + /etc/init.d/zabbix_agentd restart + else + /etc/init.d/zabbix_agentd start + fi + log "ZABBIX" "Zabbix Enabled" + else + # Disable Zabbix + /etc/init.d/zabbix_agentd stop 2>/dev/null + /etc/init.d/zabbix_agentd disable + log "ZABBIX" "Zabbix Disabled" + fi } update_zabbix_params() { - local _res - local _retstatus - local _success - local _psk - local _fqdn - local _send_data + local _res + local _retstatus + local _success + local _psk + local _fqdn + local _send_data - if [ "$1" = "on" ] - then - _res=$(curl -s --tlsv1.2 --connect-timeout 5 --retry 1 \ - -H "Content-Type: application/json" -H "X-ANLIX-ID: $(get_mac)" \ - -H "X-ANLIX-SEC: $FLM_CLIENT_SECRET" \ - --data @- "https://$FLM_SVADDR/deviceinfo/get/measureconfig") - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - json_load "$_res" - json_get_var _success success - if [ "$_success" = "1" ] - then - json_get_var _psk psk - json_get_var _fqdn fqdn - json_get_var _send_data is_active - set_zabbix_params "$_psk" "$_fqdn" "$_send_data" - else - log "ZABBIX" "Error retrieving parameters from flashman" - fi - json_close_object - else - log "ZABBIX" "Failed to get parameters in flashman" - fi - elif [ "$1" = "off" ] - then - json_cleanup - json_load_file /root/flashbox_config.json - json_add_string zabbix_send_data "n" - json_dump > /root/flashbox_config.json - json_close_object - /etc/init.d/zabbix_agentd stop - fi + if [ "$1" = "on" ] + then + _res=$(curl -s --tlsv1.2 --connect-timeout 5 --retry 1 \ + -H "Content-Type: application/json" -H "X-ANLIX-ID: $(get_mac)" \ + -H "X-ANLIX-SEC: $FLM_CLIENT_SECRET" \ + --data @- "https://$FLM_SVADDR/deviceinfo/get/measureconfig") + _retstatus=$? + if [ $_retstatus -eq 0 ] + then + json_load "$_res" + json_get_var _success success + if [ "$_success" = "1" ] + then + json_get_var _psk psk + json_get_var _fqdn fqdn + json_get_var _send_data is_active + set_zabbix_params "$_psk" "$_fqdn" "$_send_data" + else + log "ZABBIX" "Error retrieving parameters from flashman" + fi + json_close_object + else + log "ZABBIX" "Failed to get parameters in flashman" + fi + elif [ "$1" = "off" ] + then + json_cleanup + json_load_file /root/flashbox_config.json + json_add_string zabbix_send_data "n" + json_dump > /root/flashbox_config.json + json_close_object + /etc/init.d/zabbix_agentd stop + fi } diff --git a/files/usr/share/hostapdstats.sh b/files/usr/share/hostapdstats.sh new file mode 100755 index 00000000..a61d5175 --- /dev/null +++ b/files/usr/share/hostapdstats.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +. /usr/share/functions/api_functions.sh + +WLAN_ITF="$1" +EVENT="$2" +INFO="$3" + +# WPS event handlers +if [ "$EVENT" == "WPS-PBC-ACTIVE" ] +then + # Push button active + send_wps_status "0" "1" +elif [ "$EVENT" == "WPS-TIMEOUT" ] || [ "$EVENT" == "WPS-PBC-DISABLE" ] +then + # Push button disabled + send_wps_status "0" "0" + # State 1 should be "$EVENT" == "WPS-SUCCESS" but useless at the moment +elif [ "$EVENT" == "WPS-REG-SUCCESS" ] +then + # Device MAC authenticated by WPS + send_wps_status "2" "$INFO" +fi diff --git a/files/usr/share/imalive.sh b/files/usr/share/imalive.sh index eca4192f..9d977f48 100755 --- a/files/usr/share/imalive.sh +++ b/files/usr/share/imalive.sh @@ -4,114 +4,127 @@ . /usr/share/functions/common_functions.sh . /usr/share/functions/system_functions.sh . /usr/share/functions/device_functions.sh +. /usr/share/functions/network_functions.sh +. /usr/share/functions/wireless_functions.sh . /usr/share/functions/zabbix_functions.sh -# Verify if connection is up. -check_connectivity_flashman() { - if ping -q -c 2 -w 2 "$FLM_SVADDR" >/dev/null - then - # true - echo 0 - else - # false - echo 1 - fi +redo_connections() { + [ "$(get_mesh_mode)" -gt "1" ] && [ "$(is_mesh_slave)" = "1" ] && [ ! "$(is_mesh_connected)" ] && auto_change_mesh_slave_channel + renew_dhcp } -log "IMALIVE" "ROUTER STARTED!" +_anlix_version="$(cat /etc/anlix_version)" +log "IMALIVE" "ROUTER STARTED (v$_anlix_version)!" connected=false _num_ntptests=0 while [ "$connected" != true ] do - if [ "$(check_connectivity_flashman)" -eq 0 ] - then - ntpinfo=$(ntp_anlix) - if [ $ntpinfo = "unsync" ] - then - log "IMALIVE" "Waiting for NTP to sync! ..." - _num_ntptests=$(( _num_ntptests + 1 )) - if [ $_num_ntptests -gt 30 ] - then - #More than 30 checks (>150s), force a date update - log "IMALIVE" "Try resync date with Flashman!" - resync_ntp - else - sleep 5 - fi - else - log "IMALIVE" "Connected!" - log "IMALIVE" "Checking zabbix..." - check_zabbix_startup "false" - log "IMALIVE" "Running update..." - sh /usr/share/flashman_update.sh - connected=true - fi - else - log "IMALIVE" "No access to internet! Waiting to retry ..." - sleep 5 - fi + if [ "$(check_connectivity_flashman)" -eq 0 ] + then + ntpinfo=$(ntp_anlix) + if [ $ntpinfo = "unsync" ] + then + log "IMALIVE" "Sync date with Flashman!" + resync_ntp + #give some time to sync (just in second attempt) + if [ $_num_ntptests -eq 0 ] + then + _num_ntptests=1 + else + sleep 5 + fi + else + _num_ntptests=0 + if [ "$ZBX_SUPPORT" == "y" ] + then + log "IMALIVE" "Checking zabbix..." + check_zabbix_startup "false" + fi + log "IMALIVE" "Running update..." + sh /usr/share/flashman_update.sh + if [ $? == 1 ] + then + connected=true + else + sleep 5 + fi + fi + else + log "IMALIVE" "Cant reach Flashman server! Waiting to retry ..." + sleep 5 + redo_connections + fi done MQTTSEC=$(set_mqtt_secret) -log "IMALIVE" "Start main loop" +log "IMALIVE" "Start main loop (v$_anlix_version)" numbacks=1 while true do - MQTTSEC=$(set_mqtt_secret) - if [ -z $MQTTSEC ] - then - log "IMALIVE" "Empty MQTT Secret... Waiting..." - else - log "IMALIVE" "Running MQTT client" - anlix-mqtt flashman/update/$(get_mac) --clientid $(get_mac) \ - --host $FLM_SVADDR --port $MQTT_PORT \ - --cafile /etc/ssl/certs/ca-certificates.crt \ - --shell "sh /usr/share/mqtt.sh " --username $(get_mac) --password $MQTTSEC - if [ $? -eq 0 ] - then - log "IMALIVE" "MQTT Exit OK" - numbacks=1 - else - log "IMALIVE" "MQTT Exit with code $?" - fi - fi + MQTTSEC=$(set_mqtt_secret) + if [ -z $MQTTSEC ] + then + log "IMALIVE" "Empty MQTT Secret... Waiting..." + else + [ "$(type -t anlix_force_clean_memory)" ] && anlix_force_clean_memory + log "IMALIVE" "Running MQTT client (v$_anlix_version)" + anlix-mqtt flashman/update/$(get_mac) --clientid $(get_mac) \ + --host $FLM_SVADDR --port $MQTT_PORT \ + --cafile /etc/ssl/certs/ca-certificates.crt \ + --shell "sh /usr/share/mqtt.sh " --username $(get_mac) --password $MQTTSEC + if [ $? -eq 0 ] + then + log "IMALIVE" "MQTT Exit OK" + numbacks=1 + else + log "IMALIVE" "MQTT Exit with code $?" + fi + fi - #if we were disconnected because of lack of connectivity - # try again only when connection is restored - if [ ! "$(check_connectivity_flashman)" -eq 0 ] - then - log "IMALIVE" "Cant reach Flashman server!" - connected=false - while [ "$connected" != true ] - do - if [ "$(check_connectivity_flashman)" -eq 0 ] - then - log "IMALIVE" "Reconnected!" - log "IMALIVE" "Checking zabbix..." - check_zabbix_startup "true" - log "IMALIVE" "Running update..." - sh /usr/share/flashman_update.sh - connected=true - numbacks=1 - else - sleep 5 - fi - done - fi + #if we were disconnected because of lack of connectivity + # try again only when connection is restored + if [ "$(check_connectivity_flashman)" -eq 1 ] + then + log "IMALIVE" "Cant reach Flashman server! Waiting to retry ..." + connected=false + while [ "$connected" != true ] + do + if [ "$(check_connectivity_flashman)" -eq 0 ] + then + if [ "$ZBX_SUPPORT" == "y" ] + then + log "IMALIVE" "Checking zabbix..." + check_zabbix_startup "true" + fi + log "IMALIVE" "Running update..." + sh /usr/share/flashman_update.sh + if [ $? == 1 ] + then + connected=true + numbacks=1 + else + sleep 5 + fi + else + sleep 5 + redo_connections + fi + done + fi - #backoff - _rand=$(head /dev/urandom | tr -dc "123456789") - ran=${_rand:0:2} - backoff=$(( numbacks + ( ran % numbacks ) )) + #backoff + _rand=$(head /dev/urandom | tr -dc "123456789") + ran=${_rand:0:2} + backoff=$(( numbacks + ( ran % numbacks ) )) - sleep $backoff - numbacks=$(( numbacks + 1 )) - if [ $numbacks -gt 60 ] - then - numbacks=60 - fi - log "IMALIVE" "Retrying count $numbacks ..." + sleep $backoff + numbacks=$(( numbacks + 1 )) + if [ $numbacks -gt 60 ] + then + numbacks=60 + fi + log "IMALIVE" "Retrying count $numbacks ..." done diff --git a/files/usr/share/keepalive.sh b/files/usr/share/keepalive.sh index a63f003a..758aa647 100755 --- a/files/usr/share/keepalive.sh +++ b/files/usr/share/keepalive.sh @@ -7,39 +7,54 @@ . /usr/share/functions/device_functions.sh . /usr/share/functions/wireless_functions.sh . /usr/share/functions/network_functions.sh +. /usr/share/functions/api_functions.sh _need_update=0 +_force_update=0 _cert_error=0 +_anlix_version="$(cat /etc/anlix_version)" while true do - sleep 300 + sleep 300 - _rand=$(head /dev/urandom | tr -dc "012345") - _number=${_rand:0:1} + _rand=$(head /dev/urandom | tr -dc "012345") + _number=${_rand:0:1} - if [ "$_number" -eq 3 ] || [ "$1" == "now" ] - then - # Get WiFi data - json_cleanup - json_load "$(get_wifi_local_config)" - json_get_var _local_ssid_24 local_ssid_24 - json_get_var _local_password_24 local_password_24 - json_get_var _local_channel_24 local_channel_24 - json_get_var _local_hwmode_24 local_hwmode_24 - json_get_var _local_htmode_24 local_htmode_24 - json_get_var _local_5ghz_capable local_5ghz_capable - json_get_var _local_ssid_50 local_ssid_50 - json_get_var _local_password_50 local_password_50 - json_get_var _local_channel_50 local_channel_50 - json_get_var _local_hwmode_50 local_hwmode_50 - json_get_var _local_htmode_50 local_htmode_50 - json_close_object + if [ "$_number" -eq 3 ] || [ "$1" == "now" ] + then + # Get WiFi data + json_cleanup + json_load "$(get_wifi_local_config)" + json_get_var _local_ssid_24 local_ssid_24 + json_get_var _local_password_24 local_password_24 + json_get_var _local_channel_24 local_channel_24 + json_get_var _local_hwmode_24 local_hwmode_24 + json_get_var _local_htmode_24 local_htmode_24 + json_get_var _local_state_24 local_state_24 + json_get_var _local_5ghz_capable local_5ghz_capable + json_get_var _local_ssid_50 local_ssid_50 + json_get_var _local_password_50 local_password_50 + json_get_var _local_channel_50 local_channel_50 + json_get_var _local_hwmode_50 local_hwmode_50 + json_get_var _local_htmode_50 local_htmode_50 + json_get_var _local_state_50 local_state_50 + json_close_object - log "KEEPALIVE" "Ping Flashman ..." - # - # WARNING! No spaces or tabs inside the following string! - # - _data="id=$(get_mac)&\ + # Get WPS state if exists + _local_wps_state="0" + if [ -f "/tmp/wps_state.json" ] + then + json_cleanup + json_load_file /tmp/wps_state.json + json_get_var _local_wps_state wps_content + json_close_object + fi + + log "KEEPALIVE" "Ping Flashman (v$_anlix_version) ..." + # + # WARNING! No spaces or tabs inside the following string! + # + _data="id=$(get_mac)&\ flm_updater=0&\ version=$(get_flashbox_version)&\ model=$(get_hardware_model)&\ @@ -50,82 +65,104 @@ pppoe_password=$(uci -q get network.wan.password)&\ wan_ip=$(get_wan_ip)&\ wan_negociated_speed=$(get_wan_negotiated_speed)&\ wan_negociated_duplex=$(get_wan_negotiated_duplex)&\ -lan_addr=$(get_lan_subnet)&\ +lan_addr=$(get_lan_ipaddr)&\ lan_netmask=$(get_lan_netmask)&\ wifi_ssid=$_local_ssid_24&\ wifi_password=$_local_password_24&\ wifi_channel=$_local_channel_24&\ wifi_band=$_local_htmode_24&\ wifi_mode=$_local_hwmode_24&\ +wifi_state=$_local_state_24&\ wifi_5ghz_capable=$_local_5ghz_capable&\ wifi_ssid_5ghz=$_local_ssid_50&\ wifi_password_5ghz=$_local_password_50&\ wifi_channel_5ghz=$_local_channel_50&\ wifi_band_5ghz=$_local_htmode_50&\ wifi_mode_5ghz=$_local_hwmode_50&\ +wifi_state_5ghz=$_local_state_50&\ connection_type=$(get_wan_type)&\ -ntp=$(ntp_anlix)" - _url="deviceinfo/syn/" - _res=$(rest_flashman "$_url" "$_data") +ntp=$(ntp_anlix)&\ +sysuptime=$(sys_uptime)&\ +wanuptime=$(wan_uptime)&\ +wpsstate=$_local_wps_state" + _url="deviceinfo/syn/" + _res=$(rest_flashman "$_url" "$_data") + + _retstatus=$? + if [ $_retstatus -eq 0 ] + then + _cert_error=0 + json_cleanup + json_load "$_res" + json_get_var _do_update do_update + json_get_var _do_newprobe do_newprobe + json_get_var _mqtt_status mqtt_status + json_close_object + + if [ "$_do_newprobe" = "1" ] + then + log "KEEPALIVE" "Router Registred in Flashman Successfully!" + # On a new probe, force a new registry in mqtt secret + reset_mqtt_secret > /dev/null + sh /usr/share/flashman_update.sh + fi + + if [ "$_do_update" = "1" ] + then + _need_update=$(( _need_update + 1 )) + else + _need_update=0 + fi - _retstatus=$? - if [ $_retstatus -eq 0 ] - then - _cert_error=0 - json_cleanup - json_load "$_res" - json_get_var _do_update do_update - json_get_var _do_newprobe do_newprobe - json_get_var _mqtt_status mqtt_status - json_close_object + if [ $_need_update -gt 7 ] + then + if [ $_force_update -eq 1 ] + then + _force_update=0 + else + lock -n /tmp/lock_firmware || _force_update=1 + fi - if [ "$_do_newprobe" = "1" ] - then - log "KEEPALIVE" "Router Registred in Flashman Successfully!" - # On a new probe, force a new registry in mqtt secret - reset_mqtt_secret > /dev/null - sh /usr/share/flashman_update.sh - fi + if [ $_force_update -eq 0 ] + then + lock -u /tmp/lock_firmware + # More than 7 checks (>20 min), force a firmware update + log "KEEPALIVE" "Running update ..." + sh /usr/share/flashman_update.sh + fi + _need_update=0 + fi - if [ "$_do_update" = "1" ] - then - _need_update=$(( _need_update + 1 )) - else - _need_update=0 - fi + if [ "$_mqtt_status" = "0" ] + then + # Check is mqtt is running + mqttpid=$(pgrep anlix-mqtt) + if [ "$mqttpid" ] && [ $mqttpid -gt 0 ] + then + log "KEEPALIVE" "MQTT not connected to Flashman! Restarting..." + kill -9 $mqttpid + fi + fi + elif [ $_retstatus -eq 2 ] + then + log "KEEPALIVE" "Fail in Flashman Certificate! Retry $_cert_error" + # Certificate problems are related to desync dates + # Wait NTP, or correct if we can... + _cert_error=$(( _cert_error + 1 )) + if [ $_cert_error -gt 7 ] + then + # More than 7 checks (>20 min), force a date update + log "KEEPALIVE" "Try resync date with Flashman!" + resync_ntp + _cert_error=0 + fi + else + log "KEEPALIVE" "Fail in Rest Flashman! Aborting..." + fi - if [ $_need_update -gt 7 ] - then - # More than 7 checks (>20 min), force a firmware update - log "KEEPALIVE" "Running update ..." - sh /usr/share/flashman_update.sh - fi + #always keep the updater locker free + lock -u /tmp/lock_updater - if [ "$_mqtt_status" = "0" ] - then - # Check is mqtt is running - mqttpid=$(pgrep anlix-mqtt) - if [ "$mqttpid" ] && [ $mqttpid -gt 0 ] - then - log "KEEPALIVE" "MQTT not connected to Flashman! Restarting..." - kill -9 $mqttpid - fi - fi - elif [ $_retstatus -eq 2 ] - then - log "KEEPALIVE" "Fail in Flashman Certificate! Retry $_cert_error" - # Certificate problems are related to desync dates - # Wait NTP, or correct if we can... - _cert_error=$(( _cert_error + 1 )) - if [ $_cert_error -gt 7 ] - then - # More than 7 checks (>20 min), force a date update - log "KEEPALIVE" "Try resync date with Flashman!" - resync_ntp - _cert_error=0 - fi - else - log "KEEPALIVE" "Fail in Rest Flashman! Aborting..." - fi - fi + [ "$(type -t anlix_force_clean_memory)" ] && anlix_force_clean_memory + fi done diff --git a/files/usr/share/lua/auth.lua b/files/usr/share/lua/auth.lua new file mode 100644 index 00000000..35690d3d --- /dev/null +++ b/files/usr/share/lua/auth.lua @@ -0,0 +1,61 @@ +local auth={}; + +auth.user = "" +auth.is_auth = false + +function auth.get_user() + return auth.user +end + +function auth.is_authorized() + return auth.is_auth +end + +function auth.decode_provider() + local result = run_process("pk b64dec /tmp/provider.data") + local status, data = pcall(function() return json.decode(result) end) + if not status then + return false + end + + local cur_time = os.time() + if data.expire < cur_time then + return false + end + + auth.user = data.user + return true +end + +function auth.authenticate(auth_data) + + local provider_json = auth_data.provider + local provider_sign = auth_data.sign + + if provider_json == nil or provider_sign == nil then + return false + end + + if not (type(provider_json) == "string" and type(provider_sign) == "string") then + return false + end + + -- check the provider information + touch_file("/tmp/provider.data") + append_to_file("/tmp/provider.data", provider_json) + touch_file("/tmp/provider.data.sig") + append_to_file("/tmp/provider.data.sig", provider_sign) + + local result = run_process("pk verify /etc/provider.pubkey /tmp/provider.data") + + auth.is_auth = false + if string.sub(result, 1, 2) == "OK" then + auth.is_auth = auth.decode_provider() + end + + os.remove("/tmp/provider.data") + os.remove("/tmp/provider.data.sig") + return auth.is_auth +end + +return auth diff --git a/files/usr/share/lua/config.lua b/files/usr/share/lua/config.lua new file mode 100644 index 00000000..78c3f72c --- /dev/null +++ b/files/usr/share/lua/config.lua @@ -0,0 +1,122 @@ +flashman = require("flashman") + +function handle_config(command, data) + + local app_protocol_ver = data.version + + if command == "diagnose" then + -- Diagnose router and forward result to reply + local data = flashman.run_diagnostic() + web.send_json(data) + return + elseif command == "retrySapoFlashman" then + -- Force a retry on sapo flashman communication + local slave_mac = data.slave_mac + flashman.retry_sapo_flashman(slave_mac) + web.send_json({success = true}) + return + elseif command == "getLoginInfo" then + -- Send information for diagnose app login + local resp = {} + resp["mac"] = flashman.get_router_id() + resp["version"] = flashman.get_router_version() + resp["release"] = flashman.get_router_release() + resp["conn_type"] = flashman.get_wan_type() + resp["flashman"] = flashman.get_server() + resp["wifi"] = flashman.get_wifi_config() + resp["mesh_master"] = flashman.get_mesh_master() + if (resp["conn_type"] == "pppoe") then + resp["pppoe"] = {} + resp["pppoe"]["user"] = flashman.get_pppoe_user() + resp["pppoe"]["pass"] = flashman.get_pppoe_pass() + elseif (resp["conn_type"] == "none") then + local config_file = json.decode(read_file("/root/flashbox_config.json")) + resp["bridge"] = {} + resp["bridge"]["switch"] = (config_file["bridge_disable_switch"] == "y") + local ip_config = config_file["bridge_fix_ip"] + if (ip_config ~= nil and ip_config ~= "") then + resp["bridge"]["ip"] = ip_config + resp["bridge"]["gateway"] = config_file["bridge_fix_gateway"] + resp["bridge"]["dns"] = config_file["bridge_fix_dns"] + else + resp["bridge"]["ip"] = "" + end + end + web.send_json(resp) + return + elseif command == "getRoutersInfo" then + local routers = ubus("anlix_sapo", "get_router_status") + local resp = {} + resp["ok"] = true; + if(routers ~= nil and next(routers) ~= nil) then + resp["routers"] = routers + end + web.send_json(resp) + return + elseif command == "nobridge" then + -- Disable bridge and reply with ok so that + web.send_json({success = true}) -- reply before changing network + flashman.disable_bridge() + return + elseif command == "wan" then + -- Change WAN type with given parameters + local config_file = json.decode(read_file("/root/flashbox_config.json")) + config_file["did_change_wan_local"] = "y" + local conn_type = data.conn_type + local local_conn_type = flashman.get_wan_type() + if conn_type == "dhcp" then + -- Change to DHCP, ignore if already in DHCP + if local_conn_type == "dhcp" then + web.send_json({success = true}) -- simply reply with success + return + end + write_file("/root/flashbox_config.json", json.encode(config_file)) + web.send_json({success = true}) -- reply before changing network + flashman.set_wan_type("dhcp", "none", "none") + elseif conn_type == "pppoe" then + -- Change to PPPoE, assume we always need to update credentials + local user = data.user + local pass = data.password + if user == nil or pass == nil or user == "" or pass == "" then + web.error_handle(web.ERROR_PARAMETERS, nil) + return + end + write_file("/root/flashbox_config.json", json.encode(config_file)) + web.send_json({success = true}) -- reply before changing network + if local_conn_type == "pppoe" then + flashman.set_pppoe_credentials(user, pass) + else + flashman.set_wan_type("pppoe", user, pass) + end + elseif conn_type == "bridge" then + local disable_switch = data.disable_switch + if (disable_switch) then + disable_switch = "y" + else + disable_switch = "n" + end + local ip = data.fix_ip + local gateway = data.fix_gateway + local dns = data.fix_dns + if ip ~= nil and ip ~= "" then + if gateway == nil or gateway == "" or dns == nil or dns == "" then + -- Validate presence of gateway and dns parameters if using fix ip + web.error_handle(web.ERROR_PARAMETERS, nil) + return + end + end + local local_config = read_file("/root/flashbox_config.json") + local_config = json.decode(local_config) + write_file("/root/flashbox_config.json", json.encode(config_file)) + web.send_json({success = true}) -- reply before changing network + if local_config.bridge_mode ~= "y" then + -- Enable bridge mode + flashman.enable_bridge(disable_switch, ip, gateway, dns) + else + -- Update bridge parameters, assume we always need to update + flashman.update_bridge(disable_switch, ip, gateway, dns) + end + end + end + +end diff --git a/files/usr/share/lua/flashman.lua b/files/usr/share/lua/flashman.lua new file mode 100644 index 00000000..3a4cab47 --- /dev/null +++ b/files/usr/share/lua/flashman.lua @@ -0,0 +1,184 @@ + +local flashman={}; + +function flashman.get_router_id() + local result = run_process("sh -c \". /usr/share/functions/device_functions.sh; get_mac\"") + -- remove \n + return result:sub(1,-2) +end + +function flashman.get_router_version() + local result = run_process("sh -c \". /usr/share/functions/common_functions.sh; get_flashbox_version\"") + -- remove \n + return result:sub(1,-2) +end + +function flashman.get_router_release() + local result = run_process("sh -c \". /usr/share/functions/common_functions.sh; get_flashbox_release\"") + -- remove \n + return result:sub(1,-2) +end + +function flashman.get_wifi_config() + local result = run_process("sh -c \". /usr/share/functions/wireless_functions.sh; get_wifi_local_config\"") + -- remove \n + return result:sub(1,-2) +end + +function flashman.get_router_ssid() + local result = run_process("sh -c \". /usr/share/functions/wireless_functions.sh; get_wifi_local_config | jsonfilter -e '@[\\\"local_ssid_24\\\"]'\"") + -- remove \n + return result:sub(1,-2) +end + +function flashman.get_mac_from_ip(ip) + local result = run_process("sh -c \". /usr/share/functions/dhcp_functions.sh; get_device_mac_from_ip " .. ip .. "\"") + -- remove \n + return result:sub(1,-2) +end + +function flashman.get_wan_type() + local result = run_process("sh -c \". /usr/share/functions/network_functions.sh; get_wan_type\"") + -- remove \n + return result:sub(1,-2) +end + +function flashman.get_pppoe_user() + local result = run_process("sh -c \"uci -q get network.wan.username\"") + -- remove \n + return result:sub(1,-2) +end + +function flashman.get_pppoe_pass() + local result = run_process("sh -c \"uci -q get network.wan.password\"") + -- remove \n + return result:sub(1,-2) +end + +function flashman.retry_sapo_flashman(slave_mac) + run_process("sh -c \". /usr/share/functions/network_functions.sh; set_mesh_slaves " .. slave_mac .. "\"") +end + +function flashman.get_mesh_master() + local result = run_process("sh -c \". /usr/share/functions/network_functions.sh; get_mesh_master\"") + -- remove \n + return result:sub(1,-2) +end + +function flashman.set_wan_type(conn_type, user, pass) + local result = run_process("sh -c \". /usr/share/functions/network_functions.sh; set_wan_type " .. conn_type .. " " .. user .. " " .. pass .. " y &\"") +end + +function flashman.set_pppoe_credentials(user, pass) + local result = run_process("sh -c \". /usr/share/functions/network_functions.sh; set_pppoe_credentials " .. user .. " " .. pass .. " y &\"") +end + +function flashman.enable_bridge(switch, ip, gw, dns) + local result = run_process("sh -c \". /usr/share/functions/network_functions.sh; enable_bridge_mode y y " .. switch .. " " .. ip .. " " .. gw .. " " .. dns .. " &\"") +end + +function flashman.update_bridge(switch, ip, gw, dns) + local result = run_process("sh -c \". /usr/share/functions/network_functions.sh; update_bridge_mode y " .. switch .. " " .. ip .. " " .. gw .. " " .. dns .. " &\"") +end + +function flashman.disable_bridge() + local result = run_process("sh -c \". /usr/share/functions/network_functions.sh; disable_bridge_mode n y &\"") +end + +function flashman.run_diagnostic() + local result = run_process("sh -c \". /usr/share/functions/api_functions.sh; run_diagnostics_test\"") + -- remove \n + return result:sub(1,-2) +end + +function flashman.is_authenticated() + local result = run_process("sh -c \". /usr/share/functions/common_functions.sh; if is_authenticated; then echo 1; else echo 0; fi\"") + -- remove \n + result = result:sub(1,-2) + + if result == "1" then + return true + else + return false + end +end + +function flashman.get_router_passwd() + local result = run_process("sh -c \". /usr/share/functions/api_functions.sh; get_flashapp_pass\"") + -- remove \n + result = result:sub(1,-2) + if result == nil or result == "" then + result = nil + end + return result +end + +function flashman.save_router_passwd_local(pass) + run_process("sh -c \". /usr/share/functions/api_functions.sh; set_flashapp_pass ".. pass .."\"") + return true +end + +function flashman.save_router_passwd_flashman(passwd, app_id, app_secret) + local flashman_addr = flashman.get_server() + auth = {} + auth["id"]=flashman.get_router_id() + auth["secret"]=flashman.get_router_secret() + auth["app_id"]=app_id + auth["app_secret"]=app_secret + auth["router_passwd"]=passwd + post_data = json.encode(auth) + + post_data = post_data:gsub("\"","\\\"") + cmd_curl = "curl -s --tlsv1.2 -X POST -H \"Content-Type:application/json\" -d \"".. post_data .."\" https://".. flashman_addr .."/deviceinfo/app/addpass?api=1" + + local result = run_process(cmd_curl) + local jres = json.decode(result) + + if jres["is_registered"] == 1 then + return true + elseif jres["is_registered"] == nil then + -- Legacy flashman doesn't have the url, can't set password on flashman + return true + else + return false + end +end + +function flashman.get_router_secret() + local result = run_process(". /usr/share/flashman_init.conf; echo $FLM_CLIENT_SECRET") + -- remove \n + return result:sub(1,-2) +end + +function flashman.get_server() + local result = run_process(". /usr/share/flashman_init.conf; echo $FLM_SVADDR") + -- remove \n + return result:sub(1,-2) +end + +function flashman.update(remote_addr, app_id, app_secret) + local flashman_addr = flashman.get_server() + -- Add App to the flashman base + auth = {} + auth["id"]=flashman.get_router_id() + auth["secret"]=flashman.get_router_secret() + auth["app_id"]=app_id + auth["app_secret"]=app_secret + auth["app_mac"]=flashman.get_mac_from_ip(remote_addr) + post_data = json.encode(auth) + + post_data = post_data:gsub("\"","\\\"") + cmd_curl = "curl -s --tlsv1.2 -X POST -H \"Content-Type:application/json\" -d \"".. post_data .."\" https://".. flashman_addr .."/deviceinfo/app/add?api=1" + + local result = run_process(cmd_curl) + + local jres = json.decode(result) + + if jres["is_registered"] == 1 then + return true + else + return false + end +end + +return flashman diff --git a/files/usr/share/lua/lib.lua b/files/usr/share/lua/lib.lua new file mode 100644 index 00000000..f2875f29 --- /dev/null +++ b/files/usr/share/lua/lib.lua @@ -0,0 +1,129 @@ +local _ubus = require "ubus" +local _ubus_connection = nil + +-- Generic Routines + +function run_process(proc) + local handle = io.popen(proc) + local result = handle:read("*a") + handle:close() + return result +end + +function check_file(path) + local file = io.open(path, "rb") + if not file then + return false + else + file:close() + return true + end +end + +function write_file(path, content) + local file = io.open(path, "wb") + if not file then return false end + file:write(content) + file:close() + return true +end + +function read_file(path) + local file = io.open(path, "rb") + if not file then return nil end + local content = file:read "*all" + file:close() + return content +end + +function read_lines(path) + if not check_file(path) then return nil end + local file = io.lines(path) + local content = {} + for line in file do + table.insert(content, line) + end + return content +end + +function trim_file(path) + if not check_file(path) then return end + local file = io.lines(path) + local content = {} + local line_count = 0 + for line in file do + table.insert(content, line) + line_count = line_count + 1 + end + file = io.open(path, "wb") + for index, line in ipairs(content) do + if (index > 1 or line_count <= 5) then + file:write(line .. "\n") + end + end +end + +function append_to_file(path, content) + local file = io.open(path, "ab") + if not file then return false end + file:write(content) + file:close() + return true +end + +function remove_from_file(path, data) + if not check_file(path) then return false end + local file = io.lines(path) + local ret = false + local content = {} + for line in file do + if not line:match(data) then + table.insert(content, line) + else + ret = true + end + end + file = io.open(path, "wb") + for index, line in ipairs(content) do + file:write(line .. "\n") + end + file:close() + return ret +end + +function touch_file(path) + local file = io.open(path, "wb") + if not file then return false end + local content = file:write "" + file:close() + return true +end + +-- Ubus Routines + +function ubus(object, method, data) + if not _ubus_connection then + _ubus_connection = _ubus.connect() + if not _ubus_connection then + return nil + end + end + + if object and method then + if type(data) ~= "table" then + data = { } + end + return _ubus_connection:call(object, method, data) + else + return nil + end +end + +-- Ubus Logger + +function logger(info) + if info then + ubus("log", "write", { event = "uHTTP: " .. info }) + end +end + diff --git a/files/usr/share/lua/webHandle.lua b/files/usr/share/lua/webHandle.lua new file mode 100644 index 00000000..4f377327 --- /dev/null +++ b/files/usr/share/lua/webHandle.lua @@ -0,0 +1,64 @@ +local web={}; + +web.ERROR_PROT_VER = 1 +web.ERROR_GEN_SECRET = 2 +web.ERROR_PARAMETERS = 3 +web.ERROR_PASSWD_SAVE = 4 +web.ERROR_ROUTER_PASSWD = 5 +web.ERROR_CMD_UNKNOWN = 6 +web.ERROR_FLASHMAN_UPDATE = 7 +web.ERROR_SECRET_MATCH = 8 +web.ERROR_AUTH_FAIL = 10 +web.ERROR_READ_MAC = 11 +web.ERROR_URL = 20 +web.ERROR_DATA = 21 +web.ERROR_COMM_AUTH_PROVIDER = 22 +web.ERROR_AUTH_PROVIDER = 23 +web.ERROR_NO_CHANGE = 30 + +function web.error_string(errid) + if errid == web.ERROR_PROT_VER then return "Invalid Protocol Version" + elseif errid == web.ERROR_GEN_SECRET then return "Error generating secret for app" + elseif errid == web.ERROR_PARAMETERS then return "Invalid Parameters" + elseif errid == web.ERROR_PASSWD_SAVE then return "Error saving password" + elseif errid == web.ERROR_ROUTER_PASSWD then return "Password not match" + elseif errid == web.ERROR_CMD_UNKNOWN then return "Command not implemented" + elseif errid == web.ERROR_FLASHMAN_UPDATE then return "Error updating flashman" + elseif errid == web.ERROR_SECRET_MATCH then return "Secret not match" + elseif errid == web.ERROR_AUTH_FAIL then return "Authorization Fail" + elseif errid == web.ERROR_READ_MAC then return "Error reading mac address" + elseif errid == web.ERROR_URL then return "Invalid URL" + elseif errid == web.ERROR_DATA then return "Invalid DATA" + elseif errid == web.ERROR_COMM_AUTH_PROVIDER then return "Command need provider authorization" + elseif errid == web.ERROR_AUTH_PROVIDER then return "Provider Authorization Fail" + elseif errid == web.ERROR_NO_CHANGE then return "No changes to current configuration" + else return "Unknown Error" + end +end + +function web.error_handle(errid, auth) + resp = {} + err = {} + err["errno"] = errid + err["errstr"] = web.error_string(errid) + if auth ~= nil then resp["auth"] = auth end + resp["Error"] = err + + uhttpd.send("Status: 500 Internal Server Error\r\n") + uhttpd.send("Content-Type: text/json\r\n\r\n") + uhttpd.send(json.encode(resp)) +end + +function web.send_json(data) + uhttpd.send("Status: 200 OK\r\n") + uhttpd.send("Content-Type: text/json\r\n\r\n") + uhttpd.send(json.encode(data)) +end + +function web.send_plain(data) + uhttpd.send("Status: 200 OK\r\n") + uhttpd.send("Content-Type: text/plain\r\n\r\n") + uhttpd.send(data) +end + +return web diff --git a/files/usr/share/mqtt.sh b/files/usr/share/mqtt.sh index 7795e299..9aadf130 100644 --- a/files/usr/share/mqtt.sh +++ b/files/usr/share/mqtt.sh @@ -5,42 +5,79 @@ . /usr/share/functions/dhcp_functions.sh . /usr/share/functions/api_functions.sh . /usr/share/functions/zabbix_functions.sh +. /usr/share/functions/wireless_functions.sh case "$1" in 1) - log "MQTTMSG" "Running Update" - sh /usr/share/flashman_update.sh $2 - ;; + log "MQTTMSG" "Running Update" + sh /usr/share/flashman_update.sh $2 + ;; boot) - log "MQTTMSG" "Rebooting" - /sbin/reboot - ;; + log "MQTTMSG" "Rebooting" + /sbin/reboot + ;; rstmqtt) - log "MQTTMSG" "Clean up MQTT secret" - reset_mqtt_secret - ;; + log "MQTTMSG" "Clean up MQTT secret" + reset_mqtt_secret + ;; rstapp) - log "MQTTMSG" "Clean up APP secret" - reset_flashapp_pass - ;; + log "MQTTMSG" "Clean up APP secret" + reset_flashapp_pass + ;; log) - log "MQTTMSG" "Sending LIVE log " - send_boot_log "live" - ;; + log "MQTTMSG" "Sending LIVE log " + send_boot_log "live" + ;; onlinedev) - log "MQTTMSG" "Sending Online Devices..." - send_online_devices - ;; + if lock -n /tmp/get_online_devs.lock + then + log "MQTTMSG" "Sending Online Devices..." + send_online_devices + lock -u /tmp/get_online_devs.lock + fi + ;; ping) - log "MQTTMSG" "Running ping test" - run_ping_ondemand_test - ;; + log "MQTTMSG" "Running ping test" + run_ping_ondemand_test + ;; measure) - log "MQTTMSG" "Changing Zabbix PSK settings" - update_zabbix_params "$2" - ;; + log "MQTTMSG" "Changing Zabbix PSK settings" + if [ "$ZBX_SUPPORT" == "y" ] + then + update_zabbix_params "$2" + fi + ;; +status) + if lock -n /tmp/get_status.lock + then + log "MQTTMSG" "Collecting status information" + router_status + lock -u /tmp/get_status.lock + fi + ;; +wifistate) + log "MQTTMSG" "Changing wireless radio state" + change_wifi_state "$2" "$3" + ;; +speedtest) + if lock -n /tmp/set_speedtest.lock + then + log "MQTTMSG" "Starting speed test..." + run_speed_ondemand_test "$2" "$3" "$4" "$5" + lock -u /tmp/set_speedtest.lock + fi + ;; +wps) + if lock -n /tmp/set_wps.lock + then + log "MQTTMSG" "WPS push button pressed" + set_wps_push_button "$2" + lock -u /tmp/set_wps.lock + fi + ;; *) - log "MQTTMSG" "Cant recognize message: $1" - ;; + log "MQTTMSG" "Cant recognize message: $1" + ;; esac +[ "$(type -t anlix_force_clean_memory)" ] && anlix_force_clean_memory diff --git a/files/usr/share/netstats.sh b/files/usr/share/netstats.sh new file mode 100755 index 00000000..0482eed5 --- /dev/null +++ b/files/usr/share/netstats.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +. /usr/share/functions/device_functions.sh +. /usr/share/functions/network_functions.sh + +SLEEP_TIME=60 +[ "$(type -t anlix_force_clean_memory)" ] && SLEEP_TIME=300 + +while true +do + # Collect and store wan traffic information + store_wan_bytes + [ "$(type -t anlix_force_clean_memory)" ] && anlix_force_clean_memory + sleep $SLEEP_TIME +done diff --git a/src/MQTTClient.c b/src/MQTTClient.c index d0401b4e..fc1980ea 100755 --- a/src/MQTTClient.c +++ b/src/MQTTClient.c @@ -293,9 +293,12 @@ int cycle(MQTTClient* c, Timer* timer) len = MQTTSerialize_ack(c->buf, c->buf_size, PUBREC, 0, msg.id); if (len <= 0) rc = FAILURE; - else + else { rc = sendPacket(c, len, timer); - if (rc == FAILURE) + if(rc < 0) + rc = SEND_ERROR; + } + if (rc < 0) goto exit; // there was a problem } break; @@ -311,8 +314,8 @@ int cycle(MQTTClient* c, Timer* timer) (packet_type == PUBREC) ? PUBREL : PUBCOMP, 0, mypacketid)) <= 0) rc = FAILURE; else if ((rc = sendPacket(c, len, timer)) != SUCCESS) // send the PUBREL packet - rc = FAILURE; // there was a problem - if (rc == FAILURE) + rc = SEND_ERROR; // there was a problem + if (rc < 0) goto exit; // there was a problem break; } @@ -326,7 +329,7 @@ int cycle(MQTTClient* c, Timer* timer) if (keepalive(c) != SUCCESS) { //check only keepalive FAILURE status so that previous FAILURE status can be considered as FAULT - rc = FAILURE; + rc = KEEALIVE_TIMEOUT; } exit: @@ -341,6 +344,7 @@ int cycle(MQTTClient* c, Timer* timer) int MQTTYield(MQTTClient* c, int timeout_ms) { int rc = SUCCESS; + int tmprc; Timer timer; TimerInit(&timer); @@ -348,9 +352,10 @@ int MQTTYield(MQTTClient* c, int timeout_ms) do { - if (cycle(c, &timer) < 0) + tmprc = cycle(c, &timer); + if (tmprc < 0) { - rc = FAILURE; + rc = tmprc; break; } } while (!TimerIsExpired(&timer)); diff --git a/src/MQTTClient.h b/src/MQTTClient.h index 798e6bfd..98349e1b 100755 --- a/src/MQTTClient.h +++ b/src/MQTTClient.h @@ -55,7 +55,13 @@ enum QoS { QOS0, QOS1, QOS2, SUBFAIL=0x80 }; /* all failure return codes must be negative */ -enum returnCode { BUFFER_OVERFLOW = -2, FAILURE = -1, SUCCESS = 0 }; +enum returnCode { + SEND_ERROR = -4, + KEEALIVE_TIMEOUT = -3, + BUFFER_OVERFLOW = -2, + FAILURE = -1, + SUCCESS = 0 +}; /* The Platform specific header must define the Network and Timer structures and functions * which operate on them. diff --git a/src/Makefile b/src/Makefile index 4bad53ac..e13cfda4 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,7 @@ CC = gcc OBJS = paho/MQTTConnectClient.o paho/MQTTSerializePublish.o paho/MQTTPacket.o paho/MQTTSubscribeClient.o paho/MQTTDeserializePublish.o paho/MQTTConnectServer.o paho/MQTTSubscribeServer.o paho/MQTTUnsubscribeServer.o paho/MQTTUnsubscribeClient.o -all: anlix-mqtt +all: anlix-mqtt pk %.o: %.c $(CC) $(CFLAGS) -Ipaho -c -o $@ $< @@ -9,5 +9,8 @@ all: anlix-mqtt anlix-mqtt: $(OBJS) MQTTClient.o anlix-mqtt-transport.o anlix-mqtt.o $(CC) $(LDFLAGS) -o $@ $(OBJS) MQTTClient.o anlix-mqtt-transport.o anlix-mqtt.o -lmbedtls -lmbedx509 -lmbedcrypto +pk: pk.o + $(CC) $(LDFLAGS) -o $@ pk.o -lmbedtls -lmbedx509 -lmbedcrypto + clean: - rm *.o paho/*.o anlix-mqtt + rm *.o paho/*.o anlix-mqtt pk diff --git a/src/anlix-mqtt.c b/src/anlix-mqtt.c index 3feb42a9..ff9d285e 100644 --- a/src/anlix-mqtt.c +++ b/src/anlix-mqtt.c @@ -283,7 +283,7 @@ int main(int argc, char** argv) data.username.cstring = opts.username; data.password.cstring = opts.password; - data.keepAliveInterval = 10; + data.keepAliveInterval = 30; data.cleansession = 1; printlog ("Connecting to %s %d", opts.host, opts.port); @@ -311,7 +311,7 @@ int main(int argc, char** argv) rc = MQTTYield(&c, 1000); if(rc != SUCCESS) { toStop = 1; - printlog ("MQTT Yield FAILURE, disconnecting..."); + printlog ("MQTT Yield exit (%d), disconnecting...", rc); } } diff --git a/src/pk.c b/src/pk.c new file mode 100644 index 00000000..87f2a61b --- /dev/null +++ b/src/pk.c @@ -0,0 +1,189 @@ +/* + * Public key-based signature verification program + * + * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: GPL-2.0 + * + * 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 2 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * + * echo 'teste' | openssl base64 | openssl dgst -sha256 -sign provedor.key | openssl base64 + */ + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#if defined(MBEDTLS_PLATFORM_C) +#include "mbedtls/platform.h" +#else +#include +#include +#define mbedtls_snprintf snprintf +#define mbedtls_printf printf +#define mbedtls_exit exit +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ + +#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_MD_C) || \ + !defined(MBEDTLS_SHA256_C) || !defined(MBEDTLS_PK_PARSE_C) || \ + !defined(MBEDTLS_FS_IO) +int main( void ) +{ + mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_MD_C and/or " + "MBEDTLS_SHA256_C and/or MBEDTLS_PK_PARSE_C and/or " + "MBEDTLS_FS_IO not defined.\n"); + return( 0 ); +} +#else + +#include "mbedtls/error.h" +#include "mbedtls/md.h" +#include "mbedtls/pk.h" +#include "mbedtls/base64.h" + +#include "mbedtls/entropy.h" +#include "mbedtls/ctr_drbg.h" + +#include +#include + +int readfile(char *filename, unsigned char *buffer, int sizebuf) +{ + FILE *f; + int i; + if( ( f = fopen( filename, "rb" ) ) == NULL ) + return 0; + + i = fread( buffer, 1, sizebuf, f ); + fclose( f ); + + return i; +} + +#define MAX_BUF_SIZE 512 + +int main( int argc, char *argv[] ) +{ + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; + mbedtls_pk_context pk; + mbedtls_entropy_context entropy; + mbedtls_ctr_drbg_context ctr_drbg; + unsigned char hash[32]; + unsigned char bufin[MAX_BUF_SIZE]; + unsigned char bufout[MAX_BUF_SIZE]; + const char *pers = "mbedtls_pk_sign"; + char filename[64]; + size_t ilen, olen; + + mbedtls_pk_init( &pk ); + mbedtls_entropy_init( &entropy ); + mbedtls_ctr_drbg_init( &ctr_drbg ); + + if( argc < 3 ) + goto exit; + + if ((strncmp(argv[1], "b64enc", 6) == 0) || (strncmp(argv[1], "b64dec", 6) == 0)) { + ilen = readfile(argv[2], bufin, sizeof( bufin )); + if(ilen < 0) + goto exit; + // convert to base64 + if (strncmp(argv[1], "b64enc", 6) == 0) { + if( mbedtls_base64_encode( bufout, sizeof( bufout ), &olen, bufin, ilen ) != 0 ) + goto exit; + } + else { + if( mbedtls_base64_decode( bufout, sizeof( bufout ), &olen, bufin, ilen ) != 0 ) + goto exit; + } + + if(olen>=sizeof( bufout )-1) + bufout[sizeof( bufout )-1] = 0; + else + bufout[olen]=0; + printf("%s", bufout); + + exit_code = MBEDTLS_EXIT_SUCCESS; + goto exit; + } + + if( argc < 4 ) + goto exit; + + /* + * Compute the SHA-256 hash of the input file + */ + if( ( ret = mbedtls_md_file( + mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 ), + argv[3], hash ) ) != 0 ) + goto exit; + + if (strncmp(argv[1], "sign", 4) == 0) { + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, + (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) + goto exit; + + if( ( ret = mbedtls_pk_parse_keyfile( &pk, argv[2], "" ) ) != 0 ) + goto exit; + + if( ( ret = mbedtls_pk_sign( &pk, MBEDTLS_MD_SHA256, hash, 0, bufin, &ilen, + mbedtls_ctr_drbg_random, &ctr_drbg ) ) != 0 ) + goto exit; + + if( mbedtls_base64_encode( bufout, sizeof( bufout ), &olen, bufin, ilen ) != 0 ) + goto exit; + + if(olen>=sizeof( bufout )-1) + bufout[sizeof( bufout )-1] = 0; + else + bufout[olen]=0; + printf("%s\n", bufout); + } + + if (strncmp(argv[1], "verify", 6) == 0) { + if( ( ret = mbedtls_pk_parse_public_keyfile( &pk, argv[2] ) ) != 0 ) + goto exit; + + snprintf( filename, sizeof(filename), "%s.sig", argv[3] ); + + ilen = readfile(filename, bufin, sizeof( bufin )); + if( mbedtls_base64_decode( bufout, sizeof( bufout ), &olen, bufin, ilen ) != 0 ) + goto exit; + + if( ( ret = mbedtls_pk_verify( &pk, MBEDTLS_MD_SHA256, hash, 0, + bufout, olen ) ) != 0 ) + goto exit; + + printf("OK\n"); + } + + exit_code = MBEDTLS_EXIT_SUCCESS; + +exit: + mbedtls_pk_free( &pk ); + mbedtls_ctr_drbg_free( &ctr_drbg ); + mbedtls_entropy_free( &entropy ); + + if( exit_code != MBEDTLS_EXIT_SUCCESS ) + mbedtls_printf("FAIL\n"); + + return( exit_code ); +} +#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_SHA256_C && + MBEDTLS_PK_PARSE_C && MBEDTLS_FS_IO */