remote: close file on usteer_init_local_id fread fail
[project/usteer.git] / main.c
diff --git a/main.c b/main.c
index b6dbffa5f937885f696485aa5270a95525416f90..99aa6ade7a3e1d8d1c5ee322a8607d9dca985ae8 100644 (file)
--- a/main.c
+++ b/main.c
 #include <stdarg.h>
 #include <syslog.h>
 
+#include <libubox/blobmsg_json.h>
+
 #include "usteer.h"
+#include "event.h"
+#include "node.h"
 
 struct ubus_context *ubus_ctx;
 struct usteer_config config = {};
+struct blob_attr *host_info_blob;
 uint64_t current_time;
+static int dump_time;
 
 LIST_HEAD(node_handlers);
 
@@ -35,6 +41,14 @@ const char * const event_types[__EVENT_TYPE_MAX] = {
        [EVENT_TYPE_ASSOC] = "assoc",
 };
 
+void log_msg(char *msg)
+{
+       if (config.syslog)
+               syslog(LOG_INFO, "%s\n", msg);
+       else
+               fprintf(stderr, "%s\n", msg);
+}
+
 void debug_msg(int level, const char *func, int line, const char *format, ...)
 {
        va_list ap;
@@ -72,20 +86,35 @@ void usteer_init_defaults(void)
 
        config.sta_block_timeout = 30 * 1000;
        config.local_sta_timeout = 120 * 1000;
+       config.measurement_report_timeout = 120 * 1000;
        config.local_sta_update = 1 * 1000;
        config.max_retry_band = 5;
+       config.max_neighbor_reports = 8;
        config.seen_policy_timeout = 30 * 1000;
        config.band_steering_threshold = 5;
-       config.load_balancing_threshold = 5;
+       config.load_balancing_threshold = 0;
        config.remote_update_interval = 1000;
        config.initial_connect_delay = 0;
-       config.remote_node_timeout = 120 * 1000;
+       config.remote_node_timeout = 10;
 
-       config.roam_kick_delay = 100;
+       config.steer_reject_timeout = 60000;
+
+       config.band_steering_interval = 120000;
+       config.band_steering_min_snr = -60;
+
+       config.link_measurement_interval = 30000;
+
+       config.probe_steering = 0;
+
+       config.roam_kick_delay = 10000;
+       config.roam_process_timeout = 5 * 1000;
        config.roam_scan_tries = 3;
+       config.roam_scan_timeout = 0;
        config.roam_scan_interval = 10 * 1000;
        config.roam_trigger_interval = 60 * 1000;
 
+       config.min_snr_kick_delay = 5 * 1000;
+
        config.load_kick_enabled = false;
        config.load_kick_threshold = 75;
        config.load_kick_delay = 10 * 1000;
@@ -115,17 +144,50 @@ static int usage(const char *prog)
                "               5: include extra testing messages\n"
                " -i <name>:    Connect to other instances on interface <name>\n"
                " -s:           Output log messages via syslog instead of stderr\n"
+               " -D <n>:       Do not daemonize, wait for <n> seconds and print\n"
+               "               remote hosts and nodes\n"
                "\n", prog);
        return 1;
 }
 
+static void
+usteer_dump_timeout(struct uloop_timeout *t)
+{
+       struct usteer_remote_host *host;
+       struct usteer_remote_node *rn;
+       struct blob_buf b = {};
+       char *str;
+       void *c;
+
+       blob_buf_init(&b, 0);
+
+       c = blobmsg_open_table(&b, "hosts");
+       avl_for_each_element(&remote_hosts, host, avl)
+               usteer_dump_host(&b, host);
+       blobmsg_close_table(&b, c);
+
+       c = blobmsg_open_table(&b, "nodes");
+       for_each_remote_node(rn)
+               usteer_dump_node(&b, &rn->node);
+       blobmsg_close_table(&b, c);
+
+       str = blobmsg_format_json(b.head, true);
+       blob_buf_free(&b);
+
+       puts(str);
+       free(str);
+
+       uloop_end();
+}
+
 int main(int argc, char **argv)
 {
+       struct uloop_timeout dump_timer;
        int ch;
 
        usteer_init_defaults();
 
-       while ((ch = getopt(argc, argv, "i:sv")) != -1) {
+       while ((ch = getopt(argc, argv, "D:i:sv")) != -1) {
                switch(ch) {
                case 'v':
                        config.debug_level++;
@@ -136,6 +198,9 @@ int main(int argc, char **argv)
                case 'i':
                        usteer_interface_add(optarg);
                        break;
+               case 'D':
+                       dump_time = atoi(optarg);
+                       break;
                default:
                        return usage(argv[0]);
                }
@@ -143,6 +208,7 @@ int main(int argc, char **argv)
 
        openlog("usteer", 0, LOG_USER);
 
+       config_set_event_log_types(NULL);
        usteer_update_time();
        uloop_init();
 
@@ -153,9 +219,13 @@ int main(int argc, char **argv)
        }
 
        ubus_add_uloop(ubus_ctx);
-       usteer_ubus_init(ubus_ctx);
-       usteer_interface_init();
-       usteer_local_nodes_init(ubus_ctx);
+       if (dump_time) {
+               dump_timer.cb = usteer_dump_timeout;
+               uloop_timeout_set(&dump_timer, dump_time * 1000);
+       } else {
+               usteer_ubus_init(ubus_ctx);
+               usteer_local_nodes_init(ubus_ctx);
+       }
        uloop_run();
 
        uloop_done();