#!/bin/sh
# tlp - restore ThinkPad wwan state after suspend / hibernate
#
# Copyright (c) 2012 Thomas Koch <linrunner at gmx.net>
# This software is licensed under the GPL v2.

. "${PM_FUNCTIONS}"

readonly LIB=/usr/lib64/tlp-pm/tlp-functions
readonly RFLIB=/usr/lib64/tlp-pm/tlp-rf-func

suspend_device () {
	local state
	
	state=$(cat $2)
    echo 0 > $2 # workaround: switch off before suspend
	savestate $1 $state
	echo_debug "pm" "49wwan.suspend wwan=$state"
}

resume_device () {
	state_exists $1 || return
	restorestate $1 > $2
	echo_debug "pm" "49wwan.resume wwan=$(cat $2)"
}

[ -f $LIB ] || exit 0
[ -f $RFLIB ] || exit 0
. $LIB
. $RFLIB

read_defaults || exit 0

[ "$TLP_ENABLE" = "1" ] || exit 0

echo_debug "pm" "49wwan.$1"

get_devc wwan
[ -n "$devc" ] || exit 0

case $1 in
	hibernate|suspend)
		suspend_device tp_wwan $devc
		;;
		
	thaw|resume)
		resume_device tp_wwan $devc
		;;
		
	*) exit $NA
		;;
esac

exit 0
