Compare commits

...

121 Commits

Author SHA1 Message Date
Amit Kumar
2575f33e57 ponmngr: added documentaion files 2023-01-17 12:38:41 +00:00
Janusz Dziedzic
51b2ffd607 easy-soc-libs: 7.2.7 2023-01-17 12:34:50 +00:00
vdutta
091c4b81f9 bbf: 6.8.19 2023-01-17 17:44:46 +05:30
nevadita.chatterjee
c68554a42c map-controller: Fixing pidof in reload 2023-01-17 16:48:26 +05:30
Jakob Olsson
10de78cd1a map-topology: 2.5.1.15 2023-01-17 11:40:17 +01:00
Filip Matusiak
6bd995e445 map-controller: 4.1.0.2
Signed-off-by: Filip Matusiak <filip.matusiak@iopsys.eu>
2023-01-17 09:41:52 +01:00
suvendhu
087e0e3750 icwmp: Added dslforum.org in dhcp option 60 2023-01-16 16:58:40 +05:30
Sukru Senli
c3f5c269aa iop: genconfig: in customerconfigs use the same branch as in iowrt repo 2023-01-16 11:57:04 +01:00
vdutta
4ef1ac4703 udpecho: 2.0.3 2023-01-16 15:20:05 +05:30
vdutta
b9c58a99a5 twamp: 1.2.4 2023-01-16 14:48:48 +05:30
vdutta
4bec432070 swmodd: 2.1.20 2023-01-16 14:45:27 +05:30
vdutta
e2556a0f3d stunc: 1.1.15 2023-01-16 14:44:02 +05:30
vdutta
f265b9fe7b usermngr: 1.0.6 2023-01-16 14:41:59 +05:30
Anjan Chanda
c2bf977fb6 iop: add libwifiutils package in default config 2023-01-16 09:52:51 +01:00
Anjan Chanda
44030e710a wfadatad: add libwifiutils.so as package dependency 2023-01-16 09:52:51 +01:00
Anjan Chanda
e0028e8079 map-controller: add libwifiutils.so as package dependency 2023-01-16 09:52:51 +01:00
Anjan Chanda
9c14d21609 easy-soc-libs: 7.2.6: fix build on platforms having no WiFi 2023-01-16 09:52:51 +01:00
Amit Kumar
d690e1a7a5 ponmngr: Updated XPON bbf json for Transceiver 2023-01-16 07:50:30 +00:00
vdutta
bfacccba18 obuspa: Integrate obuspa-7.0.0 2023-01-16 12:47:36 +05:30
Marek Puzyniak
8b93d6ce3a wifimngr: 15.0.4 2023-01-13 16:35:16 +00:00
Marek Puzyniak
69d12b567d easy-soc-libs: 7.2.5 2023-01-13 16:33:28 +00:00
Jakob Olsson
4fbede4cb2 map-controller: 4.1.0.1 2023-01-13 16:55:53 +01:00
Jakob Olsson
e758208a17 map-agent: 4.1.0.1 2023-01-13 16:42:26 +01:00
Amin Ben Romdhane
a5f04ddb5f bbf: 6.8.18 2023-01-13 11:18:25 +01:00
vdutta
48913ed4bf sulu: 1.3.26 2023-01-13 12:20:48 +05:30
Amin Ben Romdhane
a8e8d4b109 ssdpd: 1.0.4 2023-01-12 13:33:40 +00:00
Amit Kumar
3a968d1914 map-topology: Updated Makefile commit version 2023-01-12 17:56:20 +05:30
Amit Kumar
58f4ad8e5a map-topology: cherry-pick from 6.5 2023-01-12 09:47:28 +05:30
Amit Kumar
549d681fab ponmngr: updated bbf json file for transceiver 2023-01-11 08:54:02 +00:00
Amin Ben Romdhane
5313770972 usermngr: 1.0.5 2023-01-10 17:39:46 +01:00
Amin Ben Romdhane
9046c71d00 bbf: 6.8.17 2023-01-10 17:38:27 +01:00
Filip Matusiak
87a71c7389 map-controller: validate thresholds in sta_steering section of config
Signed-off-by: Filip Matusiak <filip.matusiak@iopsys.eu>
2023-01-10 11:38:46 +00:00
Janusz Dziedzic
834bab34ab easy-soc-libs: 7.2.4
Signed-off-by: Janusz Dziedzic <janusz.dziedzic@iopsys.eu>
2023-01-10 09:30:51 +00:00
Anjan Chanda
a04593f02d wfadatad-decollector-4.0.0.1: deprecate wfadatad (deagent) package 2023-01-05 13:14:16 +01:00
Anjan Chanda
f7456c22f9 wfa-capi: 2.0.1 2023-01-05 10:07:03 +01:00
Anjan Chanda
34e5487f75 map-agent: 4.1.0.0 2023-01-04 17:01:55 +01:00
Anjan Chanda
a49e91f18e map-controller: 4.1.0.0 2023-01-04 17:01:55 +01:00
Anjan Chanda
ff55ae40f9 ieee1905: 7.0.2 2023-01-04 17:01:55 +01:00
Anjan Chanda
3bdc11c5c4 wifimngr: 15.0.3 2023-01-04 17:01:55 +01:00
Anjan Chanda
2cd976f5b9 easy-soc-libs: 7.2.3 2023-01-04 17:01:55 +01:00
Sukru Senli
cc306932e8 iop: do not select ethmngr by default
this causes problem building for airoha due to libethernet's dependency to xpon_bsp which is selected as =m
2023-01-04 16:55:49 +01:00
Anjan Chanda
d3927168b2 wifimngr: 15.0.2 2023-01-04 16:03:14 +01:00
Anjan Chanda
96ede99d63 easy-soc-libs: 7.2.1 2023-01-04 16:02:35 +01:00
Sukru Senli
86e90969e3 dslmngr: allow compiling for non broadcom targets
to be able to use test stub libdsl
2023-01-04 14:46:56 +01:00
Sukru Senli
99024c3111 dslmngr: move dsl scripts from target feeds to dslmngr package 2023-01-04 13:57:16 +01:00
Anjan Chanda
93777c899c wifimngr: 15.0.1 2023-01-04 13:14:30 +01:00
Anjan Chanda
d4bf893482 ieee1905: 7.0.1 2023-01-04 12:52:05 +01:00
Anjan Chanda
9da34a4fff easy-soc-libs: 7.2.0 2023-01-04 12:52:05 +01:00
Padmalochan Mohapatra
f7e6238928 qos Improvements on mtk qos tc+iptable classification 2023-01-03 15:26:20 +00:00
Sukru Senli
9192b863ea ethmngr: update port config generation and get correct max speed 2023-01-03 16:14:18 +01:00
Sukru Senli
0ef4d4e6b1 ethmngr: make scripts available for all targets even though ethmngr/libethernet pair is not available 2023-01-03 15:40:31 +01:00
Sukru Senli
af22e1abc3 iop: let easy-soc libraries be selected by the managers 2023-01-03 15:37:40 +01:00
Sukru Senli
b9e6f56110 iop: select ethmngr and qosmngr 2023-01-03 15:14:10 +01:00
Sukru Senli
d8454fab29 ethmngr: merge port-management into ethmngr 2023-01-03 15:06:39 +01:00
Wenpeng Song
8abeee9d23 Update packages endptmngr and dectmngr
dectmngr-3.5.6: Send CALL_REJECT only for an unanswered incoming call 
endptmngr: Fix CALL_REJECT and ON-HOOK handling

(cherry picked from commit 8605c1e455)
2023-01-03 13:35:30 +00:00
Sukru Senli
1164e33371 qosmngr: simplify Makefile 2023-01-03 13:01:34 +01:00
Janusz Dziedzic
15a65a071e wifimngr: 14.3.3
Signed-off-by: Janusz Dziedzic <janusz.dziedzic@iopsys.eu>
2023-01-02 15:29:19 +00:00
Janusz Dziedzic
ecddbb5992 easy-soc-libs: 6.9.0
Signed-off-by: Janusz Dziedzic <janusz.dziedzic@iopsys.eu>
2023-01-02 15:29:19 +00:00
Sukru Senli
4dbf7ac1da qosmngr: add intall section for ipq95xx target 2023-01-02 16:21:51 +01:00
Sukru Senli
f071d28911 qosmngr: allow selecting for ipq95xx target 2023-01-02 13:07:22 +01:00
Suresh Krishna
16e834d0f6 ipq95xx: add support for building target ipq95xx based on mac80211
Signed-off-by: Suresh Krishna <quic_sureshkr@quicinc.com>
2023-01-02 11:34:58 +00:00
Suvendhu Hansa
881711bb11 dhcp option 43 handling 2022-12-30 08:30:19 +00:00
Padmalochan Mohapatra
6961bbb4a7 qos : tc-Classification dead code cleanup 2022-12-30 03:16:49 +00:00
Padmalochan Mohapatra
591f9d9dde qos : Classification with tc+iptables for QoS on MTK_PANTHER 2022-12-29 12:09:38 +00:00
subramanian c
d942f2c606 qos: Deprecate firewall.qos and handle through qos config 2022-12-27 04:32:07 +00:00
Marina Maslova
01819a7f72 qos: enable should be 1 by default 2022-12-26 13:11:44 +03:00
Yalu Zhang
c8969996c7 Update package voicemngr and libvoice-broadcom
Get voice port configuration from the board database
2022-12-23 16:11:48 +01:00
nevadita.chatterjee
0bb0ade1ec map-topology:2.5.1.14 2022-12-22 10:40:59 +05:30
Amin Ben Romdhane
52c338366b ssdpd: 1.0.4 2022-12-21 23:25:36 +01:00
Marina Maslova
0dae8c3786 qos: default uplink limit should be 0 (unlimited) 2022-12-21 23:31:02 +03:00
vdutta
cbbe02096f ssdpd: 1.0.3 2022-12-21 22:22:11 +05:30
vdutta
fae6a213ac ssdpd: 1.0.2 2022-12-21 22:10:49 +05:30
vdutta
5e57b31c45 uspd: 2.2.23 2022-12-21 22:00:55 +05:30
vdutta
eb5437892d bbf: 6.8.16 2022-12-21 21:57:58 +05:30
vdutta
12e2a84ad1 ssdpd: 1.0.1 2022-12-21 21:46:20 +05:30
vdutta
0b11d79816 bbf: host access_control dm support 2022-12-21 19:09:40 +05:30
subramanian c
56fffd6b9c Firewall: Handle access control through /etc/config/hosts 2022-12-21 13:13:37 +00:00
sverma
0c28e45434 add psk mode on i1905, agent and controller 2022-12-21 13:06:06 +01:00
Jakob Olsson
72f48f9230 map-agent: 2.10.4.17 2022-12-21 13:04:29 +01:00
Jakob Olsson
787810e8ab ieee1905: 6.0.21 2022-12-21 12:57:30 +01:00
Jakob Olsson
15f2cd62e6 map-agent: 2.10.4.16 2022-12-21 12:49:16 +01:00
Jakob Olsson
6153f47f95 map-controller: 2.11.0.24 2022-12-21 12:19:42 +01:00
Jakob Olsson
1ec4f0f0da map-controller: 2.11.0.23 2022-12-21 11:43:43 +01:00
Jakob Olsson
c0e5dfae7f map-agent: 2.10.4.15 2022-12-21 11:42:10 +01:00
Jakob Olsson
d3766ede6c ieee1905: uci-defaults: convert old 'option ifname' to 'list ifname' entries 2022-12-21 11:35:02 +01:00
Sukru Senli
f03743634f iop: config: select ip6tables-zz-legacy 2022-12-21 11:30:41 +01:00
vdutta
5419eb07d2 sulu: use mosquitto uci for services 2022-12-21 14:27:38 +05:30
vdutta
34c0b3bb9e obuspa: 6.0.0.14 2022-12-21 14:23:49 +05:30
vdutta
d664b70bf6 bbf: 6.8.14 2022-12-21 14:22:36 +05:30
Jakob Olsson
dd674c2d93 map-controller: 2.11.0.22 2022-12-20 16:41:41 +01:00
Jakob Olsson
19ff43afe2 map-agent: 2.10.4.14 2022-12-20 16:41:34 +01:00
Saurabh Verma
2f80620644 map-controller: init.d: add support for other enc methods 2022-12-20 16:14:44 +01:00
vdutta
67555eed9f obuspa: 6.0.0.13 2022-12-20 18:32:41 +05:30
vdutta
8e7738a153 bbf: 6.8.13 2022-12-20 18:27:10 +05:30
suvendhu
5ca4dabf49 bbf: added uci-default script mqtt dm 2022-12-20 12:54:29 +00:00
vdutta
e6042743cb icwmp: 9.1.4 2022-12-20 18:23:47 +05:30
suvendhu
7353a6bfe7 Fix GW info overwrite on boot 2022-12-20 10:55:38 +00:00
Padmalochan Mohapatra
deef704d42 Revert "Revert "qosmngr : standard Linux support via tc+iptables"" 2022-12-20 09:30:24 +00:00
Jakob Olsson
a1e93540c5 map-agent: 2.10.4.13 2022-12-19 14:34:10 +01:00
vdutta
d37e6944f5 usermngr: 1.0.4 2022-12-19 18:53:21 +05:30
Amin Ben Romdhane
794c6f09b4 bbf: 6.8.12 2022-12-19 10:10:32 +01:00
Amin Ben Romdhane
39f2dab3f2 Add ssdpd package 2022-12-18 13:36:59 +00:00
Sukru Senli
a53706b95b Revert "qos: Deprecate firewall.qos and handle through qos config"
This reverts commit cf16fa7a6f.
2022-12-16 21:50:06 +01:00
Sukru Senli
53e13bc58c Revert "qosmngr : standard Linux support via tc+iptables"
This reverts commit 60d606e0fb.
2022-12-16 21:49:58 +01:00
Sukru Senli
9ed7feed87 sulu: 1.3.24 2022-12-16 17:52:27 +01:00
vdutta
4b05713ae7 obuspa: 6.0.0.12 2022-12-16 20:27:30 +05:30
vdutta
08a31cccad sulu: 1.3.23 2022-12-16 20:26:52 +05:30
suvendhu
5ed51849bb ponmngr: Added Device.XPON. json plugin 2022-12-16 12:51:46 +00:00
vdutta
677c712117 sulu: 1.3.22 2022-12-16 18:12:14 +05:30
Anjan Chanda
04fb03e1f4 ieee1905: 6.0.20 2022-12-16 13:19:18 +01:00
Jakob Olsson
d6cddef202 map-agent: 2.10.4.12 2022-12-16 12:08:22 +01:00
Jakob Olsson
c4a417a4b0 map-controller: 2.11.0.21 2022-12-16 12:01:03 +01:00
vdutta
8e6d97453d sulu: 1.3.21 2022-12-16 13:46:21 +05:30
Padmalochan Mohapatra
60d606e0fb qosmngr : standard Linux support via tc+iptables 2022-12-16 06:06:21 +00:00
vdutta
5c1afe5b78 bbf: 6.8.11 2022-12-16 09:29:20 +05:30
vdutta
aefcd070d6 sulu: Append sulu version info 2022-12-15 16:26:18 +05:30
vdutta
2a8316d7a1 sulu: 1.3.19 2022-12-15 12:53:48 +05:30
subramanian c
cf16fa7a6f qos: Deprecate firewall.qos and handle through qos config 2022-12-15 06:32:24 +00:00
vdutta
ee58c5e429 icwmp: 9.1.3 2022-12-14 20:37:00 +05:30
vdutta
a17b91452c bbf: 6.8.10 2022-12-14 20:22:28 +05:30
Vivek Kumar Dutta
185fd76b46 sulu: Add https support 2022-12-14 14:34:37 +00:00
112 changed files with 6328 additions and 863 deletions

View File

