a26818e0d3cc596cfe08f8e22fcc52b576c2ac6e
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
15 * Copyright (C) 2020 embedd.ch
16 * Copyright (C) 2020 Felix Fietkau <nbd@nbd.name>
17 * Copyright (C) 2020 John Crispin <john@phrozen.org>
27 struct ubus_context
*ubus_ctx
;
28 struct usteer_config config
= {};
29 uint64_t current_time
;
31 LIST_HEAD(node_handlers
);
33 const char * const event_types
[__EVENT_TYPE_MAX
] = {
34 [EVENT_TYPE_PROBE
] = "probe",
35 [EVENT_TYPE_AUTH
] = "auth",
36 [EVENT_TYPE_ASSOC
] = "assoc",
39 void log_msg(char *msg
)
42 syslog(LOG_INFO
, "%s\n", msg
);
44 fprintf(stderr
, "%s\n", msg
);
47 void debug_msg(int level
, const char *func
, int line
, const char *format
, ...)
51 if (config
.debug_level
< level
)
55 fprintf(stderr
, "[%s:%d] ", func
, line
);
59 vsyslog(level
>= MSG_DEBUG
? LOG_DEBUG
: LOG_INFO
, format
, ap
);
61 vfprintf(stderr
, format
, ap
);
66 void debug_msg_cont(int level
, const char *format
, ...)
70 if (config
.debug_level
< level
)
74 vfprintf(stderr
, format
, ap
);
78 void usteer_init_defaults(void)
80 memset(&config
, 0, sizeof(config
));
82 config
.sta_block_timeout
= 30 * 1000;
83 config
.local_sta_timeout
= 120 * 1000;
84 config
.local_sta_update
= 1 * 1000;
85 config
.max_retry_band
= 5;
86 config
.seen_policy_timeout
= 30 * 1000;
87 config
.band_steering_threshold
= 5;
88 config
.load_balancing_threshold
= 5;
89 config
.remote_update_interval
= 1000;
90 config
.initial_connect_delay
= 0;
91 config
.remote_node_timeout
= 120 * 1000;
93 config
.roam_kick_delay
= 100;
94 config
.roam_scan_tries
= 3;
95 config
.roam_scan_interval
= 10 * 1000;
96 config
.roam_trigger_interval
= 60 * 1000;
98 config
.load_kick_enabled
= false;
99 config
.load_kick_threshold
= 75;
100 config
.load_kick_delay
= 10 * 1000;
101 config
.load_kick_min_clients
= 10;
102 config
.load_kick_reason_code
= 5; /* WLAN_REASON_DISASSOC_AP_BUSY */
104 config
.debug_level
= MSG_FATAL
;
107 void usteer_update_time(void)
111 clock_gettime(CLOCK_MONOTONIC
, &ts
);
112 current_time
= (uint64_t) ts
.tv_sec
* 1000 + ts
.tv_nsec
/ 1000000;
115 static int usage(const char *prog
)
117 fprintf(stderr
, "Usage: %s [options]\n"
119 " -v: Increase debug level (repeat for more messages):\n"
120 " 1: info messages\n"
121 " 2: debug messages\n"
122 " 3: verbose debug messages\n"
123 " 4: include network messages\n"
124 " 5: include extra testing messages\n"
125 " -i <name>: Connect to other instances on interface <name>\n"
126 " -s: Output log messages via syslog instead of stderr\n"
131 int main(int argc
, char **argv
)
135 usteer_init_defaults();
137 while ((ch
= getopt(argc
, argv
, "i:sv")) != -1) {
140 config
.debug_level
++;
143 config
.syslog
= true;
146 usteer_interface_add(optarg
);
149 return usage(argv
[0]);
153 openlog("usteer", 0, LOG_USER
);
155 config_set_event_log_types(NULL
);
156 usteer_update_time();
159 ubus_ctx
= ubus_connect(NULL
);
161 fprintf(stderr
, "Failed to connect to ubus\n");
165 ubus_add_uloop(ubus_ctx
);
166 usteer_ubus_init(ubus_ctx
);
167 usteer_interface_init();
168 usteer_local_nodes_init(ubus_ctx
);