icwmp,obuspa,gateway-info: Fix ShellCheck issues

This commit is contained in:
Suvendhu Hansa 2025-07-29 18:11:53 +05:30 committed by IOPSYS Dev
parent d3d1b444de
commit 41495cf6e5
No known key found for this signature in database
3 changed files with 149 additions and 155 deletions

View file

@ -40,22 +40,22 @@ get_vivsoi() {
#hex-string 2 character=1 Byte #hex-string 2 character=1 Byte
# length in hex string will be twice of actual Byte length # length in hex string will be twice of actual Byte length
[ "$len" -gt "8" ] || return [ "${len}" -gt 8 ] || return
data="${opt125}" data="${opt125}"
rem_len="${len}" rem_len="${len}"
while [ $rem_len -gt 0 ]; do while [ "${rem_len}" -gt 0 ]; do
ent_id=${data:0:8} ent_id=${data:0:8}
ent_id=$(printf "%d\n" "0x$ent_id") ent_id=$(printf "%d\n" "0x$ent_id")
if [ $ent_id -ne 3561 ]; then if [ "${ent_id}" -ne 3561 ]; then
len_val=${data:8:2} len_val=${data:8:2}
data_len=$(printf "%d\n" "0x$len_val") data_len=$(printf "%d\n" "0x$len_val")
# add 4 byte for ent_id and 1 byte for len # add 4 byte for ent_id and 1 byte for len
data_len=$(( data_len * 2 + 10 )) data_len=$(( data_len * 2 + 10 ))
# move ahead data to next enterprise id # move ahead data to next enterprise id
data=${data:"${data_len}":"${rem_len}"} data=${data:"${data_len}":"${rem_len}"}
rem_len=$(( rem_len - $data_len )) rem_len=$(( rem_len - data_len ))
continue continue
fi fi
@ -66,7 +66,7 @@ get_vivsoi() {
data_len=$(( data_len * 2 + 10 )) data_len=$(( data_len * 2 + 10 ))
opt_len=$(printf "%d\n" "0x$len_val") opt_len=$(printf "%d\n" "0x$len_val")
[ $opt_len -eq 0 ] && return [ "${opt_len}" -eq 0 ] && return
# populate the option data of enterprise id # populate the option data of enterprise id
sub_data_len=$(( opt_len * 2)) sub_data_len=$(( opt_len * 2))
@ -74,7 +74,7 @@ get_vivsoi() {
sub_data=${data:10:"${sub_data_len}"} sub_data=${data:10:"${sub_data_len}"}
# parsing of suboption of option 125 # parsing of suboption of option 125
while [ $sub_data_len -gt 0 ]; do while [ "${sub_data_len}" -gt 0 ]; do
# get the suboption id # get the suboption id
sub_opt_id=${sub_data:0:2} sub_opt_id=${sub_data:0:2}
sub_opt_id=$(printf "%d\n" "0x$sub_opt_id") sub_opt_id=$(printf "%d\n" "0x$sub_opt_id")
@ -85,20 +85,20 @@ get_vivsoi() {
sub_opt_len=$(( sub_opt_len * 2 )) sub_opt_len=$(( sub_opt_len * 2 ))
# get the value of sub option starting 4 means starting after length # get the value of sub option starting 4 means starting after length
sub_opt_val=${sub_data:4:${sub_opt_len}} sub_opt_val=${sub_data:4:"${sub_opt_len}"}
# assign the value found in sub option # assign the value found in sub option
case "${sub_opt_id}" in case "${sub_opt_id}" in
"4") "4")
OUI=$(echo -n $sub_opt_val | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '') OUI=$(echo -n "${sub_opt_val}" | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '')
GW_DISCOVERED=1 GW_DISCOVERED=1
;; ;;
"5") "5")
SERIAL=$(echo -n $sub_opt_val | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '') SERIAL=$(echo -n "${sub_opt_val}" | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '')
GW_DISCOVERED=1 GW_DISCOVERED=1
;; ;;
"6") "6")
CLASS=$(echo -n $sub_opt_val | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '') CLASS=$(echo -n "${sub_opt_val}" | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '')
GW_DISCOVERED=1 GW_DISCOVERED=1
;; ;;
esac esac
@ -110,7 +110,7 @@ get_vivsoi() {
sub_data_len=$((sub_data_len - sub_opt_end)) sub_data_len=$((sub_data_len - sub_opt_end))
# fetch next sub option hex string # fetch next sub option hex string
sub_data=${sub_data:${sub_opt_end}:${sub_data_len}} sub_data=${sub_data:"${sub_opt_end}":"${sub_data_len}"}
done done
# move ahead data to next enterprise id # move ahead data to next enterprise id
@ -131,15 +131,13 @@ send_host_query() {
sleep 5 sleep 5
json_load "$(ubus call umdns browse)" json_load "$(ubus call umdns browse)"
json_select discovered_services if ! json_select discovered_services; then
if [ "${?}" -ne 0 ]; then
json_cleanup json_cleanup
loop=$(( loop - 1 )) loop=$(( loop - 1 ))
continue continue
fi fi
json_select _usp-agt-mqtt._tcp if ! json_select _usp-agt-mqtt._tcp; then
if [ "${?}" -ne 0 ]; then
json_cleanup json_cleanup
loop=$(( loop - 1 )) loop=$(( loop - 1 ))
continue continue
@ -156,7 +154,7 @@ send_host_query() {
json_get_keys keys json_get_keys keys
for key in $keys; do for key in $keys; do
json_select $key json_select "${key}"
json_get_var _host host "" json_get_var _host host ""
if [ -z "${_host}" ] || [[ "${sent_host}" =~ " ${_host}" ]]; then if [ -z "${_host}" ] || [[ "${sent_host}" =~ " ${_host}" ]]; then
@ -166,9 +164,10 @@ send_host_query() {
sent_host="${sent_host} ${_host}" sent_host="${sent_host} ${_host}"
cmd="ubus call umdns query '{\"question\":\"$_host\",\"interface\":\"$intf\"}'" cmd="ubus call umdns query '{\"question\":\"$_host\",\"interface\":\"$intf\"}'"
eval $cmd sh -c "${cmd}"
resp=0 resp=0
json_select .. json_select ..
sleep 2 # umdns query sometime takes time to resolve so adding some sleep
done done
json_cleanup json_cleanup
@ -185,32 +184,29 @@ get_usp_agent_id() {
fi fi
json_load "$(ubus call umdns browse)" json_load "$(ubus call umdns browse)"
json_select discovered_services if ! json_select discovered_services; then
if [ "${?}" -ne 0 ]; then
json_cleanup json_cleanup
echo ${ID} echo "${ID}"
return 0 return 0
fi fi
json_select _usp-agt-mqtt._tcp if ! json_select _usp-agt-mqtt._tcp; then
if [ "${?}" -ne 0 ]; then
json_cleanup json_cleanup
echo ${ID} echo "${ID}"
return 0 return 0
fi fi
json_get_keys keys json_get_keys keys
for key in $keys; do for key in $keys; do
json_select $key json_select "${key}"
json_select $family if ! json_select "${family}"; then
if [ "${?}" -ne 0 ]; then
json_select .. json_select ..
continue continue
fi fi
json_get_keys ips json_get_keys ips
for ip in $ips; do for ip in $ips; do
json_get_var ip_val $ip json_get_var ip_val "${ip}"
if [ "${ip_val}" != "${dhcp_ip}" ]; then if [ "${ip_val}" != "${dhcp_ip}" ]; then
continue continue
fi fi
@ -219,8 +215,8 @@ get_usp_agent_id() {
json_select txt json_select txt
json_get_keys txts json_get_keys txts
for _txt in $txts; do for _txt in $txts; do
json_get_var text_val $_txt json_get_var text_val "${_txt}"
if [[ "${text_val:0:3}" == "ID=" ]]; then if [[ "${text_val:0:3}" = "ID=" ]]; then
ID="${text_val:3}" ID="${text_val:3}"
break break
fi fi
@ -238,16 +234,16 @@ get_usp_agent_id() {
done done
json_cleanup json_cleanup
echo ${ID} echo "${ID}"
} }
get_mac_address() { get_mac_address() {
ip="${1}" ip="${1}"
device="${2}" device="${2}"
mac="$(cat /proc/net/arp | grep $ip | awk '{print $4}')" mac=$(grep "${ip}" /proc/net/arp | awk '{print $4}')
if [ -z "${mac}" ]; then if [ -z "${mac}" ]; then
arp_resp="$(arping -b -f -c 5 -I $device $ip | grep 'Unicast reply from' | awk '{print $5}')" arp_resp=$(arping -b -f -c 5 -I "${device}" "${ip}" | grep 'Unicast reply from' | awk '{print $5}')
if [ -n "${arp_resp}" ]; then if [ -n "${arp_resp}" ]; then
mac=${arp_resp:1:-1} mac=${arp_resp:1:-1}
fi fi
@ -260,7 +256,7 @@ send_unknown_gw_event() {
mac="${1}" mac="${1}"
cmd="ubus -t 5 send gateway-info.gateway.unknown '{\"hwaddr\":\"$mac\"}'" cmd="ubus -t 5 send gateway-info.gateway.unknown '{\"hwaddr\":\"$mac\"}'"
eval $cmd sh -c "${cmd}"
} }
send_cwmp_gw_event() { send_cwmp_gw_event() {
@ -269,14 +265,14 @@ send_cwmp_gw_event() {
serial="${3}" serial="${3}"
cmd="ubus -t 5 send gateway-info.gateway.cwmp '{\"oui\":\"$oui\",\"class\":\"$class\",\"serial\":\"$serial\"}'" cmd="ubus -t 5 send gateway-info.gateway.cwmp '{\"oui\":\"$oui\",\"class\":\"$class\",\"serial\":\"$serial\"}'"
eval $cmd sh -c "${cmd}"
} }
send_usp_gw_event() { send_usp_gw_event() {
endpoint="${1}" endpoint="${1}"
cmd="ubus -t 5 send gateway-info.gateway.usp '{\"endpoint\":\"$endpoint\"}'" cmd="ubus -t 5 send gateway-info.gateway.usp '{\"endpoint\":\"$endpoint\"}'"
eval $cmd sh -c "${cmd}"
} }
config_load gateway config_load gateway
@ -287,13 +283,13 @@ if [ "${enable}" -eq 0 ]; then
return 0 return 0
fi fi
if [ "${wan_intf}" == "${INTERFACE}" ]; then if [ "${wan_intf}" = "${INTERFACE}" ]; then
if [ "${1}" == "deconfig" ]; then if [ "${1}" = "deconfig" ]; then
rm -rf /var/state/gwinfo rm -rf /var/state/gwinfo
return 0 return 0
fi fi
json_load "$(ifstatus ${INTERFACE})" json_load "$(ifstatus "${INTERFACE}")"
json_get_var dev_name device "" json_get_var dev_name device ""
json_select data json_select data
json_get_var dhcp_ip dhcpserver "" json_get_var dhcp_ip dhcpserver ""
@ -303,7 +299,7 @@ if [ "${wan_intf}" == "${INTERFACE}" ]; then
return 0 return 0
fi fi
MAC="$(get_mac_address $dhcp_ip $dev_name)" MAC=$(get_mac_address "${dhcp_ip}" "${dev_name}")
mkdir -p /var/state mkdir -p /var/state
touch /var/state/gwinfo touch /var/state/gwinfo
@ -326,8 +322,8 @@ if [ "${wan_intf}" == "${INTERFACE}" ]; then
return 0 return 0
fi fi
len=$(printf "$opt125"|wc -c) len=$(echo -n "${opt125}" | wc -c)
get_vivsoi "$opt125" "$len" get_vivsoi "${opt125}" "${len}"
if [ "${GW_DISCOVERED}" -eq 0 ]; then if [ "${GW_DISCOVERED}" -eq 0 ]; then
send_unknown_gw_event "${MAC}" send_unknown_gw_event "${MAC}"
@ -341,19 +337,18 @@ if [ "${wan_intf}" == "${INTERFACE}" ]; then
uci -q -c /var/state commit gwinfo uci -q -c /var/state commit gwinfo
# Check for USP parameters # Check for USP parameters
ubus -t 15 wait_for umdns if ! ubus -t 15 wait_for umdns; then
if [ "${?}" -ne 0 ]; then
send_cwmp_gw_event "${OUI}" "${CLASS}" "${SERIAL}" send_cwmp_gw_event "${OUI}" "${CLASS}" "${SERIAL}"
return 0 return 0
fi fi
resp=$(send_host_query $dev_name) resp=$(send_host_query "${dev_name}")
if [ "${resp}" -ne 0 ]; then if [ "${resp}" -ne 0 ]; then
send_cwmp_gw_event "${OUI}" "${CLASS}" "${SERIAL}" send_cwmp_gw_event "${OUI}" "${CLASS}" "${SERIAL}"
return 0 return 0
fi fi
ID="$(get_usp_agent_id $dhcp_ip)" ID=$(get_usp_agent_id "${dhcp_ip}")
if [ -z "${ID}" ]; then if [ -z "${ID}" ]; then
send_cwmp_gw_event "${OUI}" "${CLASS}" "${SERIAL}" send_cwmp_gw_event "${OUI}" "${CLASS}" "${SERIAL}"
return 0 return 0

View file

@ -16,12 +16,12 @@ get_opt43() {
local opt43="$1" local opt43="$1"
local len="$2" local len="$2"
[ "$len" -gt "2" ] || return [ "${len}" -gt 2 ] || return
first_byte=${opt43:0:2} first_byte=${opt43:0:2}
first_byte=$(printf "%d\n" "0x$first_byte") first_byte=$(printf "%d\n" "0x$first_byte")
if [ $len -ge 4 ] && [ $first_byte -ge 1 ] && [ $first_byte -le 4 ]; then if [ "${len}" -ge 4 ] && [ "${first_byte}" -ge 1 ] && [ "${first_byte}" -le 4 ]; then
# it is in encapsulated form # it is in encapsulated form
# opt43 encapsulated vendor-specific option has data in below format # opt43 encapsulated vendor-specific option has data in below format
# Code Len Data item Code Len Data item Code # Code Len Data item Code Len Data item Code
@ -35,7 +35,7 @@ get_opt43() {
data="${opt43}" data="${opt43}"
rem_len="${len}" rem_len="${len}"
# parsing of suboption of option 43 # parsing of suboption of option 43
while [ $rem_len -gt 0 ]; do while [ "${rem_len}" -gt 0 ]; do
# get the suboption id # get the suboption id
sub_opt_id=${data:0:2} sub_opt_id=${data:0:2}
sub_opt_id=$(printf "%d\n" "0x$sub_opt_id") sub_opt_id=$(printf "%d\n" "0x$sub_opt_id")
@ -50,13 +50,13 @@ get_opt43() {
# assign the value found in sub option # assign the value found in sub option
case "${sub_opt_id}" in case "${sub_opt_id}" in
"1") DHCP_ACS_URL=$(echo -n $sub_opt_val | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '') "1") DHCP_ACS_URL=$(echo -n "${sub_opt_val}" | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '')
;; ;;
"2") DHCP_PROV_CODE=$(echo -n $sub_opt_val | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '') "2") DHCP_PROV_CODE=$(echo -n "${sub_opt_val}" | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '')
;; ;;
"3") MIN_WAIT_INVL=$(echo -n $sub_opt_val | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '') "3") MIN_WAIT_INVL=$(echo -n "${sub_opt_val}" | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '')
;; ;;
"4") INVL_MULTIPLIER=$(echo -n $sub_opt_val | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '') "4") INVL_MULTIPLIER=$(echo -n "${sub_opt_val}" | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '')
;; ;;
esac esac
@ -70,7 +70,7 @@ get_opt43() {
rem_len=$((rem_len - sub_opt_end)) rem_len=$((rem_len - sub_opt_end))
done done
else else
DHCP_ACS_URL=$(echo -n $opt43 | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '') DHCP_ACS_URL=$(echo -n "${opt43}" | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '')
fi fi
} }
@ -92,9 +92,9 @@ if [ "$discovery_enable" = "0" ]; then
return 0 return 0
fi fi
if [ "${wan_intf}" == "${INTERFACE}" ]; then if [ "${wan_intf}" = "${INTERFACE}" ]; then
if [ -n "$opt43" ]; then if [ -n "$opt43" ]; then
len=$(printf "$opt43"|wc -c) len=$(echo -n "$opt43"|wc -c)
get_opt43 "$opt43" "$len" get_opt43 "$opt43" "$len"
fi fi

View file

@ -57,18 +57,18 @@ get_vivsoi() {
data="${opt125}" data="${opt125}"
rem_len="${len}" rem_len="${len}"
while [ $rem_len -gt 0 ]; do while [ "${rem_len}" -gt 0 ]; do
ent_id=${data:0:8} ent_id=${data:0:8}
ent_id=$(printf "%d\n" "0x$ent_id") ent_id=$(printf "%d\n" "0x$ent_id")
if [ $ent_id -ne 3561 ]; then if [ "${ent_id}" -ne 3561 ]; then
len_val=${data:8:2} len_val=${data:8:2}
data_len=$(printf "%d\n" "0x$len_val") data_len=$(printf "%d\n" "0x$len_val")
# add 4 byte for ent_id and 1 byte for len # add 4 byte for ent_id and 1 byte for len
data_len=$(( data_len * 2 + 10 )) data_len=$(( data_len * 2 + 10 ))
# move ahead data to next enterprise id # move ahead data to next enterprise id
data=${data:"${data_len}":"${rem_len}"} data=${data:"${data_len}":"${rem_len}"}
rem_len=$(( rem_len - $data_len )) rem_len=$(( rem_len - data_len ))
continue continue
fi fi
@ -79,7 +79,7 @@ get_vivsoi() {
data_len=$(( data_len * 2 + 10 )) data_len=$(( data_len * 2 + 10 ))
opt_len=$(printf "%d\n" "0x$len_val") opt_len=$(printf "%d\n" "0x$len_val")
[ $opt_len -eq 0 ] && return [ "${opt_len}" -eq 0 ] && return
# populate the option data of enterprise id # populate the option data of enterprise id
sub_data_len=$(( opt_len * 2)) sub_data_len=$(( opt_len * 2))
@ -98,28 +98,28 @@ get_vivsoi() {
sub_opt_len=$(( sub_opt_len * 2 )) sub_opt_len=$(( sub_opt_len * 2 ))
# get the value of sub option starting 4 means starting after length # get the value of sub option starting 4 means starting after length
sub_opt_val=${sub_data:4:${sub_opt_len}} sub_opt_val=${sub_data:4:"${sub_opt_len}"}
# assign the value found in sub option # assign the value found in sub option
case "${sub_opt_id}" in case "${sub_opt_id}" in
"25") "25")
URL=$(echo -n $sub_opt_val | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '') URL=$(echo -n "${sub_opt_val}" | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '')
CONTROLLER_DISCOVERED=1 CONTROLLER_DISCOVERED=1
;; ;;
"26") "26")
PROV_CODE=$(echo -n $sub_opt_val | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '') PROV_CODE=$(echo -n "${sub_opt_val}" | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '')
CONTROLLER_DISCOVERED=1 CONTROLLER_DISCOVERED=1
;; ;;
"27") "27")
RETRY_MIN_INTERVAL=$(echo -n $sub_opt_val | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '') RETRY_MIN_INTERVAL=$(echo -n "${sub_opt_val}" | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '')
CONTROLLER_DISCOVERED=1 CONTROLLER_DISCOVERED=1
;; ;;
"28") "28")
RETRY_INTERVAL_MUL=$(echo -n $sub_opt_val | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '') RETRY_INTERVAL_MUL=$(echo -n "${sub_opt_val}" | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '')
CONTROLLER_DISCOVERED=1 CONTROLLER_DISCOVERED=1
;; ;;
"29") "29")
ENDPOINT_ID=$(echo -n $sub_opt_val | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '') ENDPOINT_ID=$(echo -n "${sub_opt_val}" | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '')
CONTROLLER_DISCOVERED=1 CONTROLLER_DISCOVERED=1
;; ;;
esac esac
@ -131,7 +131,7 @@ get_vivsoi() {
sub_data_len=$((sub_data_len - sub_opt_end)) sub_data_len=$((sub_data_len - sub_opt_end))
# fetch next sub option hex string # fetch next sub option hex string
sub_data=${sub_data:${sub_opt_end}:${sub_data_len}} sub_data=${sub_data:"${sub_opt_end}":"${sub_data_len}"}
done done
# move ahead data to next enterprise id # move ahead data to next enterprise id
@ -146,7 +146,7 @@ get_access_role()
lan_proto="$(uci -q get network.lan.proto)" lan_proto="$(uci -q get network.lan.proto)"
if [ "${lan_proto}" == "dhcp" ]; then if [ "${lan_proto}" = "dhcp" ]; then
mode="extender" mode="extender"
else else
mode="full_access" mode="full_access"
@ -169,12 +169,11 @@ get_agent_topic()
echo "${agent_topic}" echo "${agent_topic}"
} }
config_load obuspa config_load obuspaconfig_get_bool enable_obuspa global enabled 1
config_get_bool enable_obuspa global enabled 1
config_get wan_intf global interface config_get wan_intf global interface
config_get_bool dhcp_discovery global dhcp_discovery 1 config_get_bool dhcp_discovery global dhcp_discovery 1
if [ "$enable_obuspa" = "0" ] || [ "$dhcp_discovery" = "0" ]; then if [ "${enable_obuspa}" -eq 0 ] || [ "${dhcp_discovery}" -eq 0 ]; then
return 0 return 0
fi fi
@ -190,9 +189,9 @@ if [ -z "${wan_intf}" ]; then
fi fi
fi fi
if [ "${wan_intf}" == "${INTERFACE}" ]; then if [ "${wan_intf}" = "${INTERFACE}" ]; then
if [ -n "$opt125" ]; then if [ -n "$opt125" ]; then
len=$(printf "$opt125"|wc -c) len=$(echo -n "${opt125}"|wc -c)
get_vivsoi "$opt125" "$len" get_vivsoi "$opt125" "$len"
fi fi
@ -228,10 +227,10 @@ if [ "${wan_intf}" == "${INTERFACE}" ]; then
;; ;;
*) *)
# This is an FQDN, perform DNS query # This is an FQDN, perform DNS query
nslookup $URL > /tmp/fqdn_ip nslookup "${URL}" > /tmp/fqdn_ip
nslookup -type=ptr $URL > /tmp/fqdn_ptr nslookup -type=ptr "${URL}" > /tmp/fqdn_ptr
nslookup -type=srv $URL > /tmp/fqdn_srv nslookup -type=srv "${URL}" > /tmp/fqdn_srv
nslookup -type=txt $URL > /tmp/fqdn_srv nslookup -type=txt "${URL}" > /tmp/fqdn_srv
# TODO extend to collect information from dns-sd records # TODO extend to collect information from dns-sd records
;; ;;
@ -247,16 +246,16 @@ if [ "${wan_intf}" == "${INTERFACE}" ]; then
fi fi
fi fi
if [ "${proto}" == "mqtt" ] || [ "${proto}" == "mqtts" ]; then if [ "${proto}" = "mqtt" ] || [ "${proto}" = "mqtts" ]; then
offered_proto="MQTT" offered_proto="MQTT"
if [ "${proto}" == "mqtt" ]; then if [ "${proto}" = "mqtt" ]; then
mtp_encrypt="TCP/IP" mtp_encrypt="TCP/IP"
else else
mtp_encrypt="TLS" mtp_encrypt="TLS"
fi fi
elif [ "${proto}" == "ws" ] || [ "${proto}" == "wss" ]; then elif [ "${proto}" = "ws" ] || [ "${proto}" = "wss" ]; then
offered_proto="WebSocket" offered_proto="WebSocket"
if [ "${proto}" == "wss" ]; then if [ "${proto}" = "wss" ]; then
mtp_encrypt="1" mtp_encrypt="1"
else else
mtp_encrypt="0" mtp_encrypt="0"
@ -265,7 +264,7 @@ if [ "${wan_intf}" == "${INTERFACE}" ]; then
controllers=$(uci -q show obuspa | grep "=controller" | cut -d'=' -f1 | cut -d'.' -f2) controllers=$(uci -q show obuspa | grep "=controller" | cut -d'=' -f1 | cut -d'.' -f2)
for controller in $controllers; do for controller in $controllers; do
dhcp_disc=$(uci -q get obuspa.$controller.dhcp_discovered) dhcp_disc=$(uci -q get obuspa."${controller}".dhcp_discovered)
if [ "${dhcp_disc}" -eq 1 ]; then if [ "${dhcp_disc}" -eq 1 ]; then
dhcp_controller="${controller}" dhcp_controller="${controller}"
break break
@ -273,27 +272,27 @@ if [ "${wan_intf}" == "${INTERFACE}" ]; then
done done
if [ -n "${dhcp_controller}" ]; then if [ -n "${dhcp_controller}" ]; then
cont_proto="$(uci -q get obuspa.$dhcp_controller.Protocol)" cont_proto=$(uci -q get obuspa."${dhcp_controller}".Protocol)
if [ "${cont_proto}" == "MQTT" ]; then if [ "${cont_proto}" = "MQTT" ]; then
dhcp_mqtt="$(uci -q get obuspa.$dhcp_controller.mqtt)" dhcp_mqtt=$(uci -q get obuspa."${dhcp_controller}".mqtt)
mtps=$(uci -q show obuspa | grep "=mtp" | cut -d'=' -f1 | cut -d'.' -f2) mtps=$(uci -q show obuspa | grep "=mtp" | cut -d'=' -f1 | cut -d'.' -f2)
for mtp in $mtps; do for mtp in $mtps; do
mtp_mqtt="$(uci -q get obuspa.$mtp.mqtt)" mtp_mqtt=$(uci -q get obuspa."${mtp}".mqtt)
if [ "${mtp_mqtt}" == "${dhcp_mqtt}" ]; then if [ "${mtp_mqtt}" = "${dhcp_mqtt}" ]; then
dhcp_mtp="${mtp}" dhcp_mtp="${mtp}"
break break
fi fi
done done
elif [ "${cont_proto}" == "WebSocket" ]; then elif [ "${cont_proto}" = "WebSocket" ]; then
cont_port="$(uci -q get obuspa.$dhcp_controller.Port)" cont_port=$(uci -q get obuspa."${dhcp_controller}".Port)
cont_encr="$(uci -q get obuspa.$dhcp_controller.EnableEncryption)" cont_encr=$(uci -q get obuspa."${dhcp_controller}".EnableEncryption)
mtps=$(uci -q show obuspa | grep "=mtp" | cut -d'=' -f1 | cut -d'.' -f2) mtps=$(uci -q show obuspa | grep "=mtp" | cut -d'=' -f1 | cut -d'.' -f2)
for mtp in $mtps; do for mtp in $mtps; do
mtp_port="$(uci -q get obuspa.$mtp.Port)" mtp_port=$(uci -q get obuspa."${mtp}".Port)
mtp_encr="$(uci -q get obuspa.$mtp.EnableEncryption)" mtp_encr=$(uci -q get obuspa."${mtp}".EnableEncryption)
if [ "${mtp_port}" == "${cont_port}" ] && [ "${mtp_encr}" == "${cont_encr}" ]; then if [ "${mtp_port}" = "${cont_port}" ] && [ "${mtp_encr}" = "${cont_encr}" ]; then
dhcp_mtp="${mtp}" dhcp_mtp="${mtp}"
break break
fi fi
@ -306,43 +305,43 @@ if [ "${wan_intf}" == "${INTERFACE}" ]; then
if [ -n "${dhcp_controller}" ]; then if [ -n "${dhcp_controller}" ]; then
## Handling of controller section ## Handling of controller section
ct_endpoint=$(uci -q get obuspa.$dhcp_controller.EndpointID) ct_endpoint=$(uci -q get obuspa."${dhcp_controller}".EndpointID)
ct_proto=$(uci -q get obuspa.$dhcp_controller.Protocol) ct_proto=$(uci -q get obuspa."${dhcp_controller}".Protocol)
ct_prov=$(uci -q get obuspa.$dhcp_controller.ProvisioningCode) ct_prov=$(uci -q get obuspa."${dhcp_controller}".ProvisioningCode)
if [ "${ct_proto}" = "MQTT" ]; then if [ "${ct_proto}" = "MQTT" ]; then
ct_topic=$(uci -q get obuspa.$dhcp_controller.Topic) ct_topic=$(uci -q get obuspa."${dhcp_controller}".Topic)
else else
ct_topic=$(uci -q get obuspa.$dhcp_controller.Path) ct_topic=$(uci -q get obuspa."${dhcp_controller}".Path)
fi fi
if [ -n "${ENDPOINT_ID}" ] && [ "${ct_endpoint}" != "${ENDPOINT_ID}" ]; then if [ -n "${ENDPOINT_ID}" ] && [ "${ct_endpoint}" != "${ENDPOINT_ID}" ]; then
uci -q set obuspa.$dhcp_controller.EndpointID="${ENDPOINT_ID}" uci -q set obuspa."${dhcp_controller}".EndpointID="${ENDPOINT_ID}"
uci_change=1 uci_change=1
fi fi
if [ -n "${offered_proto}" ] && [ "${ct_proto}" != "${offered_proto}" ]; then if [ -n "${offered_proto}" ] && [ "${ct_proto}" != "${offered_proto}" ]; then
uci -q set obuspa.$dhcp_controller.Protocol="${offered_proto}" uci -q set obuspa."${dhcp_controller}".Protocol="${offered_proto}"
if [ "${offered_proto}" != "MQTT" ]; then if [ "${offered_proto}" != "MQTT" ]; then
uci -q set obuspa.$dhcp_controller.mqtt="" uci -q delete obuspa."${dhcp_controller}".mqtt
uci -q set obuspa.$dhcp_controller.Topic="" uci -q delete obuspa."${dhcp_controller}".Topic
uci -q set obuspa.$dhcp_controller.Host="${ip}" uci -q set obuspa."${dhcp_controller}".Host="${ip}"
uci -q set obuspa.$dhcp_controller.Port="${port}" uci -q set obuspa."${dhcp_controller}".Port="${port}"
uci -q set obuspa.$dhcp_controller.Path="${ct_topic}" uci -q set obuspa."${dhcp_controller}".Path="${ct_topic}"
uci -q set obuspa.$dhcp_controller.EnableEncryption="${mtp_encrypt}" uci -q set obuspa."${dhcp_controller}".EnableEncryption="${mtp_encrypt}"
else else
uci -q set obuspa.$dhcp_controller.EnableEncryption="" uci -q delete obuspa."${dhcp_controller}".EnableEncryption
uci -q set obuspa.$dhcp_controller.Path="" uci -q delete obuspa."${dhcp_controller}".Path
uci -q set obuspa.$dhcp_controller.Host="" uci -q delete obuspa."${dhcp_controller}".Host
uci -q set obuspa.$dhcp_controller.Port="" uci -q delete obuspa."${dhcp_controller}".Port
if [ -z "${dhcp_mqtt}" ]; then if [ -z "${dhcp_mqtt}" ]; then
uci -q set obuspa.$dhcp_controller.mqtt='dhcpmqtt' uci -q set obuspa."${dhcp_controller}".mqtt='dhcpmqtt'
else else
uci -q set obuspa.$dhcp_controller.mqtt="${dhcp_mqtt}" uci -q set obuspa."${dhcp_controller}".mqtt="${dhcp_mqtt}"
fi fi
uci -q set obuspa.$dhcp_controller.Topic="${ct_topic}" uci -q set obuspa."${dhcp_controller}".Topic="${ct_topic}"
fi fi
proto_changed=1 proto_changed=1
@ -355,38 +354,38 @@ if [ "${wan_intf}" == "${INTERFACE}" ]; then
protocol="${offered_proto}" protocol="${offered_proto}"
fi fi
if [ "${protocol}" == "MQTT" ]; then if [ "${protocol}" = "MQTT" ]; then
uci -q set obuspa.$dhcp_controller.Topic="${topic}" uci -q set obuspa."${dhcp_controller}".Topic="${topic}"
else else
uci -q set obuspa.$dhcp_controller.Path="${topic}" uci -q set obuspa."${dhcp_controller}".Path="${topic}"
fi fi
uci_change=1 uci_change=1
fi fi
if [ -n "${PROV_CODE}" ] && [ "${ct_prov}" != "${PROV_CODE}" ]; then if [ -n "${PROV_CODE}" ] && [ "${ct_prov}" != "${PROV_CODE}" ]; then
uci -q set obuspa.$dhcp_controller.ProvisioningCode="${PROV_CODE}" uci -q set obuspa."${dhcp_controller}".ProvisioningCode="${PROV_CODE}"
uci_change=1 uci_change=1
fi fi
if [ "${proto_changed}" -eq 1 ]; then if [ "${proto_changed}" -eq 1 ]; then
if [ "${offered_proto}" == "WebSocket" ]; then if [ "${offered_proto}" = "WebSocket" ]; then
if [ -n "${dhcp_mqtt}" ]; then if [ -n "${dhcp_mqtt}" ]; then
uci -q del obuspa.$dhcp_mqtt uci -q delete obuspa."${dhcp_mqtt}"
fi fi
if [ -z "${dhcp_mtp}" ]; then if [ -z "${dhcp_mtp}" ]; then
sec=$(uci -q add obuspa mtp) sec=$(uci -q add obuspa mtp)
uci -q rename obuspa."${sec}"='dhcpmtp' uci -q rename obuspa."${sec}"='dhcpmtp'
dhcp_mtp="dhcpmtp" dhcp_mtp="dhcpmtp"
uci -q set obuspa.$dhcp_mtp.Enable='1' uci -q set obuspa."${dhcp_mtp}".Enable='1'
fi fi
uci -q set obuspa.$dhcp_mtp.mqtt='' uci -q set obuspa."${dhcp_mtp}".mqtt=''
uci -q set obuspa.$dhcp_mtp.ResponseTopicConfigured='' uci -q set obuspa."${dhcp_mtp}".ResponseTopicConfigured=''
uci -q set obuspa.$dhcp_mtp.Protocol='WebSocket' uci -q set obuspa."${dhcp_mtp}".Protocol='WebSocket'
uci -q set obuspa.$dhcp_mtp.Port="${port}" uci -q set obuspa."${dhcp_mtp}".Port="${port}"
uci -q set obuspa.$dhcp_mtp.EnableEncryption="${mtp_encrypt}" uci -q set obuspa."${dhcp_mtp}".EnableEncryption="${mtp_encrypt}"
uci_change=1 uci_change=1
else else
@ -397,78 +396,78 @@ if [ "${wan_intf}" == "${INTERFACE}" ]; then
sec=$(uci -q add obuspa mqtt) sec=$(uci -q add obuspa mqtt)
uci -q rename obuspa."${sec}"='dhcpmqtt' uci -q rename obuspa."${sec}"='dhcpmqtt'
dhcp_mqtt="dhcpmqtt" dhcp_mqtt="dhcpmqtt"
uci -q set obuspa.$dhcp_mqtt.Enable='1' uci -q set obuspa."${dhcp_mqtt}".Enable='1'
uci -q set obuspa.$dhcp_mqtt.Username="${user}" uci -q set obuspa."${dhcp_mqtt}".Username="${user}"
uci -q set obuspa.$dhcp_mqtt.Password="${pass}" uci -q set obuspa."${dhcp_mqtt}".Password="${pass}"
fi fi
uci -q set obuspa.$dhcp_mqtt.BrokerAddress="${ip}" uci -q set obuspa."${dhcp_mqtt}".BrokerAddress="${ip}"
uci -q set obuspa.$dhcp_mqtt.BrokerPort="${port}" uci -q set obuspa."${dhcp_mqtt}".BrokerPort="${port}"
uci -q set obuspa.$dhcp_mqtt.TransportProtocol="${mtp_encrypt}" uci -q set obuspa."${dhcp_mqtt}".TransportProtocol="${mtp_encrypt}"
uci -q set obuspa.$dhcp_mqtt.ProtocolVersion='5.0' uci -q set obuspa."${dhcp_mqtt}".ProtocolVersion='5.0'
if [ -z "${dhcp_mtp}" ]; then if [ -z "${dhcp_mtp}" ]; then
sec=$(uci -q add obuspa mtp) sec=$(uci -q add obuspa mtp)
uci -q rename obuspa."${sec}"='dhcpmtp' uci -q rename obuspa."${sec}"='dhcpmtp'
dhcp_mtp="dhcpmtp" dhcp_mtp="dhcpmtp"
uci -q set obuspa.$dhcp_mtp.Enable='1' uci -q set obuspa."${dhcp_mtp}".Enable='1'
fi fi
agent_topic=$(get_agent_topic) agent_topic=$(get_agent_topic)
uci -q set obuspa.$dhcp_mtp.Port="" uci -q delete obuspa."${dhcp_mtp}".Port
uci -q set obuspa.$dhcp_mtp.EnableEncryption="" uci -q delete obuspa."${dhcp_mtp}".EnableEncryption
uci -q set obuspa.$dhcp_mtp.Protocol='MQTT' uci -q set obuspa."${dhcp_mtp}".Protocol='MQTT'
uci -q set obuspa.$dhcp_mtp.ResponseTopicConfigured="${agent_topic}" uci -q set obuspa."${dhcp_mtp}".ResponseTopicConfigured="${agent_topic}"
uci -q set obuspa.$dhcp_mtp.mqtt="${dhcp_mqtt}" uci -q set obuspa."${dhcp_mtp}".mqtt="${dhcp_mqtt}"
uci_change=1 uci_change=1
fi fi
else else
if [ "${ct_proto}" == "WebSocket" ]; then if [ "${ct_proto}" = "WebSocket" ]; then
conf_ip="$(uci -q get obuspa.$dhcp_controller.Host)" conf_ip="$(uci -q get obuspa."${dhcp_controller}".Host)"
conf_port="$(uci -q get obuspa.$dhcp_mtp.Port)" conf_port="$(uci -q get obuspa."${dhcp_mtp}".Port)"
conf_encr="$(uci -q get obuspa.$dhcp_mtp.EnableEncryption)" conf_encr="$(uci -q get obuspa."${dhcp_mtp}".EnableEncryption)"
if [ -n "${ip}" ] && [ "${conf_ip}" != "${ip}" ]; then if [ -n "${ip}" ] && [ "${conf_ip}" != "${ip}" ]; then
uci -q set obuspa.$dhcp_controller.Host="${ip}" uci -q set obuspa."${dhcp_controller}".Host="${ip}"
uci_change=1 uci_change=1
fi fi
if [ -n "${port}" ] && [ "${conf_port}" != "${port}" ]; then if [ -n "${port}" ] && [ "${conf_port}" != "${port}" ]; then
uci -q set obuspa.$dhcp_mtp.Port="${port}" uci -q set obuspa."${dhcp_mtp}".Port="${port}"
uci -q set obuspa.$dhcp_controller.Port="${port}" uci -q set obuspa."${dhcp_controller}".Port="${port}"
uci_change=1 uci_change=1
fi fi
if [ -n "${mtp_encrypt}" ] && [ "${conf_encr}" != "${mtp_encrypt}" ]; then if [ -n "${mtp_encrypt}" ] && [ "${conf_encr}" != "${mtp_encrypt}" ]; then
uci -q set obuspa.$dhcp_mtp.EnableEncryption="${mtp_encrypt}" uci -q set obuspa."${dhcp_mtp}".EnableEncryption="${mtp_encrypt}"
uci -q set obuspa.$dhcp_controller.EnableEncryption="${mtp_encrypt}" uci -q set obuspa."${dhcp_controller}".EnableEncryption="${mtp_encrypt}"
uci_change=1 uci_change=1
fi fi
else else
conf_ip="$(uci -q get obuspa.$dhcp_mqtt.BrokerAddress)" conf_ip=$(uci -q get obuspa."${dhcp_mqtt}".BrokerAddress)
conf_port="$(uci -q get obuspa.$dhcp_mqtt.BrokerPort)" conf_port=$(uci -q get obuspa."${dhcp_mqtt}".BrokerPort)
conf_encr="$(uci -q get obuspa.$dhcp_mqtt.TransportProtocol)" conf_encr=$(uci -q get obuspa."${dhcp_mqtt}".TransportProtocol)
if [ -n "${port}" ] && [ "${conf_port}" != "${port}" ]; then if [ -n "${port}" ] && [ "${conf_port}" != "${port}" ]; then
uci -q set obuspa.$dhcp_mqtt.BrokerPort="${port}" uci -q set obuspa."${dhcp_mqtt}".BrokerPort="${port}"
uci_change=1 uci_change=1
fi fi
if [ -n "${mtp_encrypt}" ] && [ "${conf_encr}" != "${mtp_encrypt}" ]; then if [ -n "${mtp_encrypt}" ] && [ "${conf_encr}" != "${mtp_encrypt}" ]; then
uci -q set obuspa.$dhcp_mqtt.TransportProtocol="${mtp_encrypt}" uci -q set obuspa."${dhcp_mqtt}".TransportProtocol="${mtp_encrypt}"
uci_change=1 uci_change=1
fi fi
if [ -n "${ip}" ] && [ "${conf_ip}" != "${ip}" ]; then if [ -n "${ip}" ] && [ "${conf_ip}" != "${ip}" ]; then
uci -q set obuspa.$dhcp_mqtt.BrokerAddress="${ip}" uci -q set obuspa."${dhcp_mqtt}".BrokerAddress="${ip}"
uci_change=1 uci_change=1
fi fi
fi fi
fi fi
else else
uci -q del obuspa.dhcpmtp uci -q delete obuspa.dhcpmtp
uci -q del obuspa.dhcpmqtt uci -q delete obuspa.dhcpmqtt
sec=$(uci -q add obuspa controller) sec=$(uci -q add obuspa controller)
uci -q rename obuspa."${sec}"='dhcpcontroller' uci -q rename obuspa."${sec}"='dhcpcontroller'
@ -480,7 +479,7 @@ if [ "${wan_intf}" == "${INTERFACE}" ]; then
uci -q set obuspa.dhcpcontroller.Enable='1' uci -q set obuspa.dhcpcontroller.Enable='1'
if [ -n "${offered_proto}" ]; then if [ -n "${offered_proto}" ]; then
if [ "${offered_proto}" == "MQTT" ]; then if [ "${offered_proto}" = "MQTT" ]; then
user="$(uci -q get obuspa.global.username)" user="$(uci -q get obuspa.global.username)"
pass="$(uci -q get obuspa.global.password)" pass="$(uci -q get obuspa.global.password)"