@@ -5,11 +5,11 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=libbbfdm
PKG_VERSION:=6.8.9
PKG_VERSION:=6.8.19
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/bbf.git
PKG_SOURCE_VERSION:=4ad900a9bb6b4a0dd38edc1d14e1b6cbfeaa8e9b
PKG_SOURCE_VERSION:=4e82190d88f73494dbc6d261e6eb507e348e10e3
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
@@ -158,6 +158,10 @@ define Package/libbbfdm/default/install
$(CP) $(PKG_BUILD_DIR)/libbbfdm.so $(1)/lib/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/scripts/* $(1)/usr/share/bbfdm
$(LN) /usr/share/bbfdm/bbf.diag $(1)/usr/libexec/rpcd/bbf.diag
ifeq ($(CONFIG_PACKAGE_mosquitto-ssl),y)
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) ./files/etc/uci-defaults/01-mosquitto-config $(1)/etc/uci-defaults/
endif
endef
define Package/libbbfdm/default/prerm

View File

@@ -42,7 +42,7 @@
]
},
"Port": {
"type": "string",
"type": "unsignedInt",
"read": true,
"write": true,
"version": "2.0",
@@ -50,6 +50,11 @@
"cwmp",
"usp"
],
"range": [
{
"max": 65535
}
],
"mapping": [
{
"type": "uci",

View File

@@ -0,0 +1,46 @@
#!/bin/sh
config_mosquitto_owrt() {
sec=$(uci -q get mosquitto.owrt)
if [ -z "${sec}" ]; then
sec=$(uci -q add mosquitto owrt)
uci -q rename mosquitto."${sec}"="owrt"
fi
uci -q set mosquitto.owrt.use_uci="1"
uci -q set mosquitto.owrt.write_pid="1"
uci -q commit mosquitto
}
config_mosquitto_general() {
sec=$(uci -q get mosquitto.mosquitto)
if [ -z "${sec}" ]; then
sec=$(uci -q add mosquitto mosquitto)
uci -q rename mosquitto."${sec}"="mosquitto"
fi
uci -q set mosquitto.mosquitto.log_dest="syslog"
uci -q set mosquitto.mosquitto.log_facility="5"
uci -q set mosquitto.mosquitto.log_timestamp="1"
uci -q set mosquitto.mosquitto.log_types="error warning notice"
uci -q set mosquitto.mosquitto.per_listener_settings="1"
uci -q commit mosquitto
}
config_mosquitto_persistence() {
sec=$(uci -q get mosquitto.persistence)
if [ -z "${sec}" ]; then
sec=$(uci -q add mosquitto persistence)
uci -q rename mosquitto."${sec}"="persistence"
fi
uci -q set mosquitto.persistence.persistence="0"
uci -q set mosquitto.persistence.location="/var/run"
uci -q commit mosquitto
}
if [ -f "/etc/config/mosquitto" ]; then
config_mosquitto_owrt
config_mosquitto_general
config_mosquitto_persistence
fi

View File

@@ -8,13 +8,13 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=dectmngr
PKG_RELEASE:=3
PKG_VERSION:=3.5.5
PKG_VERSION:=3.5.6
LOCAL_DEV=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/dectmngr.git
PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=cf4e91ffe0a1d83140fef5b41d16e581e5341cec
PKG_SOURCE_VERSION:=81450033d98fcdb68911e2148f48d190492090a6
PKG_MIRROR_HASH:=skip
endif

View File

@@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=dslmngr
PKG_VERSION:=1.1.2
PKG_VERSION:=1.2.0
LOCAL_DEV=0
ifneq ($(LOCAL_DEV),1)
@@ -68,6 +68,10 @@ define Build/Compile
endef
define Package/dslmngr/install
$(CP) ./files/common/* $(1)/
ifeq ($(CONFIG_TARGET_brcmbca),y)
$(CP) ./files/broadcom/* $(1)/
endif
$(INSTALL_DIR) $(1)/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/dslmngr $(1)/sbin/
endef

View File

@@ -0,0 +1,311 @@
#!/bin/sh
. /lib/functions.sh
# ATM #
check_pvc() {
local vpi=$1
local vci=$2
local ret
ret=$(xtmctl operate conn --show | awk -v test="$vpi/$vci" '{if ($3==test ) print $5 }')
case $ret in
''|*[!0-9]*) return 0 ;;
*) return $ret ;;
esac
}
check_xtm_list() {
local qclass=$1
local pcr scr mbs
local ret
case $# in
1)
pcr=0
scr=0
mbs=0
;;
2)
pcr=$2
scr=0
mbs=0
;;
4)
pcr=$2
scr=$3
mbs=$4
;;
esac
ret=$(xtmctl operate tdte --show | awk -v test="$qclass" -v pcr="$pcr" -v scr="$scr" -v mbs="$mbs" '{if ($2==test && $3==pcr && $4==scr && $5==mbs ) print $1 }')
case $ret in
''|*[!0-9]*) return 0 ;;
*) return $ret ;;
esac
}
configure_atm_device() {
local name vpi vci device link_type encapsulation qos_class pcr mbs scr i
config_get name $1 name "ATM"
config_get vpi $1 vpi "8"
config_get vci $1 vci "35"
config_get device $1 device "atm0"
config_get link_type $1 link_type "eoa"
config_get encapsulation $1 encapsulation "llc"
config_get qos_class $1 qos_class "ubr"
config_get pcr $1 pcr
config_get mbs $1 mbs
config_get scr $1 scr
check_pvc $vpi $vci
ret=$?
if [ "$ret" -eq 0 ]; then
check_xtm_list $qos_class $pcr $scr $mbs
ret=$?
if [ "$ret" -eq 0 ]; then
case $qos_class in # ubr, cbr, gfr, vbr-nrt, vbr-rt, ubr+, abr
ubr)
xtmctl operate tdte --add "$qos_class"
;;
ubr_pcr|ubr+)
xtmctl operate tdte --add "$qos_class" $pcr
;;
cbr)
xtmctl operate tdte --add "$qos_class" $pcr
;;
nrtvbr|vbr-nrt)
xtmctl operate tdte --add "$qos_class" $pcr $scr $mbs
;;
rtvbr|vbr-rt)
xtmctl operate tdte --add "$qos_class" $pcr $scr $mbs
;;
gfr)
;;
abr)
;;
esac
fi
case $link_type in # EoA, IPoA, PPPoA, CIP
EoA|eoa)
[ $encapsulation == "vcmux" ] && encapsulation="vcmux_eth" || encapsulation="llcsnap_eth"
;;
PPPoA|pppoa)
[ $encapsulation == "vcmux" ] && encapsulation="vcmux_pppoa" || encapsulation="llcencaps_ppp"
;;
IPoA|ipoa)
[ $encapsulation == "vcmux" ] && encapsulation="vcmux_ipoa" || encapsulation="llcsnap_rtip"
;;
CIP|cip)
;;
esac
check_xtm_list $qos_class $pcr $scr $mbs
ret="$?"
xtmctl operate conn --add 1.$vpi.$vci aal5 $encapsulation 0 1 $ret
for i in `seq 0 7`; do
xtmctl operate conn --addq 1.$vpi.$vci $i wrr 1 dt # queue priority 0-7
done
xtmctl operate conn --createnetdev 1.$vpi.$vci $device
xtmctl operate intf --state 1 enable
fi
}
remove_atm_devices() {
local vpi vci rest
local vpivci=`xtmctl operate conn --show | grep "ATM\|mode" | awk '{if (NR!=1 && $1!="PTM") {print $3}}'`
for i in $vpivci
do
rest=${i#\/}
vpi=${rest%%\/*}
vci=${rest#*\/}
echo "xtmctl operate conn --delete 1.$vpi.$vci"
xtmctl operate conn --delete 1.$vpi.$vci
echo "xtmctl operate conn --deletenetdev 1.$vpi.$vci"
xtmctl operate conn --deletenetdev 1.$vpi.$vci
done
}
create_atm_devices() {
echo "Creating ATM Device(s)"
config_load dsl
config_foreach configure_atm_device atm-device
}
# ATM END #
# PTM #
check_ptm() {
local ret
local ptmprio=$1
local dslat=$2
if [ "$ptmprio" -eq 2 ]; then
ptmprio="high"
else
ptmprio="low"
fi
ret=$(xtmctl operate conn --show | awk -v dslat="$dslat" -v ptmprio="$ptmprio" '{if ($2 == dslat && $3 == ptmprio ) print $2 }')
case $ret in
''|*[!0-9]*) return 0 ;;
*) return $ret ;;
esac
}
configure_ptm_device() {
local name device priority portid i
config_get name $1 name "PTM"
config_get device $1 device "ptm0"
config_get priority $1 priority 1
config_get portid $1 portid 1
check_ptm $priority $portid
ret=$?
if [ "$ret" -eq 0 ]; then
xtmctl operate conn --add $portid.$priority
for i in `seq 0 7`; do
xtmctl operate conn --addq $portid.$priority $i wrr 1 dt -1 -1 3000 # queue priority 0-7
done
echo "xtmctl operate conn --createnetdev $portid.$priority $device"
xtmctl operate conn --createnetdev $portid.$priority $device
xtmctl operate intf --state 1 enable
fi
}
remove_ptm_devices() {
local delptm
local x=0
IFS=$'\n'
for i in `xtmctl operate conn --show | grep "PTM\|mode"`
do
if [ $x -eq 1 ]; then
delptm=$(echo $i | awk '{if ($1!="ATM") print $2"."$11}')
echo "xtmctl operate conn --delete $delptm"
xtmctl operate conn --delete $delptm
xtmctl operate conn --deletenetdev $delptm
fi
x=1
done
unset IFS
}
create_ptm_devices() {
echo "Creating PTM Device(s)"
config_load dsl
config_foreach configure_ptm_device ptm-device
}
# PTM END #
prioritize_arp()
{
ebtables -t nat -D POSTROUTING -j mark --mark-or 0x7 -p ARP >/dev/null
ebtables -t nat -A POSTROUTING -j mark --mark-or 0x7 -p ARP >/dev/null
}
xtm_remove_devices() {
remove_atm_devices
remove_ptm_devices
}
xtm_create_devices() {
local tpstc="$(xdslctl info --show | grep TPS-TC)"
if echo "$tpstc" | grep -q "ATM Mode"; then
create_atm_devices
elif echo "$tpstc" | grep -q "PTM Mode"; then
create_ptm_devices
fi
}
xdsl_configure() {
local VDSL=0
local GFAST=0
local mod=""
local modes=""
local profile=""
config_load dsl
# Modes
config_get mode line mode
for mod in $mode; do
[ $mod == "gdmt" ] && modes="${modes}d"
[ $mod == "glite" ] && modes="${modes}l"
[ $mod == "t1413" ] && modes="${modes}t"
[ $mod == "adsl2" ] && modes="${modes}2"
[ $mod == "adsl2p" ] && modes="${modes}p"
[ $mod == "annexl" ] && modes="${modes}e"
[ $mod == "annexm" ] && modes="${modes}m"
[ $mod == "vdsl2" ] && modes="${modes}v" && VDSL=1
[ $mod == "gfast" ] && modes="${modes}f" && GFAST=1
done
# VDSL Profiles
config_get profile line profile
# Capabilities
config_get_bool bitswap line bitswap 1
[ $bitswap -eq 1 ] && bitswap="on" || bitswap="off"
config_get_bool sra line sra 1
[ $sra -eq 1 ] && sra="on" || sra="off"
# config_get_bool trellis line trellis 1
config_get_bool sesdrop line sesdrop 0
[ $sesdrop -eq 1 ] && sesdrop="on" || sesdrop="off"
# VDSL2 only
config_get_bool us0 line us0 1
[ $us0 -eq 1 ] && us0="on" || us0="off"
# config_get_bool dynamicd line dynamicd 1
# config_get_bool dynamicf line dynamicf 1
config_get_bool sos line sos 0
[ $sos -eq 1 ] && sos="on" || sos="off"
config_get_bool phyReXmtUs line phyReXmtUs 0
config_get_bool phyReXmtDs line phyReXmtDs 1
phyReXmt=$(( $((phyReXmtUs<<1)) + phyReXmtDs))
if [ $VDSL -eq 1 -o $GFAST -eq 1 ]; then
echo "xdslctl start --up --mod $modes --profile "$profile" --sra $sra --bitswap $bitswap --us0 $us0 --sesdrop $sesdrop --SOS $sos --phyReXmt $phyReXmt"
xdslctl start --up --mod $modes --profile "$profile" --sra $sra --bitswap $bitswap --us0 $us0 --sesdrop $sesdrop --SOS $sos --phyReXmt $phyReXmt
# G.Fast hardware to VDSL hardware, to set the driver bit kPhyCfg2EnableGfastVdslMMTimeOut0.
# Enable V43 tone for GFAST.
echo "xdslctl configure1 --phycfg 0 0 0 0 0 0 0 0 0 0 0 0x1400400 0x1400400"
xdslctl configure1 --phycfg 0 0 0 0 0 0 0 0 0 0 0 0x1400400 0x1400400
else
echo "xdslctl start --up --mod $modes --sra $sra --bitswap $bitswap --sesdrop $sesdrop --SOS $sos --phyReXmt $phyReXmt"
xdslctl start --up --mod $modes --sra $sra --bitswap $bitswap --sesdrop $sesdrop --SOS $sos --phyReXmt $phyReXmt
fi
if [ $GFAST -eq 1 ]; then
# G.Fast hardware to VDSL hardware, to set the driver bit kPhyCfg2EnableGfastVdslMMTimeOut0.
# Enable V43 tone for GFAST.
echo "xdslctl configure1 --phycfg 0 0 0 0 0 0 0 0 0 0 0 0x1400400 0x1400400"
xdslctl configure1 --phycfg 0 0 0 0 0 0 0 0 0 0 0 0x1400400 0x1400400
fi
}
xdsl_stop() {
# echo "Stopping DSL"
# stop causes IRQ issues
# xdslctl stop
return 0
}
xdsl_init() {
prioritize_arp
echo "Starting DSL"
xtmctl start
xtmctl operate intf --state 1 enable
}

View File

@@ -0,0 +1,53 @@
# OEM specific parameters
config oem-parameters 'oem'
# option country_code "0000" # 2 bytes hex
# option vendor_id "IO" # 4 bytes string
# option vendor_suffix "0000" # 2 bytes hex
# option sw_version "iopsys" # 16 bytes string
# option serial_nr "00000000" # 32 bytes string
# DSL Modes
config dsl-line line
list mode gdmt
list mode glite
list mode t1413
list mode adsl2
list mode adsl2p
list mode annexl
list mode annexm
list mode vdsl2
# VDSL2 profiles
list profile 8a
list profile 8b
list profile 8c
list profile 8d
list profile 12a
list profile 12b
list profile 17a
list profile 30a
option bitswap 1
option sra 1
option us0 1 # VDSL2 only
option sesdrop 0
option sos 0
option phyReXmtUs 0
option phyReXmtDs 1
config atm-device atm0
option name 'ATM'
option vpi '8'
option vci '35'
option device atm0
option link_type 'eoa' # EoA, IPoA, PPPoA, CIP
option encapsulation 'llc' # llc, vcmux
option qos_class 'ubr' # ubr, cbr, gfr, vbr-nrt, vbr-rt, ubr+, abr
# option pcr '512'
# option scr '256'
# option mbs '1024'
config ptm-device ptm0
option name 'PTM'
option device 'ptm0'
option priority '1'
option portid '1'

View File

@@ -0,0 +1,7 @@
[ "$STATUS" == "up" -o "$STATUS" == "down" ] || exit 0
. /lib/functions.sh
include /lib/dsl
xtm_remove_devices
xtm_create_devices

View File

@@ -0,0 +1,7 @@
if [ "$STATUS" == "up" ]; then
ubus call led.dsl set '{"state":"ok"}'
elif [ "$STATUS" == "down" ]; then
ubus call led.dsl set '{"state":"off"}'
elif [ "$STATUS" == "training" ]; then
ubus call led.dsl set '{"state":"alert"}'
fi

View File

@@ -0,0 +1,48 @@
#!/bin/sh /etc/rc.common
. /lib/functions.sh
include /lib/dsl
START=20
USE_PROCD=1
DSLMNGR=$(which dslmngr)
start_service() {
[ -n "$DSLMNGR" ] && {
procd_open_instance
procd_set_param command "$DSLMNGR"
procd_set_param respawn
procd_close_instance
}
xdsl_configure
xtm_create_devices
}
stop_service() {
[ -n "$DSLMNGR" ] && service_stop $DSLMNGR
xtm_remove_devices
xdsl_stop
}
boot() {
local HASADSL="$(db -q get hw.board.hasAdsl)"
local HASVDSL="$(db -q get hw.board.hasVdsl)"
[ "$HASADSL" == "1" -o "$HASVDSL" == "1" ] || return
xdsl_init
start
}
reload_service() {
stop
start
}
service_triggers() {
procd_add_reload_trigger dsl
}

View File

@@ -7,13 +7,13 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=easy-soc-libs
PKG_VERSION:=6.8.0
PKG_VERSION:=7.2.7
PKG_RELEASE:=1
LOCAL_DEV=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=ddc7b272bec5e3b5c2a216a1f86cd5589a1a4a19
PKG_SOURCE_VERSION:=3d6d1347668408e77c327ddf81602e70af8b3d98
PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/easy-soc-libs.git
PKG_MAINTAINER:=Anjan Chanda <anjan.chanda@iopsys.eu>
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)_$(PKG_SOURCE_VERSION).tar.xz
@@ -59,6 +59,10 @@ else ifeq ($(CONFIG_TARGET_airoha),y)
TARGET_PLATFORM=ECONET
TARGET_WIFI_TYPE=MAC80211
TARGET_CFLAGS +=-DIOPSYS_ECONET
else ifeq ($(CONFIG_TARGET_ipq95xx),y)
TARGET_PLATFORM=IPQ95XX
TARGET_WIFI_TYPE=MAC80211
TARGET_CFLAGS +=-DIPQ95XX
else
$(info Unexpected CONFIG_TARGET, use default MAC80211)
TARGET_PLATFORM=MAC80211
@@ -71,13 +75,27 @@ export TARGET_WIFI_TYPE
subdirs := \
$(if $(CONFIG_PACKAGE_libeasy),libeasy) \
$(if $(CONFIG_PACKAGE_libwifiutils),libwifi) \
$(if $(CONFIG_PACKAGE_libwifi),libwifi) \
$(if $(CONFIG_PACKAGE_libdsl),libdsl) \
$(if $(CONFIG_PACKAGE_libethernet),libethernet) \
$(if $(CONFIG_PACKAGE_libqos),libqos)
EASY_SOC_LIBS := \
ifneq ($(CONFIG_PACKAGE_libwifi),)
TARGET_CFLAGS +=-DHAS_WIFI
endif
esl-pkgs := \
$(if $(CONFIG_PACKAGE_libeasy),libeasy) \
$(if $(CONFIG_PACKAGE_libwifiutils),libwifiutils) \
$(if $(CONFIG_PACKAGE_libwifi),libwifi) \
$(if $(CONFIG_PACKAGE_libdsl),libdsl) \
$(if $(CONFIG_PACKAGE_libethernet),libethernet) \
$(if $(CONFIG_PACKAGE_libqos),libqos)
esl-pkgs-all := \
libeasy \
libwifiutils \
libwifi \
libdsl \
libethernet \
@@ -127,15 +145,15 @@ define Build/Compile
$(Build/Compile/rebuild)
touch $(PKG_BUILD_DIR)/.config_$(CONFIG_TARGET_PROFILE)
$(call Build/Compile/Default)
$(foreach dir,$(subdirs),$(call Build/Compile/$(dir)))
$(foreach dir,$(esl-pkgs),$(call Build/Compile/$(dir)))
endef
define Build/InstallDev
$(foreach dir,$(subdirs),$(call Build/InstallDev/$(dir),$(1),$(2));)
$(foreach dir,$(esl-pkgs),$(call Build/InstallDev/$(dir),$(1),$(2));)
endef
define Package/easy-soc-libs/install
:
endef
$(eval $(foreach e,$(EASY_SOC_LIBS),$(call BuildPackage,$(e))))
$(eval $(foreach e,$(esl-pkgs-all),$(call BuildPackage,$(e))))

View File

@@ -1,29 +1,49 @@
define Package/libwifiutils
$(call Package/easy-soc-libs)
TITLE:= WiFi utility library (libwifiutils.so)
DEPENDS+=+libnl +libnl-route +libeasy
endef
define Build/InstallDev/libwifiutils
$(INSTALL_DIR) $(1)/usr/include
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_BUILD_DIR)/libwifi/wifidefs.h $(1)/usr/include/
$(CP) $(PKG_BUILD_DIR)/libwifi/wifiutils.h $(1)/usr/include/
$(CP) $(PKG_BUILD_DIR)/libwifi/libwifiutils*.so* $(1)/usr/lib/
endef
define Package/libwifiutils/install
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_BUILD_DIR)/libwifi/libwifiutils*.so* $(1)/usr/lib/
endef
define Package/libwifi
$(call Package/easy-soc-libs)
TITLE:= WiFi library (libwifi)
DEPENDS+=+libnl +libnl-route +libeasy +TARGET_brcmbca:bcmkernel
DEPENDS+=+libnl +libnl-route +libeasy +libwifiutils +TARGET_brcmbca:bcmkernel
endef
define Package/libwifi/config
if PACKAGE_libdsl
if PACKAGE_libwifi
config LIBWIFI_DEBUG
depends on PACKAGE_libwifi
bool "Enable wifi debugging"
default n
endif
endef
define Build/InstallDev/libwifi
$(INSTALL_DIR) $(1)/usr/include
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_BUILD_DIR)/libwifi/wifiops.h $(1)/usr/include/
$(CP) $(PKG_BUILD_DIR)/libwifi/wifi.h $(1)/usr/include/
$(CP) $(PKG_BUILD_DIR)/libwifi/libwifi*.so* $(1)/usr/lib/
$(CP) $(PKG_BUILD_DIR)/libwifi/libwifi-7*.so* $(1)/usr/lib/
endef
define Package/libwifi/install
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_BUILD_DIR)/libwifi/libwifi*.so* $(1)/usr/lib/
$(CP) $(PKG_BUILD_DIR)/libwifi/libwifi-7*.so* $(1)/usr/lib/
endef

View File

@@ -13,7 +13,7 @@ LOCAL_DEV=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/endptmngr.git
PKG_SOURCE_VERSION:=dc12712af8c4088f7873502ca845e51c68a1ada9
PKG_SOURCE_VERSION:=fb85081443c19b5062bede49c80b1802c0f05d34
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
endif

View File

@@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=ethmngr
PKG_VERSION:=2.0.1
PKG_VERSION:=2.1.0
PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=5a0ff3bc7c49dcb05129f423ef8e0c4929f6aa03
@@ -23,7 +23,7 @@ define Package/ethmngr
SECTION:=utils
CATEGORY:=Utilities
TITLE:=Ethernet status and configration utility
DEPENDS:=+libethernet +libuci +libubox +ubus +libpthread +libnl-genl
DEPENDS:=+(TARGET_brcmbca||TARGET_airoha||TARGET_ipq95xx):libethernet +libuci +libubox +ubus +libpthread +libnl-genl
endef
define Package/ethmngr/description
@@ -37,10 +37,24 @@ TARGET_CFLAGS += \
-I$(STAGING_DIR)/usr/include/libnl3 \
-D_GNU_SOURCE
ifeq ($(CONFIG_TARGET_brcmbca)$(CONFIG_TARGET_airoha)$(CONFIG_TARGET_ipq95xx),)
define Build/Compile
endef
endif
define Package/ethmngr/install
$(INSTALL_DIR) $(1)/etc/init.d $(1)/usr/sbin
$(INSTALL_BIN) ./files/ethmngr.init $(1)/etc/init.d/ethmngr
$(CP) ./files/common/* $(1)/
ifneq ($(CONFIG_TARGET_brcmbca),)
$(CP) ./files/broadcom/* $(1)/
else ifneq ($(CONFIG_TARGET_airoha),)
$(CP) ./files/airoha/* $(1)/
else
$(CP) ./files/linux/* $(1)/
endif
ifneq ($(CONFIG_TARGET_brcmbca)$(CONFIG_TARGET_airoha)$(CONFIG_TARGET_ipq95xx),)
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/ethmngr $(1)/usr/sbin/
endif
endef
$(eval $(call BuildPackage,ethmngr))

View File

@@ -0,0 +1,208 @@
#!/bin/sh
. /lib/functions.sh
unset -f switchmgr
# alias for switchmgr
switchmgr() {
"/userfs/bin/switchmgr" "$@"
}
unset -f tc3162_get_lan_port
# get lan port port by ifname
# arg1: port ifname, ex: eth0.1
tc3162_get_lan_port() {
[[ -z "$1" ]] && return 255
local ifname="$1"
local if_idx=255
# only for tc3162 eth switch ports (eth0.x, 0 < x < 7)
case "${ifname}" in
eth0.*)
;;
*)
logger -t "port-management" \
"unsupported - ${ifname} is not tc3162 switch port"
return 255
;;
esac
let "if_idx=$(echo "${ifname}" | cut -f2 -d'.')"
[[ -z "${if_idx}" ]] && return 255
[[ ${if_idx} -lt 1 || ${if_idx} -gt 6 ]] && {
logger -t "port-management" \
"incorrect tc3162 lan port index ${if_idx} picked from ifname ${ifname}"
return 255
}
let "if_idx=${if_idx}-1"
return ${if_idx}
}
unset -f tc3162_get_mapped_port
# get mapped switch port by ifname
# arg1: port ifname, ex: eth0.1
tc3162_get_mapped_port() {
[[ -z "$1" ]] && return 255
local ifname="$1"
local if_idx=255
local prtmap_procfile="/proc/tc3162/eth_portmap"
local lan_prt=255
local port=255
local prtmap_out_line_num=4
local prtmap_out_line=""
# check "lan port map" marker in portmap output string
prtmap_out_line="$(sed -n "${prtmap_out_line_num}p" ${prtmap_procfile})"
[[ ${prtmap_out_line} != "lan_port_map" ]] && return 255
tc3162_get_lan_port "${ifname}"
let "if_idx=$?"
[[ -z "${if_idx}" || ${if_idx} -eq 255 ]] && return
# get lan portmapping string "lan_port mapped_port" for ifname by it's index
let "prtmap_out_line_num=${prtmap_out_line_num}+1+${if_idx}"
prtmap_out_line="$(sed -n "${prtmap_out_line_num}p" ${prtmap_procfile})"
# get and check lan port index from lan portmapping string
lan_prt=$(echo "${prtmap_out_line}" | cut -f 1 -d' ')
[[ -z "${lan_prt}" || "${if_idx}" != "${lan_prt}" ]] && return 255
# get and check mapped port from lan portmapping string
let "port=$(echo "${prtmap_out_line}" | cut -f 2 -d' ')"
[[ ${port} -lt 0 || ${port} -gt 255 ]] && return 255
return ${port}
}
unset -f get_max_port_speed
# arg1: port ifname, ex: eth0.1
get_max_port_speed() {
[[ -z "$1" ]] && { echo 0; return; }
local ifname="$1"
local port=255
local speed=0
[[ -d "/sys/class/net/${ifname}" ]] || {
logger -t "port-management" "interface ${ifname} is not found"
return
}
tc3162_get_lan_port "${ifname}"
let "port=$?"
[[ -z "${port}" || ${port} -eq 255 ]] && return
# tc3162 capability for all ports is 1Gbps
speed=1000
echo $speed
}
unset -f power_updown
# arg1: port ifname, ex: eth0.1
# arg2: port enabled, ex: 0/1/off/on/..
power_updown() {
[[ -z "$1" ]] && return
[[ -z "$2" ]] && return
local ifname="$1"
local enabled="$2"
local port=255
[[ -d "/sys/class/net/${ifname}" ]] || {
logger -t "port-management" "interface ${ifname} is not found"
return
}
let "enabled=$(get_bool "${enabled}" "-1")"
[[ ${enabled} -eq -1 ]] && return
tc3162_get_lan_port "${ifname}"
let "port=$?"
[[ -z "${port}" || ${port} -eq 255 ]] && return
switchmgr phy admin "${port}" "${enabled}"
}
unset -f set_port_settings
# arg1: port ifname, ex: eth0.1
# arg2: port enabled, ex: 0/1/off/on/..
# arg3: port speed, ex: 1000
# arg4: port duplex, ex: full
# arg5: port autoneg, ex: 0/1/off/on/..
# arg6: port eee, ex: 0/1/off/on/..
# arg7: port pause, ex: 0/1/off/on/..
set_port_settings() {
[[ -z "$1" ]] && return
[[ -z "$2" ]] && return
[[ -z "$3" ]] && return
[[ -z "$4" ]] && return
[[ -z "$5" ]] && return
[[ -z "$6" ]] && return
[[ -z "$7" ]] && return
local ifname="$1"
local enabled="$2"
local speed="$3"
local duplex="$4"
local autoneg=$5
local eee="$6"
local pause="$7"
local port=255
local speedmode=1
local last_speed=0
[[ -d "/sys/class/net/${ifname}" ]] || {
logger -t "port-management" "interface ${ifname} is not found"
return
}
let "enabled=$(get_bool "${enabled}" "-1")"
[[ ${enabled} -eq -1 ]] && return
let "autoneg=$(get_bool "${autoneg}" "-1")"
[[ ${autoneg} -eq -1 ]] && return
let "eee=$(get_bool "${eee}" "-1")"
[[ ${eee} -eq -1 ]] && return
let "pause=$(get_bool "${pause}" "-1")"
[[ ${pause} -eq -1 ]] && return
duplex="$(echo "${duplex}" | awk '{print tolower($0)}')"
[[ "${duplex}" != "half" && "${duplex}" != "full" ]] && return
tc3162_get_lan_port "${ifname}"
let "port=$?"
[[ -z "${port}" || ${port} -eq 255 ]] && return
last_speed="$(switchmgr phy maxspeed "${port}" | cut -f2 -d':')"
[[ -z "${last_speed}" || "${last_speed}" == "*Down*" ]] \
&& last_speed=${speed}
switchmgr phy pause "${port}" "${pause}"
# set speedmode: speed+duplex+autoneg
# FIXME: switchmgr has no separate setting for 1Gbps speed - use autoneg instead
if [[ ${autoneg} -eq 1 || ${speed} -gt 100 ]]; then
switchmgr phy speedmode ${port} "1"
else
[[ ${speed} -gt 10 ]] && let "speedmode=2" || let "speedmode=4"
[[ "${duplex}" == "half" ]] && let "speedmode=${speedmode}+1"
switchmgr phy speedmode "${port}" "${speedmode}"
fi
# TODO: implement MAC control register manipulations (mapped ports used) for
# eee settings change
# separate (tx/rx) pause (flow control) settings change
# set speed to 1Gbps separately from autoneg mode
# FIXME: workaround for duplex/pause settings being not applied if speed is unchanged
[[ ${last_speed} -eq ${speed} ]] && power_updown "${ifname}" 0
power_updown "${ifname}" ${enabled}
}

View File

@@ -0,0 +1,140 @@
# arg1: port ifname, ex: eth0
get_max_port_speed() {
if [ -z "$1" ]; then
echo 0
return
fi
local ifname="$1"
local phycap="$(ethctl $ifname media-type 2>/dev/null | grep 'PHY Capabilities' | awk '{print$NF}' | cut -d'|' -f1)"
local speed=1000
case "$phycap" in
10GFD) speed=10000 ;;
5GFD) speed=5000 ;;
2.5GFD) speed=2500 ;;
1GFD|1GHD) speed=1000 ;;
100MFD|100MHD) speed=100 ;;
10MFD|10MHD) speed=10 ;;
esac
echo $speed
}
# arg1: port name, ex: eth0
get_port_number() {
[ -z "$1" ] && return
local ports="0 1 2 3 4 5 6 7"
local units="0 1"
local port="$1"
local ifname
for unit in $units; do
for prt in $ports; do
ifname="$(ethswctl getifname $unit $prt 2>/dev/null | awk '{print$NF}')"
if [ "$ifname" == "$port" ]; then
echo "$unit $prt"
return
fi
done
done
}
# arg1: port ifname, ex: eth0
# arg2: port enabled, ex: 1
power_updown() {
local ifname="$1"
local enabled=$2
local updown="up"
[ $enabled -eq 0 ] && updown="down"
ethctl $ifname phy-power $updown >/dev/null
}
# arg1: port ifname, ex: eth0
# arg2: port enabled, ex: 1
# arg3: port speed, ex: 1000
# arg4: port duplex, ex: full
# arg5: port autoneg, ex: on
# arg6: port eee, ex: 0
# arg7: port pause, ex: 0
set_port_settings() {
local ifname="$1"
local enabled=$2
local speed="$3"
local duplex=$4
local autoneg=$5
local eee=$6
local pause=$7
[ -d /sys/class/net/$ifname ] || return
local unitport="$(get_port_number $ifname)"
local unit=$(echo $unitport | cut -d ' ' -f 1)
local port=$(echo $unitport | cut -d ' ' -f 2)
[ $autoneg -eq 1 ] && autoneg="on" || autoneg="off"
[ "$duplex" == "half" ] && duplex=0 || duplex=1
[ "$duplex" == 0 ] && dplx="HD" || dplx="FD"
[ "$autoneg" == "on" ] && media_type="auto" || media_type="$speed$dplx"
phycrossbar="$(ethctl $ifname phy-crossbar | head -1)"
crossbartype="$(echo $phycrossbar | awk '{print$2$3}')"
# Take only the last PHY Endpoint (non-Serdes) into account as Serdes port number precedes
[ "$crossbartype" == "oncrossbar" ] && pyhendpoint="$(echo $phycrossbar | awk '{print$NF}')"
phycaps="$(ethctl $ifname media-type ${pyhendpoint:+ port $pyhendpoint} | awk -F'PHY Capabilities: ' '{print$2}')"
numofcaps="$(echo $phycaps | tr '|' ' ' | wc -w)"
if [ "$numofcaps" == "1" ]; then
logger -t "port-management" "$ifname is capable of $phycaps only; not setting speed/duplex"
else
logger -t "port-management" "$ifname is capable of $phycaps; setting speed/duplex to $media_type"
ethctl $ifname media-type $media_type ${pyhendpoint:+ port $pyhendpoint} &>/dev/null
fi
[ $eee -eq 1 ] && eee="on" || eee="off"
ethtool --set-eee $ifname eee $eee 2>/dev/null
case $pause in
off|0)
pause=0x0
auto=off
rx=off
tx=off
;;
on|1)
pause=0x2
auto=off
rx=on
tx=on
;;
auto)
pause=0x1
auto=on
rx=on
tx=on
;;
tx)
pause=0x3
auto=off
rx=off
tx=on
;;
rx)
pause=0x4
auto=off
rx=on
tx=off
;;
esac
if [ "$auto" == "on" ]; then
# Use ethswctl utility to set pause autoneg
# as ethtool is not setting it properly
ethswctl -c pause -n $unit -p $port -v $pause 2>&1 >/dev/null
else
ethtool --pause $ifname autoneg $auto rx $rx tx $tx 2>/dev/null
fi
power_updown $ifname $enabled
}

View File

@@ -1,12 +1,15 @@
#!/bin/sh /etc/rc.common
START=15
STOP=90
USE_PROCD=1
PROG=/usr/sbin/ethmngr
. /lib/functions.sh
include /lib/network
include /lib/ethernet
configure_ports(){
configure_ethernet_port(){
local cfg=$1
local ifname enabled speed duplex autoneg eee pause
@@ -24,11 +27,22 @@ configure_ports(){
}
start_service() {
[ -f /lib/network/port.sh ] || return
if [ -s /etc/config/ports ]; then
config_load ports
config_foreach configure_ethernet_port ethport
fi
config_load ports
config_foreach configure_ports ethport
config_foreach configure_ports sfpport
if [ -f $PROG ]; then
procd_open_instance
procd_set_param command ${PROG}
procd_set_param respawn
procd_close_instance
fi
}
reload_service() {
stop
start
}
service_triggers() {

View File

@@ -2,7 +2,8 @@
populate_config_from_db() {
. /lib/functions.sh
include /lib/network
. /lib/network/utils.sh
include /lib/ethernet
portorder="$(db -q get hw.board.ethernetPortOrder)"
for port in $portorder; do

View File

@@ -1,19 +0,0 @@
#!/bin/sh /etc/rc.common
START=95
STOP=10
USE_PROCD=1
PROG=/usr/sbin/ethmngr
start_service() {
procd_open_instance
procd_set_param command ${PROG}
procd_set_param respawn
procd_close_instance
}
reload_service() {
stop
start
}

View File

@@ -0,0 +1,95 @@
# arg1: port ifname, ex: eth0
get_max_port_speed() {
if [ -z "$1" ]; then
echo 0
return
fi
local ifname="$1"
local phycap="$(ethtool $ifname | grep -A 10 "Supported link modes" | grep 000 | tail -n 1 | awk '{print$NF}')"
local speed=1000
case "$phycap" in
10000*) speed=10000 ;;
5000*) speed=5000 ;;
2500*) speed=2500 ;;
1000*) speed=1000 ;;
100*) speed=100 ;;
10*) speed=10 ;;
esac
echo $speed
}
# arg1: port ifname, ex: eth0
# arg2: port enabled, ex: 1
power_updown() {
local ifname="$1"
local enabled=$2
local updown="up"
[ $enabled -eq 0 ] && updown="down"
ip link set dev $ifname $updown
}
# arg1: port ifname, ex: eth0
# arg2: port enabled, ex: 1
# arg3: port speed, ex: 1000
# arg4: port duplex, ex: full
# arg5: port autoneg, ex: on
# arg6: port eee, ex: 0
# arg7: port pause, ex: 0
set_port_settings() {
local ifname="$1"
local enabled=$2
local speed="$3"
local duplex=$4
local autoneg=$5
local eee=$6
local pause=$7
[ -d /sys/class/net/$ifname ] || return
[ $autoneg -eq 1 ] && autoneg="on" || autoneg="off"
ethtool --change $ifname speed $speed duplex $duplex autoneg $autoneg
[ $eee -eq 1 ] && eee="on" || eee="off"
ethtool --set-eee $ifname eee $eee 2>/dev/null
case $pause in
off|0)
pause=0x0
auto=off
rx=off
tx=off
;;
on|1)
pause=0x2
auto=off
rx=on
tx=on
;;
auto)
pause=0x1
auto=on
rx=on
tx=on
;;
tx)
pause=0x3
auto=off
rx=off
tx=on
;;
rx)
pause=0x4
auto=off
rx=on
tx=off
;;
esac
ethtool --pause $ifname autoneg $auto rx $rx tx $tx 2>/dev/null
power_updown $ifname $enabled
}

View File

@@ -8,11 +8,11 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=icwmp
PKG_VERSION:=9.1.2
PKG_VERSION:=9.1.6
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/icwmp.git
PKG_SOURCE_VERSION:=b964edb3570797286584793dbadfbef323cddbeb
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

@@ -205,6 +205,16 @@ enable_dnsmasq_option125() {
fi
}
set_vendor_id() {
local wan="${1}"
local proto="$(uci -q get network.$wan.proto)"
if [ "${proto}" == "dhcp" ]; then
uci -q set network.$wan.vendorid="dslforum.org"
ubus call uci commit '{"config":"network"}'
fi
}
enable_disable_dhcp_option125() {
local wan="${1}"
local action="${2}"
@@ -240,7 +250,7 @@ enable_disable_dhcp_option125() {
uci -q set network.$wan.reqopts="$newreqopts"
network_uci_update=1
fi
.
if [ ${send125_present} -eq 0 ]; then
configure_send_op125 "${sendopts}" "${wan}" "network"
network_uci_update=1
@@ -290,8 +300,9 @@ copy_cwmp_etc_files_to_varstate() {
if [ -f /etc/icwmpd/cwmp ]; then
uci -q -c /etc/icwmpd delete cwmp.acs
uci -q -c /etc/icwmpd delete cwmp.gatewayinfo
uci -q -c /etc/icwmpd commit cwmp
cp -f /etc/icwmpd/cwmp /var/state/cwmp
cat /etc/icwmpd/cwmp >> /var/state/cwmp
fi
if [ -f /etc/icwmpd/icwmpd_backup_session.xml ]; then
@@ -394,15 +405,23 @@ validate_defaults() {
}
boot() {
local enable_cwmp="0"
local dhcp_discovery="0"
config_load cwmp
config_get dhcp_discovery acs dhcp_discovery "0"
config_get_bool enable_cwmp cpe enable 1
if [ "$enable_cwmp" = "0" ]; then
return 0
fi
config_get dhcp_discovery acs dhcp_discovery "0"
config_get wan_interface cpe default_wan_interface "wan"
if [ "${dhcp_discovery}" == "enable" ] || [ "${dhcp_discovery}" == "1" ]; then
# Set dhcp option 43 if not already configured
enable_dhcp_option43 "${wan_interface}"
# Set dhcp option 60
set_vendor_id "${wan_interface}"
fi
config_get lan_interface cpe default_lan_interface ""
@@ -421,6 +440,9 @@ boot() {
regenerate_ssl_link "${ssl_capath}"
fi
# Copy backup data so that if it restart latter on, it gets the info
copy_cwmp_etc_files_to_varstate
start
}
@@ -443,9 +465,6 @@ start_service() {
return 1;
}
# Copy backup data so that if it restart latter on it gets the info
copy_cwmp_etc_files_to_varstate
procd_open_instance icwmp
procd_set_param command "$PROG"
procd_append_param command -b

View File

@@ -1,122 +0,0 @@
#!/bin/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
}
wan_intf=$(uci -q get cwmp.cpe.default_wan_interface)
if [ -n "${wan_intf}" ] && [ "${wan_intf}" == "${INTERFACE}" ]; then
if [ -n "$opt125" ]; then
len=$(printf "$opt125"|wc -c)
get_vivsoi "$opt125" "$len"
fi
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

View File

@@ -5,12 +5,12 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=ieee1905
PKG_VERSION:=6.0.16
PKG_VERSION:=7.0.2
LOCAL_DEV=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=3b12bdd1b0e75f4e5b744e18f00ab5ac703382e6
PKG_SOURCE_VERSION:=47c04c502edf441fef9f14307be5f07541614049
PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/ieee1905.git
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)_$(PKG_SOURCE_VERSION).tar.xz
PKG_MIRROR_HASH:=skip

View File

@@ -44,7 +44,8 @@ validate_ap_section() {
uci_validate_section ieee1905 $section "${1}" \
'band:or("2", "5", "60", "6")' \
'ssid:string' \
'encryption:or("psk2", "sae-mixed", "sae", string)' \
'encryption:or("psk2", "sae-mixed", "sae",
"psk", "psk-mixed", "none", string)' \
'key:string' \
'uuid:string' \
'manufacturer:string' \

View File

@@ -0,0 +1,18 @@
#!/bin/sh
. /lib/functions.sh
config_load ieee1905
ifname_to_list() {
local section=$1
config_get ifname $section ifname # get list or option as space separated values
ifname=${ifname//,/\ } # convert csv with space separation
uci del ieee1905.${section}.ifname # delete entry
for i in ${ifname}; do
uci add_list ieee1905.${section}.ifname="$i" # writeback entry as list
done
}
config_foreach ifname_to_list al-iface

View File

@@ -56,8 +56,8 @@ CONFIG_LOCALMIRROR="https://download.iopsys.eu/iopsys/mirror/"
# EasySoC HAL #
CONFIG_PACKAGE_inbd=y
CONFIG_PACKAGE_libwifi=y
CONFIG_PACKAGE_port-management=y
CONFIG_PACKAGE_qosmngr=y
CONFIG_PACKAGE_libwifiutils=y
CONFIG_PACKAGE_wifimngr=y
# Multi-AP #
@@ -153,6 +153,7 @@ CONFIG_PACKAGE_ip-bridge=y
CONFIG_PACKAGE_ip-full=y
CONFIG_PACKAGE_iperf3=y
CONFIG_PACKAGE_ipset=y
CONFIG_PACKAGE_ip6tables-zz-legacy=y
CONFIG_PACKAGE_iptables-zz-legacy=y
CONFIG_PACKAGE_iptables-mod-conntrack-extra=y
CONFIG_PACKAGE_iptables-mod-filter=y

View File

@@ -276,11 +276,22 @@ function genconfig {
setup_dirs()
{
git remote -v | grep -q http || {
CUSTBRANCH="$(git rev-parse --abbrev-ref HEAD)"
if git ls-remote $CUSTREPO -q 2>/dev/null; then
if [ ! -d "$CUSTPATH" ]; then
git clone "$CUSTREPO" "$CUSTPATH"
echo "Cloning $CUSTBRANCH branch of $CUSTREPO"
git clone -b "$CUSTBRANCH" "$CUSTREPO" "$CUSTPATH" 2>/dev/null || {
DEFBRANCH="$(git remote show $CUSTREPO | grep 'HEAD branch' | cut -d' ' -f5)"
echo "$CUSTBRANCH branch is not found, cloning $DEFBRANCH branch of $CUSTREPO"
git clone "$CUSTREPO" "$CUSTPATH"
}
elif [ $IMPORT -eq 1 ]; then
cd $CUSTPATH
echo "Checking out $CUSTBRANCH branch in $CUSTPATH"
git checkout "$CUSTBRANCH" 2>/dev/null || {
DEFBRANCH="$(git symbolic-ref refs/remotes/origin/HEAD | cut -d '/' -f4)"
echo "Checking out $CUSTBRANCH branch has failed, using $DEFBRANCH branch in $CUSTPATH"
}
v "git pull"
git pull
cd - >/dev/null #go back
@@ -340,7 +351,7 @@ function genconfig {
echo "" >> .config
fi
# Special handling for targets which use TARGET_DEVICES
# Special handling for targets which use TARGET_DEVICES
case "$target" in
iopsys_ramips | airoha | iopsys_mediatek | brcmbca | ipq95xx)
# This assumes the device name to be unique within one target,

View File

@@ -192,12 +192,6 @@ function genconfig_min {
git remote -v | grep -qE '(git@|ssh://)' && {
DEVELOPER=1
bcmAllowed=0
endptAllowed=0
git ls-remote git@dev.iopsys.eu:broadcom/bcmcreator.git -q 2>/dev/null && bcmAllowed=1
git ls-remote git@dev.iopsys.eu:iopsys/endptmngr.git -q 2>/dev/null && endptAllowed=1
}
v() {

View File

@@ -16,7 +16,7 @@ LOCAL_DEV=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/$(PKG_NAME).git
PKG_SOURCE_VERSION:=b53e93ca1a2fdda56ca9caffb6020e158e684f3d
PKG_SOURCE_VERSION:=d066c9d5c14757ab38e9ecb265ba24f5b33cdbce
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
endif

View File

@@ -5,9 +5,9 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=map-agent
PKG_VERSION:=2.10.4.11
PKG_VERSION:=4.1.0.1
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_VERSION:=0852c7803475f7fb919f680d02437ba9672c42fc
PKG_SOURCE_VERSION:=c708092f56110637f04d87d309dcbce8fd389b89
PKG_MAINTAINER:=Anjan Chanda <anjan.chanda@iopsys.eu>
PKG_LICENSE:=BSD-3-Clause

View File

@@ -104,7 +104,11 @@ validate_radio_section() {
'include_sta_metric:bool:false' \
'rcpi_hysteresis_margin:range(0,255)' \
'report_util_threshold:range(0,255)' \
'encryption:or("sae", "psk2", "sae-mixed")'
'encryption:or("sae", "sae+aes", "psk2",
"psk2+aes", "sae-mixed", "sae-mixed+aes",
"none", "psk-mixed", "psk-mixed+aes",
"wpa", "wpa+aes", "wpa2", "wpa2+aes",
"psk", "psk+aes")' \
[ "$?" -ne 0 ] && {
logger -s -t "mapagent" "Validation of radio section failed"

View File

@@ -5,9 +5,9 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=map-controller
PKG_VERSION:=2.11.0.20
PKG_VERSION:=4.1.0.2
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_VERSION:=5ff7f037c040d337982a1e3a51693fb8e0682046
PKG_SOURCE_VERSION:=8b7bb003611247309b072350d7986e304b0d228b
LOCAL_DEV=0
ifneq ($(LOCAL_DEV),1)
@@ -26,7 +26,7 @@ define Package/map-controller
SECTION:=utils
CATEGORY:=Utilities
TITLE:=WiFi Multi-AP Controller (EasyMesh R2)
DEPENDS:=+libuci +libubox +ubus +libeasy +libieee1905 +ieee1905 +map-plugin
DEPENDS:=+libuci +libubox +ubus +libeasy +libwifiutils +libieee1905 +ieee1905 +map-plugin
endef
define Package/map-controller/description

View File

@@ -45,7 +45,13 @@ validate_sta_steering_section() {
'use_bcn_metrics:bool:false' \
'use_usta_metrics:bool:false' \
'bandsteer:bool:false' \
'diffsnr:range(0,100)'
'diffsnr:range(0,100)' \
'rcpi_threshold_2g:range(0,220)' \
'rcpi_threshold_5g:range(0,220)' \
'rcpi_threshold_6g:range(0,220)' \
'report_rcpi_threshold_2g:range(0,220)' \
'report_rcpi_threshold_5g:range(0,220)' \
'report_rcpi_threshold_6g:range(0,220)'
[ "$?" -ne 0 ] && {
logger -s -t "mapcontroller" "Validation of sta_steering section failed"
@@ -62,7 +68,10 @@ validate_ap_section() {
'band:or("2", "5", "6")' \
'ssid:string' \
'encryption:or("sae", "sae+aes", "psk2",
"psk2+aes", "sae-mixed", "sae-mixed+aes")' \
"psk2+aes", "sae-mixed", "sae-mixed+aes",
"none", "psk-mixed", "psk-mixed+aes",
"wpa", "wpa+aes", "wpa2", "wpa2+aes",
"psk", "psk+aes")' \
'key:string' \
'vid:range(1,65535):1' \
'type:or("backhaul", "fronthaul", "combined")' \
@@ -190,7 +199,7 @@ reload_service() {
return
fi
pidof "mapcontroller" > /dev/null
pidof "/usr/sbin/mapcontroller" > /dev/null
if [[ $? -ne 0 ]] ; then
start
return

View File

@@ -6,11 +6,11 @@ include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=map-topology
PKG_VERSION:=2.5.1.13
PKG_VERSION:=2.5.1.15
LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_VERSION:=aaa55a72e719184af32d57a9b40bec1c440774a9
PKG_SOURCE_VERSION:=14ff07452aec4ff6f2268ef7bea9ff417252b7be
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/map-topology.git
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.xz

View File

@@ -4,3 +4,4 @@ config topology 'topology'
option depth '8'
option interval '60'
option maxlog '32'
option profile '2'

View File

@@ -0,0 +1,126 @@
#!/bin/sh
. /lib/functions.sh
day=""
IP_RULE=""
process_ac_schedule() {
local acs_id="$1"
local is_enabled
local access_control
local start_time=""
local stop_time=""
local mac=""
handle_day_list() {
local value=$1
val=$(echo $value | cut -c 1-3)
if [ -z $day ]; then
day="$val"
else
day="$day,$val"
fi
}
config_list_foreach "$acs_id" "day" handle_day_list
config_get is_enabled "$acs_id" "enable" 1
config_get access_control "$acs_id" "dm_parent"
if [ "$is_enabled" == "0" ] || [ -z "$access_control" ]; then
return
fi
IP_RULE=""
mac=$(uci -q get hosts.$access_control.macaddr)
access_policy=$(uci -q get hosts.$access_control.access_policy)
config_get start_time "$acs_id" "start_time"
config_get duration "$acs_id" "duration"
if [ -z "$mac" ] && [ -z "$start_time" ] && [ -z "$duration" ] && [ -z "$day" ] && [ -z "$access_policy" ]; then
return
fi
if [ -n "$mac" ]; then
IP_RULE="$IP_RULE -m mac --mac-source $mac"
fi
# as per iptables manual default starttime is 00:00
# default stoptime is 23:59
if [ -z "$start_time" ]; then
start_time="0:0"
fi
if [ -n "$duration" ]; then
hh=$(echo $start_time | awk -F: '{ print $1 }')
mm=$(echo $start_time | awk -F: '{ print $2 }')
hh_s=`expr $hh \* 3600`
mm_s=`expr $mm \* 60`
ss=$(( hh_s + mm_s ))
stop_ss=$(( ss + duration ))
hh=$(( stop_ss / 3600 ))
if [ $hh -lt 24 ]; then
rem_ss=$(( stop_ss % 3600 ))
mm=$(( rem_ss / 60 ))
ss=$(( rem_ss % 60 ))
stop_time="$hh:$mm:$ss"
else
stop_time="23:59"
fi
else
stop_time="23:59"
fi
# conversion to utc
zone=$(date +%z | cut -c 1)
utc_h=$(date -u -d @$(date "+%s" -d "$start_time") +%H)
local_h=$(echo $start_time | awk -F: '{ print $1 }')
if [ "$zone" == "+" ] && [ $utc_h -gt $local_h ]; then
start_utc="0:0"
else
start_utc=$(date -u -d @$(date "+%s" -d "$start_time") +%H:%M)
fi
utc_h=$(date -u -d @$(date "+%s" -d "$stop_time") +%H)
local_h=$(echo $stop_time | awk -F: '{ print $1 }')
if [ "$zone" == "-" ] && [ $utc_h -lt $local_h ]; then
stop_utc="23:59"
else
stop_utc=$(date -u -d @$(date "+%s" -d "$stop_time") +%H:%M)
fi
IP_RULE="$IP_RULE -m time --timestart $start_utc --timestop $stop_utc"
if [ -n "$day" ]; then
IP_RULE="$IP_RULE --weekdays $day"
fi
if [ "$access_policy" == "Deny" ]; then
IP_RULE="$IP_RULE -j DROP"
else
IP_RULE="$IP_RULE -j ACCEPT"
fi
iptables -w -A hosts_forward ${IP_RULE}
ip6tables -w -A hosts_forward ${IP_RULE}
day=""
}
iptables -w -F hosts_forward
ip6tables -w -F hosts_forward
iptables -w -t filter -N hosts_forward
ret=$?
[ $ret -eq 0 ] && iptables -w -t filter -I FORWARD -j hosts_forward
ip6tables -w -t filter -N hosts_forward
ret=$?
[ $ret -eq 0 ] && ip6tables -w -t filter -I FORWARD -j hosts_forward
# Load /etc/config/hosts UCI file
config_load hosts
config_foreach process_ac_schedule ac_schedule

View File

@@ -71,6 +71,10 @@ start_service() {
config_load "hosts"
validate_hosts_config || return 1;
if [ -f "/proc/sys/net/netfilter/nf_conntrack_timestamp" ]; then
echo 1 >/proc/sys/net/netfilter/nf_conntrack_timestamp
fi
procd_open_instance
procd_set_param command "/usr/sbin/topologyd"
procd_set_param respawn

View File

@@ -0,0 +1,12 @@
#!/bin/sh
if [ -f /etc/firewall.hosts ]; then
uci -q get firewall.hosts || {
uci -q set firewall.hosts=include
uci -q set firewall.hosts.path="/etc/firewall.hosts"
uci -q set firewall.hosts.reload=1
}
fi
exit 0

View File

@@ -5,13 +5,13 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=obuspa
PKG_VERSION:=6.0.0.11
PKG_VERSION:=7.0.0.1
LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/fork/obuspa.git
PKG_SOURCE_VERSION:=668748cd4801aa5af12d61d9b0837064b9f933cc
PKG_SOURCE_VERSION:=5d4bacd53a8ca27948108009bb48c2c6c9508c1d
PKG_MAINTAINER:=Vivek Dutta <vivek.dutta@iopsys.eu>
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
@@ -110,6 +110,7 @@ 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/50-add-mqtt-usp-test $(1)/etc/uci-defaults/
endef
$(eval $(call BuildPackage,obuspa))

View File

@@ -11,54 +11,22 @@ config obuspa 'global'
#option log_dest '/var/log/obuspa'
# Adds Device.LocalAgent.MTP.
config mtp 'agent_mtp'
config mtp 'test_mtp'
option Protocol 'MQTT'
option ResponseTopicConfigured '/usp/endpoint'
option mqtt 'localmqtt'
option mqtt 'testmqtt'
# Adds Device.MQTT.Client.
config mqtt 'localmqtt'
config mqtt 'testmqtt'
option BrokerAddress '127.0.0.1'
option BrokerPort '1883'
option TransportProtocol 'TCP/IP'
# Adds Device.LocalAgent.Controller.
config controller 'localcontroller'
config controller 'testcontroller'
option EndpointID 'proto::interop-usp-controller'
option Protocol 'MQTT'
option Topic '/usp/controller'
option mqtt 'localmqtt'
option mqtt 'testmqtt'
option assigned_role_name 'full_access'
# Add Device.LocalAgent.Subscription.
#config subscription 'sub_event'
# option ID 'uci-sub-events'
# option NotifType 'Event'
# list ReferenceList 'Device.Boot!'
# list ReferenceList 'Device.LocalAgent.TransferComplete!'
# option Persistent 'true'
# option controller 'localcontroller'
#config subscription 'sub_op_comp'
# option ID 'uci-sub-op_complete'
# option NotifType 'OperationComplete'
# list ReferenceList 'Device.DeviceInfo.FirmwareImage.*.Download()'
# list ReferenceList 'Device.DeviceInfo.FirmwareImage.*.Activate()'
# option Persistent 'true'
# option controller 'localcontroller'
#config challenge 'admin'
# option Description 'Request to get Administrative access'
# option role_name 'full_access'
# option Enable '1'
# option Value 'YWRtaW4='
# option Retries 2
# option LockoutPeriod 60
#config challenge 'user'
# option Description 'Request to get User access'
# option role_name 'user'
# option Enable '1'
# option Value 'dXNlcg=='
# option Retries 3
# option LockoutPeriod 30

View File

@@ -314,7 +314,7 @@ publish_endpoint()
{
local AgentEndpointID serial oui user pass
if ! uci -q get obuspa.localmqtt; then
if ! uci -q get obuspa.testmqtt; then
return 0;
fi
@@ -330,11 +330,11 @@ publish_endpoint()
if [ -z "${AgentEndpointID}" ]; then
serial=$(get_serial_from_db)
oui=$(get_oui_from_db)
AgentEndpointID="os::${oui}-${serial}"
AgentEndpointID="os::${oui}-${serial//+/%2B}"
fi
config_get user localmqtt Username
config_get pass localmqtt Password
config_get user testmqtt Username
config_get pass testmqtt Password
# publish Agent's EndpointID in mosquito broker for discovery by usp-js
# This is a work around till obuspa adds supports for mDNS discovery

View File

@@ -0,0 +1,14 @@
add_usp_test()
{
if ! uci_get mosquitto usptest >/dev/null 2>&1; then
uci_add mosquitto listener usptest
uci_set mosquitto usptest enabled 1
uci_set mosquitto usptest port '9001'
uci_set mosquitto usptest protocol 'websockets'
uci_set mosquitto usptest require_certificates '0'
uci_set mosquitto usptest auth_plugin '/usr/lib/mosquitto_auth_shadow.so'
fi
}
uci_load mosquitto
add_usp_test

View File

@@ -1,140 +0,0 @@
diff --git a/src/core/device.h b/src/core/device.h
index adf8fa6..072f953 100644
--- a/src/core/device.h
+++ b/src/core/device.h
@@ -111,6 +111,7 @@ typedef struct
// Following member variables only set if USP message was received over MQTT
int mqtt_instance;
char *mqtt_topic; // only set if reply_to was specified in the received MQTT packet
+ char *mqtt_topic_recv;
// Following member variables only set if USP message was received over CoAP
@@ -252,7 +253,7 @@ void DEVICE_MTP_NotifyMqttConnDeleted(int mqtt_instance);
int DEVICE_MTP_ValidateMqttReference(dm_req_t *req, char *value);
void DEVICE_CONTROLLER_SetRolesFromMqtt(int mqtt_instance, ctrust_role_t role);
char *DEVICE_CONTROLLER_GetControllerTopic(int mqtt_instance);
-
+int validate_controller_topic_by_endpointid(char *endpointid, mtp_protocol_t proto, char *recv_topic);
//------------------------------------------------------------------------------
// Tables used to convert to/from an enumeration to/from a string
extern const enum_entry_t mtp_protocols[kMtpProtocol_Max];
diff --git a/src/core/device_controller.c b/src/core/device_controller.c
index 62c803f..103388d 100755
--- a/src/core/device_controller.c
+++ b/src/core/device_controller.c
@@ -239,6 +239,41 @@ int Async_E2ESessionReset(dm_req_t *req, kv_vector_t *input_args, int request);
extern const enum_entry_t e2e_session_modes[kE2EMode_Max];
#endif
+
+int validate_controller_topic_by_endpointid(char *endpointid, mtp_protocol_t proto, char *recv_topic)
+{
+ controller_t *cont = FindEnabledControllerByEndpointId(endpointid);
+ if (cont == NULL)
+ {
+ USP_LOG_Error("not able to find the controller from endpointid [%s]", endpointid);
+ return USP_ERR_PERMISSION_DENIED;
+ }
+#ifdef ENABLE_MQTT
+ if (proto == kMtpProtocol_MQTT)
+ {
+ controller_mtp_t *mtp = FindFirstEnabledMtp(cont, proto);
+
+ if (mtp == NULL) {
+ USP_LOG_Error("Not able to find mtp[%d] for endpointid [%s]", proto, endpointid);
+ return USP_ERR_REQUEST_DENIED;
+ }
+
+ if (mtp->protocol != proto) {
+ USP_LOG_Error("No matching mtp[%d] for endpointid [%s]", proto, endpointid);
+ return USP_ERR_REQUEST_DENIED;
+ }
+
+ char *response_topic = DEVICE_MTP_GetAgentMqttResponseTopic(mtp->mqtt_connection_instance);
+ if (response_topic && strcmp(response_topic, recv_topic) != 0 ) {
+ USP_LOG_Error("Controller response topic[%s] and recv topic[%s] mismatch, probably a spoof message", response_topic, recv_topic);
+ return USP_ERR_PERMISSION_DENIED;
+ }
+ }
+#endif
+
+ return USP_ERR_OK;
+}
+
/*********************************************************************//**
**
** DEVICE_CONTROLLER_Init
diff --git a/src/core/dm_exec.c b/src/core/dm_exec.c
index c0b95d8..6eb51e2 100755
--- a/src/core/dm_exec.c
+++ b/src/core/dm_exec.c
@@ -624,6 +624,7 @@ void DM_EXEC_PostUspRecord(unsigned char *pbuf, int pbuf_len, ctrust_role_t role
pur->mtp_reply_to.coap_encryption = mrt->coap_encryption;
pur->mtp_reply_to.coap_reset_session_hint = mrt->coap_reset_session_hint;
pur->mtp_reply_to.mqtt_topic = USP_STRDUP(mrt->mqtt_topic);
+ pur->mtp_reply_to.mqtt_topic_recv = USP_STRDUP(mrt->mqtt_topic_recv);
pur->mtp_reply_to.mqtt_instance = mrt->mqtt_instance;
pur->mtp_reply_to.wsclient_cont_instance = mrt->wsclient_cont_instance;
pur->mtp_reply_to.wsclient_mtp_instance = mrt->wsclient_mtp_instance;
@@ -1144,6 +1145,7 @@ void ProcessMessageQueueSocketActivity(socket_set_t *set)
USP_SAFE_FREE(mrt->coap_resource);
USP_SAFE_FREE(mrt->mqtt_topic);
USP_SAFE_FREE(mrt->cont_endpoint_id);
+ USP_SAFE_FREE(mrt->mqtt_topic_recv);
break;
#ifndef DISABLE_STOMP
diff --git a/src/core/mqtt.c b/src/core/mqtt.c
index 7dba9f4..3ee9c97 100644
--- a/src/core/mqtt.c
+++ b/src/core/mqtt.c
@@ -3141,6 +3141,7 @@ void ReceiveMqttMessage(mqtt_client_t *client, const struct mosquitto_message *m
mrt.mqtt_topic = response_topic;
}
+ mrt.mqtt_topic_recv = message->topic;
// Message may not be valid USP
DM_EXEC_PostUspRecord(message->payload, message->payloadlen, client->role, &mrt);
}
diff --git a/src/core/msg_handler.c b/src/core/msg_handler.c
index ce67626..4af9ade 100644
--- a/src/core/msg_handler.c
+++ b/src/core/msg_handler.c
@@ -118,7 +118,7 @@ static enum_entry_t mtp_content_types[] = {
//------------------------------------------------------------------------------
// Forward declarations. Note these are not static, because we need them in the symbol table for USP_LOG_Callstack() to show them
int HandleUspMessage(Usp__Msg *usp, char *controller_endpoint, mtp_reply_to_t *mrt);
-int ValidateUspRecord(UspRecord__Record *rec);
+int ValidateUspRecord(UspRecord__Record *rec, mtp_reply_to_t *mrt);
char *MtpSendItemToString(mtp_send_item_t *msi);
void CacheControllerRoleForCurMsg(char *endpoint_id, ctrust_role_t role, mtp_protocol_t protocol);
int QueueUspNoSessionRecord(usp_send_item_t *usi, char *endpoint_id, char *usp_msg_id, mtp_reply_to_t *mrt, time_t expiry_time);
@@ -172,7 +172,7 @@ int MSG_HANDLER_HandleBinaryRecord(unsigned char *pbuf, int pbuf_len, ctrust_rol
#endif
// Exit if USP record failed validation
- err = ValidateUspRecord(rec);
+ err = ValidateUspRecord(rec, mrt);
if (err != USP_ERR_OK)
{
goto exit;
@@ -725,7 +725,7 @@ exit:
** \return USP_ERR_OK if record is valid
**
**************************************************************************/
-int ValidateUspRecord(UspRecord__Record *rec)
+int ValidateUspRecord(UspRecord__Record *rec, mtp_reply_to_t *mrt)
{
char *endpoint_id;
@@ -806,6 +806,9 @@ int ValidateUspRecord(UspRecord__Record *rec)
return USP_ERR_REQUEST_DENIED;
}
+#if OBUSPA_CONTROLLER_MTP_VERIFY
+ return validate_controller_topic_by_endpointid(rec->from_id, mrt->protocol, mrt->mqtt_topic_recv);
+#endif
// If the code gets here, then the USP record passed validation, and the encapsulated USP message may be processed
return USP_ERR_OK;
}

