diff options
Diffstat (limited to 'package/base-files/files/sbin')
-rwxr-xr-x | package/base-files/files/sbin/hotplug | 26 | ||||
-rwxr-xr-x | package/base-files/files/sbin/ifdown | 55 | ||||
-rwxr-xr-x | package/base-files/files/sbin/ifup | 11 | ||||
-rwxr-xr-x | package/base-files/files/sbin/mount_root | 10 | ||||
-rwxr-xr-x | package/base-files/files/sbin/wifi | 116 |
5 files changed, 218 insertions, 0 deletions
diff --git a/package/base-files/files/sbin/hotplug b/package/base-files/files/sbin/hotplug new file mode 100755 index 000000000..b1b6f97b2 --- /dev/null +++ b/package/base-files/files/sbin/hotplug @@ -0,0 +1,26 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +# bypass the normal hotplug path for firmware loading +# would otherwise cause problems with drivers like bcm43xx +[ "$1" = "firmware" -a "$ACTION" = "add" ] && { + [ -f "/lib/firmware/$FIRMWARE" ] && { + echo 1 > "/sys$DEVPATH/loading" + cp "/lib/firmware/$FIRMWARE" "/sys$DEVPATH/data" + echo 0 > "/sys$DEVPATH/loading" + } + exit 0 +} + +. /etc/functions.sh + +PATH=/bin:/sbin:/usr/bin:/usr/sbin +LOGNAME=root +USER=root +export PATH LOGNAME USER + +[ \! -z "$1" -a -d /etc/hotplug.d/$1 ] && { + for script in $(ls /etc/hotplug.d/$1/* 2>&-); do ( + [ -f $script ] && . $script + ); done +} diff --git a/package/base-files/files/sbin/ifdown b/package/base-files/files/sbin/ifdown new file mode 100755 index 000000000..26d0e626d --- /dev/null +++ b/package/base-files/files/sbin/ifdown @@ -0,0 +1,55 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +[ $# = 0 ] && { echo " $0 <group>"; exit; } +. /etc/functions.sh +include /lib/network +scan_interfaces + +cfg=$1 +debug "### ifdown $cfg ###" + +config_get proto "$cfg" proto +[ -z "$proto" ] && { echo "interface not found."; exit; } + +config_get iface "$cfg" device +[ "$proto" = "static" ] && { + env -i ACTION="ifdown" INTERFACE="$config" DEVICE="$iface" PROTO=static /sbin/hotplug "iface" & +} + +# call interface stop handler +( type "stop_interface_$proto" ) >/dev/null 2>/dev/null && eval "stop_interface_$proto '$cfg'" + +# make sure all locks are removed +for lock in "/var/lock/dhcp-$iface" "/var/lock/ppp-$iface"; do + [ -f "$lock" ] && { + lock -u "$lock" + sleep 1 + } +done + +# kill active ppp daemon and other processes +config_get ifname "$cfg" ifname +pids="$(head -n1 -q /var/run/${ifname}.pid /var/run/ppp-${cfg}.pid 2>/dev/null)" +for pid in $pids; do + [ -d "/proc/$pid" ] && { + kill $pid + [ -d "/proc/$pid" ] && { + sleep 1 + kill -9 $pid 2>/dev/null >/dev/null + } + } +done +rm -f /var/run/${ifname}.pid /var/run/ppp-${cfg}.pid + +config_get ifname "$cfg" ifname +config_get device "$cfg" ifname + +[ ."$device" != ."$ifname" ] || device= +for dev in $ifname $device; do + ifconfig "$ifname" 0.0.0.0 down >/dev/null 2>/dev/null +done + +config_get iftype "$cfg" type +[ "$iftype" = "bridge" ] && brctl delbr "$ifname" >/dev/null 2>/dev/null + diff --git a/package/base-files/files/sbin/ifup b/package/base-files/files/sbin/ifup new file mode 100755 index 000000000..81ec2c089 --- /dev/null +++ b/package/base-files/files/sbin/ifup @@ -0,0 +1,11 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +. /sbin/ifdown "$@" + +config_get iftype "$1" type +config_get ifname "$1" device + +for dev in $ifname; do + setup_interface "$dev" "$1" +done diff --git a/package/base-files/files/sbin/mount_root b/package/base-files/files/sbin/mount_root new file mode 100755 index 000000000..81660f006 --- /dev/null +++ b/package/base-files/files/sbin/mount_root @@ -0,0 +1,10 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +mount none /proc -t proc +size=$(awk '/Mem:/ {l=5242880;print((s=$2/2)<l)?$2-l:s}' /proc/meminfo) +mount none /tmp -t tmpfs -o size=$size,nosuid,nodev,mode=1777 +mkdir -p /dev/pts +mount none /dev/pts -t devpts +mount -t sysfs none /sys 2>&- +mount -o remount,rw /dev/root / diff --git a/package/base-files/files/sbin/wifi b/package/base-files/files/sbin/wifi new file mode 100755 index 000000000..d877c7398 --- /dev/null +++ b/package/base-files/files/sbin/wifi @@ -0,0 +1,116 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +. /etc/functions.sh + +find_net_config() {( + local vif="$1" + local cfg + local ifname + + config_get cfg "$vif" network + + [ -z "$cfg" ] && { + include /lib/network + scan_interfaces + + config_get ifname "$vif" ifnamea + + cfg="$(find_config "$ifname")" + } + [ -z "$cfg" ] && return 0 + echo "$cfg" +)} + + +bridge_interface() {( + local cfg="$1" + [ -z "$cfg" ] && return 0 + + include /lib/network + scan_interfaces + + config_get iftype "$cfg" type + [ "$iftype" = bridge ] && config_get "$cfg" ifname +)} + + +wifi_up() { + for device in ${2:-$DEVICES}; do ( + config_get iftype "$device" type + if eval "type enable_$iftype" 2>/dev/null >/dev/null; then + eval "scan_$iftype '$device'" + eval "enable_$iftype '$device'" || echo "$device($iftype): Setup failed" + else + echo "$device($iftype): Interface type not supported" + fi + ); done +} + +wifi_down() { + for device in ${2:-$DEVICES}; do ( + config_get iftype "$device" type + if eval "type disable_$iftype" 2>/dev/null >/dev/null; then + eval "scan_$iftype '$device'" + eval "disable_$iftype '$device'" || echo "$device($iftype): Disable failed" + else + echo "$device($iftype): Interface type not supported" + fi + ); done +} + +wifi_detect() { + for driver in ${2:-$DRIVERS}; do ( + if eval "type detect_$driver" 2>/dev/null >/dev/null; then + eval "detect_$driver" || echo "$driver: Detect failed" >&2 + else + echo "$driver: Hardware detection not supported" >&2 + fi + ); done +} + +start_net() {( + local iface="$1" + local config="$2" + + include /lib/network + scan_interfaces + setup_interface "$1" "$2" +)} + +config_get_bool() { + local _tmp + config_get "$1" "$2" "$3" + eval "_tmp=\$$1" + case "$_tmp" in + 1|on|enabled) eval "$1=1";; + 0|off|disabled) eval "$1=0";; + *) eval "$1=${4:-0}";; + esac +} + +config_cb() { + config_get TYPE "$CONFIG_SECTION" TYPE + case "$TYPE" in + wifi-device) + append DEVICES "$CONFIG_SECTION" + ;; + wifi-iface) + config_get device "$CONFIG_SECTION" device + config_get vifs "$device" vifs + append vifs "$CONFIG_SECTION" + config_set "$device" vifs "$vifs" + ;; + esac +} + +DEVICES= +DRIVERS= +config_load wireless +include /lib/wifi + +case "$1" in + down) wifi_down "$2";; + detect) wifi_detect "$2";; + *) wifi_up "$2";; +esac |