Skip to content

Commit

Permalink
usteer2: add new package
Browse files Browse the repository at this point in the history
Signed-off-by: John Crispin <john@phrozen.org>
  • Loading branch information
blogic committed Oct 10, 2022
1 parent b028c95 commit a7f4abe
Show file tree
Hide file tree
Showing 18 changed files with 1,075 additions and 3 deletions.
4 changes: 2 additions & 2 deletions feeds/ucentral/ucentral-schema/Makefile
Expand Up @@ -4,10 +4,10 @@ PKG_NAME:=ucentral-schema
PKG_RELEASE:=1

PKG_SOURCE_URL=https://github.com/Telecominfraproject/wlan-ucentral-schema.git
PKG_MIRROR_HASH:=a65ff619c0bc8c0889e58c5502637e9751051a8d547f6f97c7963a32b706da3b
PKG_MIRROR_HASH:=f9dc6446a3006d475e5fc94db679950fcaf8e6e4af7e281c4f5bdefd466aa7db
PKG_SOURCE_PROTO:=git
PKG_SOURCE_DATE:=2022-05-29
PKG_SOURCE_VERSION:=0856cd5cda623339abe983973c09ff57040182c9
PKG_SOURCE_VERSION:=516829ac2b9cf7857ea1b67c9fc6e440f9e44806

PKG_MAINTAINER:=John Crispin <john@phrozen.org>
PKG_LICENSE:=BSD-3-Clause
Expand Down
@@ -0,0 +1,89 @@
{
"uuid": 2,
"radios": [
{
"band": "2G",
"country": "CA",
"channel-mode": "HE",
"channel-width": 80,
"channel": 32
}
],

"interfaces": [
{
"name": "WAN",
"role": "upstream",
"services": [ "lldp" ],
"ethernet": [
{
"select-ports": [
"WAN*"
]
}
],
"ipv4": {
"addressing": "dynamic"
},
"ssids": [
{
"name": "OpenWifi",
"wifi-bands": [
"2G"
],
"bss-mode": "ap",
"encryption": {
"proto": "psk2",
"key": "OpenWifi",
"ieee80211w": "optional"
},
"quality-thresholds" : {
"probe-request-rssi": -60,
"assoctiation-request-rssi": -60,
"client-kick-rssi": -65,
"client-kick-ban-time": 60
}
}
]
},
{
"name": "LAN",
"role": "downstream",
"services": [ "ssh", "lldp" ],
"ethernet": [
{
"select-ports": [
"LAN*"
]
}
],
"ipv4": {
"addressing": "static",
"subnet": "192.168.1.1/24",
"dhcp": {
"lease-first": 10,
"lease-count": 100,
"lease-time": "6h"
}
}
}
],
"metrics": {
"statistics": {
"interval": 120,
"types": [ "ssids", "lldp", "clients" ]
},
"health": {
"interval": 120
}
},
"services": {
"lldp": {
"describe": "uCentral",
"location": "universe"
},
"ssh": {
"port": 22
}
}
}
34 changes: 34 additions & 0 deletions feeds/ucentral/ucrun/Makefile
@@ -0,0 +1,34 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=ucrun
PKG_RELEASE:=1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL=https://github.com/ucentral-io/ucrun.git
PKG_MIRROR_HASH:=52aeece27348611197ae5f4b96b3bdf1b5d028ae4ae284806b216d502300d07a
PKG_SOURCE_DATE:=2022-02-19
PKG_SOURCE_VERSION:=5be6abebc4ae6057b47a5b3f0799d5ff01bc60c3
CMAKE_INSTALL:=1

PKG_LICENSE:=GPL-2.0-only
PKG_LICENSE_FILES:=GPL

PKG_MAINTAINER:=John Crispin <john@phrozen.org>

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk

define Package/ucrun
SECTION:=utils
CATEGORY:=Utilities
DEPENDS:=+libubox +ucode +ucode-mod-uci +ucode-mod-ubus +ucode-mod-fs
TITLE:=uCode main-loop daemon
endef

define Package/ucrun/install
$(INSTALL_DIR) $(1)/usr/bin

$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/ucrun $(1)/usr/bin
endef

$(eval $(call BuildPackage,ucrun))
@@ -0,0 +1,138 @@
From b24a5a890ccd19b0f1b50340c79c5087f08d9447 Mon Sep 17 00:00:00 2001
From: John Crispin <john@phrozen.org>
Date: Fri, 4 Mar 2022 15:56:30 +0100
Subject: [PATCH] ulog: add ringbuffer and log_event notification

Signed-off-by: John Crispin <john@phrozen.org>
---
ucode.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 73 insertions(+), 2 deletions(-)

diff --git a/ucode.c b/ucode.c
index cef50e2..9e0373a 100644
--- a/ucode.c
+++ b/ucode.c
@@ -31,6 +31,17 @@ static const char *exception_types[] = {
[EXCEPTION_EXIT] = "Exit"
};

