# Copyright (C) 2006-2014 OpenWrt.org # Copyright (C) 2006 Fokus Fraunhofer # Copyright (C) 2010 Vertical Communications debug () { ${DEBUG:-:} "$@" } # newline N=" " _C=0 NO_EXPORT=1 LOAD_STATE=1 LIST_SEP=" " # xor multiple hex values of the same length xor() { local val local ret="0x$1" local retlen=${#1} shift while [ -n "$1" ]; do val="0x$1" ret=$((ret ^ val)) shift done printf "%0${retlen}x" "$ret" } data_2bin() { local data=$1 local len=${#1} local bin_data for i in $(seq 0 2 $(($len - 1))); do bin_data="${bin_data}\x${data:i:2}" done echo -ne $bin_data } data_2xor_val() { local data=$1 local len=${#1} local xor_data for i in $(seq 0 4 $(($len - 1))); do xor_data="${xor_data}${data:i:4} " done echo -n ${xor_data:0:-1} } append() { local var="$1" local value="$2" local sep="${3:- }" eval "export ${NO_EXPORT:+-n} -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\"" } prepend() { local var="$1" local value="$2" local sep="${3:- }" eval "export ${NO_EXPORT:+-n} -- \"$var=\$value\${$var:+\${sep}\${$var}}\"" } list_contains() { local var="$1" local str="$2" local val eval "val=\" \${$var} \"" [ "${val%% $str *}" != "$val" ] } config_load() { [ -n "$IPKG_INSTROOT" ] && return 0 uci_load "$@" } reset_cb() { config_cb() { return 0; } option_cb() { return 0; } list_cb() { return 0; } } reset_cb package() { return 0 } config () { local cfgtype="$1" local name="$2" export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS=$((CONFIG_NUM_SECTIONS + 1)) name="${name:-cfg$CONFIG_NUM_SECTIONS}" append CONFIG_SECTIONS "$name" export ${NO_EXPORT:+-n} CONFIG_SECTION="$name" config_set "$CONFIG_SECTION" "TYPE" "${cfgtype}" [ -n "$NO_CALLBACK" ] || config_cb "$cfgtype" "$name" } option () { local varname="$1"; shift local value="$*" config_set "$CONFIG_SECTION" "${varname}" "${value}" [ -n "$NO_CALLBACK" ] || option_cb "$varname" "$*" } list() { local varname="$1"; shift local value="$*" local len config_get len "$CONFIG_SECTION" "${varname}_LENGTH" 0 [ $len = 0 ] && append CONFIG_LIST_STATE "${CONFIG_SECTION}_${varname}" len=$((len + 1)) config_set "$CONFIG_SECTION" "${varname}_ITEM$len" "$value" config_set "$CONFIG_SECTION" "${varname}_LENGTH" "$len" append "CONFIG_${CONFIG_SECTION}_${varname}" "$value" "$LIST_SEP" [ -n "$NO_CALLBACK" ] || list_cb "$varname" "$*" } config_unset() { config_set "$1" "$2" "" } # config_get