usteer: add support for IPv6 remote exchange
[project/usteer.git] / openwrt / usteer / files / etc / init.d / usteer
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2013 OpenWrt.org
3
4 START=50
5 USE_PROCD=1
6
7 NAME=usteer
8 PROG=/sbin/usteerd
9
10 . /lib/functions/network.sh
11 . /usr/share/libubox/jshn.sh
12 . /lib/functions.sh
13
14 load_ifaces() {
15 local network="$(uci get usteer.@usteer[-1].network)"
16 for n in $network; do
17 local device
18 json_load "$(ifstatus $n)"
19 json_get_var device l3_device
20 echo -n "$device "
21 done
22 }
23
24 _add_string() {
25 json_add_string "" "$1"
26 }
27
28 uci_option_to_json_string_array() {
29 local cfg="$1"
30 local option="$2"
31
32 json_add_array "$option"
33 config_list_foreach "$cfg" "$option" _add_string
34 json_close_array
35 }
36
37 uci_option_to_json_bool() {
38 local cfg="$1"
39 local option="$2"
40 local val
41
42 config_get_bool val "$cfg" $option
43 [ -n "$val" ] && json_add_boolean $option $val
44 }
45
46 uci_option_to_json_string() {
47 local cfg="$1"
48 local option="$2"
49 local val
50
51 config_get val "$cfg" "$option"
52 [ -n "$val" ] && json_add_string $option "$val"
53 }
54
55 uci_option_to_json() {
56 local cfg="$1"
57 local option="$2"
58 local val
59
60 config_get val "$cfg" $option
61 [ -n "$val" ] && json_add_int $option $val
62 }
63
64 uci_usteer() {
65 local cfg="$1"
66
67 uci_option_to_json_bool "$cfg" syslog
68 uci_option_to_json_bool "$cfg" ipv6
69 uci_option_to_json_bool "$cfg" load_kick_enabled
70 uci_option_to_json_bool "$cfg" assoc_steering
71 uci_option_to_json_string "$cfg" node_up_script
72 uci_option_to_json_string_array "$cfg" ssid_list
73 uci_option_to_json_string_array "$cfg" event_log_types
74
75 for opt in \
76 debug_level \
77 sta_block_timeout local_sta_timeout local_sta_update \
78 max_retry_band seen_policy_timeout \
79 load_balancing_threshold band_steering_threshold \
80 remote_update_interval \
81 min_connect_snr min_snr signal_diff_threshold \
82 initial_connect_delay \
83 roam_kick_delay roam_scan_tries \
84 roam_scan_snr roam_scan_interval \
85 roam_trigger_snr roam_trigger_interval \
86 load_kick_threshold load_kick_delay load_kick_min_clients \
87 load_kick_reason_code
88 do
89 uci_option_to_json "$cfg" "$opt"
90 done
91 }
92
93
94 load_config() {
95 [ "$ENABLED" -gt 0 ] || return
96
97 ubus -t 10 wait_for usteer
98
99 json_init
100 json_add_array interfaces
101 for i in $(load_ifaces); do
102 json_add_string "" "$i"
103 done
104 json_close_array
105
106 config_load usteer
107 config_foreach uci_usteer usteer
108
109 ubus call usteer set_config "$(json_dump)"
110 }
111
112 reload_service() {
113 start
114 load_config
115 }
116
117 service_started() {
118 load_config
119 }
120
121 service_triggers() {
122 procd_add_reload_trigger usteer
123 procd_add_raw_trigger "interface.*" 2000 /etc/init.d/usteer reload
124 }
125
126 start_service()
127 {
128 local network="$(uci -q get usteer.@usteer[-1].network)"
129 ENABLED="$(uci -q get usteer.@usteer[-1].enabled)"
130 ENABLED="${ENABLED:-1}"
131
132 [ "$ENABLED" -gt 0 ] || return
133
134 procd_open_instance
135 procd_set_param command "$PROG"
136 procd_close_instance
137 }