#!/bin/sh
MODULE="ipw2200"
ENTRY="cfg"
EREG="s#.define \(CFG_.*\) *(1<<\([0-9]*\)).*#\1 \2#p"

unset FILE
for i in /sys/bus/pci/drivers/${MODULE}/*; do
	if [ -e "${i}/${ENTRY}" ]; then
		FILE="${i}/${ENTRY}"
	fi
done
if [ -z "${FILE}" ]; then
	echo "No '${ENTRY}' found in /sys/bus/pci/drivers/${MODULE}."
	return
fi

function bit()
{
	VAL=1
	for ((i = 0; i < $2; i++)); do
		VAL=$((VAL*2))
	done
	SET="$((VAL & $3))"
	if [ "${SET}" = "0" ]; then
		SET=" "
	else
		SET="*"
	fi
	printf "%-20s\t\t0x%08X [%s] %d\n" $1 $VAL "$SET" $i
}

IFS="
"
LEVELS=`sed -ne "${EREG}" ipw2200.h`
VALUE=`cat ${FILE}`

printf "%-20s\t\t%-10s Set Bit\n" "Description" "Hex"
for i in $LEVELS; do
	IFS=" 
"
	bit $i $((${VALUE}))
done

printf "${ENTRY} = ${VALUE} (* = active)\n"