+struct log_buffer {
+ struct list_head list;
+ int severity;
+ char entry[];
+};
+
+static LIST_HEAD(log_buffer);
+static int log_count;
+static int log_max = 100;
+static uc_value_t *log_event;
+
static void
ucode_handle_exception(uc_vm_t *vm, uc_exception_t *ex)
{
@@ -287,6 +298,7 @@ static uc_value_t *
uc_ulog(uc_vm_t *vm, size_t nargs, int severity)
{
uc_value_t *res;
+ char *entry;

if (!fmtfn) {
fmtfn = (uc_cfunction_t *)ucv_object_get(uc_vm_scope_get(vm), "sprintf", NULL);
@@ -300,7 +312,37 @@ uc_ulog(uc_vm_t *vm, size_t nargs, int severity)
if (!res)
return ucv_int64_new(-1);

- ulog(severity, "%s", ucv_string_get(res));
+ entry = ucv_string_get(res);
+
+ if (log_max) {
+ struct log_buffer *log = calloc(1, sizeof(*log) + strlen(entry) + 1);
+
+ strcpy(log->entry, entry);
+ log->severity = severity;
+ list_add_tail(&log->list, &log_buffer);
+
+ if (log_event) {
+ uc_value_t *event = ucv_array_new(vm);
+
+ ucv_array_push(event, ucv_int64_new(severity));
+ ucv_array_push(event, ucv_string_new(entry));
+
+ uc_vm_stack_push(vm, ucv_get(log_event));
+ uc_vm_stack_push(vm, ucv_get(event));
+ uc_vm_call(vm, false, 1);
+ }
+
+ if (log_count == log_max) {
+ struct log_buffer *first = list_first_entry(&log_buffer, struct log_buffer, list);
+
+ list_del(&first->list);
+ free(first);
+ } else {
+ log_count++;
+ }
+ }
+
+ ulog(severity, "%s", entry);
ucv_put(res);

return ucv_int64_new(0);
@@ -330,11 +372,27 @@ uc_ulog_err(uc_vm_t *vm, size_t nargs)
return uc_ulog(vm, nargs, LOG_ERR);
}

+static uc_value_t *
+uc_ulog_dump(uc_vm_t *vm, size_t nargs)
+{
+ uc_value_t *log = ucv_array_new(vm);
+ struct log_buffer *iter;
+
+ list_for_each_entry(iter, &log_buffer, list) {
+ uc_value_t *entry = ucv_array_new(vm);
+ ucv_array_push(entry, ucv_int64_new(iter->severity));
+ ucv_array_push(entry, ucv_string_new(iter->entry));
+ ucv_array_push(log, entry);
+ }
+
+ return log;
+}
+
static void
ucode_init_ulog(ucrun_ctx_t *ucrun)
{
uc_value_t *ulog = ucv_object_get(ucrun->scope, "ulog", NULL);
- uc_value_t *identity, *channels;
+ uc_value_t *identity, *channels, *logsize;
int flags = 0, channel;

/* make sure the declartion is complete */
@@ -365,6 +423,18 @@ ucode_init_ulog(ucrun_ctx_t *ucrun)
flags |= ULOG_STDIO;
}

+ /* set the internal ring buffer size */
+ logsize = ucv_object_get(ulog, "channels", NULL);
+ if (ucv_type(logsize) == UC_INTEGER && ucv_int64_get(logsize))
+ log_max = ucv_int64_get(logsize);
+
+ /* find out if ucrun wants a notification when a new log entry is generated */
+ log_event = ucv_object_get(ulog, "event", NULL);
+ if (ucv_is_callable(log_event))
+ ucv_get(log_event);
+ else
+ log_event = NULL;
+
/* open the log */
ucrun->ulog_identity = strdup(ucv_string_get(identity));
ulog_open(flags, LOG_DAEMON, ucrun->ulog_identity);
@@ -404,6 +474,7 @@ ucode_init(ucrun_ctx_t *ucrun, int argc, const char **argv, int *rc)
uc_function_register(ucrun->scope, "ulog_note", uc_ulog_note);
uc_function_register(ucrun->scope, "ulog_warn", uc_ulog_warn);
uc_function_register(ucrun->scope, "ulog_err", uc_ulog_err);
+ uc_function_register(ucrun->scope, "ulog_dump", uc_ulog_dump);

/* add commandline parameters */
ARGV = ucv_array_new(&ucrun->vm);
--
2.25.1

27 changes: 27 additions & 0 deletions feeds/ucentral/usteer2/Makefile
@@ -0,0 +1,27 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=usteer2
PKG_RELEASE:=1
PKG_LICENSE:=ISC

PKG_MAINTAINER:=John Crispin <john@phrozen.org>

include $(INCLUDE_DIR)/package.mk

define Package/usteer2
SECTION:=utils
CATEGORY:=Utilities
DEPENDS:=+ucrun
TITLE:=wifi client steering
endef

define Build/Compile/Default

endef
Build/Compile = $(Build/Compile/Default)

define Package/usteer2/install
$(CP) ./files/* $(1)/
endef

$(eval $(call BuildPackage,usteer2))
9 changes: 9 additions & 0 deletions feeds/ucentral/usteer2/files/etc/config/usteer2
@@ -0,0 +1,9 @@
config base
option station_update 1000
option station_expiry 120

config policy
option name snr
option min_snr_kick_delay 5
option kick_reason 5
option interval 1000
13 changes: 13 additions & 0 deletions feeds/ucentral/usteer2/files/etc/init.d/usteer2
@@ -0,0 +1,13 @@
#!/bin/sh /etc/rc.common

START=99
STOP=01

USE_PROCD=1

start_service() {
procd_open_instance
procd_set_param command /usr/bin/usteer.uc
procd_set_param respawn 3600 5 0
procd_close_instance
}

0 comments on commit a7f4abe

Please sign in to comment.