From 6d7429bf56cc52161ce1932cc13d0594265b4abf Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Fri, 14 Sep 2018 23:42:50 +0200 Subject: target/linux/ramips: add all base-files changes --- target/linux/ramips/base-files/etc/board.d/01_leds | 219 ------------- .../linux/ramips/base-files/etc/board.d/02_network | 308 ----------------- target/linux/ramips/base-files/etc/config/fstab | 16 + target/linux/ramips/base-files/etc/diag.sh | 5 +- .../ramips/base-files/etc/uci-defaults/01_leds | 217 ++++++++++++ .../ramips/base-files/etc/uci-defaults/02_network | 322 ++++++++++++++++++ target/linux/ramips/base-files/lib/ramips.sh | 363 ++------------------- .../ramips/base-files/lib/upgrade/platform.sh | 6 + target/linux/ramips/base-files/usr/bin/dat2uci | 218 +++++++++++++ .../linux/ramips/base-files/usr/lib/lua/shuci.lua | 141 ++++++++ target/linux/ramips/base-files/usr/sbin/setsmp.sh | 9 + 11 files changed, 966 insertions(+), 858 deletions(-) delete mode 100755 target/linux/ramips/base-files/etc/board.d/01_leds delete mode 100755 target/linux/ramips/base-files/etc/board.d/02_network create mode 100644 target/linux/ramips/base-files/etc/config/fstab create mode 100755 target/linux/ramips/base-files/etc/uci-defaults/01_leds create mode 100755 target/linux/ramips/base-files/etc/uci-defaults/02_network create mode 100755 target/linux/ramips/base-files/usr/bin/dat2uci create mode 100755 target/linux/ramips/base-files/usr/lib/lua/shuci.lua create mode 100755 target/linux/ramips/base-files/usr/sbin/setsmp.sh diff --git a/target/linux/ramips/base-files/etc/board.d/01_leds b/target/linux/ramips/base-files/etc/board.d/01_leds deleted file mode 100755 index 01e2363..0000000 --- a/target/linux/ramips/base-files/etc/board.d/01_leds +++ /dev/null @@ -1,219 +0,0 @@ -#!/bin/sh - -. /lib/functions/uci-defaults-new.sh -. /lib/ramips.sh - -set_usb_led() { - ucidef_set_led_usbdev "usb" "USB" "$1" "1-1" -} - -set_wifi_led() { - ucidef_set_led_netdev "wifi_led" "wifi" "$1" "wlan0" -} - - -board=$(ramips_board_name) - -board_config_update - -case $board in - 3g-6200n) - set_wifi_led "edimax:amber:wlan" - set_usb_led "edimax:blue:3g" - ;; - 3g-6200nl) - set_wifi_led "edimax:green:wlan" - ;; - 3g300m) - set_usb_led "tenda:blue:3g" - ;; - air3gii) - set_wifi_led "airlive:green:wlan" - set_usb_led "airlive:green:mobile" - ;; - all0256n) - ucidef_set_rssimon "wlan0" "40000" "1" - ucidef_set_led_rssi "rssilow" "RSSILOW" "all0256n:green:rssilow" "wlan0" "1" "40" "0" "6" - ucidef_set_led_rssi "rssimedium" "RSSIMEDIUM" "all0256n:green:rssimed" "wlan0" "30" "80" "-29" "5" - ucidef_set_led_rssi "rssihigh" "RSSIHIGH" "all0256n:green:rssihigh" "wlan0" "70" "100" "-69" "8" - set_wifi_led "rt2800pci-phy0::radio" - ;; - awapn2403) - set_wifi_led "rt2800soc-phy0::radio" - ;; - ar725w) - set_wifi_led "rt2800soc-phy0::radio" - ;; - asl26555) - ucidef_set_led_default "power" "POWER" "asl26555:green:power" "1" - ucidef_set_led_netdev "eth" "ETH" "asl26555:green:eth" "eth0" - set_wifi_led "asl26555:green:wlan" - set_usb_led "asl26555:green:3g" - ;; - bc2) - set_usb_led "bc2:blue:usb" - ;; - br6425) - set_wifi_led "edimax:orange:wlan" - ;; - br-6475nd) - set_wifi_led "edimax:amber:wlan" - ;; - broadway) - set_usb_led "red:diskmounted" - set_wifi_led "red:wps_active" - ;; - br6524n) - set_wifi_led "edimax:blue:wlan" - ;; - cy-swr1100) - ucidef_set_led_default "wps" "WPS" "samsung:blue:wps" "0" - set_usb_led "samsung:blue:usb" - ;; - d105) - ucidef_set_led_default "power" "POWER" "d105:red:power" "1" - set_usb_led "d105:green:usb" - ;; - dir-300-b1|\ - dir-600-b1|\ - dir-600-b2|\ - dir-620-a1) - # ANDed with vlan switch port 4 led state - ucidef_set_led_default "wan" "WAN LED (amber)" "d-link:amber:wan" "1" - set_wifi_led "rt2800pci-phy0::radio" - ;; - dir-615-d|\ - dir-615-h1) - ucidef_set_led_default "status" "Status LED (amber)" "d-link:amber:status" "0" - set_wifi_led "rt2800pci-phy0::radio" - ;; - dir-620-d1) - set_wifi_led "d-link:green:wifi" - ;; - dir-810l) - ucidef_set_led_default "power" "POWER" "dlink:green:power" "1" - ;; - dir-610-a1 |\ - dir-300-b7 |\ - dir-320-b1 |\ - esr-9753) - set_wifi_led "rt2800pci-phy0::radio" - ;; - f5d8235-v1) - set_usb_led "f5d8235-v1:blue:storage" - ;; - f5d8235-v2) - set_usb_led "f5d8235v2:blue:storage" - ;; - fonera20n) - set_usb_led "fonera20n:orange:usb" - set_wifi_led "fonera20n:orange:wifi" - ;; - hlk-rm04) - set_wifi_led "rt2800pci-phy0::radio" - ;; - all0239-3g|\ - hw550-3g) - set_usb_led "hw550-3g:green:usb" - ;; - mlw221) - set_wifi_led "kingston:blue:wifi" - ucidef_set_led_default "system" "system" "kingston:blue:system" "1" - ;; - mofi3500-3gn) - set_usb_led "mofi3500-3gn:green:usb" - ;; - mpr-a1) - set_wifi_led "hame:blue:system" - ;; - mpr-a2) - set_wifi_led "hame:blue:system" - ;; - mzk-w300nh2) - set_wifi_led "mzkw300nh2:amber:wlan" - ;; - na930) - set_usb_led "na930:blue:status" - ;; - nw718) - set_usb_led "nw718:amber:usb" - ;; - omni-emb-hpm) - ucidef_set_led_default "power" "POWER" "emb:orange:power" "1" - ucidef_set_led_netdev "eth" "ETH" "emb:green:eth" "eth0" - set_wifi_led "emb:green:wifi" - ;; - omni-plug) - set_wifi_led "miniplug:green:wlan" - set_usb_led "miniplug:green:mobile" - ;; - px4885) - set_wifi_led "7links:orange:wifi" - set_usb_led "7links:blue:storage" - ;; - sl-r7205) - set_wifi_led "rt2800pci-phy0::radio" - ;; - v11st-fe) - set_wifi_led "rt2800pci-phy0::radio" - ;; - vocore) - ucidef_set_led_netdev "eth" "ETH" "vocore:orange:eth" "eth0" - set_wifi_led "vocore:green:status" - ;; - w306r-v20) - set_wifi_led "rt2800pci-phy0::radio" - ;; - w502u) - set_usb_led "alfa:blue:usb" - set_wifi_led "rt2800pci-phy0::radio" - ;; - wcr-150gn) - set_usb_led "wcr150gn:amber:user" - ;; - hg255d) - set_wifi_led "hg255d:wlan" - set_usb_led "hg255d:usb" - ucidef_set_led_interface "lan" "hg255d:internet" - ;; - wnce2001) - set_wifi_led "netgear:green:wlan" - ;; - rt-n14u) - ucidef_set_led_default "power" "power" "asus:blue:power" "1" - ucidef_set_led_interafce "lan" "asus:blue:lan" - ucidef_set_led_netdev "wan" "asus:blue:wan" - set_wifi_led "asus:blue:air" - set_usb_led "asus:blue:usb" - ;; - rp-n53) - ucidef_set_led_netdev "eth" "Network" "asus:white:back" "eth0" - set_wifi_led "asus:blue:wifi" - ;; - whr-300hp2 |\ - whr-600d |\ - whr-1166d) - ucidef_set_led_default "power" "power" "buffalo:green:power" "1" - ucidef_set_led_default "router" "router" "buffalo:green:router" "1" - ;; - zbt-wa05) - ucidef_set_led_default "power" "power" "zbtlink:blue:power" "1" - set_wifi_led "zbtlink:blue:air" - set_usb_led "zbtlink:blue:usb" - ;; - wr8305rt) - ucidef_set_led_default "power" "power" "wr8305rt:sys" "1" - set_usb_led "wr8305rt:usb" - set_wifi_led "wr8305rt:wifi" - ;; - y1 |\ - y1s) - ucidef_set_led_default "power" "power" "lenovo:blue:power" "1" - set_usb_led "lenovo:blue:usb" - set_wifi_led "lenovo:blue:wifi" - ;; -esac - -board_config_flush - -exit 0 diff --git a/target/linux/ramips/base-files/etc/board.d/02_network b/target/linux/ramips/base-files/etc/board.d/02_network deleted file mode 100755 index e027b3b..0000000 --- a/target/linux/ramips/base-files/etc/board.d/02_network +++ /dev/null @@ -1,308 +0,0 @@ -#!/bin/sh - -. /lib/functions.sh -. /lib/ramips.sh -. /lib/functions/uci-defaults-new.sh -. /lib/functions/system.sh - -ramips_setup_rt3x5x_vlans() -{ - if [ ! -x /sbin/swconfig ]; then - # legacy default - ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" - return - fi - local wanports="" - local lanports="" - for port in 5 4 3 2 1 0; do - if [ `swconfig dev rt305x port $port get disable` = "1" ]; then - continue - fi - if [ `swconfig dev rt305x port $port get lan` = "0" ]; then - wanports="$port $wanports" - else - lanports="$port $lanports" - fi - done - ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" - ucidef_add_switch "rt305x" "1" "1" - ucidef_add_switch_vlan "rt305x" "1" "$lanports 6t" - ucidef_add_switch_vlan "rt305x" "2" "$wanports 6t" -} - -ramips_setup_interfaces() -{ - local board="$1" - - ucidef_set_interface_loopback - - case $board in - 3g300m | \ - w150m | \ - all0256n | \ - all5002 | \ - all5003 | \ - broadway | \ - dcs-930| \ - ncs601w | \ - wnce2001) - ucidef_add_switch "switch0" "1" "0" - ucidef_set_interface_lan "eth0" - ;; - - 3g-6200nl | \ - mlw221) - ucidef_set_interface_lan "eth0.2" - ;; - - wizard8800 | \ - wl-330n | \ - wmr300) - ucidef_set_interface_lan "eth0.1" - ;; - - b2c | \ - nw718 | \ - psr-680w | \ - sl-r7205 | \ - w502u | \ - wr6202) - ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" - ;; - - awapn2403) - ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" - ucidef_add_switch "switch0" "1" "1" - ucidef_add_switch_vlan "switch0" "1" "0 6t" - ucidef_add_switch_vlan "switch0" "2" "1 6t" - ;; - - br-6475nd) - ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" - ucidef_add_switch "switch0" "1" "1" - ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 9t" - ucidef_add_switch_vlan "switch0" "2" "0 9t" - ;; - - asl26555) - ucidef_set_interface_lan "eth0.1" - ucidef_add_switch "switch0" "1" "1" - ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t" - ;; - - cy-swr1100) - ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" - ucidef_add_switch "switch0" "1" "1" - ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 9t" - ucidef_add_switch_vlan "switch0" "2" "4 9t" - ;; - - 3g-6200n | \ - dir-610-a1 | \ - dir-300-b7 | \ - dir-320-b1 | \ - dir-615-h1 | \ - hlk-rm04 | \ - mzk-w300nh2 | \ - mzk-750dhp) - ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" - ucidef_add_switch "switch0" "1" "1" - ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t" - ucidef_add_switch_vlan "switch0" "2" "4 6t" - ;; - - awm002-evb | \ - awm003-evb | \ - argus-atp52b | \ - dir-645 | \ - f5d8235-v1 | \ - f5d8235-v2 | \ - hg255d | \ - rt-n14u | \ - wrtnode | \ - ur-326n4g | \ - zbt-wa05) - ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" - ucidef_add_switch "switch0" "1" "1" - ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t" - ucidef_add_switch_vlan "switch0" "2" "0 6t" - ;; - - ur-336un) - ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" - ;; - - br6524n | \ - v11st-fe) - ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" - ucidef_add_switch "switch0" "1" "1" - ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t" - ucidef_add_switch_vlan "switch0" "2" "0 5t" - ;; - - ar725w | \ - rt-n15 | \ - wl-351) - ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" - ucidef_add_switch "switch0" "1" "1" - ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t" - ucidef_add_switch_vlan "switch0" "2" "4 5t" - ;; - - rt-n56u) - ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" - ucidef_add_switch "switch0" "1" "1" - ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t" - ucidef_add_switch_vlan "switch0" "2" "4 8t" - ;; - - tew-691gr|\ - tew-692gr) - ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" - ucidef_add_switch "switch0" "1" "1" - ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4" - ucidef_add_switch_vlan "switch0" "2" "0t 5" - ;; - - vocore) - ucidef_set_interface_lan "eth0.1" - ucidef_add_switch "switch0" "1" "1" - ucidef_add_switch_vlan "switch0" "1" "0 4 6t" - ;; - - wcr-150gn) - ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" - ucidef_add_switch "switch0" "1" "1" - ucidef_add_switch_vlan "switch0" "1" "0 6t" - ucidef_add_switch_vlan "switch0" "2" "6t" - ;; - - wr8305rt) - ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" - ucidef_add_switch "switch0" "1" "1" - ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4 6t" - ucidef_add_switch_vlan "switch0" "2" "4 6t" - ;; - - y1 |\ - y1s) - ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" - ucidef_add_switch "switch0" "1" "1" - ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5 6t" - ucidef_add_switch_vlan "switch0" "2" "0 6t" - ;; - d105 | \ - na930 | \ - omni-emb-hpm|\ - wli-tx4-ag300n) - ucidef_set_interface_lan "eth0" - ;; - - *) - RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"` - if [ -n "${RT3X5X}" ]; then - ramips_setup_rt3x5x_vlans - else - ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" - fi - ;; - esac -} - -ramips_setup_macs() -{ - local board="$1" - local lan_mac="" - local wan_mac="" - - case $board in - br-6475nd) - lan_mac=$(cat /sys/class/net/eth0/address) - wan_mac=$(mtd_get_mac_binary devdata 7) - ;; - - w306r-v20) - lan_mac=$(cat /sys/class/net/eth0/address) - wan_mac=$(macaddr_add "$lan_mac" 5) - ;; - - tew-691gr) - lan_mac=$(cat /sys/class/net/eth0/address) - wan_mac=$(macaddr_add "$lan_mac" 3) - ;; - - tew-692gr) - lan_mac=$(cat /sys/class/net/eth0/address) - wan_mac=$(macaddr_add "$lan_mac" 4) - ;; - - m3 |\ - m4 |\ - x5 |\ - x8) - lan_mac=$(cat /sys/class/net/eth0/address) - lan_mac=$(macaddr_add "$lan_mac" -2) - ;; - - bc2 |\ - broadway |\ - d105 |\ - dir-620-a1 |\ - esr-9753 |\ - freestation5 |\ - hlk-rm04 | \ - mpr-a1 | \ - mpr-a2 | \ - dir-300-b7 | \ - dir-320-b1 | \ - psr-680w |\ - sl-r7205 |\ - y1 |\ - y1s) - lan_mac=$(cat /sys/class/net/eth0/address) - lan_mac=$(macaddr_setbit_la "$lan_mac") - wan_mac=$(macaddr_add "$lan_mac" 1) - ;; - - cy-swr1100 | \ - dir-645) - lan_mac=$(mtd_get_mac_ascii nvram lanmac) - wan_mac=$(mtd_get_mac_ascii nvram wanmac) - ;; - - wcr-150gn) - wan_mac=$(mtd_get_mac_binary factory 40) - ;; - - rt-n56u) - lan_mac=$(cat /sys/class/net/eth0/address) - lan_mac=$(macaddr_setbit_la "$lan_mac") - wan_mac=$(mtd_get_mac_binary factory 32772) - ;; - - all0239-3g | \ - carambola | \ - freestation5 | \ - w502u | \ - wnce2001) - wan_mac=$(mtd_get_mac_binary factory 46) - ;; - - *) - lan_mac=$(cat /sys/class/net/eth0/address) - wan_mac=$(macaddr_add "$lan_mac" 1) - ;; - - esac - - [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac - [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac -} - -board_config_update -board=$(ramips_board_name) -ramips_setup_interfaces $board -ramips_setup_macs $board -board_config_flush - -exit 0 diff --git a/target/linux/ramips/base-files/etc/config/fstab b/target/linux/ramips/base-files/etc/config/fstab new file mode 100644 index 0000000..c984b93 --- /dev/null +++ b/target/linux/ramips/base-files/etc/config/fstab @@ -0,0 +1,16 @@ +config 'global' + option anon_swap '0' + option anon_mount '1' + option auto_swap '1' + option auto_mount '1' + option delay_root '5' + option check_fs '0' + +config 'mount' + option target '/mnt/sd*' + option enabled '1' + +config 'mount' + option target '/mnt/mmcblk*' + option enabled '1' + diff --git a/target/linux/ramips/base-files/etc/diag.sh b/target/linux/ramips/base-files/etc/diag.sh index 9ad7ccb..74b8867 100755 --- a/target/linux/ramips/base-files/etc/diag.sh +++ b/target/linux/ramips/base-files/etc/diag.sh @@ -73,8 +73,9 @@ get_status_led() { m4) status_led="m4:blue:status" ;; - mlw221) - status_led="kingston:blue:status" + mlw221|\ + mlwg2) + status_led="kingston:blue:system" ;; mofi3500-3gn) status_led="mofi3500-3gn:green:status" diff --git a/target/linux/ramips/base-files/etc/uci-defaults/01_leds b/target/linux/ramips/base-files/etc/uci-defaults/01_leds new file mode 100755 index 0000000..5d6ed2b --- /dev/null +++ b/target/linux/ramips/base-files/etc/uci-defaults/01_leds @@ -0,0 +1,217 @@ +#!/bin/sh + +. /lib/functions/uci-defaults.sh +. /lib/ramips.sh + +set_usb_led() { + ucidef_set_led_usbdev "usb" "USB" "$1" "1-1" +} + +set_wifi_led() { + ucidef_set_led_netdev "wifi_led" "wifi" "$1" "wlan0" +} + +board=$(ramips_board_name) + +case $board in + 3g-6200n) + set_wifi_led "edimax:amber:wlan" + set_usb_led "edimax:blue:3g" + ;; + 3g-6200nl) + set_wifi_led "edimax:green:wlan" + ;; + 3g300m) + set_usb_led "tenda:blue:3g" + ;; + air3gii) + set_wifi_led "airlive:green:wlan" + set_usb_led "airlive:green:mobile" + ;; + all0256n) + ucidef_set_rssimon "wlan0" "40000" "1" + ucidef_set_led_rssi "rssilow" "RSSILOW" "all0256n:green:rssilow" "wlan0" "1" "40" "0" "6" + ucidef_set_led_rssi "rssimedium" "RSSIMEDIUM" "all0256n:green:rssimed" "wlan0" "30" "80" "-29" "5" + ucidef_set_led_rssi "rssihigh" "RSSIHIGH" "all0256n:green:rssihigh" "wlan0" "70" "100" "-69" "8" + set_wifi_led "rt2800pci-phy0::radio" + ;; + awapn2403) + set_wifi_led "rt2800soc-phy0::radio" + ;; + ar725w) + set_wifi_led "rt2800soc-phy0::radio" + ;; + asl26555) + ucidef_set_led_default "power" "POWER" "asl26555:green:power" "1" + ucidef_set_led_netdev "eth" "ETH" "asl26555:green:eth" "eth0" + set_wifi_led "asl26555:green:wlan" + set_usb_led "asl26555:green:3g" + ;; + bc2) + set_usb_led "bc2:blue:usb" + ;; + br6425) + set_wifi_led "edimax:orange:wlan" + ;; + br-6475nd) + set_wifi_led "edimax:amber:wlan" + ;; + broadway) + set_usb_led "red:diskmounted" + set_wifi_led "red:wps_active" + ;; + br6524n) + set_wifi_led "edimax:blue:wlan" + ;; + cy-swr1100) + ucidef_set_led_default "wps" "WPS" "samsung:blue:wps" "0" + set_usb_led "samsung:blue:usb" + ;; + d105) + ucidef_set_led_default "power" "POWER" "d105:red:power" "1" + set_usb_led "d105:green:usb" + ;; + dir-300-b1|\ + dir-600-b1|\ + dir-600-b2|\ + dir-620-a1) + # ANDed with vlan switch port 4 led state + ucidef_set_led_default "wan" "WAN LED (amber)" "d-link:amber:wan" "1" + set_wifi_led "rt2800pci-phy0::radio" + ;; + dir-615-d|\ + dir-615-h1) + ucidef_set_led_default "status" "Status LED (amber)" "d-link:amber:status" "0" + set_wifi_led "rt2800pci-phy0::radio" + ;; + dir-620-d1) + set_wifi_led "d-link:green:wifi" + ;; + dir-810l) + ucidef_set_led_default "power" "POWER" "dlink:green:power" "1" + ;; + dir-610-a1 |\ + dir-300-b7 |\ + dir-320-b1 |\ + esr-9753) + set_wifi_led "rt2800pci-phy0::radio" + ;; + f5d8235-v1) + set_usb_led "f5d8235-v1:blue:storage" + ;; + f5d8235-v2) + set_usb_led "f5d8235v2:blue:storage" + ;; + fonera20n) + set_usb_led "fonera20n:orange:usb" + set_wifi_led "fonera20n:orange:wifi" + ;; + hlk-rm04) + set_wifi_led "rt2800pci-phy0::radio" + ;; + all0239-3g|\ + hw550-3g) + set_usb_led "hw550-3g:green:usb" + ;; + mlw221|\ + mlwg2) + set_wifi_led "kingston:blue:wifi" + ucidef_set_led_default "system" "system" "kingston:blue:system" "1" + ;; + mofi3500-3gn) + set_usb_led "mofi3500-3gn:green:usb" + ;; + mpr-a1) + set_wifi_led "hame:blue:system" + ;; + mpr-a2) + set_wifi_led "hame:blue:system" + ;; + mzk-w300nh2) + set_wifi_led "mzkw300nh2:amber:wlan" + ;; + na930) + set_usb_led "na930:blue:status" + ;; + nw718) + set_usb_led "nw718:amber:usb" + ;; + omni-emb-hpm) + ucidef_set_led_default "power" "POWER" "emb:orange:power" "1" + ucidef_set_led_netdev "eth" "ETH" "emb:green:eth" "eth0" + set_wifi_led "emb:green:wifi" + ;; + omni-plug) + set_wifi_led "miniplug:green:wlan" + set_usb_led "miniplug:green:mobile" + ;; + px4885) + set_wifi_led "7links:orange:wifi" + set_usb_led "7links:blue:storage" + ;; + sl-r7205) + set_wifi_led "rt2800pci-phy0::radio" + ;; + v11st-fe) + set_wifi_led "rt2800pci-phy0::radio" + ;; + vocore) + ucidef_set_led_netdev "eth" "ETH" "vocore:orange:eth" "eth0" + set_wifi_led "vocore:green:status" + ;; + w306r-v20) + set_wifi_led "rt2800pci-phy0::radio" + ;; + w502u) + set_usb_led "alfa:blue:usb" + set_wifi_led "rt2800pci-phy0::radio" + ;; + wcr-150gn) + set_usb_led "wcr150gn:amber:user" + ;; + hg255d) + set_wifi_led "hg255d:wlan" + set_usb_led "hg255d:usb" + ucidef_set_led_netdev "eth" "Internet" "hg255d:internet" "eth0.2" + ;; + wnce2001) + set_wifi_led "netgear:green:wlan" + ;; + rt-n14u) + ucidef_set_led_default "power" "power" "asus:blue:power" "1" + ucidef_set_led_netdev "lan" "lan" "asus:blue:lan" "eth0.1" + ucidef_set_led_netdev "wan" "wan" "asus:blue:wan" "eth0.2" + set_wifi_led "asus:blue:air" + set_usb_led "asus:blue:usb" + ;; + rp-n53) + ucidef_set_led_netdev "eth" "Network" "asus:white:back" "eth0" + set_wifi_led "asus:blue:wifi" + ;; + whr-300hp2 |\ + whr-600d |\ + whr-1166d) + ucidef_set_led_default "power" "power" "buffalo:green:power" "1" + ucidef_set_led_default "router" "router" "buffalo:green:router" "1" + ;; + zbt-wa05) + ucidef_set_led_default "power" "power" "zbtlink:blue:power" "1" + set_wifi_led "zbtlink:blue:air" + set_usb_led "zbtlink:blue:usb" + ;; + wr8305rt) + ucidef_set_led_default "power" "power" "wr8305rt:sys" "1" + set_usb_led "wr8305rt:usb" + set_wifi_led "wr8305rt:wifi" + ;; + y1 |\ + y1s) + ucidef_set_led_default "power" "power" "lenovo:blue:power" "1" + set_usb_led "lenovo:blue:usb" + set_wifi_led "lenovo:blue:wifi" + ;; +esac + +ucidef_commit_leds + +exit 0 diff --git a/target/linux/ramips/base-files/etc/uci-defaults/02_network b/target/linux/ramips/base-files/etc/uci-defaults/02_network new file mode 100755 index 0000000..568b91b --- /dev/null +++ b/target/linux/ramips/base-files/etc/uci-defaults/02_network @@ -0,0 +1,322 @@ +#!/bin/sh + +. /lib/functions.sh +. /lib/ramips.sh +. /lib/functions/uci-defaults.sh +. /lib/functions/system.sh + +ramips_setup_rt3x5x_vlans() +{ + if [ ! -x /sbin/swconfig ]; then + # legacy default + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + return + fi + local wanports="" + local lanports="" + for port in 5 4 3 2 1 0; do + if [ `swconfig dev rt305x port $port get disable` = "1" ]; then + continue + fi + if [ `swconfig dev rt305x port $port get lan` = "0" ]; then + wanports="$port $wanports" + else + lanports="$port $lanports" + fi + done + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + ucidef_add_switch "rt305x" "1" "1" + ucidef_add_switch_vlan "rt305x" "1" "$lanports 6t" + ucidef_add_switch_vlan "rt305x" "2" "$wanports 6t" +} + +ramips_setup_interfaces() +{ + local board="$1" + + ucidef_set_interface_loopback + + case $board in + 3g300m | \ + w150m | \ + all0256n | \ + all5002 | \ + all5003 | \ + broadway | \ + dcs-930| \ + ncs601w | \ + wnce2001) + ucidef_add_switch "switch0" "1" "0" + ucidef_set_interface_lan "eth0" + ;; + + 3g-6200nl | \ + mlw221) + ucidef_set_interface_lan "eth0.2" + ;; + + mlwg2 | \ + wl-330n | \ + wmr300) + ucidef_set_interface_lan "eth0.1" + ;; + + b2c | \ + nw718 | \ + psr-680w | \ + sl-r7205 | \ + w502u | \ + wr6202) + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + ;; + + awapn2403) + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + ucidef_add_switch "switch0" "1" "1" + ucidef_add_switch_vlan "switch0" "1" "0 6t" + ucidef_add_switch_vlan "switch0" "2" "1 6t" + ;; + + br-6475nd) + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + ucidef_add_switch "switch0" "1" "1" + ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 9t" + ucidef_add_switch_vlan "switch0" "2" "0 9t" + ;; + + asl26555) + ucidef_set_interface_lan "eth0.1" + ucidef_add_switch "switch0" "1" "1" + ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t" + ;; + + cy-swr1100) + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + ucidef_add_switch "switch0" "1" "1" + ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 9t" + ucidef_add_switch_vlan "switch0" "2" "4 9t" + ;; + + 3g-6200n | \ + dir-610-a1 | \ + dir-300-b7 | \ + dir-320-b1 | \ + dir-615-h1 | \ + hlk-rm04 | \ + mzk-w300nh2 | \ + mzk-750dhp) + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + ucidef_add_switch "switch0" "1" "1" + ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t" + ucidef_add_switch_vlan "switch0" "2" "4 6t" + ;; + + awm002-evb | \ + awm003-evb | \ + argus-atp52b | \ + dir-645 | \ + f5d8235-v1 | \ + f5d8235-v2 | \ + hg255d | \ + rt-n14u | \ + wrtnode | \ + ur-326n4g | \ + zbt-wa05) + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + ucidef_add_switch "switch0" "1" "1" + ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t" + ucidef_add_switch_vlan "switch0" "2" "0 6t" + ;; + + ur-336un) + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + ;; + + br6524n | \ + v11st-fe) + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + ucidef_add_switch "switch0" "1" "1" + ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t" + ucidef_add_switch_vlan "switch0" "2" "0 5t" + ;; + + ar725w | \ + rt-n15 | \ + wl-351) + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + ucidef_add_switch "switch0" "1" "1" + ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t" + ucidef_add_switch_vlan "switch0" "2" "4 5t" + ;; + + rt-n56u) + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + ucidef_add_switch "switch0" "1" "1" + ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t" + ucidef_add_switch_vlan "switch0" "2" "4 8t" + ;; + + tew-691gr|\ + tew-692gr) + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + ucidef_add_switch "switch0" "1" "1" + ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4" + ucidef_add_switch_vlan "switch0" "2" "0t 5" + ;; + + vocore) + ucidef_set_interface_lan "eth0.1" + ucidef_add_switch "switch0" "1" "1" + ucidef_add_switch_vlan "switch0" "1" "0 4 6t" + ;; + + wcr-150gn) + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + ucidef_add_switch "switch0" "1" "1" + ucidef_add_switch_vlan "switch0" "1" "0 6t" + ucidef_add_switch_vlan "switch0" "2" "6t" + ;; + + wr8305rt) + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + ucidef_add_switch "switch0" "1" "1" + ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4 6t" + ucidef_add_switch_vlan "switch0" "2" "4 6t" + ;; + + y1 |\ + y1s) + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + ucidef_add_switch "switch0" "1" "1" + ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5 6t" + ucidef_add_switch_vlan "switch0" "2" "0 6t" + ;; + d105 | \ + na930 | \ + omni-emb-hpm|\ + wli-tx4-ag300n) + ucidef_set_interface_lan "eth0" + ;; + MT7620 | MT7628 | MT7688) + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + ;; + MT7621 | MT7623) + ucidef_set_interfaces_lan_wan "eth0" "eth1" + ;; + *) + RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"` + if [ -n "${RT3X5X}" ]; then + ramips_setup_rt3x5x_vlans + else + ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" + fi + ;; + esac +} + +ramips_setup_macs() +{ + local board="$1" + local lan_mac="" + local wan_mac="" + + case $board in + br-6475nd) + lan_mac=$(cat /sys/class/net/eth0/address) + wan_mac=$(mtd_get_mac_binary devdata 7) + ;; + + w306r-v20) + lan_mac=$(cat /sys/class/net/eth0/address) + wan_mac=$(macaddr_add "$lan_mac" 5) + ;; + + tew-691gr) + lan_mac=$(cat /sys/class/net/eth0/address) + wan_mac=$(macaddr_add "$lan_mac" 3) + ;; + + tew-692gr) + lan_mac=$(cat /sys/class/net/eth0/address) + wan_mac=$(macaddr_add "$lan_mac" 4) + ;; + + m3 |\ + m4 |\ + x5 |\ + x8) + lan_mac=$(cat /sys/class/net/eth0/address) + lan_mac=$(macaddr_add "$lan_mac" -2) + ;; + + bc2 |\ + broadway |\ + d105 |\ + dir-620-a1 |\ + esr-9753 |\ + freestation5 |\ + hlk-rm04 | \ + mpr-a1 | \ + mpr-a2 | \ + dir-300-b7 | \ + dir-320-b1 | \ + psr-680w |\ + sl-r7205 |\ + y1 |\ + y1s) + lan_mac=$(cat /sys/class/net/eth0/address) + lan_mac=$(macaddr_setbit_la "$lan_mac") + wan_mac=$(macaddr_add "$lan_mac" 1) + ;; + + cy-swr1100 | \ + dir-645) + lan_mac=$(mtd_get_mac_ascii nvram lanmac) + wan_mac=$(mtd_get_mac_ascii nvram wanmac) + ;; + + wcr-150gn) + wan_mac=$(mtd_get_mac_binary factory 40) + ;; + + rt-n56u) + lan_mac=$(cat /sys/class/net/eth0/address) + lan_mac=$(macaddr_setbit_la "$lan_mac") + wan_mac=$(mtd_get_mac_binary factory 32772) + ;; + + all0239-3g | \ + carambola | \ + freestation5 | \ + w502u | \ + wnce2001) + wan_mac=$(mtd_get_mac_binary factory 46) + ;; + #MT7620 | MT7621 | MT7623 | MT7628 | MT7688) + # lan_mac=$(eth_mac r lan) + # wan_mac=$(eth_mac r wan) + # ;; + + *) + lan_mac=$(cat /sys/class/net/eth0/address) + wan_mac=$(macaddr_add "$lan_mac" 1) + ;; + + esac + + [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac + [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac +} + +[ -e /etc/config/network ] && exit 0 + +touch /etc/config/network + +board=$(ramips_board_name) + +ramips_setup_interfaces $board +ramips_setup_macs $board + +uci commit network + +exit 0 diff --git a/target/linux/ramips/base-files/lib/ramips.sh b/target/linux/ramips/base-files/lib/ramips.sh index bb42ace..64de7eb 100755 --- a/target/linux/ramips/base-files/lib/ramips.sh +++ b/target/linux/ramips/base-files/lib/ramips.sh @@ -9,338 +9,31 @@ RAMIPS_MODEL= ramips_board_detect() { local machine local name - - machine=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /machine/ {print $2}' /proc/cpuinfo) - - case "$machine" in - *"7Links PX-4885") - name="px4885" - ;; - *"8devices Carambola") - name="carambola" - ;; - *"Edimax 3g-6200n") - name="3g-6200n" - ;; - *"Edimax 3g-6200nl") - name="3g-6200nl" - ;; - *"Airlink101 AR725W") - name="ar725w" - ;; - *"AirLive Air3GII") - name="air3gii" - ;; - *"Edimax BR-6425") - name="br6425" - ;; - *"Allnet ALL0239-3G") - name="all0239-3g" - ;; - *"Allnet ALL0256N") - name="all0256n" - ;; - *"Allnet ALL5002") - name="all5002" - ;; - *"Allnet ALL5003") - name="all5003" - ;; - *"ARC FreeStation5") - name="freestation5" - ;; - *"Argus ATP-52B") - name="argus-atp52b" - ;; - *"AsiaRF AWM002 EVB") - name="awm002-evb" - ;; - *"AsiaRF AWM003 EVB") - name="awm003-evb" - ;; - *"AsiaRF AWAPN2403") - name="awapn2403" - ;; - *"Asus WL-330N") - name="wl-330n" - ;; - *"Asus WL-330N3G") - name="wl-330n3g" - ;; - *"Alpha ASL26555") - name="asl26555" - ;; - *"Aztech HW550-3G") - name="hw550-3g" - ;; - *"CY-SWR1100") - name="cy-swr1100" - ;; - *"DCS-930") - name="dcs-930" - ;; - *"DIR-300 B1") - name="dir-300-b1" - ;; - *"DIR-300 B7") - name="dir-300-b7" - ;; - *"DIR-320 B1") - name="dir-320-b1" - ;; - *"DIR-600 B1") - name="dir-600-b1" - ;; - *"DIR-600 B2") - name="dir-600-b2" - ;; - *"DIR-610 A1") - name="dir-610-a1" - ;; - *"DIR-620 A1") - name="dir-620-a1" - ;; - *"DIR-620 D1") - name="dir-620-d1" - ;; - *"DIR-615 H1") - name="dir-615-h1" - ;; - *"DIR-615 D") - name="dir-615-d" - ;; - *"DIR-645") - name="dir-645" - ;; - *"DIR-810L") - name="dir-810l" - ;; - *"DAP-1350") - name="dap-1350" - ;; - *"ESR-9753") - name="esr-9753" - ;; - *"EASYACC WI-STOR WIZARD 8800") - name="wizard8800" - ;; - *"Edimax BR-6475nD") - name="br-6475nd" - ;; - *"F7C027") - name="f7c027" - ;; - *"F5D8235 v1") - name="f5d8235-v1" - ;; - *"F5D8235 v2") - name="f5d8235-v2" - ;; - *"Hauppauge Broadway") - name="broadway" - ;; - *"Huawei D105") - name="d105" - ;; - *"La Fonera 2.0N") - name="fonera20n" - ;; - *"Asus RT-N14U") - name="rt-n14u" - ;; - *"Asus RT-N13U") - name="rt-n13u" - ;; - *"MoFi Network MOFI3500-3GN") - name="mofi3500-3gn" - ;; - *"HILINK HLK-RM04") - name="hlk-rm04" - ;; - *"HAME MPR-A1") - name="mpr-a1" - ;; - *"HAME MPR-A2") - name="mpr-a2" - ;; - *"Kingston MLW221") - name="mlw221" - ;; - *"Planex MZK-750DHP") - name="mzk-750dhp" - ;; - *"NBG-419N") - name="nbg-419n" - ;; - *"Netgear WNCE2001") - name="wnce2001" - ;; - *"NexAira BC2") - name="bc2" - ;; - *"NW718") - name="nw718" - ;; - *"Omnima EMB HPM") - name="omni-emb-hpm" - ;; - *"Omnima MiniEMBWiFi") - name="omni-emb" - ;; - *"Omnima MiniPlug") - name="omni-plug" - ;; - *"Petatel PSR-680W"*) - name="psr-680w" - ;; - *"Planex MZK-W300NH2"*) - name="mzk-w300nh2" - ;; - *"Poray IP2202") - name="ip2202" - ;; - *"Poray M3") - name="m3" - ;; - *"Poray M4") - name="m4" - ;; - *"Poray X5") - name="x5" - ;; - *"Poray X8") - name="x8" - ;; - *"PWH2004") - name="pwh2004" - ;; - *"Asus RP-N53") - name="rp-n53" - ;; - *"RT-G32 B1") - name="rt-g32-b1" - ;; - *"RT-N10+") - name="rt-n10-plus" - ;; - *"RT-N15") - name="rt-n15" - ;; - *"RT-N56U") - name="rt-n56u" - ;; - *"RUT5XX") - name="rut5xx" - ;; - *"Skyline SL-R7205"*) - name="sl-r7205" - ;; - *"Sparklan WCR-150GN") - name="wcr-150gn" - ;; - *"V22RW-2X2") - name="v22rw-2x2" - ;; - *"VoCore") - name="vocore" - ;; - *"W502U") - name="w502u" - ;; - *"WMR-300") - name="wmr300" - ;; - *"WHR-300HP2") - name="whr-300hp2" - ;; - *"WHR-600D") - name="whr-600d" - ;; - *"WHR-1166D") - name="whr-1166d" - ;; - *"WHR-G300N") - name="whr-g300n" - ;; - *"Sitecom WL-341 v3") - name="wl341v3" - ;; - *"Sitecom WL-351 v1 002") - name="wl-351" - ;; - *"Tenda 3G300M") - name="3g300m" - ;; - *"Tenda W306R V2.0") - name="w306r-v20" - ;; - *"Tenda W150M") - name="w150m" - ;; - *"TEW-691GR") - name="tew-691gr" - ;; - *"TEW-692GR") - name="tew-692gr" - ;; - *"Ralink V11ST-FE") - name="v11st-fe" - ;; - *"WLI-TX4-AG300N") - name="wli-tx4-ag300n" - ;; - *"WZR-AGL300NH") - name="wzr-agl300nh" - ;; - *"WR512-3GN-like router") - name="wr512-3gn" - ;; - *"UR-326N4G Wireless N router") - name="ur-326n4g" - ;; - *"UR-336UN Wireless N router") - name="ur-336un" - ;; - *"AWB WR6202") - name="wr6202" - ;; - *"XDX RN502J") - name="xdxrn502j" - ;; - *"HG255D") - name="hg255d" - ;; - *"V22SG") - name="v22sg" - ;; - *"WRTNODE") - name="wrtnode" - ;; - *"Wansview NCS601W") - name="ncs601w" - ;; - *"Sercomm NA930") - name="na930" - ;; - *"Zbtlink ZBT-WA05") - name="zbt-wa05" - ;; - *"ZBT WR8305RT") - name="wr8305rt" - ;; - *"Lenovo Y1") - name="y1" - ;; - *"Lenovo Y1S") - name="y1s" - ;; - *) - name="generic" - ;; + machine=$(cat /proc/cpuinfo | grep -i MT76) + case $machine in + *"MT7620"*) + name="MT7620" + ;; + *"MT7621"*) + name="MT7621" + ;; + *"MT7628"*) + name="MT7628" + ;; + *"MT7688"*) + name="MT7688" + ;; + *"MT7623"*) + name="MT7623" + ;; + *) # actually this is *NOT* acceptable. + name="generic" + ;; esac [ -z "$RAMIPS_BOARD_NAME" ] && RAMIPS_BOARD_NAME="$name" - [ -z "$RAMIPS_MODEL" ] && RAMIPS_MODEL="$machine" + # FIXME: define customer models here + [ -z "$RAMIPS_MODEL" ] && RAMIPS_MODEL="mtk-apsoc-demo" [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/" @@ -356,3 +49,15 @@ ramips_board_name() { echo "$name" } + + +ramips_model_name() { + local name + + [ -f /tmp/sysinfo/model ] && name=$(cat /tmp/sysinfo/model) + [ -z "$name" ] && name="unknown" + + echo "$name" +} + + diff --git a/target/linux/ramips/base-files/lib/upgrade/platform.sh b/target/linux/ramips/base-files/lib/upgrade/platform.sh index 407c218..3a286c0 100755 --- a/target/linux/ramips/base-files/lib/upgrade/platform.sh +++ b/target/linux/ramips/base-files/lib/upgrade/platform.sh @@ -14,6 +14,11 @@ platform_check_image() { [ "$#" -gt 1 ] && return 1 case "$board" in + MT7620 | \ + MT7621 | \ + MT7628 | \ + MT7688 | \ + MT7623 | \ 3g-6200n | \ 3g-6200nl | \ 3g300m | \ @@ -56,6 +61,7 @@ platform_check_image() { m3 | \ m4 | \ mlw221 | \ + mlwg2 | \ mofi3500-3gn | \ mpr-a1 | \ mpr-a2 | \ diff --git a/target/linux/ramips/base-files/usr/bin/dat2uci b/target/linux/ramips/base-files/usr/bin/dat2uci new file mode 100755 index 0000000..88cb695 --- /dev/null +++ b/target/linux/ramips/base-files/usr/bin/dat2uci @@ -0,0 +1,218 @@ +#!/usr/bin/env lua + +--[[ + * A tool to translate ralink driver config (*.dat) into OpenWrt + * UCI files (/etc/config/wireless). + * --- Hua Shao + * + * For UCI: http://wiki.openwrt.org/doc/techref/uci + * http://wiki.openwrt.org/doc/uci + * + * Copyright (C) 2015 Mediatek CO.,LTD. All rights reserved. + * +]] + +require "shuci" + +T={} + +if #arg < 1 then + io.stderr:write("usage: dat2uci [ucifile] \n") + return false +end + +local i,j = string.find(arg[1], ".dat") +if i then + datfile = arg[1] + ucifile = arg[2] or "/etc/config/wireless" +else + ucifile = arg[1] + datfile = arg[2] +end +print("ucifile="..ucifile) +print("datfile="..datfile) + +_,_,device = string.find(datfile, "(%w+).dat") +print("device="..device) + +local _2g_name = {"7601","7602","7603","7620","7623","7628","7688"} +for i=1, #_2g_name do + if string.find(device, _2g_name[i]) then band = "2.4G" break else band = "5G" end +end + +print("band="..band) + + +for line in io.lines(datfile) do + -- print(line) + i,j = string.find(line, "([^%s])") + if i and j then + ch = string.sub(line,i,j) + + if ch == "#" then + -- print(" "..line) + else + _,_,k,v = string.find(line, "%s*([%w_]+)%s*=%s*([^#]*)%s*") + if k then + -- print(" ",k,v) + local t = {} + T[k] = v + end + end + end +end + +uci = UCI:new() +uci:load(ucifile) + + +--[[ Device related configurations ]] + + +uci:set("wifi-device", device) +uci:set(device, "type", device) +uci:set(device, "vendor", "ralink") +uci:set(device, "band", band) + +if T.AutoChannelSelect ~= 0 then + uci:set(device, "channel", "0") + uci:set(device, "autoch", T.AutoChannelSelect or "nil") +else + uci:set(device, "channel", T.Channel or "nil") + uci:set(device, "autoch", "0") +end +uci:set(device, "radio", T.RadioOn or "nil") +uci:set(device, "wifimode", T.WirelessMode or "nil") +-- bandwidth +if T.BW == 1 and T.VHT_BW == 1 then + uci:set(device, "bw", "2") +elseif T.BW == 0 and T.VHT_BW == 0 then + uci:set(device, "bw", "0") +else + uci:set(device, "bw", "1") +end +uci:set(device, "country", T.CountryCode or "TW") +uci:set(device, "region", T.CountryRegion or "1") +uci:set(device, "bgprotect", T.BGProtection or "0") +uci:set(device, "beacon", T.BeaconPeriod or "100") +uci:set(device, "dtim", T.DtimPeriod or "1") +uci:set(device, "fragthres", T.FragThreshold or "2346") +uci:set(device, "rtsthres", T.RTSThreshold or "2347") +uci:set(device, "txpower", T.TxPower or "100") +uci:set(device, "txpreamble", T.TxPreamble or "0") +uci:set(device, "shortslot", T.ShortSlot or "1") +uci:set(device, "txburst", T.TxBurst or "1") +uci:set(device, "pktaggre", T.PktAggregate or "0") +uci:set(device, "ieee80211h", T.IEEE80211H or "0") +uci:set(device, "ht_bsscoexist", T.HT_BSSCoexistence or "0") +uci:set(device, "ht_extcha", T.HT_EXTCHA or "0") +uci:set(device, "ht_opmode", T.HT_OpMode or "0") +uci:set(device, "ht_gi", T.HT_GI or "1") +uci:set(device, "ht_rdg", T.HT_RDG or "0") +uci:set(device, "ht_stbc", T.HT_STBC or "0") +uci:set(device, "ht_amsdu", T.HT_AMSDU or "0") +uci:set(device, "ht_autoba", T.HT_AutoBA or "1") +uci:set(device, "ht_badec", T.HT_BADecline or "0") +uci:set(device, "ht_distkip", T.HT_DisallowTKIP or "0") +uci:set(device, "ht_ldpc", T.HT_LDPC or "1") +uci:set(device, "ht_txstream", T.HT_TxStream or "1") +uci:set(device, "ht_txstream", T.HT_RxStream or "1") +if band == "5G" then + uci:set(device, "aregion", T.CountryRegionABand or "7") -- 5G + uci:set(device, "vht_stbc", T.VHT_STBC or "0") -- 5G + uci:set(device, "vht_sgi", T.VHT_SGI or "1") -- 5G + uci:set(device, "vht_bw_sig", T.VHT_BW_SIGNAL or "0") -- 5G + uci:set(device, "vht_ldpc", T.VHT_LDPC or "1") -- 5G + uci:set(device, "vht_disnonvht", T.VHT_DisallowNonVHT or "0") -- 5G +end + +--uci:dump() +--[[ Interface related configurations. ]] + +function split(inputstr, delimiter) + if delimiter == nil then + delimiter = "%s" + end + local t={} ; i=1 + for str in string.gmatch(inputstr, "([^"..delimiter.."]+)") do + t[i] = str + i = i + 1 + end + return t +end + + +local i = 0 -- index of wifi-iface +local j = 0 -- index of wifi-iface with give devname + +while j < tonumber(T.BssidNum) do + if not uci:get("wifi-iface["..i.."]", "device") then + if band == "2.4G" then + uci:set("wifi-iface["..i.."]", "ra"..j) + uci:set("wifi-iface["..i.."]", "ifname", "ra"..j) + else + uci:set("wifi-iface["..i.."]", "rai"..j) + uci:set("wifi-iface["..i.."]", "ifname", "rai"..j) + end + uci:set("wifi-iface["..i.."]", "device", device) + end + if device == uci:get("wifi-iface["..i.."]", "device") then + uci:set("wifi-iface["..i.."]", "ssid", loadstring("return T.SSID"..(j+1))()) + uci:set("wifi-iface["..i.."]", "hidden", T.HideSSID or "0") + -- openwrt specific + uci:set("wifi-iface["..i.."]", "mode", "ap") + uci:set("wifi-iface["..i.."]", "network", "lan") + + -- encryption + authmode = split(T.AuthMode, ";") + if authmode[j+1] == "OPEN" then + uci:set("wifi-iface["..i.."]", "encryption", "none") + elseif authmode[j+1] == "WPAPSK" then + uci:set("wifi-iface["..i.."]", "encryption", "psk") + uci:set("wifi-iface["..i.."]", "key", loadstring("return T.WPAPSK"..(j+1))()) + elseif authmode[j+1] == "WPA2PSK" then + uci:set("wifi-iface["..i.."]", "encryption", "psk2") + uci:set("wifi-iface["..i.."]", "key", loadstring("return T.WPAPSK"..(j+1))()) + elseif authmode[j+1] == "WPA" then + uci:set("wifi-iface["..i.."]", "encryption", "wpa") + elseif authmode[j+1] == "WPA2" then + uci:set("wifi-iface["..i.."]", "encryption", "wpa2") + elseif authmode[j+1] == "WPA1WPA2" then + uci:set("wifi-iface["..i.."]", "encryption", "wpa+wpa2") + else + uci:set("wifi-iface["..i.."]", "encryption", "open") + end + + -- cipher + --[[ + cipher = split(T.EncrypType, ";") + if authmode[j+1] == "OPEN" then + uci:set("wifi-iface["..i.."]", "cipher", "none") + elseif cipher[j+1] == "AES" then + uci:set("wifi-iface["..i.."]", "cipher", "ccmp") + elseif cipher[j+1] == "TKIP" then + uci:set("wifi-iface["..i.."]", "cipher", "tkip") + elseif cipher[j+1] == "TKIPAES" then + uci:set("wifi-iface["..i.."]", "cipher", "tkip+ccmp") + else + uci:set("wifi-iface["..i.."]", "cipher", "none") + end ]] + + --uci:set("wifi-iface["..i.."]", "wepkey", "xx") + if T.IEEE8021X == 1 then + uci:set("wifi-iface["..i.."]", "auth_server", T.RADIUS_Server or "nil") + uci:set("wifi-iface["..i.."]", "auth_port", T.RADIUS_Port or "nil") + uci:set("wifi-iface["..i.."]", "auth_secret", "xx") + end + --uci:set("wifi-iface["..i.."]", "pmkcacheperiod", T.PMKCachePeriod or "nil") + --uci:set("wifi-iface["..i.."]", "preauth", T.PreAuth or "nil") + --uci:set("wifi-iface["..i.."]", "rekeyinteval", T.RekeyInterval or "nil") + j = j + 1 + end + i = i + 1 +end + +--uci:dump() +uci:save(ucifile) + +return true diff --git a/target/linux/ramips/base-files/usr/lib/lua/shuci.lua b/target/linux/ramips/base-files/usr/lib/lua/shuci.lua new file mode 100755 index 0000000..1b0109f --- /dev/null +++ b/target/linux/ramips/base-files/usr/lib/lua/shuci.lua @@ -0,0 +1,141 @@ +#!/usr/bin/env lua + +--[[ + * A pure lua library to translate between: + * lua table <--> uci config + * + * For UCI: http://wiki.openwrt.org/doc/techref/uci + * http://wiki.openwrt.org/doc/uci + * + * Copyright (C) 2015 Hua Shao + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1 + * as published by the Free Software Foundation + * + * 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. +]] + + +local shuci = {} + +function shuci.decode(path) + function file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end + end + local function linebreaker(str) + local i,_ = string.find(str, "([^%s])") + if not i then return nil end + if string.find(str, "config%s+%w+") then + local i,j,k,v = string.find(str, "config%s+([%w-_]+)%s*['\"]*([^%s\'\"]*)") + return "section", k, v + elseif string.find(str, "option%s+%w+") then + local i,j,k,v = string.find(str, "option%s+([%w-_]+)%s*['\"]([^'\"]+)['\"]") + if not k or not v then + i,j,k,v = string.find(str, "option%s+([%w-_]+)%s*['\"]*([^%s\'\"]*)") + end + return "option", k, v + elseif string.find(str, "list%s+%w+") then + local i,j,k,v = string.find(str, "list%s+([%w-_]+)%s*['\"]([^'\"]+)['\"]") + if not k or not v then + i,j,k,v = string.find(str, "list%s+([%w-_]+)%s*['\"]*([^%s\'\"]*)") + end + return "list", k, v + end + end + + if not file_exists(path) then + return + end + + local _sect_ = nil + local t = {} + for line in io.lines(path) do + local _type, _name, _value = linebreaker(line) + if _type == "section" then + if not t[_name] then + t[_name] = {} + _sect_ = t[_name] + if _value then + _sect_[".name"] = _value + end + else + if t[_name][1] then -- already a list + else -- upgrade from dict to array + local _t = t[_name] + t[_name] = {} + t[_name][1] = _t + end + t[_name][#t[_name]+1] = {} + _sect_ = t[_name][#t[_name]] + if _value then + _sect_[".name"] = _value + end + end + end + if _type == "option" then + if _name and _value then + _sect_[_name] = _value + end + end + if _type == "list" and _name and _value then + local idx + if not _sect_[_name] then + _sect_[_name] = {} + _sect_[_name][1] = _value + else + idx = #_sect_[_name] + _sect_[_name][idx+1] = _value + end + end + end + + return t +end + + +function shuci.encode(t, path) + local dump = io.write + if path then + local fp = io.open(path, "w") + dump = function(str) fp:write(str) end + end + for stype,ss in pairs(t) do + if #ss > 0 then + for _,s in ipairs(ss) do + dump(string.format("config\t%s\t'%s'\n", stype, s[".name"] or "")) + for k,v in pairs(s) do + if type(v) == "table" then + for _,vv in ipairs(v) do + dump(string.format("\tlist\t%s\t'%s'\n",k,vv)) + end + elseif type(v) == "string" and k ~= ".name" then + dump(string.format("\toption\t%s\t'%s'\n",k,v)) + elseif type(v) == "number" and k ~= ".name" then + dump(string.format("\toption\t%s\t'%s'\n",k,tonumber(v))) + end + end + dump("\n") + end + else + dump(string.format("config\t%s\t'%s'\n", stype, ss[".name"] or "")) + for k,v in pairs(ss) do + if type(v) == "table" then + for _,vv in ipairs(v) do + dump(string.format("\tlist\t%s\t'%s'\n",k,vv)) + end + elseif type(v) == "string" and k ~= ".name" then + dump(string.format("\toption\t%s\t'%s'\n",k,v)) + elseif type(v) == "number" and k ~= ".name" then + dump(string.format("\toption\t%s\t'%s'\n",k,tonumber(v))) + end + end + end + end +end + +return shuci diff --git a/target/linux/ramips/base-files/usr/sbin/setsmp.sh b/target/linux/ramips/base-files/usr/sbin/setsmp.sh new file mode 100755 index 0000000..71a7699 --- /dev/null +++ b/target/linux/ramips/base-files/usr/sbin/setsmp.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +if [ -e /tmp/smb.flag ]; +then + smp.sh storage +else + smp.sh wifi +fi + -- cgit v1.1