View File

@@ -39,6 +39,8 @@ ifneq ($(CONFIG_TARGET_brcmbca),)
else ifneq ($(CONFIG_TARGET_airoha),)
$(CP) ./files/airoha/* $(1)/
endif
$(INSTALL_DIR) $(1)/etc/bbfdm/json
$(CP) ./files/etc/bbfdm/json/* $(1)/etc/bbfdm/json/
endef
$(eval $(call BuildPackage,ponmngr))

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
<tbody><tr><td colspan="2"><div style="font-weight: bold">xpon</div><table style="width:100%"><tbody><tr><td><div style="font-weight: bold; font-size: 14px">section</div></td><td><div style="font-weight: bold; font-size: 14px">description</div></td><td><div style="font-weight: bold; font-size: 14px">multi</div></td><td><div style="font-weight: bold; font-size: 14px">options</div></td></tr><tr><td class="td_row_even"><div class="td_row_even">ani</div></td><td class="td_row_even"><div class="td_row_even">xpon ani configuration</div></td><td class="td_row_even"><div class="td_row_even">false</div></td><td class="td_row_even"><table style="width:100%"><tbody><tr><td><div style="font-weight: bold; font-size: 14px">name</div></td><td><div style="font-weight: bold; font-size: 14px">type</div></td><td><div style="font-weight: bold; font-size: 14px">required</div></td><td><div style="font-weight: bold; font-size: 14px">default</div></td><td><div style="font-weight: bold; font-size: 14px">description</div></td></tr><tr><td class="td_row_even"><div class="td_row_even">enable</div></td><td class="td_row_even"><div class="td_row_even">boolean</div></td><td class="td_row_even"><div class="td_row_even">yes</div></td><td class="td_row_even"><div class="td_row_even">false</div></td><td class="td_row_even"><div class="td_row_even">ONU is enabled as pon functionality.</div></td></tr><tr><td class="td_row_odd"><div class="td_row_odd">serial_number</div></td><td class="td_row_odd"><div class="td_row_odd">string</div></td><td class="td_row_odd"><div class="td_row_odd">yes</div></td><td class="td_row_odd"><div class="td_row_odd">null</div></td><td class="td_row_odd"><div class="td_row_odd">Serial number of ONU, Unique for each ONU.</div></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody>

View File

@@ -0,0 +1,143 @@
# Function Specification
## Introduction
This will be a short description of how to setup ONU and enable ANI.
## Overview
ponmngr UCI Config
```
config ani 'ani'
option enable '1'
option serial_number 'IOPS18000001'
```
## Notes
* `serial_number` is the unique for each ONU, In case `serial_number` has not
* been set from production in that case `serial_number` is calculated using
* the combination of vendor "IOPS" and last 4 octet of device mac address.
* same serial number should avaibale in OLT for the corresponding ONU profile
After ubus starts the xpon methods can be invoked to get the status
For all available status the command can be used without parameters, such as
```
root@iopsys:~# ubus call xpon status
{
"ONU": [
{
"Enable": true,
"Version": "",
"EquipmentID": "BVM4K00BRA",
"softwareImage": [
{
"ID": 0,
"Version": "7.2.0alpha0-5",
"IsValid": true,
"IsActive": false,
"IsCommitted": false
},
{
"ID": 1,
"Version": "7.2.0alpha0-5",
"IsValid": true,
"IsActive": true,
"IsCommitted": true
}
],
"EthernetUNI": [
{
"Enable": true,
"Status": "UP",
"ANIs": "gpon0.0",
"InterDomainID": "(VEIP,1025)",
"InterDomainName": "VEIP",
"Stats": {
"BytesSent": 39891,
"BytesReceived": 50296,
"PacketsSent": 314,
"PacketsReceived": 384
}
},
{
"Enable": true,
"Status": "UP",
"ANIs": "gpon0.0",
"InterDomainID": "(VEIP,1025)",
"InterDomainName": "VEIP",
"Stats": {
"BytesSent": 54499,
"BytesReceived": 47908,
"PacketsSent": 286,
"PacketsReceived": 273
}
},
{
"Enable": false,
"Status": "DOWN",
"ANIs": "gpon0.0",
"InterDomainID": "(VEIP,1025)",
"InterDomainName": "VEIP",
"Stats": {
"BytesSent": 0,
"BytesReceived": 0,
"PacketsSent": 0,
"PacketsReceived": 0
}
},
{
"Enable": false,
"Status": "DOWN",
"ANIs": "gpon0.0",
"InterDomainID": "(VEIP,1025)",
"InterDomainName": "VEIP",
"Stats": {
"BytesSent": 0,
"BytesReceived": 0,
"PacketsSent": 0,
"PacketsReceived": 0
}
}
],
"ANI": [
{
"Enable": true,
"Status": "Up",
"PONMode": "GPON",
"Stats": {
"BytesSent": 228,
"BytesReceived": 408394,
"PacketsSent": 2,
"PacketsReceived": 2328
}
}
],
"Transceiver": [
{
"ID": 0,
"Identifier": 3,
"ModuleVendor": "MENTECHOPTO",
"ModuleName": "MSOG22-LDCC-ACCO",
"ModuleVersion": "MNC221K90309",
"ModuleFirmwareVersion": "1.0",
"PONMode": "GPON",
"TxPower": 16,
"RxPower": -240,
"Voltage": 3300,
"Bias": 15744,
"Temperature": 270
}
]
}
]
}
```
UCI to invoke pon manager to enable status of ani, such as
```
```

View File

@@ -0,0 +1,25 @@
{
"xpon":
[
{
"section": "ani",
"description": "xpon ani configuration",
"multi": "false",
"options": [
{
"name": "enable",
"type": "boolean",
"required": "yes",
"default": "false",
"description": "ONU is enabled as pon functionality."
},{
"name": "serial_number",
"type": "string",
"required": "yes",
"default": null,
"description": "Serial number of ONU, Unique for each ONU."
}
]
}
]
}

View File

@@ -0,0 +1,936 @@
{
"json_plugin_version": 1,
"Device.XPON.": {
"type": "object",
"protocols": [
"cwmp",
"usp"
],
"access": false,
"array": false,
"dependency": "file:/etc/config/xpon",
"ONUNumberOfEntries": {
"type": "unsignedInt",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedInt",
"mapping": [
{
"type": "ubus",
"ubus": {
"object": "xpon",
"method": "status",
"args": {},
"key": "ONU.@Count"
}
}
]
},
"Device.XPON.ONU.{i}.": {
"type": "object",
"protocols": [
"cwmp",
"usp"
],
"access": false,
"array": true,
"mapping": [
{
"type": "ubus",
"ubus": {
"object": "xpon",
"method": "status",
"args": {},
"key": "ONU"
}
}
],
"Enable": {
"type": "boolean",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "boolean",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Enable"
}
]
},
"Version": {
"type": "string",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "string",
"range": [
{
"max": 14
}
],
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Version"
}
]
},
"EquipmentID": {
"type": "string",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "string",
"range": [
{
"max": 20
}
],
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "EquipmentID"
}
]
},
"SoftwareImageNumberOfEntries": {
"type": "unsignedInt",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedInt",
"mapping": [
{
"type": "ubus",
"ubus": {
"object": "xpon",
"method": "status",
"args": {},
"key": "ONU[@index].softwareImage.@Count"
}
}
]
},
"EthernetUNINumberOfEntries": {
"type": "unsignedInt",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedInt",
"mapping": [
{
"type": "ubus",
"ubus": {
"object": "xpon",
"method": "status",
"args": {},
"key": "ONU[@index].EthernetUNI.@Count"
}
}
]
},
"ANINumberOfEntries": {
"type": "unsignedInt",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedInt",
"mapping": [
{
"type": "ubus",
"ubus": {
"object": "xpon",
"method": "status",
"args": {},
"key": "ONU[@index].ANI.@Count"
}
}
]
},
"TransceiverNumberOfEntries": {
"type": "unsignedInt",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedInt",
"mapping": [
{
"type": "ubus",
"ubus": {
"object": "xpon",
"method": "status",
"args": {},
"key": "ONU[@index].Transceiver.@Count"
}
}
]
},
"Device.XPON.ONU.{i}.SoftwareImage.{i}.": {
"type": "object",
"protocols": [
"cwmp",
"usp"
],
"access": false,
"array": true,
"mapping": [
{
"type": "ubus",
"ubus": {
"object": "xpon",
"method": "status",
"args": {},
"key": "ONU[@index].softwareImage"
}
}
],
"ID": {
"type": "unsignedInt",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedInt",
"range": [
{
"min": 0,
"max": 1
}
],
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "ID"
}
]
},
"Version": {
"type": "string",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "string",
"range": [
{
"max": 14
}
],
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Version"
}
]
},
"IsCommitted": {
"type": "boolean",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "boolean",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "IsCommitted"
}
]
},
"IsActive": {
"type": "boolean",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "boolean",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "IsActive"
}
]
},
"IsValid": {
"type": "boolean",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "boolean",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "IsValid"
}
]
}
},
"Device.XPON.ONU.{i}.EthernetUNI.{i}.": {
"type": "object",
"protocols": [
"cwmp",
"usp"
],
"access": false,
"array": true,
"mapping": [
{
"type": "ubus",
"ubus": {
"object": "xpon",
"method": "status",
"args": {},
"key": "ONU[@index].EthernetUNI"
}
}
],
"Enable": {
"type": "boolean",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "boolean",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Enable"
}
]
},
"Status": {
"type": "string",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "string",
"enumerations": [
"Up",
"Down",
"unknown",
"Dormant",
"NotPresent",
"LowerLayerDown",
"Error"
],
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Status"
}
]
},
"ANIs": {
"type": "string",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "string",
"range": [
{
"max": 1024
}
],
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "ANIs"
}
]
},
"InterdomainID": {
"type": "string",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "string",
"range": [
{
"max": 256
}
],
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "InterDomainID"
}
]
},
"InterdomainName": {
"type": "string",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "string",
"range": [
{
"max": 25
}
],
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "InterDomainName"
}
]
},
"Device.XPON.ONU.{i}.EthernetUNI.{i}.Stats.": {
"type": "object",
"protocols": [
"cwmp",
"usp"
],
"access": false,
"array": false,
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Stats"
}
],
"BytesSent": {
"type": "unsignedLong",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedLong",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Stats.BytesSent"
}
]
},
"BytesReceived": {
"type": "unsignedLong",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedLong",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Stats.BytesReceived"
}
]
},
"PacketsSent": {
"type": "unsignedLong",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedLong",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Stats.PacketsSent"
}
]
},
"PacketsReceived": {
"type": "unsignedLong",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedLong",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Stats.PacketsReceived"
}
]
}
}
},
"Device.XPON.ONU.{i}.ANI.{i}.": {
"type": "object",
"protocols": [
"cwmp",
"usp"
],
"access": false,
"array": true,
"mapping": [
{
"type": "ubus",
"ubus": {
"object": "xpon",
"method": "status",
"args": {},
"key": "ONU[@index].ANI"
}
}
],
"Enable": {
"type": "boolean",
"read": true,
"write": true,
"protocols": [
"cwmp",
"usp"
],
"datatype": "boolean",
"mapping": [
{
"rpc": "get",
"data": "@Parent",
"type": "json",
"key": "Enable"
},
{
"rpc": "set",
"type": "uci",
"uci": {
"file": "xpon",
"section": {
"name": "ani"
},
"option": {
"name": "enable"
}
}
}
]
},
"Status": {
"type": "string",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "string",
"enumerations": [
"Up",
"Down",
"Dormant",
"Unknown",
"NotPresent",
"Error"
],
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Status"
}
]
},
"PONMode": {
"type": "string",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "string",
"enumerations": [
"GPON",
"XG-PON",
"NG-PON2",
"XGS-PON"
],
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "PONMode"
}
]
},
"Device.XPON.ONU.{i}.ANI.{i}.Stats.": {
"type": "object",
"protocols": [
"cwmp",
"usp"
],
"access": false,
"array": false,
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Stats"
}
],
"BytesSent": {
"type": "unsignedLong",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedLong",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Stats.BytesSent"
}
]
},
"BytesReceived": {
"type": "unsignedLong",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedLong",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Stats.BytesReceived"
}
]
},
"PacketsSent": {
"type": "unsignedLong",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedLong",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Stats.PacketsSent"
}
]
},
"PacketsReceived": {
"type": "unsignedLong",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedLong",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Stats.PacketsReceived"
}
]
}
}
},
"Device.XPON.ONU.{i}.Transceiver.{i}.": {
"type": "object",
"protocols": [
"cwmp",
"usp"
],
"access": false,
"array": true,
"mapping": [
{
"type": "ubus",
"ubus": {
"object": "xpon",
"method": "status",
"args": {},
"key": "ONU[@index].Transceiver"
}
}
],
"ID": {
"type": "unsignedInt",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedInt",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "ID"
}
]
},
"Identifier": {
"type": "unsignedInt",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedInt",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Identifier"
}
]
},
"ModuleVendor": {
"type": "string",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "string",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "ModuleVendor"
}
]
},
"ModuleName": {
"type": "string",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "string",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "ModuleName"
}
]
},
"ModuleVersion": {
"type": "string",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "string",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "ModuleVersion"
}
]
},
"ModuleFirmwareVersion": {
"type": "string",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "string",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "ModuleFirmwareVersion"
}
]
},
"PONMode": {
"type": "string",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "string",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "PONMode"
}
]
},
"RxPower": {
"type": "int",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "int",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "RxPower"
}
]
},
"TxPower": {
"type": "int",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "int",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "TxPower"
}
]
},
"Voltage": {
"type": "unsignedInt",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedInt",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Voltage"
}
]
},
"Bias": {
"type": "unsignedInt",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedInt",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Bias"
}
]
},
"Temperature": {
"type": "int",
"read": true,
"write": false,
"protocols": [
"cwmp",
"usp"
],
"datatype": "int",
"mapping": [
{
"data": "@Parent",
"type": "json",
"key": "Temperature"
}
]
}
}
}
}
}

300
ponmngr/xpon_ubus.json Normal file
View File

@@ -0,0 +1,300 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "xpon",
"object": "xpon",
"properties": {
"status": {
"type": "object",
"properties": {
"output": {
"type": "object",
"required": [
],
"properties": {
"ONU": {
"type": "array",
"items": {
"type": "object",
"required": [
"Enable",
"Version",
"EquipmentID",
"SoftwareImage",
"EthernetUNI",
"ANI",
"Transceiver"
],
"properties": {
"Enable": {
"type": "boolean",
"default": "false"
},
"Version": {
"type": "string"
},
"EquipmentID": {
"type": "string",
"minLength": 1,
"maxLength": 20
},
"SoftwareImage": {
"type": "array",
"items": {
"type": "object",
"required": [
"ID",
"Version",
"IsCommitted",
"IsActive",
"IsValid"
],
"properties": {
"ID": {
"type": "integer",
"minimum": 0,
"maximum": 1
},
"Version": {
"type": "string",
"minLength": 1,
"maxLength": 14,
"default": "7.2_BETA2"
},
"IsCommitted": {
"type": "boolean",
"default": "false"
},
"IsActive": {
"type": "boolean",
"default": "false"
},
"IsValid": {
"type": "boolean",
"default": "false"
}
}
}
},
"EthernetUNI": {
"type": "array",
"items": {
"type": "object",
"required": [
"Enable",
"Status",
"ANIs",
"InterdomainID",
"InterdomainName",
"Stats"
],
"properties": {
"Enable": {
"type": "boolean",
"default": "false"
},
"Status": {
"type": "string",
"enum": [
"Up",
"Down",
"unknown",
"Dormant",
"NotPresent",
"LowerLayerDown",
"Error"
]
},
"ANIs": {
"type": "string",
"minLength": 1,
"maxLength": 1024,
"pattern": "gpon[0-9]\\.[0-9]"
},
"InterdomainID": {
"type": "string",
"minLength": 1,
"maxLength": 256,
"pattern": "(VEIP|PPTPEthernetUNI),(1025|257)"
},
"InterdomainName": {
"type": "string",
"minLength": 1,
"maxLength": 25,
"default": "VEIP"
},
"Stats": {
"items": {
"type": "object",
"required": [
"BytesSent",
"BytesReceived",
"PacketsSent",
"PacketsReceived"
],
"properties": {
"BytesSent": {
"type": "integer",
"minimum": 0
},
"BytesReceived": {
"type": "integer",
"minimum": 0
},
"PacketsSent": {
"type": "integer",
"minimum": 0
},
"PacketsReceived": {
"type": "integer",
"minimum": 0
}
}
}
}
}
}
},
"ANI": {
"type": "array",
"items": {
"type": "object",
"required": [
"Enable",
"Status",
"PONMode",
"Stats"
],
"properties": {
"Enable": {
"type": "boolean",
"default": "false"
},
"Status": {
"type": "string",
"enum":[
"Up",
"Down",
"Dormant",
"Unknown",
"NotPresent",
"Error"
]
},
"PONMode": {
"type": "string",
"enum":[
"GPON",
"XG-PON",
"NG-PON2",
"XGS-PON"
]
},
"Stats": {
"items": {
"type": "object",
"required": [
"BytesSent",
"BytesReceived",
"PacketsSent",
"PacketsReceived"
],
"properties": {
"BytesSent": {
"type": "integer",
"minimum": 0
},
"BytesReceived": {
"type": "integer",
"minimum": 0
},
"PacketsSent": {
"type": "integer",
"minimum": 0
},
"PacketsReceived": {
"type": "integer",
"minimum": 0
}
}
}
}
}
}
},
"Transceiver": {
"type": "array",
"items": {
"type": "object",
"required": [
"ID",
"Identifier",
"ModuleVendor",
"ModuleName",
"ModuleVersion",
"ModuleFirmwareVersion",
"PONMode",
"RxPower",
"TxPower",
"Voltage",
"Bias",
"Temperature"
],
"properties": {
"ID": {
"type": "integer",
"default": 0
},
"Identier": {
"type": "integer",
"minimum": 0
},
"ModuleVendor": {
"type": "string"
},
"ModuleName": {
"type": "string"
},
"ModuleVersion": {
"type": "string"
},
"ModuleFirmwareVersion": {
"type": "string"
},
"PONMode": {
"type": "string",
"enum":[
"GPON",
"XG-PON",
"NG-PON2",
"XGS-PON"
]
},
"RxPower": {
"type": "integer"
},
"TxPower": {
"type": "integer"
},
"Voltage": {
"type": "integer"
},
"Bias": {
"type": "integer"
},
"Temperature": {
"type": "integer"
}
}
}
}
}
}
}
}
}
}
}
}
}

View File

@@ -1,31 +0,0 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=port-management
PKG_VERSION:=1.1.0
PKG_RELEASE:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
PKG_LICENSE:=GPL-2.0-only
include $(INCLUDE_DIR)/package.mk
define Package/port-management
CATEGORY:=Utilities
TITLE:=Port management tool
endef
define Package/port-management/description
Port configuration utility
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./files/* $(PKG_BUILD_DIR)/
endef
define Build/Compile
endef
define Package/port-management/install
$(CP) ./files/* $(1)/
endef
$(eval $(call BuildPackage,port-management))

View File

@@ -27,7 +27,7 @@ define Package/qosmngr
SECTION:=utils
CATEGORY:=Utilities
TITLE:=QoS Manager
DEPENDS:=@(TARGET_brcmbca||TARGET_airoha) +libuci +libubox +libubus +libblobmsg-json +libjson-c +libqos
DEPENDS:=+libuci +libubox +libubus +libblobmsg-json +libjson-c +libqos +!(TARGET_brcmbca||TARGET_airoha):tc-full
endef
define Package/qosmngr/description
@@ -40,24 +40,17 @@ define Build/Prepare
endef
endif
define Package/qosmngr/install/common
define Package/qosmngr/install
$(CP) ./files/common/* $(1)/
$(INSTALL_DIR) $(1)/usr
ifneq ($(CONFIG_TARGET_brcmbca),)
$(CP) ./files/broadcom/* $(1)/
else ifneq ($(CONFIG_TARGET_airoha),)
$(CP) ./files/airoha/* $(1)/
else
$(CP) ./files/linux/* $(1)/
endif
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/qosmngr $(1)/usr/sbin
endef
ifeq ($(CONFIG_TARGET_brcmbca),y)
define Package/qosmngr/install
$(CP) ./files/broadcom/* $(1)/
$(call Package/qosmngr/install/common,$(1))
endef
endif
ifeq ($(CONFIG_TARGET_airoha),y)
define Package/qosmngr/install
$(CP) ./files/airoha/* $(1)/
$(call Package/qosmngr/install/common,$(1))
endef
endif
$(eval $(call BuildPackage,qosmngr))

View File

@@ -4,6 +4,18 @@
ethwan="$(db -q get hw.board.ethernetWanPort)"
populate_no_of_queue(){
queue_num=4
# writing no. of queue per port into file and read on classify generate
if [ ! -d "/tmp/qos" ]; then
mkdir -p "/tmp/qos"
fi
no_queue_file="/tmp/qos/no_queue_per_port"
touch "$no_queue_file"
echo $queue_num >"$no_queue_file"
}
generate_queue(){
section="$1"
@@ -34,15 +46,19 @@ generate_queue(){
uci commit qos
}
populate_no_of_queue
if [ -s "/etc/config/qos" ]; then
if uci -q get qos.@queue[0] >/dev/null; then
# return if there is any valid content
exit
# return if there is any valid content
exit
else
rm -f /etc/config/qos
rm -f /etc/config/qos
fi
fi
touch /etc/config/qos
# generate qos queue config
config_load ports
config_foreach generate_queue ethport

View File

@@ -182,9 +182,9 @@ hw_commit_all() {
if [ "${glob_alg}" != "" ] ; then
/userfs/bin/qosrule discpline $(hw_sc_alg2str ${glob_alg}) ${weight_list} \
${shape_rate:+uplink-bandwidth} $shape_rate \
uplink-bandwidth ${shape_rate:-0} \
queuemask $queue_mask
else
/userfs/bin/qosrule discpline off
/userfs/bin/qosrule discpline Enable 0
fi
}

View File

@@ -5,9 +5,9 @@
handle_classify() {
cid="$1" #classify section ID
config_get is_enable "$cid" "enable"
config_get is_enable "$cid" "enable" 1
# no need to configure disabled classify rules
if [ -z "$is_enable" ] || [ "$is_enable" == "0" ]; then
if [ "$is_enable" == "0" ]; then
return
fi

View File

@@ -80,10 +80,10 @@ handle_policer() {
local p_sec="$1" # policer section ID
local dir=1 # default direction, upstream
config_get is_enable "$p_sec" "enable"
config_get is_enable "$p_sec" "enable" 1
# No need to configure disabled policer
if [ -z "$is_enable" ] || [ "$is_enable" == "0" ] ; then
if [ "$is_enable" == "0" ] ; then
return
fi

View File

@@ -18,10 +18,10 @@ handle_queue() {
local qid="$1" #queue section ID
local intf_name="$2"
config_get is_enable "$qid" "enable"
config_get is_enable "$qid" "enable" 1
# no need to configure disabled queues
if [ -z "${is_enable}" ] || [ "${is_enable}" == "0" ]; then
if [ "${is_enable}" == "0" ]; then
return
fi

View File

@@ -7,9 +7,9 @@
handle_shaper() {
sid="$1" #queue section ID
config_get is_enable "$sid" "enable"
config_get is_enable "$sid" "enable" 1
# no need to configure disabled queues
if [ -z "${is_enable}" ] || [ "${is_enable}" == "0" ] ; then
if [ "${is_enable}" == "0" ] ; then
return
fi

View File

@@ -2,7 +2,7 @@
# The entrypoint for the QoS setup library
. /lib/functions.sh
. /lib/network/port.sh
include /lib/ethernet
. /lib/qos/common/chains.sh
. /lib/qos/common/chains.ebtables.sh

View File

@@ -0,0 +1,75 @@
#!/bin/sh
. /lib/functions.sh
ethwan="$(db -q get hw.board.ethernetWanPort)"
cpu_model="$(cat /proc/socinfo | grep 'SoC Name' | cut -d':' -f2)"
queue_num=8
populate_no_of_queue(){
case $cpu_model in
BCM68*) queue_num=4;;
esac
if grep -qE '[0-9]+ archer$' /proc/devices; then
queue_num=4
fi
# writing no. of queue per port into file and read on classify generate
if [ ! -d "/tmp/qos" ]; then
mkdir -p "/tmp/qos"
fi
no_queue_file="/tmp/qos/no_queue_per_port"
touch "$no_queue_file"
echo $queue_num >"$no_queue_file"
}
generate_queue(){
section="$1"
config_get ifname "$section" "ifname"
local is_lan=0
if [ "$ifname" != "$ethwan" ]; then
is_lan=1
fi
local no_of_q="0 1 2 3 4 5 6 7"
if [ $is_lan -eq 1 ] -a [ $queue_num -eq 4 ]; then
no_of_q="0 1 2 3"
fi
i=0
local total_q=$((${no_of_q##* } + 1))
for i in $no_of_q; do
order=$((total_q - i))
uci add qos queue
uci rename qos.@queue[-1]="q_${i}_${ifname}"
uci set qos.@queue[-1].enable="1"
uci set qos.@queue[-1].ifname="$ifname"
uci set qos.@queue[-1].precedence="$order"
uci set qos.@queue[-1].scheduling="SP"
uci set qos.@queue[-1].rate="0"
uci set qos.@queue[-1].burst_size="0"
uci set qos.@queue[-1].weight="1"
done
uci commit qos
}
populate_no_of_queue
if [ -s "/etc/config/qos" ]; then
if uci -q get qos.@queue[0] >/dev/null; then
exit
else
rm -f /etc/config/qos
fi
fi
touch /etc/config/qos
# generate qos queue config
config_load ports
config_foreach generate_queue ethport

View File

@@ -1,6 +1,6 @@
#!/bin/sh
. /lib/functions.sh
. /lib/network/port.sh
include /lib/ethernet
IP_RULE=""
BR_RULE=""
@@ -1070,7 +1070,7 @@ handle_classify() {
local corder_file="/tmp/qos/classify.order"
while read -r line; do
line_cid=${line: 2}
line_cid=$(echo $line | cut -d '_' -f 2)
handle_ebtables_rules $line_cid
handle_iptables_rules $line_cid

View File

@@ -0,0 +1,114 @@
#!/bin/sh
. /lib/functions.sh
classify_no=0
generate_dns_rule(){
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].ifname="lo"
uci set qos.@classify[-1].proto="udp"
uci set qos.@classify[-1].ethertype="IPv4"
uci set qos.@classify[-1].dest_port="53"
uci set qos.@classify[-1].traffic_class="$1"
}
generate_dhcp_rule(){
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].ifname="lo"
uci set qos.@classify[-1].proto="udp"
uci set qos.@classify[-1].ethertype="IPv4"
uci set qos.@classify[-1].dest_port="67"
uci set qos.@classify[-1].dest_port_range="68"
uci set qos.@classify[-1].traffic_class="$1"
}
generate_igmp_rule(){
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].ifname="lo"
uci set qos.@classify[-1].proto="IGMP"
uci set qos.@classify[-1].ethertype="IPv4"
uci set qos.@classify[-1].traffic_class="$1"
}
generate_icmp_rule(){
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].ifname="lo"
uci set qos.@classify[-1].proto="icmp"
uci set qos.@classify[-1].ethertype="IPv4"
uci set qos.@classify[-1].traffic_class="$1"
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].proto="icmp"
uci set qos.@classify[-1].ethertype="IPv4"
uci set qos.@classify[-1].traffic_class="$2"
}
generate_classify(){
no_queue_file="/tmp/qos/no_queue_per_port"
queue_num=$(cat "$no_queue_file")
rm -f "$no_queue_file"
# assign queue type
if [ $queue_num -eq 8 ]; then
q_def_queue="0"
q_low="1"
q_besteffort="2"
q_normal="3"
q_video="4"
q_medium="5"
q_high="6"
q_highest="7"
elif [ $queue_num -eq 4 ]; then
q_def_queue="0"
q_normal="1"
q_medium="2"
q_highest="3"
fi
# Local generated DNS traffic goes to q_highest
generate_dns_rule $q_highest
# Local generated IGMP traffic goes to q_highest
generate_igmp_rule $q_highest
# Local generated DHCP traffic goes to q_highest
generate_dhcp_rule $q_highest
# Local generated ICMP traffic goes to q_highest rotue as q_normal
generate_icmp_rule $q_highest $q_normal
# VLAN priority tag -> Queue priority
for i in `seq 1 7`; do
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].pcp_check="$i"
uci set qos.@classify[-1].traffic_class="$i"
done
uci commit qos
}
if [ -s "/etc/config/qos" ]; then
# cleaning up for upgrade same version that contain firewall.qos
if [ -s "/etc/firewall.qos" ]; then
rm -f "/etc/firewall.qos"
if [ -s "/etc/config/firewall" ]; then
uci delete firewall.qos
fi
generate_classify
elif uci -q get qos.@classify[0] >/dev/null; then
exit
else
generate_classify
fi
fi

View File

@@ -3,30 +3,26 @@
. /lib/functions.sh
ethwan="$(db -q get hw.board.ethernetWanPort)"
cpu_model="$(cat /proc/socinfo | grep 'SoC Name' | cut -d':' -f2)"
populate_no_of_queue(){
queue_num=8
# writing no. of queue per port into file and read on classify generate
if [ ! -d "/tmp/qos" ]; then
mkdir -p "/tmp/qos"
fi
no_queue_file="/tmp/qos/no_queue_per_port"
touch "$no_queue_file"
echo $queue_num >"$no_queue_file"
}
generate_queue(){
section="$1"
config_get ifname "$section" "ifname"
local is_lan=0
if [ "$ifname" != "$ethwan" ]; then
is_lan=1
fi
local no_of_q="0 1 2 3 4 5 6 7"
if [ $is_lan -eq 1 ]; then
case $cpu_model in
BCM68*) no_of_q="0 1 2 3" ;;
esac
if grep -qE '[0-9]+ archer$' /proc/devices; then
no_of_q="0 1 2 3"
fi
fi
i=0
local total_q=$((${no_of_q##* } + 1))
for i in $no_of_q; do
@@ -37,14 +33,16 @@ generate_queue(){
uci set qos.@queue[-1].ifname="$ifname"
uci set qos.@queue[-1].precedence="$order"
uci set qos.@queue[-1].scheduling="SP"
uci set qos.@queue[-1].rate="0"
uci set qos.@queue[-1].burst_size="0"
uci set qos.@queue[-1].rate="1000000"
uci set qos.@queue[-1].burst_size="1500"
uci set qos.@queue[-1].weight="1"
done
uci commit qos
}
populate_no_of_queue
if [ -s "/etc/config/qos" ]; then
if uci -q get qos.@queue[0] >/dev/null; then
# return if there is any valid content

View File

@@ -0,0 +1,686 @@
#!/bin/sh
. /lib/functions.sh
#set -x
IP_RULE=""
MAJOR=""
POLICER_COUNT=0
Q_COUNT=0
SP_Q_PRIO=7
#counter variable to assign classify order value if not added in config
temp_order=1
# Function to handle a queue order and
# update total number of queues
handle_q_order() {
local qid="$1" #queue section ID
config_get is_enable "$qid" "enable" 1
# No need to configure disabled queues
if [ $is_enable == '0' ]; then
return
fi
config_get ifname "$qid" "ifname"
# If ifname is empty that is good enough to break
if [ -z "$ifname" ];then
return
fi
# Create precedence file containing queue order per
# interface.
local precedence_file="/tmp/qos/$ifname/q_order"
local q_no=$(cat /tmp/qos/$ifname/q_idx)
config_get precedence "$qid" "precedence"
value=${precedence}_q${q_no}
echo $value >> $precedence_file
# Update the number of queues per interface.
q_no=$((q_no + 1))
echo $q_no > /tmp/qos/$ifname/q_idx
}
# Sort queue, lower value in uci means higher precedence, so this
# function sorts the precedence in decending order
sort_q_by_precedence() {
ifname="$1"
local order_file="/tmp/qos/$ifname/q_order"
local tmp_order_file="/tmp/qos/$ifname/q_order.tmp"
sort -n -k1 $order_file > $tmp_order_file
cp $tmp_order_file $order_file
rm -f $tmp_order_file
}
sort_by_precedence() {
for interf in $(db -q get hw.board.ethernetPortOrder); do
sort_q_by_precedence $interf
done
}
# function to handle a queue section
handle_queue() {
local qid="$1" #queue section ID
local port="$2"
local port_bw="$3"
local root="$4"
local port_bs="$5"
local priority=0
config_get is_enable "$qid" "enable"
# no need to configure disabled queues
if [ "$is_enable" == "0" ]; then
return
fi
config_get ifname "$qid" "ifname"
# if ifname is empty that is good enough to break
if [ -z "$ifname" ];then
return
fi
# This is to get the qid per interface.
if [ "$port" != "$ifname" ]; then
return
fi
local precedence_file="/tmp/qos/$ifname/q_order"
local temp_order=0
while read -r line; do
line_qid=${line: -1}
if [ "$line_qid" == "$Q_COUNT" ]; then
break
fi
temp_order=$((temp_order + 1))
done < "$precedence_file"
# precedence_file so the order is calculated accordingly.
local order=`expr $SP_Q_PRIO - $temp_order`
config_get sc_alg "$qid" "scheduling"
config_get wgt "$qid" "weight" 1
config_get rate "$qid" "rate"
config_get bs "$qid" "burst_size"
config_get qsize "$qid" "queue_size" 1024
[ "$rate" == "0" ] && rate="$port_bw"
[ "$bs" == "0" ] && bs="$port_bs"
local salg=1
case "$sc_alg" in
"SP") salg=1
;;
"WRR") salg=2
;;
"WDRR") salg=3
;;
"WFQ") salg=4
;;
esac
# ignore precedence value in case of WRR, broadcom recommends that WRR queue should
# always have precedence value set to 0
if [ $salg -ne 2 ]; then
priority=$order
fi
if [ $order -ne 0 ]; then
if [ $salg -eq 2 ]; then
tc class add dev $port parent ${root}: classid ${root}:$order cbq allot $bs bandwidth ${port_bw}kbit rate ${rate}kbit prio $priority weight $wgt avpkt 1500 bounded isolated
else
tc class add dev $port parent ${root}: classid ${root}:$order cbq allot $bs bandwidth ${port_bw}kbit rate ${rate}kbit prio $priority avpkt 1500 bounded isolated
fi
tc filter add dev $port parent ${root}:0 prio $order handle $order fw classid ${root}:$order
fi
Q_COUNT=$((Q_COUNT + 1))
}
#function to handle a policer section
handle_policer() {
local p_sec="$1" # policer section ID
local dir=1 # default direction, upstream
config_get is_enable "$p_sec" "enable"
#no need to configure disabled policer
if [ $is_enable == '0' ]; then
return
fi
POLICER_COUNT=$((POLICER_COUNT + 1))
}
setup_qos() {
if [ ! -d "/tmp/qos" ]; then
mkdir -p /tmp/qos
fi
ebtables -t broute -N qos
ret=$?
if [ $ret -eq 0 ]; then
ebtables -t broute -I BROUTING -j qos
else
ebtables -t broute -D BROUTING -j qos
ebtables -t broute -I BROUTING -j qos
fi
iptables -w -t mangle -N qos_prerouting
ret=$?
[ $ret -eq 0 ] && iptables -w -t mangle -I PREROUTING -j qos_prerouting
iptables -w -t mangle -N qos_forward
ret=$?
[ $ret -eq 0 ] && iptables -w -t mangle -I FORWARD -j qos_forward
iptables -w -t mangle -N qos_output
ret=$?
[ $ret -eq 0 ] && iptables -w -t mangle -I OUTPUT -j qos_output
ip6tables -w -t mangle -N qos_prerouting
ret=$?
[ $ret -eq 0 ] && ip6tables -w -t mangle -I PREROUTING -j qos_prerouting
ip6tables -t mangle -N qos_forward
ret=$?
[ $ret -eq 0 ] && ip6tables -t mangle -I FORWARD -j qos_forward
ip6tables -t mangle -N qos_output
ret=$?
[ $ret -eq 0 ] && ip6tables -t mangle -I OUTPUT -j qos_output
}
flush_chains() {
echo "iptables -w -t mangle -F qos_forward" > /tmp/qos/classify.iptables
echo "iptables -w -t mangle -F qos_output" >> /tmp/qos/classify.iptables
echo "iptables -w -t mangle -F qos_prerouting" >> /tmp/qos/classify.iptables
echo "ip6tables -w -t mangle -F qos_forward" > /tmp/qos/classify.ip6tables
echo "ip6tables -w -t mangle -F qos_output" >> /tmp/qos/classify.ip6tables
echo "ip6tables -w -t mangle -F qos_prerouting" >> /tmp/qos/classify.ip6tables
}
init_iptables_rule() {
IP_RULE=""
}
iptables_filter_intf() {
IP_RULE="$IP_RULE -i $1"
}
iptables_filter_proto() {
IP_RULE="$IP_RULE -p $1"
}
iptables_filter_ip_src() {
IP_RULE="$IP_RULE -s $1"
}
iptables_filter_ip_dest() {
IP_RULE="$IP_RULE -d $1"
}
iptables_filter_port_dest() {
IP_RULE="$IP_RULE --dport $1"
}
iptables_filter_port_src() {
IP_RULE="$IP_RULE --sport $1"
}
iptables_filter_port_dest_range() {
IP_RULE="$IP_RULE --dport $1:$2"
}
iptables_filter_port_src_range() {
IP_RULE="$IP_RULE --sport $1:$2"
}
iptables_filter_dscp_filter() {
IP_RULE="$IP_RULE -m dscp --dscp $1"
}
iptables_filter_ip_len_min() {
IP_RULE="$IP_RULE -m length --length $1"
}
iptables_filter_ip_len_max() {
IP_RULE="$IP_RULE:$1"
}
iptables_set_dscp_mark() {
IP_RULE="$IP_RULE -j DSCP --set-dscp $1"
}
iptables_set_traffic_class() {
IP_RULE="$IP_RULE -j MARK --set-mark $1"
}
append_rule_to_mangle_table() {
if [ $2 == 4 ]; then
echo "iptables -w -t mangle -A $1 $IP_RULE" >> /tmp/qos/classify.iptables
elif [ $2 == 6 ]; then
echo "ip6tables -w -t mangle -A $1 $IP_RULE" >> /tmp/qos/classify.ip6tables
elif [ $2 == 1 ]; then
echo "iptables -w -t mangle -A $1 $IP_RULE" >> /tmp/qos/classify.iptables
echo "ip6tables -w -t mangle -A $1 $IP_RULE" >> /tmp/qos/classify.ip6tables
fi
}
handle_iptables_rules() {
cid=$1
local ip_version=0
local is_l3_rule=0
init_iptables_rule
config_get proto "$cid" "proto"
config_get traffic_class "$cid" "traffic_class"
config_get dscp_mark "$cid" "dscp_mark"
config_get dscp_filter "$cid" "dscp_filter"
config_get dest_port "$cid" "dest_port"
config_get dest_port_range "$cid" "dest_port_range"
config_get src_port "$cid" "src_port"
config_get src_port_range "$cid" "src_port_range"
config_get dest_ip "$cid" "dest_ip"
config_get src_ip "$cid" "src_ip"
config_get ip_len_min "$cid" "ip_len_min"
config_get ip_len_max "$cid" "ip_len_max"
config_get ifname "$cid" "ifname"
#check version of ip
case $src_ip$dest_ip in
*.*)
ip_version=4
;;
*:*)
ip_version=6
;;
*)
ip_version=1 #ip address not used
esac
#filter interface
if [ -n "$ifname" ]; then
if [ "$ifname" != "lo" ]; then
iptables_filter_intf $ifname
fi
fi
# filter proto
if [ -n "$proto" ]; then
iptables_filter_proto $proto
is_l3_rule=1
fi
#filter src. ip
if [ -n "$src_ip" ]; then
iptables_filter_ip_src $src_ip
is_l3_rule=1
fi
#filter dest. ip
if [ -n "$dest_ip" ]; then
iptables_filter_ip_dest $dest_ip
is_l3_rule=1
fi
#filter dest. port
if [ -n "$dest_port" -a -z "$dest_port_range" ]; then
iptables_filter_port_dest $dest_port
is_l3_rule=1
fi
#filter src. port
if [ -n "$src_port" -a -z "$src_port_range" ]; then
iptables_filter_port_src $src_port
is_l3_rule=1
fi
#filter dest. port range
if [ -n "$dest_port" -a -n "$dest_port_range" ]; then
iptables_filter_port_dest_range $dest_port $dest_port_range
is_l3_rule=1
fi
#filter src. port range
if [ -n "$src_port" -a -n "$src_port_range" ]; then
iptables_filter_port_src_range $src_port $src_port_range
is_l3_rule=1
fi
#filter dscp
if [ -n "$dscp_filter" ]; then
iptables_filter_dscp_filter $dscp_filter
is_l3_rule=1
fi
#filter min. IP packet len.
if [ -n "$ip_len_min" ]; then
iptables_filter_ip_len_min $ip_len_min
is_l3_rule=1
fi
#filter max. IP packet len.
if [ -n "$ip_len_max" ]; then
iptables_filter_ip_len_max $ip_len_max
is_l3_rule=1
fi
if [ $is_l3_rule -eq 0 ]; then
return
fi
#set dscp mark
[ -n "$dscp_mark" ] && iptables_set_dscp_mark $dscp_mark
#set packet queue mark
[ -n "$traffic_class" ] && iptables_set_traffic_class $traffic_class
#write iptables rule for dscp marking
[ -n "$IP_RULE" -a -n "$dscp_mark" ] && append_rule_to_mangle_table "qos_forward" $ip_version
if [ -n "$IP_RULE" -a -n "$traffic_class" ]; then
if [ "$ifname" == "lo" ]; then
#write iptables rule for putting WAN directed internal packets in different queue
append_rule_to_mangle_table "qos_output" $ip_version
else
#write iptables rule for putting WAN directed LAN packets in different queue
append_rule_to_mangle_table "qos_prerouting" $ip_version
fi
fi
}
handle_policer_rules() {
local c_sec=$1
local policer_name
local ifname
local pname
local pindex=-1
local ingress_rate=0
local in_burst_size=0
config_get policer_name "$c_sec" "policer"
if [ -z "$policer_name" ];then
# no need to apply policer if policer not present in this
# classification rule
return
fi
config_get ifname "$c_sec" "ifname"
if [ -z "$ifname" ]; then
# cannot associate policer as interface is not mentioned
return
fi
local i=0
local max_policer_inst=$(cat /tmp/qos/max_policer_inst)
while :
do
if [ $i -eq $max_policer_inst ]; then
break
fi
pname="$(uci -q get qos.@policer[$i].name)"
if [ "$policer_name" == "$pname" ]; then
pindex=$i
ingress_rate=$(uci -q get qos.@policer[$i].committed_rate)
in_burst_rate=$(uci -q get qos.@policer[$i].committed_burst_size)
break
fi
i=$((i + 1))
done
if [ $pindex -lt 0 ]; then
# policer not found, no need to proceed further
return
fi
config_ingress_rate_limit $ifname $ingress_rate $in_burst_size $pindex
}
config_ingress_rate_limit() {
local ifname="$1"
local ingress_rate=$2
local in_burst_size=$3
local pindex="$4"
local wanport="$(db -q get hw.board.ethernetWanPort)"
# Unit in uci file is in bps while that accepted by ethswctl is kbits
if [ $ingress_rate -lt 1000 ]; then
return
fi
ingress_rate=$((ingress_rate / 1000))
if [ $in_burst_size -eq 0 ]; then
in_burst_size=$ingress_rate
else
in_burst_size=$((in_burst_size / 1000))
fi
tc qdisc add dev $ifname ingress
tc filter add dev $ifname parent ffff: protocol ip prio $pindex u32 match ip src 0.0.0.0/0 police rate ${ingress_rate}kbit burst $in_burst_size drop flowid :$pindex
}
# Function to handle a classify order
handle_classify_order() {
local cid="$1" #classify section ID
config_get is_enable "$cid" "enable" 1
# No need to configure disabled classify
if [ $is_enable == '0' ]; then
return
fi
# Create classify file containing classify order
local corder_file="/tmp/qos/classify.order"
config_get c_order "$cid" "order"
if [ -z "$c_order" ]; then
c_order=$temp_order;
temp_order=$((temp_order + 1))
fi
value=${c_order}_${cid}
echo $value >> $corder_file
}
# Sort classify, lower value in uci means higher precedence, so this
# function sorts the classify order in assending order
sort_classify_by_order() {
local corder_file="/tmp/qos/classify.order"
local tmp_corder_file="/tmp/qos/tmp_classify.order"
sort -n -k1 $corder_file > $tmp_corder_file
cp $tmp_corder_file $corder_file
rm -f $tmp_corder_file
}
#function to handle a classify section
handle_classify() {
local corder_file="/tmp/qos/classify.order"
while read -r line; do
line_cid=$(echo $line | cut -d '_' -f 2)
handle_iptables_rules $line_cid
handle_policer_rules $line_cid
done < "$corder_file"
}
configure_classify() {
#processing classify section
rm -f /tmp/qos/classify.iptables
rm -f /tmp/qos/classify.ip6tables
rm -f /tmp/qos/classify.order
# create files that will contain the rules if not present already
mkdir -p /tmp/qos/
touch /tmp/qos/classify.iptables
touch /tmp/qos/classify.ip6tables
touch /tmp/qos/classify.order
flush_chains
# Load UCI file
config_load qos
config_foreach handle_classify_order classify
sort_classify_by_order
handle_classify
sh /tmp/qos/classify.iptables
sh /tmp/qos/classify.ip6tables
}
pre_configure_queue() {
# Delete queues
for intf in $(db get hw.board.ethernetPortOrder); do
rm -rf /tmp/qos/$intf
mkdir -p /tmp/qos/$intf
touch /tmp/qos/$intf/q_order
touch /tmp/qos/$intf/q_idx
echo 0 > /tmp/qos/$intf/q_idx
tc qdisc del dev $intf root
tc qdisc del dev $intf ingress
done
}
get_link_rate() {
intf="$1"
speed=0
config_load ports
get_speed() {
psid="$1"
iname="$2"
config_load ports
config_get ifname "$psid" "ifname"
if [ "$ifname" == "$iname" ]; then
config_get speed "$psid" "speed"
fi
}
config_foreach get_speed ethport $intf
echo "$speed"
}
configure_queue() {
qdisc_idx=0
local bs=1500
local rate=0
# Load UCI file
config_load qos
config_foreach handle_q_order queue
sort_by_precedence
get_intf_shaper_config() {
local b_size
sid="$1" #shaper section ID
config_get is_enable "$sid" "enable"
# no need to configure disabled queues
if [ "$is_enable" == "0" ]; then
return
fi
config_get ifname "$sid" "ifname"
# if ifname is empty that is good enough to break
if [ -z "$ifname" ] || ! [ "$ifname" == "$2" ];then
return
fi
config_get rate "$sid" "rate"
# Convert the rate from bps to kbps.
if [ $rate -lt 1000 ];then
return
fi
rate=$(( rate / 1000 ))
config_get b_size "$sid" "burst_size"
if [ "$b_size" == "0" ]; then
bs="$b_size"
fi
}
local wanport="$(db -q get hw.board.ethernetWanPort)"
for interf in $(db -q get hw.board.ethernetPortOrder); do
Q_COUNT=0
rate=0
# sp queue have max priority value = no. of queue configured on the port
# hence read and update SP_Q_PRIO here
local q_no=$(cat /tmp/qos/$interf/q_idx)
SP_Q_PRIO=`expr $q_no - 1`
qdisc_idx=`expr $qdisc_idx + 1`
# link_rate is in mbps and rate is in kbp
link_rate=$(get_link_rate "$interf")
# Read the shaper configuration for interface
config_foreach get_intf_shaper_config shaper $interf
if [ "$rate" == "0" ]; then
rate=$(( link_rate * 1000 ))
fi
# TODO using 1500 as allot and avpkt, if shaper config exist for interf get burst_size of shaper for actual value
tc qdisc add dev $interf root handle ${qdisc_idx}: cbq allot $bs avpkt 1500 bandwidth ${rate}kbit
# if qdisc_idx is the index corresponds to WAN port, then
# it would be the MAJOR portion of the destination class ID.
# under the same qdisc. We are programming for WAN port only.
if [ "$interf" == "$wanport" ]; then
MAJOR="$qdisc_idx"
fi
config_foreach handle_queue queue $interf $rate $qdisc_idx $bs
done
}
configure_policer() {
# Delete policer
local i=0
local max_p_inst=0
if [ -f "/tmp/qos/max_policer_inst" ]; then
max_p_inst=$(cat /tmp/qos/max_policer_inst)
fi
# reset the policer counter
echo 0 > /tmp/qos/max_policer_inst
# Load UCI file
config_load qos
config_foreach handle_policer policer
echo $POLICER_COUNT > /tmp/qos/max_policer_inst
}
configure_qos() {
pre_configure_queue
configure_queue
configure_classify
configure_policer
}
reload_qos() {
local service_name="$1"
if [ -z "$service_name" ]; then
configure_qos
elif [ "$service_name" == "queue" ]; then
pre_configure_queue
configure_queue
elif [ "$service_name" == "classify" ]; then
configure_classify
elif [ "$service_name" == "policer" ]; then
configure_policer
fi
}
reload_qos_service() {
reload_qos
}

56
ssdpd/Makefile Normal file
View File

@@ -0,0 +1,56 @@
#
# Copyright (C) 2022 OpenWrt.org
#
include $(TOPDIR)/rules.mk
PKG_NAME:=ssdpd
PKG_VERSION:=1.0.4
LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/miniupnp/miniupnp.git
PKG_SOURCE_VERSION:=207cf440a22c075cb55fb067a850be4f9c204e6e
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
endif
PKG_LICENSE:=BSD-3-Clause
PKG_LICENSE_FILES:=LICENSE
include $(INCLUDE_DIR)/package.mk
define Package/ssdpd
SECTION:=net
CATEGORY:=Network
DEPENDS:=+libnfnetlink +libpthread +libubox +libubus +libblobmsg-json +libcurl +mxml
TITLE:=MiniSSDPd - SSDP daemon
URL:=https://miniupnp.tuxfamily.org/minissdpd.html
endef
MAKE_PATH:=minissdpd
TARGET_CFLAGS += \
-D_GNU_SOURCE \
-Wall -Wextra -Werror
TARGET_LDFLAGS += \
-lpthread -lubox -lubus -lblobmsg_json -lcurl -lmxml
ifeq ($(LOCAL_DEV),1)
define Build/Prepare
$(CP) -rf ~/git/sspd/* $(PKG_BUILD_DIR)/
endef
endif
define Package/ssdpd/install
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_CONF) ./files/etc/config/ssdpd $(1)/etc/config/ssdpd
$(INSTALL_BIN) ./files/etc/init.d/ssdpd $(1)/etc/init.d/ssdpd
$(INSTALL_BIN) $(PKG_BUILD_DIR)/minissdpd/minissdpd $(1)/usr/sbin/ssdpd
endef
$(eval $(call BuildPackage,ssdpd))

View File

@@ -0,0 +1,9 @@
config ssdpd 'ssdp'
option enabled '1'
option ipv6_enabled '0'
option socket_path '/var/run/minissdpd.sock'
option ttl '2'
option interface 'br-lan'
option debug '0'

76
ssdpd/files/etc/init.d/ssdpd Executable file
View File

@@ -0,0 +1,76 @@
#!/bin/sh /etc/rc.common
START=99
STOP=02
USE_PROCD=1
PROG=/usr/sbin/ssdpd
log() {
echo "${@}"|logger -t ssdpd.init -p info
}
validate_ssdpd_ssdp_section()
{
uci_validate_section ssdpd ssdpd "ssdp" \
'enabled:bool:true' \
'debug:bool:false' \
'ipv6_enabled:bool:false' \
'socket_path:string' \
'ttl:uinteger' \
'interface:string'
}
configure_ssdp()
{
local enabled ipv6_enabled socket_path ttl interface
config_load ssdpd
validate_ssdpd_ssdp_section || {
log "Validation of ssdp section failed"
return 1;
}
[ ${enabled} -eq 0 ] && return 0
mkdir -p /tmp/ssdp/description/
procd_set_param command ${PROG}
if [ ${ipv6_enabled} -eq 1 ]; then
procd_append_param command -6
fi
if [ ${debug} -eq 1 ]; then
procd_append_param command -d
fi
if [ -n "${socket_path}" ]; then
procd_append_param command -s ${socket_path}
fi
if [ -n "${ttl}" ]; then
procd_append_param command -t ${ttl}
fi
# If no interface is given defaults for br-lan
procd_append_param command -i ${interface:-br-lan}
}
start_service() {
procd_open_instance ssdp
configure_ssdp
procd_set_param respawn
procd_close_instance
}
reload_service() {
stop
start
}
service_triggers()
{
procd_add_reload_trigger "ssdpd"
}

View File

@@ -0,0 +1,20 @@
--- a/minissdpd/openssdpsocket.c
+++ b/minissdpd/openssdpsocket.c
@@ -11,6 +11,7 @@
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
+#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
--- a/minissdpd/ifacewatch.c
+++ b/minissdpd/ifacewatch.c
@@ -130,6 +130,7 @@ ProcessInterfaceWatch(int s, int s_ssdp,
/* case RTM_DELLINK: */
case RTM_DELADDR:
is_del = 1;
+ // fall through
case RTM_NEWADDR:
/* http://linux-hacks.blogspot.fr/2009/01/sample-code-to-learn-netlink.html */
ifa = (struct ifaddrmsg *)NLMSG_DATA(nlhdr);

