contrib/meshwizard: Cleanup and add ssid_scheme option
[project/luci.git] / contrib / package / meshwizard / files / usr / bin / meshwizard / helpers / setup_wifi.sh
1 #!/bin/sh
2 # sets up a wifi interface for meshing
3 # Arguments: $1 = network interface
4
5 net="$1"
6 . /etc/functions.sh
7 . $dir/functions.sh
8
9 ##### wifi-device #####
10
11 # Get the type before we delete the wifi-device
12 config_load wireless
13 config_get type $net type
14
15 # Delete old wifi-device for $net
16
17 handle_wifidevice() {
18 if [ "$1" == "$net" -a "$cleanup" == 1 ]; then
19 section_cleanup wireless.${net}
20 else
21 if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
22 section_rename wireless $1 $net
23 fi
24 fi
25 }
26 config_foreach handle_wifidevice wifi-device
27
28 # create new wifi-device for $net
29 uci set wireless.${net}=wifi-device
30
31 # get and set wifi-device defaults
32 set_defaults "wifi_device_" wireless.${net}
33
34 channel="$(uci -q get meshwizard.netconfig.$net\_channel)"
35 vap="$(uci -q get meshwizard.netconfig.$net\_vap)"
36
37 if [ -z "$channel" -o "$channel" == "default" ]; then
38 channel=$wifi_device_channel
39 fi
40
41 uci batch << EOF
42 set wireless.${net}.type="$type"
43 set wireless.${net}.channel="$channel"
44 EOF
45
46 uci_commitverbose "Setup wifi device for $netrenamed" wireless
47
48 ##### wifi iface
49
50 # Delete old wifi-iface for $net
51 handle_interface() {
52 config_get device "$1" device
53 if [ "$device" == "$net" ]; then
54 if [ "$cleanup" == 1 ]; then
55 section_cleanup wireless.${net}_iface
56 else
57 if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
58 section_rename wireless $1 ${net}_iface
59 fi
60 fi
61 fi
62 }
63 config_foreach handle_interface wifi-iface
64
65 # create new wifi-device for $net
66 uci set wireless.$net\_iface=wifi-iface
67
68 # create new wifi-iface for $net from defaults
69 set_defaults "wifi_iface_" wireless.$net\_iface
70
71 # overwrite defaults
72 bssid="$($dir/helpers/gen_bssid.sh $channel $community)"
73 ssid="$profile_ssid"
74 if [ "$profile_ssid_scheme" == "addchannel" ]; then
75 ssid="$ssid - ch$channel"
76 fi
77
78 uci batch << EOF
79 set wireless.$net\_iface.device="${net}"
80 set wireless.$net\_iface.network="$netrenamed"
81 set wireless.$net\_iface.ssid="$ssid"
82 set wireless.$net\_iface.bssid="$bssid"
83 EOF
84
85 uci_commitverbose "Setup wifi interface for $netrenamed" wireless
86
87 ## VAP
88 ip4addr="$(uci get meshwizard.netconfig.$net\_ip4addr)"
89 if [ "$type" == "atheros" -a "$vap" == 1 ]; then
90 uci batch << EOF
91 set wireless.$net\_iface_dhcp="wifi-iface"
92 set wireless.$net\_iface_dhcp.device="$net"
93 set wireless.$net\_iface_dhcp.mode="ap"
94 set wireless.$net\_iface_dhcp.encryption="none"
95 set wireless.$net\_iface_dhcp.network="${netrenamed}dhcp"
96 set wireless.$net\_iface_dhcp.ssid="FF-AP-$ip4addr"
97 EOF
98 uci_commitverbose "Setup VAP interface for $netrenamed" wireless
99 fi
100