fix typo
[openwrt/openwrt.git] / package / base-files / default / sbin / wifi
1 #!/bin/sh
2 # Copyright (C) 2006 OpenWrt.org
3
4 . /etc/functions.sh
5
6 find_net_config() {(
7 local vif="$1"
8 local cfg
9 local ifname
10
11 config_get cfg "$vif" network
12
13 [ -z "$cfg" ] && {
14 include /lib/network
15 scan_interfaces
16
17 config_get ifname "$vif" ifnamea
18
19 cfg="$(find_config "$ifname")"
20 }
21 [ -z "$cfg" ] && return 0
22 echo "$cfg"
23 )}
24
25
26 bridge_interface() {(
27 local cfg="$1"
28 [ -z "$cfg" ] && return 0
29
30 include /lib/network
31 scan_interfaces
32
33 config_get iftype "$cfg" type
34 [ "$iftype" = bridge ] && config_get "$cfg" ifname
35 )}
36
37
38 wifi_up() {
39 for device in ${2:-$DEVICES}; do (
40 config_get iftype "$device" type
41 if eval "type enable_$iftype" 2>/dev/null >/dev/null; then
42 eval "scan_$iftype '$device'"
43 eval "enable_$iftype '$device'" || echo "$device($iftype): Setup failed"
44 else
45 echo "$device($iftype): Interface type not supported"
46 fi
47 ); done
48 }
49
50 wifi_down() {
51 for device in ${2:-$DEVICES}; do (
52 config_get iftype "$device" type
53 if eval "type disable_$iftype" 2>/dev/null >/dev/null; then
54 eval "scan_$iftype '$device'"
55 eval "disable_$iftype '$device'" || echo "$device($iftype): Disable failed"
56 else
57 echo "$device($iftype): Interface type not supported"
58 fi
59 ); done
60 }
61
62 wifi_detect() {
63 for driver in ${2:-$DRIVERS}; do (
64 if eval "type detect_$driver" 2>/dev/null >/dev/null; then
65 eval "detect_$driver" || echo "$driver: Detect failed" >&2
66 else
67 echo "$driver: Hardware detection not supported" >&2
68 fi
69 ); done
70 }
71
72 start_net() {(
73 local iface="$1"
74 local config="$2"
75
76 include /lib/network
77 scan_interfaces
78 setup_interface "$1" "$2"
79 )}
80
81 config_get_bool() {
82 local _tmp
83 config_get "$1" "$2" "$3"
84 eval "_tmp=\$$1"
85 case "$_tmp" in
86 1|on|enabled) eval "$1=1";;
87 0|off|disabled) eval "$1=0";;
88 *) eval "$1=${4:-0}";;
89 esac
90 }
91
92 config_cb() {
93 config_get TYPE "$CONFIG_SECTION" TYPE
94 case "$TYPE" in
95 wifi-device)
96 append DEVICES "$CONFIG_SECTION"
97 ;;
98 wifi-iface)
99 config_get device "$CONFIG_SECTION" device
100 config_get vifs "$device" vifs
101 append vifs "$CONFIG_SECTION"
102 config_set "$device" vifs "$vifs"
103 ;;
104 esac
105 }
106
107 DEVICES=
108 DRIVERS=
109 config_load wireless
110 include /lib/wifi
111
112 case "$1" in
113 down) wifi_down "$2";;
114 detect) wifi_detect "$2";;
115 *) wifi_up "$2";;
116 esac