dhcp option 43 handling

This commit is contained in:
Suvendhu Hansa 2022-12-30 08:30:19 +00:00 committed by Vivek Kumar Dutta
parent 6961bbb4a7
commit 881711bb11
2 changed files with 4 additions and 136 deletions

View file

@ -8,11 +8,11 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=icwmp
PKG_VERSION:=9.1.4
PKG_VERSION:=9.1.5
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/icwmp.git
PKG_SOURCE_VERSION:=fb8b5b9da6cadd53a3d12e27af0ed800b149a9f2
PKG_SOURCE_VERSION:=79284d1f4e16cf6077a7394f0c04a894b83a8a41
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
@ -93,7 +93,8 @@ define Package/icwmp/default/install
$(INSTALL_DATA) ./files/lib/upgrade/keep.d/icwmp $(1)/lib/upgrade/keep.d/icwmp
$(INSTALL_BIN) ./files/etc/icwmpd/update.sh $(1)/etc/icwmpd/update.sh
$(INSTALL_DATA) ./files/etc/bbfdm/json/CWMPManagementServer.json $(1)/etc/bbfdm/json/
$(INSTALL_BIN) ./files/etc/udhcpc.user.d/udhcpc_icwmp.user $(1)/etc/udhcpc.user.d/udhcpc_icwmp.user
$(INSTALL_BIN) $(PKG_BUILD_DIR)/files/etc/udhcpc.user.d/udhcpc_icwmp_opt125.user $(1)/etc/udhcpc.user.d/udhcpc_icwmp_opt125.user
$(INSTALL_BIN) $(PKG_BUILD_DIR)/files/etc/udhcpc.user.d/udhcpc_icwmp_opt43.user $(1)/etc/udhcpc.user.d/udhcpc_icwmp_opt43.user
endef
Package/icwmp-openssl/install = $(Package/icwmp/default/install)

View file

@ -1,133 +0,0 @@
#!/bin/sh
. /lib/functions.sh
CLASS=""
OUI=""
SERIAL=""
get_vivsoi() {
# opt125 environment variable has data in below format
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | enterprise-number1 |
# | |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | data-len1 | |
# +-+-+-+-+-+-+-+-+ option-data1 |
# / /
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -----
# | enterprise-number2 | ^
# | | |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
# | data-len2 | | optional
# +-+-+-+-+-+-+-+-+ option-data2 | |
# / / |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
# ~ ... ~ V
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -----
# Enterprise Id Len Sub Op SLen Data Sub Op SLen Data Sub Op SLen Data
# +-------------+-----+------+------+----+------+-----+----+-----+------+-----+----+
# | id | n | 1 | n1 | D1 | 2 | n2 | D2 | ... | 6 | n6 | D6 |
# +-------------+-----+------+------+----+------+-----+----+-----+------+-----+----+
local opt125="$1"
local len="$2"
local ent_id
#hex-string 2 character=1 Byte
# length in hex string will be twice of actual Byte length
[ "$len" -gt "8" ] || return
data="${opt125}"
rem_len="${len}"
while [ $rem_len -gt 0 ]; do
ent_id=${data:0:8}
ent_id=$(printf "%d\n" "0x$ent_id")
if [ $ent_id -ne 3561 ]; then
len_val=${data:8:2}
data_len=$(printf "%d\n" "0x$len_val")
# add 4 byte for ent_id and 1 byte for len
data_len=$(( data_len * 2 + 10 ))
# move ahead data to next enterprise id
data=${data:"${data_len}":"${rem_len}"}
rem_len=$(( rem_len - $data_len ))
continue
fi
# read the length of enterprise data
len_val=${data:8:2}
opt_len=$(printf "%d\n" "0x$len_val")
[ $opt_len -eq 0 ] && return
# populate the option data of enterprise id
sub_data_len=$(( opt_len * 2))
# starting 10 means ahead of length field
sub_data=${data:10:"${sub_data_len}"}
# parsing of suboption of option 125
while [ $sub_data_len -gt 0 ]; do
# get the suboption id
sub_opt_id=${sub_data:0:2}
sub_opt_id=$(printf "%d\n" "0x$sub_opt_id")
# get the length of suboption
sub_opt_len=${sub_data:2:2}
sub_opt_len=$(printf "%d\n" "0x$sub_opt_len")
sub_opt_len=$(( sub_opt_len * 2 ))
# get the value of sub option starting 4 means starting after length
sub_opt_val=${sub_data:4:${sub_opt_len}}
# assign the value found in sub option
case "${sub_opt_id}" in
"4") OUI=$(echo -n $sub_opt_val | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '')
;;
"5") SERIAL=$(echo -n $sub_opt_val | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '')
;;
"6") CLASS=$(echo -n $sub_opt_val | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf && echo '')
;;
esac
# add 2 bytes for sub_opt id and sub_opt len field
sub_opt_end=$(( sub_opt_len + 4 ))
# fetch next sub option hex string
sub_data=${sub_data:${sub_opt_end}:${sub_data_len}}
# update the remaining sub option hex string length
sub_data_len=$((sub_data_len - sub_opt_end))
done
break
done
}
config_load cwmp
config_get_bool enable_cwmp cpe enable 1
config_get wan_intf cpe default_wan_interface "wan"
if [ "$enable_cwmp" = "0" ]; then
return 0
fi
if [ "${wan_intf}" == "${INTERFACE}" ]; then
if [ -n "$opt125" ]; then
len=$(printf "$opt125"|wc -c)
get_vivsoi "$opt125" "$len"
fi
mkdir -p /var/state
touch /var/state/cwmp
sec=$(uci -q -c /var/state get cwmp.gatewayinfo)
if [ -z "${sec}" ]; then
sec=$(uci -q -c /var/state add cwmp gatewayinfo)
uci -q -c /var/state rename cwmp."${sec}"="gatewayinfo"
fi
uci -q -c /var/state set cwmp.gatewayinfo.class="$CLASS"
uci -q -c /var/state set cwmp.gatewayinfo.oui="$OUI"
uci -q -c /var/state set cwmp.gatewayinfo.serial="$SERIAL"
uci -q -c /var/state commit cwmp
fi