#!/bin/sh
#===============================================================================
#
#  atheros-post-down
#
#  Copyright (C) 2014 by Digi International Inc.
#  All rights reserved.
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License version 2 as published by
#  the Free Software Foundation.
#
#
#  !Description: Unload Atheros' wireless driver
#
#===============================================================================

set -e

[ "${IFACE}" != "wlan0" ] && exit 0

# For 'ccardimx28' do not unload the driver on halt/reboot
RUNLEVEL="$(runlevel | awk '{print $2}')"
MACHINENAME="$(cat /proc/device-tree/digi,machine,name 2>/dev/null || cat /sys/kernel/machine/name)"
if [ "${MACHINENAME}" = "ccardimx28" ]; then
	[ "${RUNLEVEL}" = "0" -o "${RUNLEVEL}" = "6" ] && exit 0
fi

if grep -qs ath6kl_sdio /proc/modules; then
	rmmod ath6kl_sdio > /dev/null
fi
