#!/bin/sh
#===============================================================================
#
#  wpasupplicant_pre-up
#
#  Copyright (C) 2009 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: Start wpa_supplicant daemon
#
#===============================================================================

set -e

[ "${IFACE}" != "wlan0" ] && exit 0
exit 0
# u-boot's 'wdmode = 2' is for testing, so exit
wdmode="$(ubootenv -p wdmode | sed 's,^wdmode=,,g')"
[ "${wdmode}" = "2" ] && exit 0

wpa_supplicant="/usr/sbin/wpa_supplicant"
wpa_supplicant_args="-Dwext -iwlan0 -c/etc/wpa_supplicant.conf"
pidfile="/var/run/wpa_supplicant.pid"

[ -x "${wpa_supplicant}" ] || exit 0

if [ -s "${pidfile}" ]; then
	pid="$(cat ${pidfile})"
	if kill -0 "${pid}" 2>/dev/null; then
		exit 0
	fi
fi

if ifconfig wlan0 up; then
	start-stop-daemon -S -q -b -m -p ${pidfile} -x ${wpa_supplicant} -- ${wpa_supplicant_args}
fi