View File

@@ -0,0 +1,11 @@
--- a/minissdpd/Makefile
+++ b/minissdpd/Makefile
@@ -41,7 +41,7 @@ endif
EXECUTABLES = minissdpd testminissdpd testcodelength \
showminissdpdnotif
MINISSDPDOBJS = minissdpd.o openssdpsocket.o daemonize.o upnputils.o \
- ifacewatch.o getroute.o getifaddr.o asyncsendto.o
+ ifacewatch.o getroute.o getifaddr.o asyncsendto.o ssdpd.o
TESTMINISSDPDOBJS = testminissdpd.o printresponse.o
SHOWMINISSDPDNOTIFOBJS = showminissdpdnotif.o printresponse.o

View File

@@ -0,0 +1,629 @@
--- /dev/null
+++ b/minissdpd/ssdpd.c
@@ -0,0 +1,626 @@
+/*
+ * Copyright (C) 2022 iopsys Software Solutions AB
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1
+ * as published by the Free Software Foundation
+ *
+ * Author: Amin Ben Romdhane <amin.benromdhane@iopsys.eu>
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <net/if.h>
+#include <syslog.h>
+
+#include <curl/curl.h>
+#include <libubox/uloop.h>
+#include <libubox/blobmsg_json.h>
+#include <libubox/list.h>
+#include <libubus.h>
+#include <mxml.h>
+
+#include "codelength.h"
+
+struct UPNPDev {
+ struct list_head list;
+ char *descURL;
+ char *st;
+ char *usn;
+};
+
+struct desc_list_elt {
+ struct list_head list;
+ char *url;
+ char *desc_path;
+ bool is_device_desc;
+};
+
+#define UPNP_DESC_PATH "/etc/upnp/description"
+#define UPNP_DISCOVER_TIMEOUT (30 * 1000)
+
+#ifndef MIN
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#endif /* MIN */
+
+/* macros used to read from unix socket */
+#define READ_BYTE_BUFFER(c) \
+ if ((int)bufferindex >= n) { \
+ n = read(s, buffer, sizeof(buffer)); \
+ if (n <= 0) break; \
+ bufferindex = 0; \
+ } \
+ c = buffer[bufferindex++];
+
+#define READ_COPY_BUFFER(dst, len) \
+ for (l = len, p = (unsigned char *)dst; l > 0; ) { \
+ unsigned int lcopy; \
+ if ((int)bufferindex >= n) { \
+ n = read(s, buffer, sizeof(buffer)); \
+ if ( n<= 0) break; \
+ bufferindex = 0; \
+ } \
+ lcopy = MIN(l, (n - bufferindex)); \
+ memcpy(p, buffer + bufferindex, lcopy); \
+ l -= lcopy; \
+ p += lcopy; \
+ bufferindex += lcopy; \
+ }
+
+LIST_HEAD(dev_list);
+LIST_HEAD(desc_list);
+
+char *ssdp_sockpath = NULL;
+
+static void upnp_discover_devices(struct uloop_timeout *timeout);
+static struct uloop_timeout upnpdiscover_timer = { .cb = upnp_discover_devices };
+
+static void add_dev_to_dev_list(char *descURL, char *st, char *usn)
+{
+ struct UPNPDev *dev = NULL;
+
+ dev = calloc(1, sizeof(struct UPNPDev));
+ list_add_tail(&dev->list, &dev_list);
+
+ dev->descURL = descURL;
+ dev->st = st;
+ dev->usn = usn;
+}
+
+void free_all_dev_list(void)
+{
+ struct UPNPDev *dev = NULL;
+
+ while (dev_list.next != &dev_list) {
+ dev = list_entry(dev_list.next, struct UPNPDev, list);
+ free(dev->descURL);
+ free(dev->st);
+ free(dev->usn);
+ free(dev);
+ list_del(&dev->list);
+ }
+}
+
+static int connectToMiniSSDPD(void)
+{
+ int s = 0;
+ struct sockaddr_un addr;
+
+ s = socket(AF_UNIX, SOCK_STREAM, 0);
+ if(s < 0)
+ return -1;
+
+ char *ssdp_s = ssdp_sockpath ? ssdp_sockpath : "/var/run/minissdpd.sock";
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sun_family = AF_UNIX;
+
+ strncpy(addr.sun_path, ssdp_s, sizeof(addr.sun_path));
+
+ if(connect(s, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) {
+ close(s);
+ return -1;
+ }
+
+ return s;
+}
+
+static int disconnectFromMiniSSDPD(int s)
+{
+ if (close(s) < 0)
+ return -1;
+ return 0;
+}
+
+static int requestDevicesFromMiniSSDPD(int s)
+{
+ unsigned char buffer[256];
+ unsigned char *p = NULL;
+ unsigned int stsize = 0, l = 0;
+ char *devtype = "ssdp:all";
+
+ buffer[0] = 3; /* request type 3 : everything */
+ stsize = strlen(devtype);
+
+ p = buffer + 1;
+ l = stsize; CODELENGTH(l, p);
+ if (p + stsize > buffer + sizeof(buffer))
+ return -1;
+
+ memcpy(p, devtype, stsize);
+ p += stsize;
+ if (write(s, buffer, p - buffer) < 0)
+ return -1;
+
+ return 0;
+}
+
+static int receiveDevicesFromMiniSSDPD(int s)
+{
+ unsigned char buffer[256];
+ ssize_t n;
+ unsigned char *p;
+ unsigned int bufferindex;
+ unsigned int i, ndev;
+ unsigned int urlsize, stsize, usnsize, l;
+ char *url, *st, *usn;
+
+ n = read(s, buffer, sizeof(buffer));
+ if (n <= 0)
+ return -1;
+
+ ndev = buffer[0];
+ bufferindex = 1;
+ for (i = 0; i < ndev; i++) {
+ DECODELENGTH_READ(urlsize, READ_BYTE_BUFFER);
+ if (n <= 0)
+ return -1;
+
+ url = (char *)malloc(urlsize);
+ if (url == NULL)
+ return -1;
+
+ READ_COPY_BUFFER(url, urlsize);
+ if (n <= 0)
+ return -1;
+
+ DECODELENGTH_READ(stsize, READ_BYTE_BUFFER);
+ if (n <= 0)
+ goto free_url_and_return;
+
+ st = (char *)malloc(stsize);
+ if (st == NULL)
+ goto free_url_and_return;
+
+ READ_COPY_BUFFER(st, stsize);
+ if (n <= 0)
+ goto free_url_and_st_and_return;
+
+ DECODELENGTH_READ(usnsize, READ_BYTE_BUFFER);
+ if (n <= 0)
+ goto free_url_and_st_and_return;
+
+ usn = (char *)malloc(usnsize);
+ if (usn == NULL)
+ goto free_url_and_st_and_return;
+
+ READ_COPY_BUFFER(usn, usnsize);
+ if (n <= 0)
+ goto free_url_and_st_and_usn_and_return;
+
+ add_dev_to_dev_list(url, st, usn);
+ }
+
+ return 0;
+
+free_url_and_st_and_usn_and_return:
+ free(usn);
+free_url_and_st_and_return:
+ free(st);
+free_url_and_return:
+ free(url);
+ return -1;
+}
+
+static int getDevicesFromMiniSSDPD(void)
+{
+ int s = 0;
+ int res = 0;
+
+ s = connectToMiniSSDPD();
+ if (s < 0)
+ return -1;
+
+ res = requestDevicesFromMiniSSDPD(s);
+ if (res < 0)
+ goto close_socket_and_return;
+
+ res = receiveDevicesFromMiniSSDPD(s);
+
+close_socket_and_return:
+ disconnectFromMiniSSDPD(s);
+
+ return res;
+}
+
+static void download_file(char *file_path, const char *url)
+{
+ CURL *curl = curl_easy_init();
+ if (curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, 500);
+
+ FILE *fp = fopen(file_path, "wb");
+ if (fp) {
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
+ curl_easy_perform(curl);
+ fclose(fp);
+ }
+
+ curl_easy_cleanup(curl);
+ }
+}
+
+static bool is_desc_exist(const char *desc_url)
+{
+ struct desc_list_elt *desc_elt = NULL;
+
+ if (!desc_url)
+ return false;
+
+ list_for_each_entry(desc_elt, &desc_list, list) {
+ if (strcmp(desc_elt->url, desc_url) == 0)
+ return true;
+ }
+
+ return false;
+}
+
+static void get_desc_name(const char *desc_url, char *str, size_t len)
+{
+ if (!desc_url || !str || len == 0)
+ return;
+
+ char *p = strstr(desc_url, "://");
+
+ snprintf(str, len, "%s", p ? p + 3 : desc_url);
+
+ for (int i = 0; str[i]; i++) {
+ if (str[i] == '/')
+ str[i] = '_';
+ }
+}
+
+static void add_desc_to_desc_list(const char *desc_path, const char *url, int is_device_desc)
+{
+ struct desc_list_elt *desc_elt;
+
+ desc_elt = calloc(1, sizeof(struct desc_list_elt));
+ list_add_tail(&desc_elt->list, &desc_list);
+
+ desc_elt->desc_path = strdup(desc_path);
+ desc_elt->url = strdup(url);
+ desc_elt->is_device_desc = is_device_desc;
+}
+
+static void free_all_desc_list(void)
+{
+ struct desc_list_elt *desc_elt = NULL;
+
+ while (desc_list.next != &desc_list) {
+ desc_elt = list_entry(desc_list.next, struct desc_list_elt, list);
+ free(desc_elt->desc_path);
+ free(desc_elt->url);
+ free(desc_elt);
+ list_del(&desc_elt->list);
+ }
+}
+
+static void __upnp_discover_devices(void)
+{
+ struct UPNPDev *dev = NULL;
+ char desc_name[128] = {0};
+ char file_path[256] = {0};
+ int res = 0, is_device_desc = 0;
+
+ /*
+ * Discover devices
+ */
+ if (!list_empty(&dev_list))
+ free_all_dev_list();
+
+ res = getDevicesFromMiniSSDPD();
+ if (res)
+ goto end;
+
+ /*
+ * Download description files
+ */
+ list_for_each_entry_reverse(dev, &dev_list, list) {
+
+ if (is_desc_exist(dev->descURL))
+ continue;
+
+ get_desc_name(dev->descURL, desc_name, sizeof(desc_name));
+ snprintf(file_path, sizeof(file_path), "%s/%s", UPNP_DESC_PATH, desc_name);
+ is_device_desc = (dev->usn && strstr(dev->usn, ":service:")) ? 0 : 1;
+
+ // Download Description
+ download_file(file_path, dev->descURL);
+
+ // Add description to descriptions list
+ add_desc_to_desc_list(file_path, dev->descURL, is_device_desc);
+ }
+
+end:
+ uloop_timeout_set(&upnpdiscover_timer, UPNP_DISCOVER_TIMEOUT);
+}
+
+static int upnp_discovery_res(struct ubus_context *ctx, struct ubus_object *obj __attribute__((unused)),
+ struct ubus_request_data *req, const char *method __attribute__((unused)), struct blob_attr *msg __attribute__((unused)))
+{
+ struct blob_buf bb = {0};
+ struct UPNPDev *dev = NULL;
+
+ memset(&bb,0,sizeof(struct blob_buf));
+ blob_buf_init(&bb, 0);
+
+ void *devices_array = blobmsg_open_array(&bb, "devices");
+ list_for_each_entry_reverse(dev, &dev_list, list) {
+ // Parse Root device and devices
+ if ((dev->st && strstr(dev->st, ":rootdevice") != NULL) || (dev->usn && strstr(dev->usn, ":device:") != NULL)) {
+ void *device_obj = blobmsg_open_table(&bb, NULL);
+ blobmsg_add_string(&bb, "descurl", dev->descURL);
+ blobmsg_add_string(&bb, "st", dev->st);
+ blobmsg_add_string(&bb, "usn", dev->usn);
+ blobmsg_add_string(&bb, "is_root_device", dev->st && strstr(dev->st, ":rootdevice") ? "1" : "0");
+ blobmsg_close_table(&bb, device_obj);
+ }
+ }
+ blobmsg_close_array(&bb, devices_array);
+
+ void *services_array = blobmsg_open_array(&bb, "services");
+ list_for_each_entry_reverse(dev, &dev_list, list) {
+ // Parse Services
+ if (dev->usn && strstr(dev->usn, ":service:") != NULL) {
+ void *service_obj = blobmsg_open_table(&bb, NULL);
+ blobmsg_add_string(&bb, "descurl", dev->descURL);
+ blobmsg_add_string(&bb, "st", dev->st);
+ blobmsg_add_string(&bb, "usn", dev->usn);
+ blobmsg_close_table(&bb, service_obj);
+ }
+ }
+ blobmsg_close_array(&bb, services_array);
+
+ ubus_send_reply(ctx, req, bb.head);
+ blob_buf_free(&bb);
+ return 0;
+}
+
+static void fill_device_instances(struct blob_buf *bb, mxml_node_t *device)
+{
+ void *device_obj = NULL;
+ mxml_node_t *b = device;
+ char buf[64] = {0};
+ bool new_device_discovery = false;
+
+ while (b) {
+
+ if (mxmlGetType(b) != MXML_ELEMENT) {
+ b = mxmlWalkNext(b, device, MXML_DESCEND);
+ continue;
+ }
+
+ const char *elm_name = mxmlGetElement(b);
+ const char *elm_val = mxmlGetOpaque(b);
+
+ if (elm_name && strcmp(elm_name, "device") == 0) {
+
+ if (new_device_discovery && device_obj)
+ blobmsg_close_table(bb, device_obj);
+
+ device_obj = blobmsg_open_table(bb, NULL);
+ blobmsg_add_string(bb, "parent_dev", buf);
+ new_device_discovery = true;
+ }
+
+ if (elm_name && strcmp(elm_name, "deviceType") == 0 && new_device_discovery)
+ blobmsg_add_string(bb, "deviceType", elm_val ? elm_val : "");
+
+ if (elm_name && strcmp(elm_name, "friendlyName") == 0 && new_device_discovery)
+ blobmsg_add_string(bb, "friendlyName", elm_val ? elm_val : "");
+
+ if (elm_name && strcmp(elm_name, "manufacturer") == 0 && new_device_discovery)
+ blobmsg_add_string(bb, "manufacturer", elm_val ? elm_val : "");
+
+ if (elm_name && strcmp(elm_name, "manufacturerURL") == 0 && new_device_discovery)
+ blobmsg_add_string(bb, "manufacturerURL", elm_val ? elm_val : "");
+
+ if (elm_name && strcmp(elm_name, "modelDescription") == 0 && new_device_discovery)
+ blobmsg_add_string(bb, "modelDescription", elm_val ? elm_val : "");
+
+ if (elm_name && strcmp(elm_name, "modelName") == 0 && new_device_discovery)
+ blobmsg_add_string(bb, "modelName", elm_val ? elm_val : "");
+
+ if (elm_name && strcmp(elm_name, "modelNumber") == 0 && new_device_discovery)
+ blobmsg_add_string(bb, "modelNumber", elm_val ? elm_val : "");
+
+ if (elm_name && strcmp(elm_name, "modelURL") == 0 && new_device_discovery)
+ blobmsg_add_string(bb, "modelURL", elm_val ? elm_val : "");
+
+ if (elm_name && strcmp(elm_name, "serialNumber") == 0 && new_device_discovery)
+ blobmsg_add_string(bb, "serialNumber", elm_val ? elm_val : "");
+
+ if (elm_name && strcmp(elm_name, "UDN") == 0 && new_device_discovery) {
+ snprintf(buf, sizeof(buf), "%s", elm_val ? elm_val : "");
+ blobmsg_add_string(bb, "UDN", buf);
+ }
+
+ if (elm_name && strcmp(elm_name, "UPC") == 0 && new_device_discovery)
+ blobmsg_add_string(bb, "UPC", elm_val ? elm_val : "");
+
+ b = mxmlWalkNext(b, device, MXML_DESCEND);
+ }
+
+ if (new_device_discovery && device_obj)
+ blobmsg_close_table(bb, device_obj);
+}
+
+static void fill_service_element(struct blob_buf *bb, mxml_node_t *service)
+{
+ mxml_node_t *b = service;
+ void *service_obj = NULL;
+ char buf[64] = {0};
+ bool new_srv_discovery = false;
+
+ while (b) {
+
+ if (mxmlGetType(b) != MXML_ELEMENT) {
+ b = mxmlWalkNext(b, service, MXML_DESCEND);
+ continue;
+ }
+
+ const char *elm_name = mxmlGetElement(b);
+ const char *elm_val = mxmlGetOpaque(b);
+
+ if (elm_name && strcmp(elm_name, "UDN") == 0)
+ snprintf(buf, sizeof(buf), "%s", elm_val ? elm_val : "");
+
+
+ if (elm_name && strcmp(elm_name, "service") == 0) {
+
+ if (new_srv_discovery && service_obj)
+ blobmsg_close_table(bb, service_obj);
+
+ service_obj = blobmsg_open_table(bb, NULL);
+ blobmsg_add_string(bb, "parent_dev", buf);
+ new_srv_discovery = true;
+ }
+
+ if (elm_name && strcmp(elm_name, "serviceType") == 0 && new_srv_discovery)
+ blobmsg_add_string(bb, "serviceType", elm_val ? elm_val : "");
+
+ if (elm_name && strcmp(elm_name, "serviceId") == 0 && new_srv_discovery)
+ blobmsg_add_string(bb, "serviceId", elm_val ? elm_val : "");
+
+ if (elm_name && strcmp(elm_name, "SCPDURL") == 0 && new_srv_discovery)
+ blobmsg_add_string(bb, "SCPDURL", elm_val ? elm_val : "");
+
+ if (elm_name && strcmp(elm_name, "controlURL") == 0 && new_srv_discovery)
+ blobmsg_add_string(bb, "controlURL", elm_val ? elm_val : "");
+
+ if (elm_name && strcmp(elm_name, "eventSubURL") == 0 && new_srv_discovery)
+ blobmsg_add_string(bb, "eventSubURL", elm_val ? elm_val : "");
+
+ b = mxmlWalkNext(b, service, MXML_DESCEND);
+ }
+
+ if (new_srv_discovery && service_obj)
+ blobmsg_close_table(bb, service_obj);
+}
+
+static int upnp_description_res(struct ubus_context *ctx, struct ubus_object *obj __attribute__((unused)),
+ struct ubus_request_data *req, const char *method __attribute__((unused)), struct blob_attr *msg __attribute__((unused)))
+{
+ struct desc_list_elt *desc_elt = NULL;
+ struct blob_buf bb = {0};
+
+ memset(&bb,0,sizeof(struct blob_buf));
+ blob_buf_init(&bb, 0);
+
+ void *desc_array = blobmsg_open_array(&bb, "descriptions");
+ list_for_each_entry(desc_elt, &desc_list, list) {
+ void *device_obj = blobmsg_open_table(&bb, NULL);
+ blobmsg_add_string(&bb, "desc_url", desc_elt->url);
+ blobmsg_add_u32(&bb, "is_device_desc", desc_elt->is_device_desc);
+ blobmsg_close_table(&bb, device_obj);
+
+ }
+ blobmsg_close_array(&bb, desc_array);
+
+ list_for_each_entry(desc_elt, &desc_list, list) {
+
+ FILE *fp = fopen(desc_elt->desc_path, "r");
+ if (!fp)
+ continue;
+
+ mxml_node_t *tree = mxmlLoadFile(NULL, fp, MXML_OPAQUE_CALLBACK);
+ fclose(fp);
+
+ if (tree) {
+ void *devices_array = blobmsg_open_array(&bb, "devices");
+ mxml_node_t *device = mxmlFindElement(tree, tree, "device", NULL, NULL, MXML_DESCEND);
+ fill_device_instances(&bb, device);
+ blobmsg_close_array(&bb, devices_array);
+
+ void *services_array = blobmsg_open_array(&bb, "services");
+ mxml_node_t *service = mxmlFindElement(tree, tree, "device", NULL, NULL, MXML_DESCEND);
+ fill_service_element(&bb, service);
+ blobmsg_close_array(&bb, services_array);
+
+ mxmlDelete(tree);
+ }
+ }
+
+ ubus_send_reply(ctx, req, bb.head);
+ blob_buf_free(&bb);
+ return 0;
+}
+
+static struct ubus_method upnp_methods[] = {
+ UBUS_METHOD_NOARG("discovery", upnp_discovery_res),
+ UBUS_METHOD_NOARG("description", upnp_description_res),
+};
+
+static struct ubus_object_type upnp_type = UBUS_OBJECT_TYPE("upnp", upnp_methods);
+
+static void upnp_discover_devices(struct uloop_timeout *timeout __attribute__((unused)))
+{
+ __upnp_discover_devices();
+}
+
+static struct ubus_object upnp_object = {
+ .name = "upnp",
+ .type = &upnp_type,
+ .methods = upnp_methods,
+ .n_methods = ARRAY_SIZE(upnp_methods),
+};
+
+void upnp_thread_discover_devices(void)
+{
+ struct ubus_context *ctx = NULL;
+ const char *ubus_socket = NULL;
+ int ret = 0;
+
+ uloop_init();
+
+ ctx = ubus_connect(ubus_socket);
+ if (!ctx) {
+ syslog(LOG_ERR, "Failed to connect to ubus\n");
+ return;
+ }
+
+ ubus_add_uloop(ctx);
+
+ __upnp_discover_devices();
+
+ ret = ubus_add_object(ctx, &upnp_object);
+ if (ret) {
+ syslog(LOG_ERR, "Failed to add 'upnp' ubus object: %s\n", ubus_strerror(ret));
+ goto end;
+ }
+
+ uloop_run();
+
+end:
+ free_all_desc_list();
+ free_all_dev_list();
+ uloop_done();
+ ubus_free(ctx);
+}

