Add new meshwizard (WIP)
[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 echo " + Setup wifi-device"
12
13 # Get the type before we delete the wifi-device
14 config_load wireless
15 config_get type $net type
16
17 # Delete old wifi-device for $net
18
19 handle_wifidevice() {
20 if [ "$1" == "$net" -a "$cleanup" == 1 ]; then
21 section_cleanup wireless.${net}
22 else
23 if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
24 section_rename wireless $1 $net
25 fi
26 fi
27 }
28 config_foreach handle_wifidevice wifi-device
29
30 # create new wifi-device for $net
31 uci set wireless.${net}=wifi-device
32
33 # get and set wifi-device defaults
34 set_defaults "wifi_device_" wireless.${net}
35
36 channel="$(uci -q get meshwizard.netconfig.$net\_channel)"
37 vap="$(uci -q get meshwizard.netconfig.$net\_vap)"
38
39 if [ -z "$channel" -o "$channel" == "default" ]; then
40 channel=$wifi_device_channel
41 fi
42
43 uci batch << EOF
44 set wireless.${net}.type="$type"
45 set wireless.${net}.channel="$channel"
46 EOF
47
48 echo " Type: $type"
49 echo " Channel: $channel"
50
51 ##### wifi iface
52
53 echo " + Setup wifi-iface"
54
55 # Delete old wifi-iface for $net
56 handle_interface() {
57 config_get device "$1" device
58 if [ "$device" == "$net" ]; then
59 if [ "$cleanup" == 1 ]; then
60 section_cleanup wireless.${net}_iface
61 else
62 if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
63 section_rename wireless $1 ${net}_iface
64 fi
65 fi
66 fi
67 }
68 config_foreach handle_interface wifi-iface
69
70 # create new wifi-device for $net
71 uci set wireless.$net\_iface=wifi-iface
72
73 # create new wifi-iface for $net from defaults
74 set_defaults "wifi_iface_" wireless.$net\_iface
75
76 # overwrite defaults
77 bssid="$($dir/helpers/gen_bssid.sh $channel $community)"
78 uci batch << EOF
79 set wireless.$net\_iface.device="${net}"
80 set wireless.$net\_iface.network="$netrenamed"
81 set wireless.$net\_iface.ssid="$profile_ssid - ch$channel"
82 set wireless.$net\_iface.bssid="$bssid"
83 EOF
84
85 echo " device: $net
86 network: $netrenamed
87 ssid: $profile_ssid - ch$channel
88 bssid: $bssid"
89
90 ## VAP
91 ip4addr="$(uci get meshwizard.netconfig.$net\_ip4addr)"
92 if [ "$type" == "atheros" -a "$vap" == 1 ]; then
93 uci batch << EOF
94 set wireless.$net\_iface_dhcp="wifi-iface"
95 set wireless.$net\_iface_dhcp.device="$net"
96 set wireless.$net\_iface_dhcp.mode="ap"
97 set wireless.$net\_iface_dhcp.encryption="none"
98 set wireless.$net\_iface_dhcp.network="${netrenamed}dhcp"
99 set wireless.$net\_iface_dhcp.ssid="FF-AP-$ip4addr"
100 EOF
101 echo " + Setting up VAP interface for $net
102 device: $net
103 network: ${netrenamed}dhcp
104 ssid: AP-$profile_ssid-$ip4addr"
105 fi
106
107 uci commit