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