3d28e3956c9b21c03c7bb305f3a3097dc15e4315
[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 . /lib/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 # Rename wifi-device for $net
16
17 handle_wifidevice() {
18         if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
19                 section_rename wireless $1 $net
20         fi
21 }
22 config_foreach handle_wifidevice wifi-device
23
24 # create new wifi-device for $net
25 uci set wireless.${net}=wifi-device
26
27 # get and set wifi-device defaults
28 set_defaults "wifi_device_" wireless.${net}
29
30 channel="$(uci -q get meshwizard.netconfig.$net\_channel)"
31
32 if [ -z "$channel" -o "$channel" == "default" ]; then
33         channel=$wifi_device_channel
34 fi
35
36 uci batch << EOF
37         set wireless.${net}.type="$type"
38         set wireless.${net}.channel="$channel"
39 EOF
40
41 uci_commitverbose "Setup wifi device for $netrenamed" wireless
42
43 ##### wifi iface
44
45 # Rename wifi-iface for $net
46 handle_interface() {
47         config_get device "$1" device
48         if [ "$device" == "$net" ]; then
49                 if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
50                         section_rename wireless $1 ${net}_iface
51                 fi
52         fi
53
54 config_foreach handle_interface wifi-iface
55
56 # create new wifi-device for $net
57 uci set wireless.$net\_iface=wifi-iface
58
59 # create new wifi-iface for $net from defaults
60 set_defaults "wifi_iface_" wireless.$net\_iface
61
62 # overwrite defaults
63 bssid="$($dir/helpers/gen_bssid.sh $channel $community)"
64
65 ssid="$profile_ssid"
66 if [ "$profile_ssid_scheme" == "addchannel" ]; then
67         ssid="$ssid - ch$channel"
68 fi
69
70 uci batch << EOF
71         set wireless.$net\_iface.device="${net}"
72         set wireless.$net\_iface.network="$netrenamed"
73         set wireless.$net\_iface.ssid="$ssid"
74         set wireless.$net\_iface.bssid="$bssid"
75 EOF
76
77 uci_commitverbose "Setup wifi interface for $netrenamed" wireless
78