#!/bin/sh 
## Load firmware configuration file to the environment variables 
. /etc/default/default.conf
[ -f /etc/config/update.conf ] && . /etc/config/update.conf
[ -f /etc/config/preserve_net.conf ] && . /etc/config/preserve_net.conf
#prepare pem files for xsupplicant
cp -rf /etc/config/8021x_ca.pem /etc/config/client*.pem /var/run

sleep 2
USERNAME_8021X=`echo ${IEEE8021X_LOGIN} | cut -d, -f1`
USERPWD_8021X=`echo ${IEEE8021X_LOGIN} | cut -d, -f2`
## bring up the xsupplicant daemon if IEEE 802.1x is enabled 
if [ "$STATE_8021X" == "1" ]; then 
	## IEEE 802.1x was enabled, build the Xsupplicant.conf first 
	echo -e \
network_list = all\\n\
default_netname = default\\n\
logfile = /var/log/xsupplicant.log\\n\
default\\n\
{\\n\
\\ttype = wired\\n\
\\tallow_types = eap_tls\\n\
\\tidentity = $USERNAME_8021X\\n\
\\teap_tls {\\n\
\\t\\tuser_cert = /var/run/clientCert.pem\\n\
\\t\\tuser_key = /var/run/clientPriv.pem\\n\
\\t\\tuser_key_pass = \"$USERPWD_8021X\"\\n\
\\t\\troot_cert = /var/run/8021x_ca.pem\\n\
\\t\\tchunk_size = 1398\\n\
\\t\\trandom_file = /dev/urandom\\n\
\\t}\\n\
} > /var/run/xsupplicant.conf  

	/usr/sbin/xsupplicant -i eth0 -v $EAP_VER_8021X -c /var/run/xsupplicant.conf -D wired &  
	sleep 5
else
	acti_logger "802.1x disabled."
fi 
exit 0 

