#!/bin/sh
#############################################################
# List smsc devices and configuration info
#############################################################
path="${0%/*}"
. "$path/inc/gwhw.inc"
. "$path/inc/smsc.inc"
. "$path/inc/hwsetup.inc"

# Without root access, we may get incorrect information
needRoot

not_full_conf=false;

ethInfo() {
	# $1: eth name
	if find_smsc "${1}"; then
		: # do nothing
	else
		printf "%-6s %s\n" "${1}" "not found or not smsc"
		return
	fi
	
	# EEPROM checks
	if checkEEPROM_installedW "${1}"; then
		eeprom="installed"
		if checkEEPROM_configured "${1}"; then
			eeprom="${configured_mac}"
		elif ! mac00FF "${configured_mac}"; then
			# linux kernel will extract MAC address, even without "configured bit"
			eeprom="${configured_mac}*"
			not_full_conf=true
		else
			eeprom="not configured"
		fi
	else
		eeprom="not installed"
	fi
	
	# DT checks
	if [ -e "${DEV_PATH}/../../of_node/local-mac-address" ]; then
		dt="$(hexdump -e '6/1 ":%02x"' "${DEV_PATH}/../../of_node/local-mac-address")"
		dt="${dt:1}"
	else
		dt="no support"
	fi &&
	if [ "${dt}" = "00:00:00:00:00:00" ]; then
		dt="not configured"
	fi
	
	printf "%-6s %-20s %-20s %s\n" "${1}" "${eeprom}" "${dt}" "${DEV_PATH}"
}

#############################################################

printf "%-6s %-20s %-20s %s\n" "ETH" "EEPROM" "DT" "PATH"
for i in $(seq 1 $((oc_eth_interfaces-1)) ); do
	ethInfo "eth${i}"
done
if ${not_full_conf}; then
	printf "* configured bit is not set\n"
fi


