Commit 0184120c authored by Bartlomiej Grzeskowiak's avatar Bartlomiej Grzeskowiak Committed by Sukru Senli

Feature#1536 Collect and fill in data in iopsys uci configuration. Part1

- mac for br-lan
- wifi led blinking
parent 7d28c5b4
#!/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}" "${2:-wlan0}"
ucidef_set_led_netdev "wifi_led" "wifi" "$1" "wlan0"
}
board=$(board_name)
board=$(ramips_board_name)
boardname="${board##*,}"
board_config_update
......
#!/bin/sh /etc/rc.common
START=20
STOP=90
USE_PROCD=1
BASEMAC="$(db -q get hw.board.basemac | tr -d ':')"
BASEMAC=${BASEMAC// /}
LASTMACOFFSET=0
MACSIZE=0
macpoffset() {
local offset=$1
local rmac=$(printf "%0.12X\n" $((0x$BASEMAC + $offset)))
rmac=$(echo $rmac | sed -e "s/.\{2\}/&:/g")
rmac=${rmac:0:17}
echo "$rmac"
}
assign_macaddr() {
local cfg="$1"
local ucif="$2"
local ifname=""
local offset=
local macaddr=""
local if=""
local dev=""
local curmac=""
[ "$cfg" == "loopback" ] && return
ifname="$(uci -q get $ucif.$cfg.ifname)"
[ "${ifname:0:1}" == "@" -o "$if" == "lo" ] && return
config_get macassigned "$cfg" macassigned
uci -q delete $ucif.$cfg.macassigned
[ "$macassigned" == "1" ] && return
offset=$LASTMACOFFSET
[ $offset -lt $MACSIZE ] || return
macaddr="$(macpoffset $offset)"
uci -q set $ucif.$cfg.macaddr="$macaddr"
LASTMACOFFSET=$((offset+1))
for if in $ifname; do
# update device section in network config if matches the ifname
for dev in $(uci show network | grep "=device" | awk -F[.,=] '{print$2}'); do
if [ "$(uci -q get network.$dev.name)" == "$if" ]; then
uci -q set network.$dev.macaddr="$macaddr"
break
fi
done
done
}
start_service() {
[ -f "/etc/macoffset" ] || return
. /usr/share/libubox/jshn.sh
local cfg offset macaddr ifname dev curmac
json_load "$(cat /etc/macoffset)"
local _i=1
json_get_var MACSIZE size
json_select config
while json_get_var cfg $_i; do
offset=$((_i-1))
_i=$((_i+1))
ifname="$(uci -q get $cfg.ifname)"
[ "${ifname:0:1}" == "@" -o "$ifname" == "lo" ] && continue
macaddr="$(macpoffset $offset)"
uci -q set $cfg.macaddr="$macaddr"
uci -q set $cfg.macassigned="1"
for if in $ifname; do
# update device section in network config if matches the ifname
for dev in $(uci show network | grep "=device" | awk -F[.,=] '{print$2}'); do
if [ "$(uci -q get network.$dev.name)" == "$if" ]; then
uci -q set network.$dev.macaddr="$macaddr"
break
fi
done
done
done
LASTMACOFFSET=$((offset+1))
uci -q commit network
config_load network
config_foreach assign_macaddr interface network
uci -q commit network
}
service_triggers()
{
procd_add_reload_trigger network
}
{
"size" : 8,
"config": [
"network.lan",
"network.wan"
]
}
{
"events" : [
{
"type": "wifi-event",
"name": "cfg09ac03",
"ifname": "wlan0",
"family": "easysoc",
"group": [
"notify"
]
},
{
"type": "wifi-event",
"name": "cfg09ac03",
"ifname": "wlan0",
"family": "easysoc",
"group": [
"notify"
]
}
]
}
config board 'board'
# Specs
option hasAdsl '0'
option hasVdsl '0'
option hasVoice '0'
option hasDect '0'
option hasUsb '1'
option hasCatv '0'
option hasSfp '0'
option hasWifi '1'
# Ethernet
option ethernetPorts '2'
option ethernetPortNames 'LAN WAN'
option ethernetPortOrder 'eth0.1 eth0.2'
option ethernetSwitchPortOrder '1 0'
option ethernetLanPorts 'eth0.1'
option ethernetWanPort 'eth0.2'
# I2C
option sx9512_i2c_device '/dev/i2c-0'
option sx9512_i2c_address 2b
option sx9512_irq_pin 10
option sx9512_active_capsense_channels 0f
option sx9512_active_led_channels ff
# Switch config
config switch switch
option ports '1:lan 0:wan 6t@eth0 6t@eth0'
############### mapping function button to driver button
config button RESET
list button gpio_reset
option minpress 5000
option hotplug resetbutton
option enable 1
###############################################################################
#
# Button config, start
#
############### gpio buttons, driver config
config gpio_button gpio_buttons
list buttons gpio_reset
config gpio_button gpio_reset
option addr 18
option mode linux
option active low
############### sx9512, i2c buttons, driver config
config 9512_button 9512_buttons
list buttons 9512_wps
list buttons 9512_wifi_2g
list buttons 9512_wifi_5g
list buttons 9512_touch_near
list buttons 9512_touch_far
config 9512_button 9512_wifi_2g
option addr 1
config 9512_button 9512_wifi_5g
option addr 2
config 9512_button 9512_wps
option addr 3
config 9512_button 9512_touch_near
option addr 8
config 9512_button 9512_touch_far
option addr 9
#
# Button config , end
#
###############################################################################
###############################################################################
#
# Led config, start
#
############### 9512 led, driver config
config 9512_led 9512_leds
list leds Internet_green
list leds Internet_red
list leds Wireless_24
list leds Wireless_5
config 9512_led Internet_green
option addr 5
config 9512_led Internet_red
option addr 4
config 9512_led Wireless_24
option addr 7
config 9512_led Wireless_5
option addr 6
############### gpio led, driver config
config gpio_led gpio_leds
list leds Status_green
list leds Status_red
list leds WPS_green
config gpio_led Status_green
option addr 8
option active low
option mode linux
config gpio_led Status_red
option addr 11
option active hi
option mode linux
config 9512_led WPS_green
option addr 12
option active low
option mode linux
############### mapping led function to driver led
config led_map led_map
list press_indicator led_wifi_2g
list press_indicator led_wifi_5g
list press_indicator led_wps
list press_indicator led_internet
list functions 'wifi_2g'
list functions 'wifi_5g'
list functions wps
list functions status
list functions internet
# dimming turn leds off unless above cutof level
option dimming_level off
option dimming_on 5
list dimming wifi
list dimming wps
list dimming status
list dimming internet
config led_map 'led_wifi_2g'
list led_action_ok 'Wireless_24 = ON'
list led_action_off 'Wireless_24 = OFF'
list led_action_notice 'Wireless_24 = FLASH_SLOW'
list led_action_alert 'Wireless_24 = FLASH_SLOW'
list led_action_error 'Wireless_24 = FLASH_FAST'
config led_map 'led_wifi_5g'
list led_action_ok 'Wireless_5 = ON'
list led_action_off 'Wireless_5 = OFF'
list led_action_notice 'Wireless_5 = FLASH_SLOW'
list led_action_alert 'Wireless_5 = FLASH_SLOW'
list led_action_error 'Wireless_5 = FLASH_FAST'
config led_map led_wps
list led_action_ok 'WPS_green=ON'
list led_action_off 'WPS_green=OFF'
list led_action_notice 'WPS_green=FLASH_SLOW'
list led_action_alert 'WPS_green=FLASH_FAST'
list led_action_error 'WPS_green=OFF'
config led_map led_status
list led_action_ok 'Status_green = ON'
list led_action_ok 'Status_red = OFF'
list led_action_off 'Status_green = OFF'
list led_action_off 'Status_red = OFF'
list led_action_notice 'Status_green = FLASH_SLOW'
list led_action_notice 'Status_red = OFF'
list led_action_alert 'Status_green = OFF'
list led_action_alert 'Status_red = FLASH_SLOW'
list led_action_error 'Status_green = OFF'
list led_action_error 'Status_red = FLASH_FAST'
config led_map led_internet
list led_action_ok 'Internet_green = ON'
list led_action_ok 'Internet_red = OFF'
list led_action_off 'Internet_green = OFF'
list led_action_off 'Internet_red = OFF'
list led_action_notice 'Internet_green = FLASH_SLOW'
list led_action_notice 'Internet_red = OFF'
list led_action_alert 'Internet_green = OFF'
list led_action_alert 'Internet_red = FLASH_SLOW'
list led_action_error 'Internet_green = OFF'
list led_action_error 'Internet_red = ON'
list led_action_eok 'Internet_green = ON'
list led_action_eok 'Internet_red = ON'
config board 'board'
# Specs
option hasAdsl '0'
option hasVdsl '0'
option hasVoice '0'
option hasDect '0'
option hasUsb '1'
option hasCatv '0'
option hasSfp '0'
option hasWifi '1'
# Ethernet
option ethernetPorts '2'
option ethernetPortNames 'LAN WAN'
option ethernetPortOrder 'eth0.1 eth0.2'
option ethernetSwitchPortOrder '1 0'
option ethernetLanPorts 'eth0.1'
option ethernetWanPort 'eth0.2'
# I2C
option sx9512_i2c_device '/dev/i2c-0'
option sx9512_i2c_address 2b
option sx9512_irq_pin 10
option sx9512_active_capsense_channels 0f
option sx9512_active_led_channels ff
# Switch config
config switch switch
option ports '1:lan 0:wan 6t@eth0 6t@eth0'
############### mapping function button to driver button
config button RESET
list button gpio_reset
option minpress 5000
option hotplug resetbutton
option enable 1
###############################################################################
#
# Button config, start
#
############### gpio buttons, driver config
config gpio_button gpio_buttons
list buttons gpio_reset
config gpio_button gpio_reset
option addr 18
option mode linux
option active low
############### sx9512, i2c buttons, driver config
config 9512_button 9512_buttons
list buttons 9512_wps
list buttons 9512_wifi_2g
list buttons 9512_wifi_5g
list buttons 9512_touch_near
list buttons 9512_touch_far
config 9512_button 9512_wifi_2g
option addr 1
config 9512_button 9512_wifi_5g
option addr 2
config 9512_button 9512_wps
option addr 3
config 9512_button 9512_touch_near
option addr 8
config 9512_button 9512_touch_far
option addr 9
#
# Button config , end
#
###############################################################################
###############################################################################
#
# Led config, start
#
############### 9512 led, driver config
config 9512_led 9512_leds
list leds Internet_green
list leds Internet_red
list leds Wireless_24
list leds Wireless_5
config 9512_led Internet_green
option addr 5
config 9512_led Internet_red
option addr 4
config 9512_led Wireless_24
option addr 7
config 9512_led Wireless_5
option addr 6
############### gpio led, driver config
config gpio_led gpio_leds
list leds Status_green
list leds Status_red
list leds WPS_green
config gpio_led Status_green
option addr 8
option active low
option mode linux
config gpio_led Status_red
option addr 11
option active hi
option mode linux
config 9512_led WPS_green
option addr 12
option active low
option mode linux
############### mapping led function to driver led
config led_map led_map
list press_indicator led_wifi_2g
list press_indicator led_wifi_5g
list press_indicator led_wps
list press_indicator led_internet
list functions 'wifi_2g'
list functions 'wifi_5g'
list functions wps
list functions status
list functions internet
# dimming turn leds off unless above cutof level
option dimming_level off
option dimming_on 5
list dimming wifi
list dimming wps
list dimming status
list dimming internet
config led_map 'led_wifi_2g'
list led_action_ok 'Wireless_24 = ON'
list led_action_off 'Wireless_24 = OFF'
list led_action_notice 'Wireless_24 = FLASH_SLOW'
list led_action_alert 'Wireless_24 = FLASH_SLOW'
list led_action_error 'Wireless_24 = FLASH_FAST'
config led_map 'led_wifi_5g'
list led_action_ok 'Wireless_5 = ON'
list led_action_off 'Wireless_5 = OFF'
list led_action_notice 'Wireless_5 = FLASH_SLOW'
list led_action_alert 'Wireless_5 = FLASH_SLOW'
list led_action_error 'Wireless_5 = FLASH_FAST'
config led_map led_wps
list led_action_ok 'WPS_green=ON'
list led_action_off 'WPS_green=OFF'
list led_action_notice 'WPS_green=FLASH_SLOW'
list led_action_alert 'WPS_green=FLASH_FAST'
list led_action_error 'WPS_green=OFF'
config led_map led_status
list led_action_ok 'Status_green = ON'
list led_action_ok 'Status_red = OFF'
list led_action_off 'Status_green = OFF'
list led_action_off 'Status_red = OFF'
list led_action_notice 'Status_green = FLASH_SLOW'
list led_action_notice 'Status_red = OFF'
list led_action_alert 'Status_green = OFF'
list led_action_alert 'Status_red = FLASH_SLOW'
list led_action_error 'Status_green = OFF'
list led_action_error 'Status_red = FLASH_FAST'
config led_map led_internet
list led_action_ok 'Internet_green = ON'
list led_action_ok 'Internet_red = OFF'
list led_action_off 'Internet_green = OFF'
list led_action_off 'Internet_red = OFF'
list led_action_notice 'Internet_green = FLASH_SLOW'
list led_action_notice 'Internet_red = OFF'
list led_action_alert 'Internet_green = OFF'
list led_action_alert 'Internet_red = FLASH_SLOW'
list led_action_error 'Internet_green = OFF'
list led_action_error 'Internet_red = ON'
list led_action_eok 'Internet_green = ON'
list led_action_eok 'Internet_red = ON'
config board 'board'
option hasAdsl '0'
option hasVdsl '0'
option hasVoice '0'
option hasDect '0'
option hasUsb '1'
option hasCatv '0'
option hasSfp '0'
option hasWifi '1'
option ethernetPorts '2'
option ethernetPortNames 'LAN WAN'
option ethernetPortOrder 'eth0.1 eth0.2'
option ethernetSwitchPortOrder '1 0'
option ethernetLanPorts 'eth0.1'
option ethernetWanPort 'eth0.2'
option sx9512_i2c_device '/dev/i2c-0'
option sx9512_i2c_address 2b
option sx9512_irq_pin 10
option sx9512_active_capsense_channels 0f
option sx9512_active_led_channels ff
# Switch config
config switch switch
option ports '1:lan 0:wan 6t@eth0 5t@eth0'
list port switch_port_0
list port switch_port_1
list port switch_port_5
list port switch_port_6
# lan
config port switch_port_1
option id 1
option matrix 78
config port switch_port_6
option id 6
option matrix 78
# wan
config port switch_port_0
option id 0
option matrix 33
config port switch_port_5
option id 5
option matrix 33
############### mapping function button to driver button
config button RESET
list button gpio_reset
option minpress 5000
option hotplug resetbutton
option enable 1
###############################################################################
#
# Button config, start
#
############### gpio buttons, driver config
config gpio_button gpio_buttons
list buttons gpio_reset
config gpio_button gpio_reset
option addr 18
option mode linux
option active low
############### sx9512, i2c buttons, driver config
config 9512_button 9512_buttons
list buttons 9512_wps
list buttons 9512_wifi_2g
list buttons 9512_wifi_5g
list buttons 9512_touch_near
list buttons 9512_touch_far
config 9512_button 9512_wifi_2g
option addr 1
config 9512_button 9512_wifi_5g
option addr 2
config 9512_button 9512_wps
option addr 3
config 9512_button 9512_touch_near
option addr 8
config 9512_button 9512_touch_far
option addr 9
#
# Button config , end
#
###############################################################################
###############################################################################
#
# Led config, start
#