small cleanup
[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 for device in ${2:-$DEVICES}; do (
40 config_get disabled "$device" disabled
41 [ "$disabled" == "1" ] && {
42 echo "'$device' is disabled"
43 set disable
44 }
45 config_get iftype "$device" type
46 if eval "type ${1}_$iftype" 2>/dev/null >/dev/null; then
47 eval "scan_$iftype '$device'"
48 eval "${1}_$iftype '$device'" || echo "$device($iftype): ${1} failed"
49 else
50 echo "$device($iftype): Interface type not supported"
51 fi
52 ); done
53 }
54
55 wifi_detect() {
56 for driver in ${2:-$DRIVERS}; do (
57 if eval "type detect_$driver" 2>/dev/null >/dev/null; then
58 eval "detect_$driver" || echo "$driver: Detect failed" >&2
59 else
60 echo "$driver: Hardware detection not supported" >&2
61 fi
62 ); done
63 }
64
65 start_net() {(
66 local iface="$1"
67 local config="$2"
68
69 include /lib/network
70 scan_interfaces
71 setup_interface "$1" "$2"
72 )}
73
74 scan_wifi() {
75 local cfgfile="$1"
76 config_cb() {
77 config_get TYPE "$CONFIG_SECTION" TYPE
78 case "$TYPE" in
79 wifi-device)
80 append DEVICES "$CONFIG_SECTION"
81 ;;
82 wifi-iface)
83 config_get device "$CONFIG_SECTION" device
84 config_get vifs "$device" vifs
85 append vifs "$CONFIG_SECTION"
86 config_set "$device" vifs "$vifs"
87 ;;
88 esac
89 }
90 config_load "${cfgfile:-wireless}"
91 }
92
93 DEVICES=
94 DRIVERS=
95 include /lib/wifi
96 scan_wifi
97
98 case "$1" in
99 down) wifi_updown "disable" "$2";;
100 detect) wifi_detect "$2";;
101 *) wifi_updown "enable" "$2";;
102 esac
This page took 0.05231 seconds and 5 git commands to generate.