a79869d8c3dc3306f994c5d21a10d837aa98b32f
[openwrt/staging/ynezz.git] / target / linux / rtl838x / base-files / etc / board.d / 02_network
1 #!/bin/sh
2
3 . /lib/functions.sh
4 . /lib/functions/uci-defaults.sh
5 . /lib/functions/system.sh
6
7 rtl838x_setup_switch()
8 {
9 local switchid net portid master device lan_role lan_list
10
11 json_select_object switch
12 # Find slave ports
13 for net in $(ls -d /sys/class/net/*); do
14 switchid=$(cat $net/phys_switch_id 2>/dev/null)
15 [ -z "$switchid" ] && continue
16 device=$(basename $net)
17 portid=$(cat $net/phys_port_name)
18 lan_role="$lan_role ${portid##p}"
19 lan_list="$lan_list $device"
20 json_select_object "switch$((switchid))"
21 json_add_boolean enable 1
22 json_add_boolean reset 0
23 json_add_boolean dsa 1
24 json_select_array ports
25 json_add_object
26 json_add_int num "${portid##p}"
27 json_add_string role "lan"
28 json_add_string device "$device"
29 json_close_object
30 json_select ..
31 json_select ..
32 done
33 # Add switch master device
34 for net in $(ls -d /sys/class/net/*/dsa); do
35 master=$(dirname $net)
36 device=$(basename $master)
37 portid=$(cat $master/phys_port_name)
38 lan_role="$lan_role ${portid##p}"
39 json_select_object "switch$((switchid))"
40 json_select_array ports
41 json_add_object
42 json_add_int num "${portid##p}"
43 json_add_string device "$device"
44 json_add_boolean need_tag 0
45 json_add_boolean want_untag 0
46 json_add_boolean master 1
47 json_close_object
48 json_select ..
49 json_select_array roles
50 json_add_object
51 json_add_string role "lan"
52 lan_role=$(echo $lan_role | xargs -n1 | sort -n | xargs)
53 json_add_string ports "$lan_role"
54 json_close_object
55 json_select ..
56 json_select ..
57 done
58 json_select ..
59 lan_list=$(echo $lan_list | xargs -n1 | sort -V | xargs)
60 ucidef_set_interface_lan "$lan_list"
61 }
62
63 rtl838x_setup_macs()
64 {
65 local board="$1"
66 local lan_mac
67 local wan_mac
68 local label_mac
69
70 case $board in
71 allnet,all-sg8208m)
72 lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
73 label_mac=$lan_mac
74 esac
75
76 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
77 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
78 [ -n "$label_mac" ] && ucidef_set_label_macaddr $label_mac
79 }
80
81 board_config_update
82 board=$(board_name)
83 rtl838x_setup_switch
84 rtl838x_setup_macs $board
85 board_config_flush
86
87 exit 0