Compare commits

...

2 Commits

Author SHA1 Message Date
Rahul
6b31f08b32 ponmngr: add ubus call
Add ubus call to get gpon status
2021-07-30 15:59:10 +05:30
Rahul
2750ca42c3 ponmngr: first commit
Script based ponmngr first commit
2021-07-27 12:51:07 +05:30
5 changed files with 195 additions and 0 deletions

40
ponmngr/Makefile Normal file
View File

@@ -0,0 +1,40 @@
#
# Copyright (C) 2021 IOPSYS
#
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=ponmngr
PKG_VERSION:=1.0.0
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_LICENSE:=GPL-2.0-only
PKG_LICENSE_FILES:=LICENSE
include $(INCLUDE_DIR)/package.mk
define Package/ponmngr
SECTION:=utils
CATEGORY:=Utilities
TITLE:=PON Manager
DEPENDS:=@(TARGET_iopsys_brcm63xx_arm) +xxd
endef
define Package/ponmngr/description
Configures pon manager
endef
#define Build/Prepare
# $(CP) -rf ./ponmngr/* $(PKG_BUILD_DIR)/
#endef
define Build/Compile
endef
define Package/ponmngr/install
$(CP) ./files/* $(1)/
endef
$(eval $(call BuildPackage,ponmngr))

View File

@@ -0,0 +1,37 @@
#!/bin/sh /etc/rc.common
# Uncomment this if functions need to called inside /lib/pon
# include /lib/pon
START=22
STOP=11
USE_PROCD=1
NAME=ponmngr
. /lib/functions.sh
include /lib/pon
start_service() {
if [ -f "/etc/config/pon" ]; then
start_pon
fi
}
stop_service() {
stop_pon
}
boot() {
start
}
service_triggers() {
procd_add_reload_trigger pon
}
reload_service() {
stop
start
}

View File

@@ -0,0 +1,27 @@
#!/bin/sh
basemac="$(db -q get hw.board.basemac | tr -d ':')"
if [ -s "/etc/config/pon" ]; then
if uci -q get pon.globals >/dev/null; then
# return if there is any valid content
exit
else
rm -f /etc/config/pon
fi
fi
touch /etc/config/pon
mac=''
if [ -z "$basemac" ]; then
mac="12345678"
else
# read last 8 characters of basemac without :
mac=${basemac: -8}
fi
uci set pon.globals=globals
uci set pon.globals.enabled="1"
uci set pon.globals.serial_number="ISSW$mac"
uci commit pon

View File

@@ -0,0 +1,72 @@
#!/bin/sh
. /lib/functions.sh
configure_snpwd() {
local serial_no password
serial_no="$1"
password="$2"
# serial number comprises of 2 parts, vendor id and vendor specific, the vendor id is
# a string while the vendor specific is a hex, so split the 2 and set accordingly
local vendor_id vendor_specific
vendor_id=${serial_no:0:4}
vendor_specific=${serial_no: -8}
# attempt to conver vendor_id from string to hex
if [ -n "$(which xxd)" ]; then
vendor_id=$(echo $vendor_id | xxd -c 256 -ps | sed "s/..$//")
else
# if cannot convert to hex, return as cli will not accept non hex input
return
fi
bdmf_shell -c `cat /var/bdmf_sh_id` -cmd /b/configure gpon onu_sn={vendor_id=$vendor_id,vendor_specific=$vendor_specific}
if [ -n "$password" ]; then
bdmf_shell -c `cat /var/bdmf_sh_id` -cmd /b/configure gpon password=$password
fi
}
configure_pon() {
local enabled serial_no password
config_load pon
config_get enabled globals "enabled"
if [ "$enabled" == "0" ]; then
exit
fi
config_get serial_no globals "serial_number"
config_get password globals "password"
configure_snpwd $serial_no $password
}
start_pon() {
if [ -n "$(which gponctl)" ]; then
configure_pon
gponctl start
fi
}
stop_pon() {
if [ -n "$(which gponctl)" ]; then
gponctl stop
fi
}
get_pon_status() {
json_init
status="$(gponctl getstate)"
admin_status="$(echo $status | head -n1 | awk '{print $8;}')"
json_add_string "admin_status" "$admin_status"
op_status="$(echo $status | head -n1 | awk '{print $12;}')"
case $op_status in
NUMBER)
op_status="$(echo $status | head -n1 | awk '{print $13;}')"
;;
esac
op_status=${op_status:1:2}
json_add_string "operational_status" "$op_status"
json_dump
}

View File

@@ -0,0 +1,19 @@
#!/bin/sh
. /usr/share/libubox/jshn.sh
. /lib/functions.sh
include /lib/pon
case "$1" in
list)
echo '{ "status": {} }'
;;
call)
case "$2" in
status)
get_pon_status
;;
esac
;;
esac