gateway-info: Added support for USP events

This commit is contained in:
Suvendhu Hansa 2025-03-11 07:42:11 +00:00 committed by IOPSYS Dev
parent 2be4eeebb7
commit 74cbe1062a
No known key found for this signature in database
2 changed files with 82 additions and 39 deletions

View file

@ -8,13 +8,13 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=gateway-info
PKG_VERSION:=1.0.0
PKG_VERSION:=1.0.1
LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/bbf/gateway-info.git
PKG_SOURCE_VERSION:=26e407a25b156da75e3941d54ddd74294cd9eae8
PKG_SOURCE_VERSION:=b77871a883797db5c9fce232e2d2f183e59c682d
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
endif
@ -29,7 +29,7 @@ define Package/gateway-info
CATEGORY:=Utilities
TITLE:=GatewayInfo Data Model Support
DEPENDS:=+libuci +libubox +libubus +libblobmsg-json +umdns
DEPENDS+=+libbbfdm-api +libbbfdm-ubus +dm-service
DEPENDS+=+libbbfdm-api +libbbfdm-ubus +dm-service +iputils-arping
endef
define Package/gateway-info/description

View file

@ -243,11 +243,42 @@ get_usp_agent_id() {
get_mac_address() {
ip="${1}"
device="${2}"
mac="$(cat /proc/net/arp | grep $ip | awk '{print $4}')"
if [ -z "${mac}" ]; then
arp_resp="$(arping -b -f -c 5 -I $device $ip | grep 'Unicast reply from' | awk '{print $5}')"
if [ -n "${arp_resp}" ]; then
mac=${arp_resp:1:-1}
fi
fi
echo "${mac}"
}
send_unknown_gw_event() {
mac="${1}"
cmd="ubus -t 5 send gateway-info.gateway.unknown '{\"hwaddr\":\"$mac\"}'"
eval $cmd
}
send_cwmp_gw_event() {
oui="${1}"
class="${2}"
serial="${3}"
cmd="ubus -t 5 send gateway-info.gateway.cwmp '{\"oui\":\"$oui\",\"class\":\"$class\",\"serial\":\"$serial\"}'"
eval $cmd
}
send_usp_gw_event() {
endpoint="${1}"
cmd="ubus -t 5 send gateway-info.gateway.usp '{\"endpoint\":\"$endpoint\"}'"
eval $cmd
}
config_load gateway
config_get wan_intf global wan_interface "wan"
@ -257,39 +288,6 @@ if [ "${wan_intf}" == "${INTERFACE}" ]; then
return 0
fi
if [ -z "$opt125" ]; then
return 0
fi
len=$(printf "$opt125"|wc -c)
get_vivsoi "$opt125" "$len"
if [ "${GW_DISCOVERED}" -eq 0 ]; then
return 0
fi
mkdir -p /var/state
touch /var/state/gwinfo
sec=$(uci -q -c /var/state get gwinfo.gatewayinfo)
if [ -z "${sec}" ]; then
sec=$(uci -q -c /var/state add gwinfo gatewayinfo)
uci -q -c /var/state rename gwinfo."${sec}"="gatewayinfo"
fi
uci -q -c /var/state set gwinfo.gatewayinfo.hwaddr=""
uci -q -c /var/state set gwinfo.gatewayinfo.endpoint=""
uci -q -c /var/state set gwinfo.gatewayinfo.class="$CLASS"
uci -q -c /var/state set gwinfo.gatewayinfo.oui="$OUI"
uci -q -c /var/state set gwinfo.gatewayinfo.serial="$SERIAL"
uci -q -c /var/state set gwinfo.gatewayinfo.proto="CWMP"
uci -q -c /var/state commit gwinfo
# Check for USP parameters
ubus -t 15 wait_for umdns
if [ "${?}" -ne 0 ]; then
return 0
fi
json_load "$(ifstatus ${INTERFACE})"
json_get_var dev_name device ""
json_select data
@ -300,20 +298,65 @@ if [ "${wan_intf}" == "${INTERFACE}" ]; then
return 0
fi
MAC="$(get_mac_address $dhcp_ip $dev_name)"
mkdir -p /var/state
touch /var/state/gwinfo
sec=$(uci -q -c /var/state get gwinfo.gatewayinfo)
if [ -z "${sec}" ]; then
sec=$(uci -q -c /var/state add gwinfo gatewayinfo)
uci -q -c /var/state rename gwinfo."${sec}"="gatewayinfo"
fi
uci -q -c /var/state set gwinfo.gatewayinfo.hwaddr="$MAC"
uci -q -c /var/state set gwinfo.gatewayinfo.endpoint=""
uci -q -c /var/state set gwinfo.gatewayinfo.class=""
uci -q -c /var/state set gwinfo.gatewayinfo.oui=""
uci -q -c /var/state set gwinfo.gatewayinfo.serial=""
uci -q -c /var/state set gwinfo.gatewayinfo.proto=""
uci -q -c /var/state commit gwinfo
if [ -z "$opt125" ]; then
send_unknown_gw_event "${MAC}"
return 0
fi
len=$(printf "$opt125"|wc -c)
get_vivsoi "$opt125" "$len"
if [ "${GW_DISCOVERED}" -eq 0 ]; then
send_unknown_gw_event "${MAC}"
return 0
fi
uci -q -c /var/state set gwinfo.gatewayinfo.class="$CLASS"
uci -q -c /var/state set gwinfo.gatewayinfo.oui="$OUI"
uci -q -c /var/state set gwinfo.gatewayinfo.serial="$SERIAL"
uci -q -c /var/state set gwinfo.gatewayinfo.proto="CWMP"
uci -q -c /var/state commit gwinfo
# Check for USP parameters
ubus -t 15 wait_for umdns
if [ "${?}" -ne 0 ]; then
send_cwmp_gw_event "${OUI}" "${CLASS}" "${SERIAL}"
return 0
fi
resp=$(send_host_query $dev_name)
if [ "${resp}" -ne 0 ]; then
send_cwmp_gw_event "${OUI}" "${CLASS}" "${SERIAL}"
return 0
fi
ID="$(get_usp_agent_id $dhcp_ip)"
if [ -z "${ID}" ]; then
send_cwmp_gw_event "${OUI}" "${CLASS}" "${SERIAL}"
return 0
fi
MAC="$(get_mac_address $dhcp_ip)"
uci -q -c /var/state set gwinfo.gatewayinfo.hwaddr="$MAC"
uci -q -c /var/state set gwinfo.gatewayinfo.endpoint="$ID"
uci -q -c /var/state set gwinfo.gatewayinfo.proto="USP"
uci -q -c /var/state commit gwinfo
send_usp_gw_event "${ID}"
fi