From 047e533140e4644003465331ce91d018bde2602e Mon Sep 17 00:00:00 2001 From: suvendhu Date: Thu, 25 May 2023 18:21:01 +0530 Subject: [PATCH] obuspa: Support dhcp deployment via option 125 --- obuspa/Makefile | 7 ++- obuspa/files/etc/config/obuspa | 2 + obuspa/files/etc/init.d/obuspa | 10 +++- .../etc/uci-defaults/02-obuspa-dhcp-option | 59 +++++++++++++++++++ 4 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 obuspa/files/etc/uci-defaults/02-obuspa-dhcp-option diff --git a/obuspa/Makefile b/obuspa/Makefile index c3df4d96a..bce81b388 100644 --- a/obuspa/Makefile +++ b/obuspa/Makefile @@ -5,13 +5,13 @@ include $(TOPDIR)/rules.mk PKG_NAME:=obuspa -PKG_VERSION:=7.0.2.23 +PKG_VERSION:=7.0.2.24 LOCAL_DEV:=0 ifneq ($(LOCAL_DEV),1) PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://dev.iopsys.eu/bbf/obuspa.git -PKG_SOURCE_VERSION:=cb4f6a8370bca0fc350c74f46399b30b71813332 +PKG_SOURCE_VERSION:=23f8a46822c3a0911abb3c764b6b4106a7bea6a5 PKG_MAINTAINER:=Vivek Dutta PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz PKG_MIRROR_HASH:=skip @@ -102,6 +102,7 @@ define Package/obuspa/install $(INSTALL_DIR) $(1)/etc/obuspa $(INSTALL_DIR) $(1)/etc/bbfdm/json $(INSTALL_DIR) $(1)/etc/uci-defaults + $(INSTALL_DIR) $(1)/etc/udhcpc.user.d $(INSTALL_BIN) $(PKG_BUILD_DIR)/obuspa $(1)/usr/sbin/ $(INSTALL_BIN) ./files/etc/init.d/obuspa $(1)/etc/init.d/ $(INSTALL_DATA) ./files/etc/config/obuspa $(1)/etc/config/ @@ -110,6 +111,8 @@ define Package/obuspa/install $(INSTALL_DATA) ./files/etc/bbfdm/json/USPAgent.json $(1)/etc/bbfdm/json/USPAgent.json $(INSTALL_DATA) ./files/etc/bbfdm/json/TransferComplete.json $(1)/etc/bbfdm/json/TransferComplete.json $(INSTALL_BIN) ./files/etc/uci-defaults/01-fix-upgrade-uci $(1)/etc/uci-defaults/ + $(INSTALL_BIN) ./files/etc/uci-defaults/02-obuspa-dhcp-option $(1)/etc/uci-defaults/ + $(INSTALL_BIN) $(PKG_BUILD_DIR)/files/etc/udhcpc.user.d/udhcpc_obuspa_opt125.user $(1)/etc/udhcpc.user.d/udhcpc_obuspa_opt125.user endef $(eval $(call BuildPackage,obuspa)) diff --git a/obuspa/files/etc/config/obuspa b/obuspa/files/etc/config/obuspa index d50a760db..af338366d 100644 --- a/obuspa/files/etc/config/obuspa +++ b/obuspa/files/etc/config/obuspa @@ -1,6 +1,8 @@ config obuspa 'global' option enabled '1' option debug '0' + option dhcp_discovery '1' + option interface 'wan' option log_level '1' option prototrace '0' option db_file '/etc/obuspa/usp.db' diff --git a/obuspa/files/etc/init.d/obuspa b/obuspa/files/etc/init.d/obuspa index b0ebfd5f5..c69d7d458 100755 --- a/obuspa/files/etc/init.d/obuspa +++ b/obuspa/files/etc/init.d/obuspa @@ -226,8 +226,8 @@ validate_controller_section() 'Path:string' \ 'EnableEncryption:bool' \ 'PeriodicNotifInterval:uinteger' \ - 'SessionMode:string:Allow' - + 'SessionMode:string:Allow' \ + 'ProvisioningCode:string' } validate_subscription_section() @@ -319,7 +319,7 @@ configure_controller() { local EndpointID Enable local Protocol Destination - local Topic mqtt stomp assigned_role_name AssignedRole ParameterName + local Topic mqtt stomp assigned_role_name AssignedRole ParameterName ProvisioningCode local Host Port Path EnableEncryption Reference SessionMode PeriodicNotifInterval local dm_ref sec @@ -358,6 +358,10 @@ configure_controller() db_set "${BASEPATH}.Enable" "${Enable}" db_set "${BASEPATH}.EndpointID" "${EndpointID}" + if [ -n "${ProvisioningCode}" ]; then + db_set "${BASEPATH}.ProvisioningCode" "${ProvisioningCode}" + fi + if [ -n "${PeriodicNotifInterval}" ]; then db_set "${BASEPATH}.PeriodicNotifInterval" "${PeriodicNotifInterval}" fi diff --git a/obuspa/files/etc/uci-defaults/02-obuspa-dhcp-option b/obuspa/files/etc/uci-defaults/02-obuspa-dhcp-option new file mode 100644 index 000000000..b2fa041de --- /dev/null +++ b/obuspa/files/etc/uci-defaults/02-obuspa-dhcp-option @@ -0,0 +1,59 @@ +#!/bin/sh + +. /lib/functions.sh + +configure_dhcp_options() { + local enabled inerface discovery + config_load obuspa + config_get_bool enabled global enabled 1 + config_get interface global interface "wan" + config_get_bool discovery global dhcp_discovery 1 + + if [ "${enabled}" -eq 0 ]; then + return 0 + fi + + if [ "${discovery}" -eq 1 ]; then + network_uci_update=0 + reqopts="$(uci -q get network."${interface}".reqopts)" + proto="$(uci -q get network."${interface}".proto)" + local req125_present=0 + + for ropt in $reqopts; do + case $ropt in + 125) req125_present=1 ;; + *) ;; + esac + done + + sendopts="$(uci -q get network."${interface}".sendopts)" + opt124="124:" + send124_present=0 + for sopt in $sendopts; do + if [[ "$sopt" == "$opt124"* ]]; then + send124_present=1 + break + fi + done + + if [ "${proto}" = "dhcp" ]; then + if [ ${req125_present} -eq 0 ]; then + newreqopts="$reqopts 125" + uci -q set network."${interface}".reqopts="$newreqopts" + network_uci_update=1 + fi + + if [ ${send124_present} -eq 0 ]; then + newsendopts="${sendopts} 124:00:00:0D:E9:04:03:75:73:70" + uci -q set network."${interface}".sendopts="$newsendopts" + network_uci_update=1 + fi + fi + + if [ ${network_uci_update} -eq 1 ]; then + uci commit network + fi + fi +} + +configure_dhcp_options