#!/bin/sh

# Action script to disable the wireless interface of EeePC models with
# rt2860sta during suspend and enable it back during resume.
#
# The problem is that if the interface is enabled when suspending,
# the kernel locks up during resume
#

PATH=/sbin:/usr/sbin:/bin:/usr/bin

# do nothing if package is removed
[ -r /usr/share/eeepc-acpi-scripts/functions.sh ] || exit 0

OLD_STATE_FILE=/var/run/eeepc-turn-wlan-on
WLAN_CTRL=/etc/acpi/actions/wireless.sh

# pm-action(8) - <action> <suspend method>
#
# On suspend or hibernate, disable wlan
# re-enable on resume or thaw (if it was enabled during suspend).

case "${1}" in
    suspend|hibernate)
        $WLAN_CTRL detect
        if [ $? = "1" ] ; then
            # wireless is on
            if lspci | grep -q 'RT2860'; then
                # it is rt2860sta; needs to be shut down
                touch $OLD_STATE_FILE
                $WLAN_CTRL off
            fi
        fi
    ;;
    resume|thaw)
        if [ -e $OLD_STATE_FILE ]; then
            rm $OLD_STATE_FILE
            $WLAN_CTRL on
        fi
    ;;
esac

