mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
ponmngr: initial implementation
This commit is contained in:
parent
5fbc784901
commit
16134d0a2d
6 changed files with 186 additions and 0 deletions
38
ponmngr/Makefile
Normal file
38
ponmngr/Makefile
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#
|
||||
# Copyright (C) 2013-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
|
||||
CATEGORY:=Utilities
|
||||
TITLE:=ponmngr packets manager daemon
|
||||
endef
|
||||
|
||||
define Package/ponmngr/description
|
||||
Configures pon
|
||||
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))
|
||||
2
ponmngr/files/etc/config/pon
Normal file
2
ponmngr/files/etc/config/pon
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
config globals globals
|
||||
option enable 1
|
||||
30
ponmngr/files/etc/init.d/pon
Executable file
30
ponmngr/files/etc/init.d/pon
Executable file
|
|
@ -0,0 +1,30 @@
|
|||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=98
|
||||
STOP=10
|
||||
|
||||
USE_PROCD=1
|
||||
NAME=ponmngr
|
||||
|
||||
include /lib/pon
|
||||
|
||||
|
||||
start_service() {
|
||||
if [ -f "/etc/config/pon" ]; then
|
||||
start_pon
|
||||
fi
|
||||
}
|
||||
|
||||
boot() {
|
||||
start
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
stop_pon
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
|
||||
27
ponmngr/files/etc/uci-defaults/60-pon-generate
Executable file
27
ponmngr/files/etc/uci-defaults/60-pon-generate
Executable 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="BRCM$mac"
|
||||
|
||||
uci commit pon
|
||||
70
ponmngr/files/lib/pon/broadcom.sh
Executable file
70
ponmngr/files/lib/pon/broadcom.sh
Executable file
|
|
@ -0,0 +1,70 @@
|
|||
#!/bin/sh
|
||||
. /lib/functions.sh
|
||||
. /usr/share/libubox/jshn.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
|
||||
vendor_id=$(echo $vendor_id | hexdump -e '4/1 "%02X" "\n"')
|
||||
vendor_id=${vendor_id:0:8}
|
||||
|
||||
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
|
||||
password=$(echo $password | hexdump -n ${#password} -e '16/1 "%02X""\n"')
|
||||
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
|
||||
}
|
||||
19
ponmngr/files/usr/libexec/rpcd/pon
Executable file
19
ponmngr/files/usr/libexec/rpcd/pon
Executable 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
|
||||
|
||||
Loading…
Add table
Reference in a new issue