#!/bin/sh

# pm-utils hook to handle suspend/resume properly for ipw2200 wifi cards.
# See Debian BTS: 546909 for details
# See Kernel.org BTS: 14206 for details

if [ -r "${PM_FUNCTIONS}" ]; then
	. "${PM_FUNCTIONS}" 
elif [ -r "${FUNCTIONS}" ]; then
	. "${FUNCTIONS}"
else
	# pm-utils version is too old, or something else is wrong
	exit $NA
fi

RETVAL=0 	# Set this to 0 initially
IPW2200="ipw2200"

ipw2200_unload()
{
        # Unload the module
        modprobe -r $IPW2200
	RETVAL=$?
}

ipw2200_load()
{
        modprobe $IPW2200
	RETVAL=$?
}

case "$1" in
	hibernate|suspend)
                ipw2200_unload
		;;
	thaw|resume)
                ipw2200_load
		;;
	*) exit $NA
		;;
esac

# We can't return a nonzero exit code (aside from $NA, $DX, and $NX) to
# to pm-utils or the entire sleep operation will be inhibited, so...
# No matter what we do, the log prefix and message will conflict a bit.
case "$RETVAL" in
	0)
		exit $RETVAL
		;;
	*)
        echo "modprobe exited with a failure"
		exit $NA
		;;
esac

