63b2f121bda4547b3fd1aa724b9db9e5b1df329c
[openwrt.git] / package / base-files / default / sbin / wifi
1 #!/bin/sh
2 # Copyright (C) 2006 OpenWrt.org
3
4 . /etc/functions.sh
5
6 config_get_bool() {
7         local _tmp
8         config_get "$1" "$2" "$3"
9         eval "_tmp=\$$1"
10         case "$_tmp" in
11                 1|on|enabled) eval "$1=1";;
12                 0|off|disabled) eval "$1=0";;
13                 *) eval "$1=${4:-0}";;
14         esac
15 }
16
17 config_cb() {
18         config_get TYPE "$CONFIG_SECTION" TYPE
19         case "$TYPE" in
20                 wifi-device)
21                         append DEVICES "$CONFIG_SECTION"
22                 ;;
23                 wifi-iface)
24                         config_get device "$CONFIG_SECTION" device
25                         config_get vifs "$device" vifs 
26                         append vifs "$CONFIG_SECTION"
27                         config_set "$device" vifs "$vifs"
28                 ;;
29         esac
30 }
31
32 config_load wireless
33
34 [ -d /lib/wifi -a -n "$(ls /lib/wifi/*.sh 2>&-)" ] && {
35         for script in /lib/wifi/*.sh; do
36                 . $script
37         done
38 }
39
40 for device in $DEVICES; do (
41         config_get type "$device" type
42         eval "type setup_$type" 2>/dev/null >/dev/null && {
43                 eval "scan_$type '$device'"
44                 eval "setup_$type '$device'" && {
45                         # TODO: set up network settings
46                         /bin/true
47                 } || echo "$device($type): Setup failed" || true
48         } || echo "$device($type): Interface type not supported"
49 ); done