+proto_wireless()
+{
+ # Bring interface up
+ bring_if_up
+
+ # Check if a socket exists, meaning wpa_supplicant is running
+ if [ -S /var/run/wpa_supplicant/${DEVICE} ]; then
+ echo "wpa_supplicant already running"
+
+ # Make sure wpa_supplicant is responding
+ if ! wpa_cli -i ${DEVICE} status; then
+ echo "Stopping unresponding wpa_supplicant"
+ killall wpa_supplicant
+ rm /var/run/wpa_supplicant/${DEVICE}
+ fi
+ fi
+
+ # Start wpa_supplicant if it is not running
+ if [ ! -S /var/run/wpa_supplicant/${DEVICE} ]; then
+ echo "Starting wpa_supplicant"
+ wpa_supplicant ${WPA_SUPP_OPTS} -i ${DEVICE}
+ fi
+
+ count=0
+ while ! wpa_cli -i ${DEVICE} status | grep "wpa_state=COMPLETED"; do
+ echo "Waiting for wpa_supplicant to complete"
+ sleep 0.25
+
+ let count=count+1
+ if [ $count -gt 20 ]; then
+ echo "wpa_supplicant failure"
+ exit ${EXIT_CODE_WARNING}
+ fi
+ done
+
+ # Obtain SSID that wpa_supplicant connected to, if applicable
+ SSID=$(wpa_cli -i ${DEVICE} status | egrep "^ssid=" | \
+ sed 's!^ssid=\(.*\)!\1!')
+
+ # Convert spaces to underscores in SSID field
+ SSID=$(echo ${SSID} | sed -e "s!\ !_!g")
+
+ echo "wpa_supplicant connected to network \"${SSID}\""
+
+ if [ -z "${SSID}" ]; then
+ echo "Not connected to any network"
+ exit ${EXIT_CODE_WARNING}
+ fi
+
+ if [ ! -d /etc/sysconfig/network/ssid ]; then
+ echo "Missing \"/etc/sysconfig/network/ssid\" directory"
+ exit ${EXIT_CODE_WARNING}
+ fi
+
+ # Warning:
+ # wpa_supplicant will connect to a given network SSID even if the case is incorrect
+ # (MyNetwork and MYNETWORK will work). But the ssid network file configuration
+ # case must match exactly what was returned by wpa_supplicant
+ if [ ! -f "/etc/sysconfig/network/ssid/${SSID}" ]; then
+ echo "${0}: Missing network configuration file \"/etc/sysconfig/network/ssid/${SSID}\""
+ exit ${EXIT_CODE_FAILURE}