View File

@@ -0,0 +1,311 @@
--- a/minissdpd/minissdpd.c
+++ b/minissdpd/minissdpd.c
@@ -32,6 +32,8 @@
#include <pwd.h>
#include <grp.h>
#endif
+/* for uloop thread */
+#include <pthread.h>
/* LOG_PERROR does not exist on Solaris */
#ifndef LOG_PERROR
@@ -52,6 +54,10 @@
#define MIN(x,y) (((x)<(y))?(x):(y))
#endif
+extern char *ssdp_sockpath;
+void upnp_thread_discover_devices(void);
+void ssdpd_ubus_stop(void);
+
/* current request management structure */
struct reqelem {
int socket;
@@ -1220,6 +1226,12 @@ static void ssdpDiscover(int s, int ipv6
}
}
+static void *thread_discover_devices(void *args __attribute__((unused)))
+{
+ upnp_thread_discover_devices();
+ return NULL;
+}
+
/* main(): program entry point */
int main(int argc, char * * argv)
{
@@ -1264,6 +1276,7 @@ int main(int argc, char * * argv)
unsigned char ttl = 2; /* UDA says it should default to 2 */
const char * searched_device = NULL; /* if not NULL, search/filter a specific device type */
int opt;
+ pthread_t upnp_thread;
LIST_INIT(&reqlisthead);
LIST_INIT(&servicelisthead);
@@ -1309,6 +1322,7 @@ int main(int argc, char * * argv)
break;
case 's':
sockpath = optarg;
+ ssdp_sockpath = optarg;
break;
#ifndef NO_BACKGROUND_NO_PIDFILE
case 'p':
@@ -1496,6 +1510,11 @@ int main(int argc, char * * argv)
if(s_ssdp6 >= 0)
ssdpDiscover(s_ssdp6, 1, searched_device);
+ int err = pthread_create(&upnp_thread, NULL, &thread_discover_devices, NULL);
+ if (err < 0) {
+ syslog(LOG_ERR, "Error when creating upnp thread");
+ }
+
/* Main loop */
while(!quitting) {
/* fill readfds fd_set */
@@ -1704,6 +1723,8 @@ quit:
if(unlink(pidfilename) < 0)
syslog(LOG_ERR, "unlink(%s): %m", pidfilename);
#endif
+ ssdpd_ubus_stop();
+ pthread_join(upnp_thread, NULL);
closelog();
return ret;
}
--- a/minissdpd/ssdpd.c
+++ b/minissdpd/ssdpd.c
@@ -39,10 +39,9 @@ struct desc_list_elt {
struct list_head list;
char *url;
char *desc_path;
- bool is_device_desc;
};
-#define UPNP_DESC_PATH "/etc/upnp/description"
+#define UPNP_DESC_PATH "/tmp/ssdp/description"
#define UPNP_DISCOVER_TIMEOUT (30 * 1000)
#ifndef MIN
@@ -282,6 +281,21 @@ static bool is_desc_exist(const char *de
return false;
}
+static bool is_device_exist(const char *dev_url)
+{
+ struct UPNPDev *dev = NULL;
+
+ if (!dev_url)
+ return false;
+
+ list_for_each_entry(dev, &dev_list, list) {
+ if (strcmp(dev->descURL, dev_url) == 0)
+ return true;
+ }
+
+ return false;
+}
+
static void get_desc_name(const char *desc_url, char *str, size_t len)
{
if (!desc_url || !str || len == 0)
@@ -297,7 +311,7 @@ static void get_desc_name(const char *de
}
}
-static void add_desc_to_desc_list(const char *desc_path, const char *url, int is_device_desc)
+static void add_desc_to_desc_list(const char *desc_path, const char *url)
{
struct desc_list_elt *desc_elt;
@@ -306,7 +320,6 @@ static void add_desc_to_desc_list(const
desc_elt->desc_path = strdup(desc_path);
desc_elt->url = strdup(url);
- desc_elt->is_device_desc = is_device_desc;
}
static void free_all_desc_list(void)
@@ -324,10 +337,12 @@ static void free_all_desc_list(void)
static void __upnp_discover_devices(void)
{
+ struct desc_list_elt *desc_elt = NULL;
+ struct desc_list_elt *desc_elt_tmp = NULL;
struct UPNPDev *dev = NULL;
char desc_name[128] = {0};
char file_path[256] = {0};
- int res = 0, is_device_desc = 0;
+ int res = 0;
/*
* Discover devices
@@ -349,13 +364,26 @@ static void __upnp_discover_devices(void
get_desc_name(dev->descURL, desc_name, sizeof(desc_name));
snprintf(file_path, sizeof(file_path), "%s/%s", UPNP_DESC_PATH, desc_name);
- is_device_desc = (dev->usn && strstr(dev->usn, ":service:")) ? 0 : 1;
// Download Description
download_file(file_path, dev->descURL);
// Add description to descriptions list
- add_desc_to_desc_list(file_path, dev->descURL, is_device_desc);
+ add_desc_to_desc_list(file_path, dev->descURL);
+ }
+
+ /*
+ * Remove unused descriptions
+ */
+ list_for_each_entry_safe(desc_elt, desc_elt_tmp, &desc_list, list) {
+
+ if (is_device_exist(desc_elt->url))
+ continue;
+
+ free(desc_elt->desc_path);
+ free(desc_elt->url);
+ free(desc_elt);
+ list_del(&desc_elt->list);
}
end:
@@ -371,15 +399,27 @@ static int upnp_discovery_res(struct ubu
memset(&bb,0,sizeof(struct blob_buf));
blob_buf_init(&bb, 0);
+ void *root_devices_array = blobmsg_open_array(&bb, "root_devices");
+ list_for_each_entry_reverse(dev, &dev_list, list) {
+ // Parse root device
+ if (dev->st && strstr(dev->st, ":rootdevice") != NULL) {
+ void *device_obj = blobmsg_open_table(&bb, NULL);
+ blobmsg_add_string(&bb, "descurl", dev->descURL);
+ blobmsg_add_string(&bb, "st", dev->st);
+ blobmsg_add_string(&bb, "usn", dev->usn);
+ blobmsg_close_table(&bb, device_obj);
+ }
+ }
+ blobmsg_close_array(&bb, root_devices_array);
+
void *devices_array = blobmsg_open_array(&bb, "devices");
list_for_each_entry_reverse(dev, &dev_list, list) {
- // Parse Root device and devices
- if ((dev->st && strstr(dev->st, ":rootdevice") != NULL) || (dev->usn && strstr(dev->usn, ":device:") != NULL)) {
+ // Parse devices
+ if (dev->usn && strstr(dev->usn, ":device:") != NULL) {
void *device_obj = blobmsg_open_table(&bb, NULL);
blobmsg_add_string(&bb, "descurl", dev->descURL);
blobmsg_add_string(&bb, "st", dev->st);
blobmsg_add_string(&bb, "usn", dev->usn);
- blobmsg_add_string(&bb, "is_root_device", dev->st && strstr(dev->st, ":rootdevice") ? "1" : "0");
blobmsg_close_table(&bb, device_obj);
}
}
@@ -472,7 +512,7 @@ static void fill_device_instances(struct
blobmsg_close_table(bb, device_obj);
}
-static void fill_service_element(struct blob_buf *bb, mxml_node_t *service)
+static void fill_service_instances(struct blob_buf *bb, mxml_node_t *service)
{
mxml_node_t *b = service;
void *service_obj = NULL;
@@ -525,6 +565,32 @@ static void fill_service_element(struct
blobmsg_close_table(bb, service_obj);
}
+static void fill_device_service_instances(struct blob_buf *bb, bool is_device)
+{
+ struct desc_list_elt *desc_elt = NULL;
+
+ list_for_each_entry(desc_elt, &desc_list, list) {
+
+ FILE *fp = fopen(desc_elt->desc_path, "r");
+ if (!fp)
+ continue;
+
+ mxml_node_t *tree = mxmlLoadFile(NULL, fp, MXML_OPAQUE_CALLBACK);
+ fclose(fp);
+
+ if (tree) {
+ mxml_node_t *node = mxmlFindElement(tree, tree, "device", NULL, NULL, MXML_DESCEND);
+
+ if (is_device)
+ fill_device_instances(bb, node);
+ else
+ fill_service_instances(bb, node);
+
+ mxmlDelete(tree);
+ }
+ }
+}
+
static int upnp_description_res(struct ubus_context *ctx, struct ubus_object *obj __attribute__((unused)),
struct ubus_request_data *req, const char *method __attribute__((unused)), struct blob_attr *msg __attribute__((unused)))
{
@@ -534,39 +600,25 @@ static int upnp_description_res(struct u
memset(&bb,0,sizeof(struct blob_buf));
blob_buf_init(&bb, 0);
+ // Descriptions Array
void *desc_array = blobmsg_open_array(&bb, "descriptions");
list_for_each_entry(desc_elt, &desc_list, list) {
void *device_obj = blobmsg_open_table(&bb, NULL);
blobmsg_add_string(&bb, "desc_url", desc_elt->url);
- blobmsg_add_u32(&bb, "is_device_desc", desc_elt->is_device_desc);
blobmsg_close_table(&bb, device_obj);
}
blobmsg_close_array(&bb, desc_array);
- list_for_each_entry(desc_elt, &desc_list, list) {
-
- FILE *fp = fopen(desc_elt->desc_path, "r");
- if (!fp)
- continue;
-
- mxml_node_t *tree = mxmlLoadFile(NULL, fp, MXML_OPAQUE_CALLBACK);
- fclose(fp);
-
- if (tree) {
- void *devices_array = blobmsg_open_array(&bb, "devices");
- mxml_node_t *device = mxmlFindElement(tree, tree, "device", NULL, NULL, MXML_DESCEND);
- fill_device_instances(&bb, device);
- blobmsg_close_array(&bb, devices_array);
-
- void *services_array = blobmsg_open_array(&bb, "services");
- mxml_node_t *service = mxmlFindElement(tree, tree, "device", NULL, NULL, MXML_DESCEND);
- fill_service_element(&bb, service);
- blobmsg_close_array(&bb, services_array);
+ // Devices Array
+ void *devices_array = blobmsg_open_array(&bb, "devices");
+ fill_device_service_instances(&bb, true);
+ blobmsg_close_array(&bb, devices_array);
- mxmlDelete(tree);
- }
- }
+ // Services Array
+ void *services_array = blobmsg_open_array(&bb, "services");
+ fill_device_service_instances(&bb, false);
+ blobmsg_close_array(&bb, services_array);
ubus_send_reply(ctx, req, bb.head);
blob_buf_free(&bb);
@@ -624,3 +676,8 @@ end:
uloop_done();
ubus_free(ctx);
}
+
+void ssdpd_ubus_stop(void)
+{
+ uloop_end();
+}
+
--- a/minissdpd/config.h
+++ b/minissdpd/config.h
@@ -32,7 +32,7 @@
/* When NO_BACKGROUND_NO_PIDFILE is defined, minissdpd does not go to
* background and does not create any pidfile */
-/*#define NO_BACKGROUND_NO_PIDFILE*/
+#define NO_BACKGROUND_NO_PIDFILE
/* define HAVE_IP_MREQN to use struct ip_mreqn instead of struct ip_mreq
* for setsockopt(IP_MULTICAST_IF). Available with Linux 2.4+,

View File

@@ -9,13 +9,13 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=stunc
PKG_RELEASE:=1
PKG_VERSION:=1.1.14
PKG_VERSION:=1.1.15
LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/stunc.git
PKG_SOURCE_VERSION:=06b63878a448b593d907bb3e9c1381dc0e69bca6
PKG_SOURCE_VERSION:=09f9868a79e1b5037a99a97fd4dee678869fe98a
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
endif

View File

@@ -13,7 +13,7 @@ menu "SULU_CORE"
config SULU_CORE_VERSION
string "SULU repo version"
default "c7e62f7f7cda1961012e8149d220ac1eb26d362f"
default "5380c46eefc7dc2907ca749e9b3aaa6321039ee8"
endmenu
menu "SULU_PLUGIN_LCM"
@@ -35,7 +35,7 @@ menu "SULU_PLUGIN_LCM"
config SULU_PLUGIN_LCM_VERSION
depends on SULU_PLUGIN_LCM_ENABLE
string "Version"
default "ccd70b399b31530dc1af6a871eee94fbb179d794"
default "8e954f0adb3388e9ab2171df9c6bf85a1b82b020"
endmenu
menu "SULU_PLUGIN_MULTIAP"
@@ -57,7 +57,7 @@ menu "SULU_PLUGIN_MULTIAP"
config SULU_PLUGIN_MULTIAP_VERSION
depends on SULU_PLUGIN_MULTIAP_ENABLE
string "Version"
default "3c79d57bee453e7b62c7b7626e33bf273212bbc9"
default "db3828affb373a9ca9bae0b07591ab5c417825a7"
endmenu
menu "SULU_THEME_IOPSYS"

View File

@@ -5,11 +5,11 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=sulu-builder
PKG_VERSION:=1.3.16
PKG_VERSION:=1.3.26
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/websdk/sulu-builder.git
PKG_SOURCE_VERSION:=81d4bb268914dc3822293e93519ae6adbd6ddbea
PKG_SOURCE_VERSION:=6d6848119bffdbe0ec9b8116caf6375749299dc0
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
@@ -40,7 +40,7 @@ define Download/sulu_core
FILE:=$(SULU_DL_FILE)
URL:=$(CONFIG_SULU_CORE_URL)
PROTO:=git
SUBDIR:=core
SUBDIR:=sulu
VERSION:=${CONFIG_SULU_CORE_VERSION}
HASH:=skip
endef
@@ -139,6 +139,10 @@ ifeq ($(CONFIG_SULU_THEME_CUSTOM_ENABLE),y)
endif
endef
define Build/Compile
VERSION="v${PKG_VERSION}" $(MAKE) -C $(PKG_BUILD_DIR)/
endef
define Package/${PKG_NAME}/install
$(INSTALL_DIR) $(1)/sulu
$(INSTALL_DIR) $(1)/sulu/config
@@ -158,20 +162,16 @@ endif
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/etc/init.d/sulu $(1)/etc/init.d/sulu
$(INSTALL_DIR) $(1)/etc/mosquitto/conf.d/
$(INSTALL_DATA) ./files/etc/mosquitto/conf.d/obuspa.conf $(1)/etc/mosquitto/conf.d/
$(INSTALL_DATA) ./files/etc/mosquitto/conf.d/sulu.conf $(1)/etc/mosquitto/conf.d/
$(INSTALL_DATA) ./files/etc/mosquitto/sulu.password $(1)/etc/mosquitto/sulu.password
$(INSTALL_DIR) $(1)/etc/nginx/conf.d
$(INSTALL_DATA) ./files/etc/nginx/conf.d/sulu.conf $(1)/etc/nginx/conf.d/
$(INSTALL_DIR) $(1)/etc/sulu
$(INSTALL_DATA) ./files/etc/sulu/roles.json $(1)/etc/sulu/
$(INSTALL_BIN) ./files/etc/sulu/sulu.sh $(1)/etc/sulu/
$(INSTALL_DATA) ./files/etc/sulu/nginx.locations $(1)/etc/sulu/
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) ./files/etc/uci-defaults/99-fix-sulu-config $(1)/etc/uci-defaults/
$(INSTALL_BIN) ./files/etc/uci-defaults/40-add-sulu-nginx-config $(1)/etc/uci-defaults/
$(INSTALL_BIN) ./files/etc/uci-defaults/01-update-nginx-uci-template $(1)/etc/uci-defaults/
$(INSTALL_BIN) ./files/etc/uci-defaults/10-add-mqtt-config $(1)/etc/uci-defaults/
endef
$(eval $(call BuildPackage,${PKG_NAME}))

View File

@@ -1,9 +1,4 @@
config global 'global'
option root '/sulu'
option port '8080'
option ws_port '9001'
option enabled '1'
option enable_system_credentials '1'
option role_based_access '1'
list user 'admin'
list user 'user'

View File

@@ -33,9 +33,9 @@ start_service() {
return 0
fi
update_nginx_template
configure_sulu "${enable_system_credentials}" "${role_based_access}" 1
update_nginx_config "${enabled}" 1
update_sulu_connection_port
generate_sulu_conn_config "${role_based_access}"
procd_close_instance
}
@@ -46,5 +46,5 @@ reload_service() {
service_triggers()
{
procd_add_reload_trigger "sulu"
procd_add_reload_trigger "sulu" "nginx"
}

View File

@@ -1,3 +0,0 @@
listener 1883 127.0.0.1
allow_anonymous true

View File

@@ -1,4 +0,0 @@
listener 9001
protocol websockets
require_certificate false
allow_anonymous false

View File

@@ -1 +0,0 @@
admin:$6$OmM9kU/lYct3KJ9j$iP0WK4ezEtRm8+EAggNp7WbJFoWO0p7IUdI0v/hr1WcVHyfFAC30Pb8Csn7GqwwqI2dcmnDOAITnimo2VNe6ug==

View File

@@ -1,27 +0,0 @@
server {
listen 8080;
listen [::]:8080;
server_name _sulu;
root /sulu;
location / {
autoindex on;
expires -1;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,Content-Type,Range';
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,Content-Type,Range' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
}
}
}

View File

@@ -0,0 +1,50 @@
error_page 497 301 =307 https://$host:$server_port$request_uri;
location /robots.txt {
return 200 "User-agent: *\nDisallow: /\n";
}
location /sitemap.xml {
return 200 "User-agent: *\nDisallow: /\n";
}
location /ws {
proxy_pass_request_headers on;
proxy_cache off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,Content-Type,Range' always;
proxy_pass http://websocket;
}
location / {
autoindex on;
expires -1;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,Content-Type,Range';
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,Content-Type,Range' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
}
}

View File

@@ -2,7 +2,6 @@
. /lib/functions.sh
ACL_FILE="/tmp/sulu/mqtt.acl"
_RESTART_SERVICES="0"
mkdir -p /tmp/sulu/
@@ -20,9 +19,10 @@ function _get_agent_id()
if [ -z "${endpointid}" ]; then
oui="$(db -q get device.deviceinfo.ManufacturerOUI)"
serial="$(db -q get device.deviceinfo.SerialNumber)"
echo "${oui}-${serial}"
echo "${oui}-${serial//+/%2B}"
else
echo "$(echo "${endpointid/::/,}"|cut -d "," -f 2)"
endpointid="$(echo "${endpointid/::/,}"|cut -d "," -f 2)"
endpointid="${endpointid//+/%2B}"
fi
}
@@ -34,9 +34,9 @@ function _get_endpoint_id()
if [ -z "${endpointid}" ]; then
oui="$(db -q get device.deviceinfo.ManufacturerOUI)"
serial="$(db -q get device.deviceinfo.SerialNumber)"
echo "os::${oui}-${serial}"
echo "os::${oui}-${serial//+/%2B}"
else
echo "${endpointid}"
echo "${endpointid//+/%2B}"
fi
}
@@ -49,24 +49,47 @@ function _get_sulu_root()
{
local root
root="$(uci -q get sulu.global.root)"
root="$(uci -q get nginx._sulu_s.root)"
echo "${root:-/sulu}"
}
function _get_sulu_port()
function _get_usp_upstream_port()
{
local port
port="$(uci -q get sulu.global.port)"
echo "${port:-8080}"
port="$(uci -q get mosquitto.sulu.port)"
echo "${port:-9009}"
}
function _get_sulu_ws_port()
function _get_sulu_acl_file()
{
local file
file="$(uci -q get mosquitto.sulu.acl_file)"
echo "${file}"
}
function _get_sulu_tls_port()
{
local port listen
listen="$(uci -q get nginx._sulu_s.listen)"
port="$(echo $listen|grep -Eo '[0-9]+'|head -n 1)"
echo "${port:-8443}"
}
function update_nginx_template()
{
local port
port="$(uci -q get sulu.global.ws_port)"
echo "${port:-9001}"
UCI_TEMPLATE="/etc/nginx/uci.conf.template"
port="$(_get_usp_upstream_port)"
if ! grep -q "upstream websocket { server 127.0.0.1:${port}; }" ${UCI_TEMPLATE}; then
sed -i "s/upstream websocket { server 127.0.0.1:[0-9]\+; }/upstream websocket { server 127.0.0.1:${var}; }/" ${UCI_TEMPLATE}
log "Restarting nginx"
ubus call uci commit '{"config":"nginx"}'
fi
}
function generate_sulu_conn_config()
@@ -86,8 +109,9 @@ function generate_sulu_conn_config()
json_add_object 'connections';
json_add_object 'rbac';
json_add_string 'toId' "$(_get_endpoint_id)";
json_add_int 'port' "$(_get_sulu_ws_port)";
json_add_string 'protocol' 'ws';
json_add_int 'port' "$(_get_sulu_tls_port)";
json_add_string 'path' "/ws";
json_add_string 'protocol' 'wss';
json_add_array 'auth';
json_close_array;
@@ -106,8 +130,9 @@ function generate_sulu_conn_config()
json_add_object 'main';
json_add_string 'fromId' 'proto::interop-usp-controller';
json_add_string 'toId' "$(_get_endpoint_id)";
json_add_int 'port' "$(_get_sulu_ws_port)";
json_add_string 'protocol' 'ws';
json_add_int 'port' "$(_get_sulu_tls_port)";
json_add_string 'path' "/ws";
json_add_string 'protocol' 'wss';
json_add_string 'publishEndpoint' "/usp/endpoint";
json_add_string 'subscribeEndpoint' "/usp/controller";
json_add_array 'auth';
@@ -140,7 +165,7 @@ function update_sulu_connection_port()
local port ws_port SCONF
SCONF="$(_get_sulu_root)/config/connectionConfig.json"
ws_port="$(_get_sulu_ws_port)"
ws_port="$(_get_sulu_tls_port)"
port="$(jq '.connections.rbac.port' ${SCONF})"
if [ "${port}" -ne "${ws_port}" ]; then
@@ -278,78 +303,40 @@ function _remove_obuspa_config_rbac()
}
function _create_acl() {
local agentid rbac users
local agentid rbac users restart
local ACL_FILE
rbac="${1:-0}"
restart="0"
[ -f "${ACL_FILE}" ] && rm -f "${ACL_FILE}"
if [ "${rbac}" -eq "0" ]; then
return 0;
ACL_FILE="$(_get_sulu_acl_file)"
if [ -z "${ACL_FILE}" -o "${rbac}" -eq "0" ]; then
return 0
fi
agentid="$(_get_agent_id)"
users="$(_get_sulu_users)"
for f in ${users}; do
echo "user ${f}" >> ${ACL_FILE}
echo "topic read /usp/${agentid}/${f}/controller/reply-to/#" >> ${ACL_FILE}
echo "topic write /usp/${agentid}/${f}/endpoint/#" >> ${ACL_FILE}
echo "topic read /usp/${agentid}/${f}/controller/#" >> ${ACL_FILE}
echo "" >> ${ACL_FILE}
done
}
function update_mosquitto_broker_config()
{
local system_cred rbac restart ws_port
MB_SULU_CONF="/etc/mosquitto/conf.d/sulu.conf"
system_cred="${1}"
rbac="${2}"
restart=0
ws_port="$(_get_sulu_ws_port)"
if [ "${system_cred}" -eq "1" ]; then
if grep -q "password_file " ${MB_SULU_CONF}; then
sed -i '/password_file /d' ${MB_SULU_CONF}
restart=1
fi
if ! grep -q "plugin .*mosquitto_auth_shadow.so" ${MB_SULU_CONF}; then
echo "plugin /usr/lib/mosquitto_auth_shadow.so" >> ${MB_SULU_CONF}
restart=1
fi
else
if grep -q 'plugin .*mosquitto_auth_shadow.so' ${MB_SULU_CONF}; then
sed -i '/plugin .*mosquitto_auth_shadow.so/d' ${MB_SULU_CONF}
restart=1
fi
if ! grep -q "password_file /etc/mosquitto/sulu.password" ${MB_SULU_CONF}; then
echo "password_file /etc/mosquitto/sulu.password" >> ${MB_SULU_CONF}
restart=1
fi
if [ -f "${ACL_FILE}" ]; then
rm -f "${ACL_FILE}"
fi
touch "${ACL_FILE}"
if [ "${rbac}" -eq "1" ]; then
_create_acl "${rbac}"
if ! grep -q "acl_file ${ACL_FILE}" ${MB_SULU_CONF}; then
echo "acl_file ${ACL_FILE}" >> ${MB_SULU_CONF}
restart=1
fi
else
if grep -q "acl_file ${ACL_FILE}" ${MB_SULU_CONF}; then
sed -i '/acl_file /d' ${MB_SULU_CONF}
restart=1
fi
users="$(_get_sulu_users)"
agentid="$(_get_agent_id)"
for f in ${users}; do
if ! grep -q "user $f" ${ACL_FILE}; then
echo "user ${f}" >> ${ACL_FILE}
echo "topic read /usp/${agentid}/${f}/controller/reply-to/#" >> ${ACL_FILE}
echo "topic write /usp/${agentid}/${f}/endpoint/#" >> ${ACL_FILE}
echo "topic read /usp/${agentid}/${f}/controller/#" >> ${ACL_FILE}
echo "" >> ${ACL_FILE}
restart="1"
fi
done
fi
if ! grep -q "listener ${ws_port}" ${MB_SULU_CONF}; then
sed -i "s/listener [0-9]\+/listener ${ws_port}/" ${MB_SULU_CONF}
restart=1
fi
if [ "${_RESTART_SERVICES}" -eq "1" -a "${restart}" -eq "1" ]; then
slog "Restarting mqtt broker..."
/etc/init.d/mosquitto restart &
if [ "${restart}" -gt "0" ]; then
slog "Restarting mosquitto..."
ubus call uci commit '{"config":"mosquitto"}'
fi
}
@@ -380,44 +367,6 @@ function update_obuspa_config()
fi
}
function update_nginx_config()
{
local enabled restart port
NCONF="/etc/nginx/conf.d/sulu.conf"
restart=0
enabled="${1:-0}"
_RESTART_SERVICES="${2:-0}"
port="$(_get_sulu_port)"
root="$(_get_sulu_root)"
if [ "${enabled}" -eq "1" ]; then
if [ ! -f "${NCONF}" ]; then
cp /etc/sulu/nginx.conf ${NCONF}
restart=1
fi
if ! grep -q "listen ${port}" ${NCONF}; then
sed -i "s/listen [0-9]\+/listen ${port}/" ${NCONF}
sed -i "s/listen \[::\]:[0-9]\+/listen [::]:${port}/" ${NCONF}
restart=1
fi
if ! grep -q "root ${root}" ${NCONF}; then
sed -i "s/root .*;/root ${root//\//\\/};/" ${NCONF}
restart=1
fi
else
if [ -f "${NCONF}" ]; then
rm -f ${NCONF}
restart=1
fi
fi
if [ "${_RESTART_SERVICES}" -eq "1" -a "${restart}" -eq "1" ]; then
slog "Restarting nginx..."
ubus call uci commit '{"config":"nginx"}'
fi
}
function configure_sulu()
{
local sys_cred rbac restart
@@ -433,7 +382,7 @@ function configure_sulu()
_RESTART_SERVICES="${restart}"
update_mosquitto_broker_config "${sys_cred}" "${rbac}"
set_sulu_connection_mode "${rbac}"
update_obuspa_config "${rbac}"
_create_acl "${rbac}"
}

View File

@@ -0,0 +1,12 @@
#!/bin/sh
UCI_TEMPLATE="/etc/nginx/uci.conf.template"
update_nginx_uci_template()
{
if ! grep -q "upstream websocket" ${UCI_TEMPLATE}; then
sed -i '/#UCI_HTTP_CONFIG$/i\ map $http_upgrade $connection_upgrade { default upgrade; "" close; }' ${UCI_TEMPLATE}
sed -i '/#UCI_HTTP_CONFIG$/i\ upstream websocket { server 127.0.0.1:9009; }' ${UCI_TEMPLATE}
fi
}
update_nginx_uci_template

View File

@@ -0,0 +1,37 @@
#!/bin/sh
. /lib/functions.sh
if [ ! -f "/etc/config/mosquitto" ]; then
echo "Local mosquitto broker not available"
return 0
fi
add_obuspa_config()
{
if ! uci_get mosquitto obuspa >/dev/null 2>&1; then
uci_add mosquitto listener obuspa
uci_set mosquitto obuspa enabled 1
uci_set mosquitto obuspa port '1883'
uci_set mosquitto obuspa no_remote_access '1'
uci_set mosquitto obuspa allow_anonymous '1'
fi
}
add_sulu_config()
{
if ! uci_get mosquitto sulu >/dev/null 2>&1; then
uci_add mosquitto listener sulu
uci_set mosquitto sulu enabled 1
uci_set mosquitto sulu port '9009'
uci_set mosquitto sulu no_remote_access '1'
uci_set mosquitto sulu protocol 'websockets'
uci_set mosquitto sulu require_certificates '0'
uci_set mosquitto sulu auth_plugin '/usr/lib/mosquitto_auth_shadow.so'
uci_set mosquitto sulu acl_file '/tmp/sulu/mqtt.acl'
fi
}
uci_load mosquitto
add_obuspa_config
add_sulu_config

View File

@@ -0,0 +1,35 @@
#!/bin/sh
. /lib/functions.sh
add_sulu_nginx_uci()
{
uci_load nginx
if ! uci_get nginx _sulu_s >/dev/null 2>&1; then
uci_add nginx server _sulu_s
uci_set nginx _sulu_s root '/sulu'
uci_add_list nginx _sulu_s listen "8443 http2 ssl"
uci_add_list nginx _sulu_s listen "[::]:8443 http2 ssl"
uci_set nginx _sulu_s server_name '_sulu_s'
uci_add_list nginx _sulu_s include 'restrict_locally'
uci_add_list nginx _sulu_s include '/etc/sulu/nginx.locations'
uci_set nginx _sulu_s uci_manage_ssl 'self-signed'
uci_set nginx _sulu_s ssl_certificate '/etc/nginx/conf.d/_lan.crt'
uci_set nginx _sulu_s ssl_certificate_key '/etc/nginx/conf.d/_lan.key'
uci_set nginx _sulu_s ssl_session_cache 'shared:SSL:32k'
uci_set nginx _sulu_s ssl_session_timeout '64m'
uci_set nginx _sulu_s access_log 'off; # logd openwrt'
fi
if ! uci_get nginx _suluredirect >/dev/null 2>&1; then
uci_add nginx server _suluredirect
uci_add_list nginx _suluredirect listen "8080"
uci_add_list nginx _suluredirect listen "[::]:8080"
uci_set nginx _suluredirect server_name '_suluredirect'
uci_set nginx _suluredirect return 'https://$host:8443$request_uri'
fi
}
add_sulu_nginx_uci

View File

@@ -5,7 +5,6 @@
config_load sulu
config_get enable_system_credentials global enable_system_credentials 1
config_get role_based_access global role_based_access 0
config_get enabled global enabled 0
configure_sulu "${enable_system_credentials}" "${role_based_access}" 0
generate_sulu_conn_config "${role_based_access}"

View File

@@ -5,11 +5,11 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=sulu
PKG_VERSION:=1.3.16
PKG_VERSION:=1.3.26
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/websdk/sulu.git
PKG_SOURCE_VERSION:=81d4bb268914dc3822293e93519ae6adbd6ddbea
PKG_SOURCE_VERSION:=6d6848119bffdbe0ec9b8116caf6375749299dc0
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_SOURCE_VERSION)
PKG_SOURCE:=$(PKG_NAME)-$(PKG_SOURCE_VERSION).tar.gz
@@ -49,20 +49,16 @@ endif
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/etc/init.d/sulu $(1)/etc/init.d/sulu
$(INSTALL_DIR) $(1)/etc/mosquitto/conf.d/
$(INSTALL_DATA) ./files/etc/mosquitto/conf.d/obuspa.conf $(1)/etc/mosquitto/conf.d/
$(INSTALL_DATA) ./files/etc/mosquitto/conf.d/sulu.conf $(1)/etc/mosquitto/conf.d/
$(INSTALL_DATA) ./files/etc/mosquitto/sulu.password $(1)/etc/mosquitto/sulu.password
$(INSTALL_DIR) $(1)/etc/nginx/conf.d
$(INSTALL_DATA) ./files/etc/nginx/conf.d/sulu.conf $(1)/etc/nginx/conf.d/
$(INSTALL_DIR) $(1)/etc/sulu
$(INSTALL_DATA) ./files/etc/sulu/roles.json $(1)/etc/sulu/
$(INSTALL_BIN) ./files/etc/sulu/sulu.sh $(1)/etc/sulu/
$(INSTALL_DATA) ./files/etc/sulu/nginx.locations $(1)/etc/sulu/
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) ./files/etc/uci-defaults/99-fix-sulu-config $(1)/etc/uci-defaults/
$(INSTALL_BIN) ./files/etc/uci-defaults/40-add-sulu-nginx-config $(1)/etc/uci-defaults/
$(INSTALL_BIN) ./files/etc/uci-defaults/01-update-nginx-uci-template $(1)/etc/uci-defaults/
$(INSTALL_BIN) ./files/etc/uci-defaults/10-add-mqtt-config $(1)/etc/uci-defaults/
endef
$(eval $(call BuildPackage,sulu))

View File

@@ -1,9 +1,4 @@
config global 'global'
option root '/sulu'
option port '8080'
option ws_port '9001'
option enabled '1'
option enable_system_credentials '1'
option role_based_access '1'
list user 'admin'
list user 'user'

View File

@@ -33,9 +33,9 @@ start_service() {
return 0
fi
update_nginx_template
configure_sulu "${enable_system_credentials}" "${role_based_access}" 1
update_nginx_config "${enabled}" 1
update_sulu_connection_port
generate_sulu_conn_config "${role_based_access}"
procd_close_instance
}
@@ -46,5 +46,5 @@ reload_service() {
service_triggers()
{
procd_add_reload_trigger "sulu"
procd_add_reload_trigger "sulu" "nginx"
}

View File

@@ -1,3 +0,0 @@
listener 1883 127.0.0.1
allow_anonymous true

View File

@@ -1,4 +0,0 @@
listener 9001
protocol websockets
require_certificate false
allow_anonymous false

View File

@@ -1 +0,0 @@
admin:$6$OmM9kU/lYct3KJ9j$iP0WK4ezEtRm8+EAggNp7WbJFoWO0p7IUdI0v/hr1WcVHyfFAC30Pb8Csn7GqwwqI2dcmnDOAITnimo2VNe6ug==

View File

@@ -1,27 +0,0 @@
server {
listen 8080;
listen [::]:8080;
server_name _sulu;
root /sulu;
location / {
autoindex on;
expires -1;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,Content-Type,Range';
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,Content-Type,Range' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
}
}
}

View File

@@ -0,0 +1,50 @@
error_page 497 301 =307 https://$host:$server_port$request_uri;
location /robots.txt {
return 200 "User-agent: *\nDisallow: /\n";
}
location /sitemap.xml {
return 200 "User-agent: *\nDisallow: /\n";
}
location /ws {
proxy_pass_request_headers on;
proxy_cache off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,Content-Type,Range' always;
proxy_pass http://websocket;
}
location / {
autoindex on;
expires -1;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,Content-Type,Range';
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,Content-Type,Range' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
}
}

View File

@@ -2,7 +2,6 @@
. /lib/functions.sh
ACL_FILE="/tmp/sulu/mqtt.acl"
_RESTART_SERVICES="0"
mkdir -p /tmp/sulu/
@@ -20,9 +19,10 @@ function _get_agent_id()
if [ -z "${endpointid}" ]; then
oui="$(db -q get device.deviceinfo.ManufacturerOUI)"
serial="$(db -q get device.deviceinfo.SerialNumber)"
echo "${oui}-${serial}"
echo "${oui}-${serial//+/%2B}"
else
echo "$(echo "${endpointid/::/,}"|cut -d "," -f 2)"
endpointid="$(echo "${endpointid/::/,}"|cut -d "," -f 2)"
endpointid="${endpointid//+/%2B}"
fi
}
@@ -34,9 +34,9 @@ function _get_endpoint_id()
if [ -z "${endpointid}" ]; then
oui="$(db -q get device.deviceinfo.ManufacturerOUI)"
serial="$(db -q get device.deviceinfo.SerialNumber)"
echo "os::${oui}-${serial}"
echo "os::${oui}-${serial//+/%2B}"
else
echo "${endpointid}"
echo "${endpointid//+/%2B}"
fi
}
@@ -49,24 +49,47 @@ function _get_sulu_root()
{
local root
root="$(uci -q get sulu.global.root)"
root="$(uci -q get nginx._sulu_s.root)"
echo "${root:-/sulu}"
}
function _get_sulu_port()
function _get_usp_upstream_port()
{
local port
port="$(uci -q get sulu.global.port)"
echo "${port:-8080}"
port="$(uci -q get mosquitto.sulu.port)"
echo "${port:-9009}"
}
function _get_sulu_ws_port()
function _get_sulu_acl_file()
{
local file
file="$(uci -q get mosquitto.sulu.acl_file)"
echo "${file}"
}
function _get_sulu_tls_port()
{
local port listen
listen="$(uci -q get nginx._sulu_s.listen)"
port="$(echo $listen|grep -Eo '[0-9]+'|head -n 1)"
echo "${port:-8443}"
}
function update_nginx_template()
{
local port
port="$(uci -q get sulu.global.ws_port)"
echo "${port:-9001}"
UCI_TEMPLATE="/etc/nginx/uci.conf.template"
port="$(_get_usp_upstream_port)"
if ! grep -q "upstream websocket { server 127.0.0.1:${port}; }" ${UCI_TEMPLATE}; then
sed -i "s/upstream websocket { server 127.0.0.1:[0-9]\+; }/upstream websocket { server 127.0.0.1:${var}; }/" ${UCI_TEMPLATE}
log "Restarting nginx"
ubus call uci commit '{"config":"nginx"}'
fi
}
function generate_sulu_conn_config()
@@ -86,8 +109,9 @@ function generate_sulu_conn_config()
json_add_object 'connections';
json_add_object 'rbac';
json_add_string 'toId' "$(_get_endpoint_id)";
json_add_int 'port' "$(_get_sulu_ws_port)";
json_add_string 'protocol' 'ws';
json_add_int 'port' "$(_get_sulu_tls_port)";
json_add_string 'path' "/ws";
json_add_string 'protocol' 'wss';
json_add_array 'auth';
json_close_array;
@@ -106,8 +130,9 @@ function generate_sulu_conn_config()
json_add_object 'main';
json_add_string 'fromId' 'proto::interop-usp-controller';
json_add_string 'toId' "$(_get_endpoint_id)";
json_add_int 'port' "$(_get_sulu_ws_port)";
json_add_string 'protocol' 'ws';
json_add_int 'port' "$(_get_sulu_tls_port)";
json_add_string 'path' "/ws";
json_add_string 'protocol' 'wss';
json_add_string 'publishEndpoint' "/usp/endpoint";
json_add_string 'subscribeEndpoint' "/usp/controller";
json_add_array 'auth';
@@ -140,7 +165,7 @@ function update_sulu_connection_port()
local port ws_port SCONF
SCONF="$(_get_sulu_root)/config/connectionConfig.json"
ws_port="$(_get_sulu_ws_port)"
ws_port="$(_get_sulu_tls_port)"
port="$(jq '.connections.rbac.port' ${SCONF})"
if [ "${port}" -ne "${ws_port}" ]; then
@@ -278,78 +303,40 @@ function _remove_obuspa_config_rbac()
}
function _create_acl() {
local agentid rbac users
local agentid rbac users restart
local ACL_FILE
rbac="${1:-0}"
restart="0"
[ -f "${ACL_FILE}" ] && rm -f "${ACL_FILE}"
if [ "${rbac}" -eq "0" ]; then
return 0;
ACL_FILE="$(_get_sulu_acl_file)"
if [ -z "${ACL_FILE}" -o "${rbac}" -eq "0" ]; then
return 0
fi
agentid="$(_get_agent_id)"
users="$(_get_sulu_users)"
for f in ${users}; do
echo "user ${f}" >> ${ACL_FILE}
echo "topic read /usp/${agentid}/${f}/controller/reply-to/#" >> ${ACL_FILE}
echo "topic write /usp/${agentid}/${f}/endpoint/#" >> ${ACL_FILE}
echo "topic read /usp/${agentid}/${f}/controller/#" >> ${ACL_FILE}
echo "" >> ${ACL_FILE}
done
}
function update_mosquitto_broker_config()
{
local system_cred rbac restart ws_port
MB_SULU_CONF="/etc/mosquitto/conf.d/sulu.conf"
system_cred="${1}"
rbac="${2}"
restart=0
ws_port="$(_get_sulu_ws_port)"
if [ "${system_cred}" -eq "1" ]; then
if grep -q "password_file " ${MB_SULU_CONF}; then
sed -i '/password_file /d' ${MB_SULU_CONF}
restart=1
fi
if ! grep -q "plugin .*mosquitto_auth_shadow.so" ${MB_SULU_CONF}; then
echo "plugin /usr/lib/mosquitto_auth_shadow.so" >> ${MB_SULU_CONF}
restart=1
fi
else
if grep -q 'plugin .*mosquitto_auth_shadow.so' ${MB_SULU_CONF}; then
sed -i '/plugin .*mosquitto_auth_shadow.so/d' ${MB_SULU_CONF}
restart=1
fi
if ! grep -q "password_file /etc/mosquitto/sulu.password" ${MB_SULU_CONF}; then
echo "password_file /etc/mosquitto/sulu.password" >> ${MB_SULU_CONF}
restart=1
fi
if [ -f "${ACL_FILE}" ]; then
rm -f "${ACL_FILE}"
fi
touch "${ACL_FILE}"
if [ "${rbac}" -eq "1" ]; then
_create_acl "${rbac}"
if ! grep -q "acl_file ${ACL_FILE}" ${MB_SULU_CONF}; then
echo "acl_file ${ACL_FILE}" >> ${MB_SULU_CONF}
restart=1
fi
else
if grep -q "acl_file ${ACL_FILE}" ${MB_SULU_CONF}; then
sed -i '/acl_file /d' ${MB_SULU_CONF}
restart=1
fi
users="$(_get_sulu_users)"
agentid="$(_get_agent_id)"
for f in ${users}; do
if ! grep -q "user $f" ${ACL_FILE}; then
echo "user ${f}" >> ${ACL_FILE}
echo "topic read /usp/${agentid}/${f}/controller/reply-to/#" >> ${ACL_FILE}
echo "topic write /usp/${agentid}/${f}/endpoint/#" >> ${ACL_FILE}
echo "topic read /usp/${agentid}/${f}/controller/#" >> ${ACL_FILE}
echo "" >> ${ACL_FILE}
restart="1"
fi
done
fi
if ! grep -q "listener ${ws_port}" ${MB_SULU_CONF}; then
sed -i "s/listener [0-9]\+/listener ${ws_port}/" ${MB_SULU_CONF}
restart=1
fi
if [ "${_RESTART_SERVICES}" -eq "1" -a "${restart}" -eq "1" ]; then
slog "Restarting mqtt broker..."
/etc/init.d/mosquitto restart &
if [ "${restart}" -gt "0" ]; then
slog "Restarting mosquitto..."
ubus call uci commit '{"config":"mosquitto"}'
fi
}
@@ -380,44 +367,6 @@ function update_obuspa_config()
fi
}
function update_nginx_config()
{
local enabled restart port
NCONF="/etc/nginx/conf.d/sulu.conf"
restart=0
enabled="${1:-0}"
_RESTART_SERVICES="${2:-0}"
port="$(_get_sulu_port)"
root="$(_get_sulu_root)"
if [ "${enabled}" -eq "1" ]; then
if [ ! -f "${NCONF}" ]; then
cp /etc/sulu/nginx.conf ${NCONF}
restart=1
fi
if ! grep -q "listen ${port}" ${NCONF}; then
sed -i "s/listen [0-9]\+/listen ${port}/" ${NCONF}
sed -i "s/listen \[::\]:[0-9]\+/listen [::]:${port}/" ${NCONF}
restart=1
fi
if ! grep -q "root ${root}" ${NCONF}; then
sed -i "s/root .*;/root ${root//\//\\/};/" ${NCONF}
restart=1
fi
else
if [ -f "${NCONF}" ]; then
rm -f ${NCONF}
restart=1
fi
fi
if [ "${_RESTART_SERVICES}" -eq "1" -a "${restart}" -eq "1" ]; then
slog "Restarting nginx..."
ubus call uci commit '{"config":"nginx"}'
fi
}
function configure_sulu()
{
local sys_cred rbac restart
@@ -433,7 +382,7 @@ function configure_sulu()
_RESTART_SERVICES="${restart}"
update_mosquitto_broker_config "${sys_cred}" "${rbac}"
set_sulu_connection_mode "${rbac}"
update_obuspa_config "${rbac}"
_create_acl "${rbac}"
}

View File

@@ -0,0 +1,12 @@
#!/bin/sh
UCI_TEMPLATE="/etc/nginx/uci.conf.template"
update_nginx_uci_template()
{
if ! grep -q "upstream websocket" ${UCI_TEMPLATE}; then
sed -i '/#UCI_HTTP_CONFIG$/i\ map $http_upgrade $connection_upgrade { default upgrade; "" close; }' ${UCI_TEMPLATE}
sed -i '/#UCI_HTTP_CONFIG$/i\ upstream websocket { server 127.0.0.1:9009; }' ${UCI_TEMPLATE}
fi
}
update_nginx_uci_template

View File

@@ -0,0 +1,37 @@
#!/bin/sh
. /lib/functions.sh
if [ ! -f "/etc/config/mosquitto" ]; then
echo "Local mosquitto broker not available"
return 0
fi
add_obuspa_config()
{
if ! uci_get mosquitto obuspa >/dev/null 2>&1; then
uci_add mosquitto listener obuspa
uci_set mosquitto obuspa enabled 1
uci_set mosquitto obuspa port '1883'
uci_set mosquitto obuspa no_remote_access '1'
uci_set mosquitto obuspa allow_anonymous '1'
fi
}
add_sulu_config()
{
if ! uci_get mosquitto sulu >/dev/null 2>&1; then
uci_add mosquitto listener sulu
uci_set mosquitto sulu enabled 1
uci_set mosquitto sulu port '9009'
uci_set mosquitto sulu no_remote_access '1'
uci_set mosquitto sulu protocol 'websockets'
uci_set mosquitto sulu require_certificates '0'
uci_set mosquitto sulu auth_plugin '/usr/lib/mosquitto_auth_shadow.so'
uci_set mosquitto sulu acl_file '/tmp/sulu/mqtt.acl'
fi
}
uci_load mosquitto
add_obuspa_config
add_sulu_config

View File

@@ -0,0 +1,35 @@
#!/bin/sh
. /lib/functions.sh
add_sulu_nginx_uci()
{
uci_load nginx
if ! uci_get nginx _sulu_s >/dev/null 2>&1; then
uci_add nginx server _sulu_s
uci_set nginx _sulu_s root '/sulu'
uci_add_list nginx _sulu_s listen "8443 http2 ssl"
uci_add_list nginx _sulu_s listen "[::]:8443 http2 ssl"
uci_set nginx _sulu_s server_name '_sulu_s'
uci_add_list nginx _sulu_s include 'restrict_locally'
uci_add_list nginx _sulu_s include '/etc/sulu/nginx.locations'
uci_set nginx _sulu_s uci_manage_ssl 'self-signed'
uci_set nginx _sulu_s ssl_certificate '/etc/nginx/conf.d/_lan.crt'
uci_set nginx _sulu_s ssl_certificate_key '/etc/nginx/conf.d/_lan.key'
uci_set nginx _sulu_s ssl_session_cache 'shared:SSL:32k'
uci_set nginx _sulu_s ssl_session_timeout '64m'
uci_set nginx _sulu_s access_log 'off; # logd openwrt'
fi
if ! uci_get nginx _suluredirect >/dev/null 2>&1; then
uci_add nginx server _suluredirect
uci_add_list nginx _suluredirect listen "8080"
uci_add_list nginx _suluredirect listen "[::]:8080"
uci_set nginx _suluredirect server_name '_suluredirect'
uci_set nginx _suluredirect return 'https://$host:8443$request_uri'
fi
}
add_sulu_nginx_uci

Some files were not shown because too many files have changed in this diff Show More