don't run mdev on hotplug pseudo-events that come from user space
[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_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_cb() {
82         config_get TYPE "$CONFIG_SECTION" TYPE
83         case "$TYPE" in
84                 wifi-device)
85                         append DEVICES "$CONFIG_SECTION"
86                 ;;
87                 wifi-iface)
88                         config_get device "$CONFIG_SECTION" device
89                         config_get vifs "$device" vifs 
90                         append vifs "$CONFIG_SECTION"
91                         config_set "$device" vifs "$vifs"
92                 ;;
93         esac
94 }
95
96 DEVICES=
97 DRIVERS=
98 config_load wireless
99 include /lib/wifi
100
101 case "$1" in
102         down) wifi_down "$2";;
103         detect) wifi_detect "$2";;
104         *) wifi_up "$2";;
105 esac