blob: 8f6b695ae60c8ec6e10343aa70895c9b0b5c3e49 [file] [log] [blame]
#!/bin/sh
#
# This script monitors CONTROL_PATH folder and decides which is the
# led sequence that has to be echoed to the LEDS_FILE.
. /etc/utils.sh
BASE_PATH="/tmp/gpio"
CONTROL_PATH="$BASE_PATH/ledcontrol"
# Output file.
LEDSTATE_FILE="$BASE_PATH/ledstate"
# Indicator files.
SECUREBOOT_FILE="$CONTROL_PATH/secure_boot"
HALT_FILE="$CONTROL_PATH/halted"
KEYBOX_FILE="$CONTROL_PATH/invalid_keybox"
OVERTEMP_FILE="$CONTROL_PATH/overtemperature"
HDPAIRING_FILE="$CONTROL_PATH/hdd_bad_pair"
HDMOUNT_FILE="$CONTROL_PATH/hdd_mount_err"
BADBLOCK_FILE="$CONTROL_PATH/flash_bad_blocks"
TPM_ERROR_FILE="$CONTROL_PATH/tpm_err"
TUNER_FILE="$CONTROL_PATH/tuner_err"
WAITPOWER_FILE="$CONTROL_PATH/waitpower"
LINK_DOWN_FILE="$BASE_PATH/link_down"
IP_FILE="$BASE_PATH/ipconnected"
REGERR_FILE="$CONTROL_PATH/reg_err"
REGPOLL_FILE="$CONTROL_PATH/regpoll"
BOOTED_FILE="$CONTROL_PATH/booted"
TPM_ENROLL_FILE="$CONTROL_PATH/tpm_enroll"
GCD_REG_FILE="$CONTROL_PATH/gcd_registered"
MONLOG_CREDS_FILE="$CONTROL_PATH/monlog_creds"
PARAMS_FILE="$CONTROL_PATH/has_params"
AUTHORIZATION_FILE="$CONTROL_PATH/app_authorized"
CERT_FILE="$CONTROL_PATH/app_cert"
APP_RUNNING_FILE="$CONTROL_PATH/app_running"
TUNER_LOCK_FILE="$CONTROL_PATH/app_tuner_lock"
DATA_STREAM_FILE="$CONTROL_PATH/app_data"
APP_INITIALIZING_FILE="$CONTROL_PATH/app_init"
UPDATE_CHECK_COMPLETE_FILE="$CONTROL_PATH/update_check_complete"
UPDATING_FILE="$CONTROL_PATH/updating"
# Bit sequences.
ALL_LEDS_OFF="0"
HW_FAIL_LED_ON="1" # solid red
SW_FAIL_LED_ON="1" # solid red
NO_INTERNET_LED_ON="1 0" # blink red
LINK_DOWN_LED_ON="x2 3 0" # slow blink purple
NO_IP_LED_ON="3 0 3 0 3 0" # fast blink purple
NO_SATELLITE_LED_ON="3" # solid purple
FASTWAIT_LED_ON="2 0 2 0 2 0" # fast blink blue
WAITING_LED_ON="x2 2 0" # slow blink blue
RUNNING_LED_ON="2" # solid blue
IFNAME="lan0"
change_state() {
# Check if the new state is different from the previous one
if [ ! -e "$LEDSTATE_FILE" ] || [ "$last_ledstate" != "$1" ]; then
leds $2
last_leds="$2"
atomic $LEDSTATE_FILE "$1"
last_ledstate="$1"
echo "state changed to: $last_ledstate $last_leds"
fi
}
does_interface_exist() {
[ -e "/sys/class/net/$1" ]
}
has_ip_address() {
# FIXME TODO(efirst): The line below is commented out until we support IPv6.
# [ -n "$(ip -f inet6 addr show dev $1 scope global)" ] ||
[ -n "$(ip -f inet addr show dev $1 scope global)" ]
}
is_link_up() {
is-interface-up "$IFNAME"
}
watch-dir $CONTROL_PATH |
while read f; do
if is_link_up; then
test ! -e "$LINK_DOWN_FILE" || rm -f "$LINK_DOWN_FILE"
if has_ip_address $IFNAME; then
echo "IP address acquired on $IFNAME" >"$IP_FILE"
else
rm -f "$IP_FILE"
fi
else
echo "Link down" >"$LINK_DOWN_FILE"
rm -f "$IP_FILE"
fi
if [ ! -e /tmp/DEBUG ] && [ ! -f "$SECUREBOOT_FILE" ]; then
change_state UNSECUREBOOT "$HW_FAIL_LED_ON"
elif [ -f "$HALT_FILE" ]; then
change_state HALT "$HW_FAIL_LED_ON"
elif [ -f "$KEYBOX_FILE" -a ! -f /rw/ignore-bad-keybox ]; then
change_state INVALID_KEYBOX "$HW_FAIL_LED_ON"
elif [ -f "$OVERTEMP_FILE" ]; then
change_state OVERTEMP "$HW_FAIL_LED_ON"
elif [ -f "$HDPAIRING_FILE" ]; then
change_state HDPAIR_FAIL "$HW_FAIL_LED_ON"
elif [ -f "$HDMOUNT_FILE" ]; then
change_state HDMOUNT_FAIL "$HW_FAIL_LED_ON"
elif [ -f "$BADBLOCK_FILE" ]; then
change_state BADBLOCK "$HW_FAIL_LED_ON"
elif [ -f "$TPM_ERROR_FILE" ]; then
change_state TPM_ERROR "$HW_FAIL_LED_ON"
elif [ -f "$TUNER_FILE" ]; then
change_state TUNER_FAIL "$HW_FAIL_LED_ON"
elif [ -f "$WAITPOWER_FILE" ]; then
change_state POWEROFF "$ALL_LEDS_OFF"
elif [ -f "$LINK_DOWN_FILE" ]; then
change_state LINKDOWN "$LINK_DOWN_LED_ON"
elif [ ! -f "$IP_FILE" ]; then
change_state NOIP "$NO_IP_LED_ON"
elif [ -f "$REGERR_FILE" ]; then
change_state REG_ERROR "$SW_FAIL_LED_ON"
elif [ -f "$REGPOLL_FILE" ]; then
change_state REG_POLL "$FASTWAIT_LED_ON"
elif [ ! -f "$BOOTED_FILE" ]; then
change_state BOOTING "$WAITING_LED_ON"
elif [ ! -f "$UPDATE_CHECK_COMPLETE_FILE" ]; then
change_state UPDATE_CHECK_FAILED "$NO_INTERNET_LED_ON"
elif [ ! -f "$TPM_ENROLL_FILE" ]; then
change_state TPM_NOTENROLLED "$NO_INTERNET_LED_ON"
elif [ ! -f "$GCD_REG_FILE" ]; then
change_state GCD_UNREGISTERED "$NO_INTERNET_LED_ON"
elif [ ! -f "$MONLOG_CREDS_FILE" ]; then
change_state NO_MONLOG_CREDS "$NO_INTERNET_LED_ON"
elif [ ! -f "$PARAMS_FILE" ]; then
change_state NOPARAMS "$NO_INTERNET_LED_ON"
elif [ ! -f "$AUTHORIZATION_FILE" ]; then
change_state APP_NOTAUTHORIZED "$NO_INTERNET_LED_ON"
elif [ ! -f "$CERT_FILE" ]; then
change_state APP_NOCERT "$NO_INTERNET_LED_ON"
elif [ ! -f "$APP_RUNNING_FILE" ]; then
change_state APP_ERROR "$SW_FAIL_LED_ON"
elif [ ! -f "$TUNER_LOCK_FILE" ]; then
change_state APP_NOTUNERLOCK "$NO_SATELLITE_LED_ON"
elif [ ! -f "$DATA_STREAM_FILE" ]; then
change_state APP_NODATA "$NO_SATELLITE_LED_ON"
elif [ -f "$APP_INITIALIZING_FILE" ]; then
change_state APP_INIT "$WAITING_LED_ON"
elif [ -f "$UPDATING_FILE" ]; then
change_state UPDATING "$WAITING_LED_ON"
else
change_state RUNNING "$RUNNING_LED_ON"
fi
done