Remove buggy i2c-gpio driver
[openwrt.git] / package / base-files / files / 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" ifname
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_updown() {
39 [ enable = "$1" ] && wifi_updown disable "$2"
40 for device in ${2:-$DEVICES}; do (
41 config_get disabled "$device" disabled
42 [ 1 == "$disabled" ] && {
43 echo "'$device' is disabled"
44 set disable
45 }
46 config_get iftype "$device" type
47 if eval "type ${1}_$iftype" 2>/dev/null >/dev/null; then
48 eval "scan_$iftype '$device'"
49 eval "${1}_$iftype '$device'" || echo "$device($iftype): ${1} failed"
50 else
51 echo "$device($iftype): Interface type not supported"
52 fi
53 ); done
54 }
55
56 wifi_detect() {
57 for driver in ${2:-$DRIVERS}; do (
58 if eval "type detect_$driver" 2>/dev/null >/dev/null; then
59 eval "detect_$driver" || echo "$driver: Detect failed" >&2
60 else
61 echo "$driver: Hardware detection not supported" >&2
62 fi
63 ); done
64 }
65
66 start_net() {(
67 local iface="$1"
68 local config="$2"
69
70 include /lib/network
71 scan_interfaces
72 setup_interface "$1" "$2"
73 )}
74
75 set_wifi_up() {
76 local cfg="$1"
77 local ifname="$2"
78 uci set "/var/state/wireless.${cfg}.up=1"
79 uci set "/var/state/wireless.${cfg}.ifname=$ifname"
80 }
81
82 set_wifi_down() {
83 local cfg="$1"
84 local vifs vif vifstr
85 [ -f /var/state/wireless ] || return
86
87 config_get vifs "$cfg" vifs
88 for vif in $vifs; do
89 append vifstr "$vif" "|"
90 done
91 FILE="/var/state/wireless.$$"
92 grep -vE "^config_set '($vifstr)' " /var/state/wireless > "$FILE"
93 mv "$FILE" /var/state/wireless
94 }
95
96 scan_wifi() {
97 local cfgfile="$1"
98 config_cb() {
99 config_get TYPE "$CONFIG_SECTION" TYPE
100 case "$TYPE" in
101 wifi-device)
102 append DEVICES "$CONFIG_SECTION"
103 ;;
104 wifi-iface)
105 config_get device "$CONFIG_SECTION" device
106 config_get vifs "$device" vifs
107 append vifs "$CONFIG_SECTION"
108 config_set "$device" vifs "$vifs"
109 ;;
110 esac
111 }
112 config_load "${cfgfile:-wireless}"
113 }
114
115 DEVICES=
116 DRIVERS=
117 include /lib/wifi
118 scan_wifi
119
120 case "$1" in
121 down) wifi_updown "disable" "$2";;
122 detect) wifi_detect "$2";;
123 *) wifi_updown "enable" "$2";;
124 esac
This page took 0.049656 seconds and 5 git commands to generate.