| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#include <stdint.h> |
| 28 |
#include <unistd.h> |
| 29 |
#include <stdlib.h> |
| 30 |
#include <errno.h> |
| 31 |
#include <getopt.h> |
| 32 |
#include <limits.h> |
| 33 |
#include <sys/signal.h> |
| 34 |
#include <sys/stat.h> |
| 35 |
|
| 36 |
#include <osmocom/core/talloc.h> |
| 37 |
#include <osmocom/core/application.h> |
| 38 |
#include <osmocom/core/timer.h> |
| 39 |
#include <osmocom/core/msgb.h> |
| 40 |
#include <osmocom/vty/telnet_interface.h> |
| 41 |
#include <osmocom/vty/logging.h> |
| 42 |
#include <osmocom/vty/ports.h> |
| 43 |
|
| 44 |
#include "misc/lc15bts_misc.h" |
| 45 |
#include "misc/lc15bts_mgr.h" |
| 46 |
#include "misc/lc15bts_par.h" |
| 47 |
#include "misc/lc15bts_bid.h" |
| 48 |
#include "misc/lc15bts_power.h" |
| 49 |
#include "misc/lc15bts_swd.h" |
| 50 |
|
| 51 |
#include "lc15bts_led.h" |
| 52 |
|
| 53 |
static int no_rom_write = 0; |
| 54 |
static int daemonize = 0; |
| 55 |
void *tall_mgr_ctx; |
| 56 |
|
| 57 |
|
| 58 |
#define SENSOR_TIMER_SECS (6 * 3600) |
| 59 |
|
| 60 |
|
| 61 |
#define HOURS_TIMER_SECS (1 * 3600) |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
static struct lc15bts_mgr_instance manager = { |
| 66 |
.config_file = "lc15bts-mgr.cfg", |
| 67 |
.temp = { |
| 68 |
.supply_temp_limit = { |
| 69 |
.thresh_warn_max = 80, |
| 70 |
.thresh_crit_max = 85, |
| 71 |
.thresh_warn_min = -40, |
| 72 |
}, |
| 73 |
.soc_temp_limit = { |
| 74 |
.thresh_warn_max = 95, |
| 75 |
.thresh_crit_max = 100, |
| 76 |
.thresh_warn_min = -40, |
| 77 |
}, |
| 78 |
.fpga_temp_limit = { |
| 79 |
.thresh_warn_max = 95, |
| 80 |
.thresh_crit_max = 100, |
| 81 |
.thresh_warn_min = -40, |
| 82 |
}, |
| 83 |
.rmsdet_temp_limit = { |
| 84 |
.thresh_warn_max = 80, |
| 85 |
.thresh_crit_max = 85, |
| 86 |
.thresh_warn_min = -40, |
| 87 |
}, |
| 88 |
.ocxo_temp_limit = { |
| 89 |
.thresh_warn_max = 80, |
| 90 |
.thresh_crit_max = 85, |
| 91 |
.thresh_warn_min = -40, |
| 92 |
}, |
| 93 |
.tx0_temp_limit = { |
| 94 |
.thresh_warn_max = 80, |
| 95 |
.thresh_crit_max = 85, |
| 96 |
.thresh_warn_min = -20, |
| 97 |
}, |
| 98 |
.tx1_temp_limit = { |
| 99 |
.thresh_warn_max = 80, |
| 100 |
.thresh_crit_max = 85, |
| 101 |
.thresh_warn_min = -20, |
| 102 |
}, |
| 103 |
.pa0_temp_limit = { |
| 104 |
.thresh_warn_max = 80, |
| 105 |
.thresh_crit_max = 85, |
| 106 |
.thresh_warn_min = -40, |
| 107 |
}, |
| 108 |
.pa1_temp_limit = { |
| 109 |
.thresh_warn_max = 80, |
| 110 |
.thresh_crit_max = 85, |
| 111 |
.thresh_warn_min = -40, |
| 112 |
} |
| 113 |
}, |
| 114 |
.volt = { |
| 115 |
.supply_volt_limit = { |
| 116 |
.thresh_warn_max = 30000, |
| 117 |
.thresh_crit_max = 30500, |
| 118 |
.thresh_warn_min = 19000, |
| 119 |
.thresh_crit_min = 17500, |
| 120 |
} |
| 121 |
}, |
| 122 |
.pwr = { |
| 123 |
.supply_pwr_limit = { |
| 124 |
.thresh_warn_max = 110, |
| 125 |
.thresh_crit_max = 120, |
| 126 |
}, |
| 127 |
.pa0_pwr_limit = { |
| 128 |
.thresh_warn_max = 50, |
| 129 |
.thresh_crit_max = 60, |
| 130 |
}, |
| 131 |
.pa1_pwr_limit = { |
| 132 |
.thresh_warn_max = 50, |
| 133 |
.thresh_crit_max = 60, |
| 134 |
} |
| 135 |
}, |
| 136 |
.vswr = { |
| 137 |
.tx0_vswr_limit = { |
| 138 |
.thresh_warn_max = 3000, |
| 139 |
.thresh_crit_max = 5000, |
| 140 |
}, |
| 141 |
.tx1_vswr_limit = { |
| 142 |
.thresh_warn_max = 3000, |
| 143 |
.thresh_crit_max = 5000, |
| 144 |
} |
| 145 |
}, |
| 146 |
.gps = { |
| 147 |
.gps_fix_limit = { |
| 148 |
.thresh_warn_max = 7, |
| 149 |
} |
| 150 |
}, |
| 151 |
.state = { |
| 152 |
.action_norm = SENSOR_ACT_NORM_PA0_ON | SENSOR_ACT_NORM_PA1_ON, |
| 153 |
.action_warn = 0, |
| 154 |
.action_crit = 0, |
| 155 |
.action_comb = 0, |
| 156 |
.state = STATE_NORMAL, |
| 157 |
} |
| 158 |
}; |
| 159 |
|
| 160 |
static struct osmo_timer_list sensor_timer; |
| 161 |
static void check_sensor_timer_cb(void *unused) |
| 162 |
{ |
| 163 |
lc15bts_check_temp(no_rom_write); |
| 164 |
lc15bts_check_power(no_rom_write); |
| 165 |
lc15bts_check_vswr(no_rom_write); |
| 166 |
osmo_timer_schedule(&sensor_timer, SENSOR_TIMER_SECS, 0); |
| 167 |
|
| 168 |
lc15bts_swd_event(&manager, SWD_CHECK_SENSOR); |
| 169 |
} |
| 170 |
|
| 171 |
static struct osmo_timer_list hours_timer; |
| 172 |
static void hours_timer_cb(void *unused) |
| 173 |
{ |
| 174 |
lc15bts_update_hours(no_rom_write); |
| 175 |
|
| 176 |
osmo_timer_schedule(&hours_timer, HOURS_TIMER_SECS, 0); |
| 177 |
|
| 178 |
lc15bts_swd_event(&manager, SWD_UPDATE_HOURS); |
| 179 |
} |
| 180 |
|
| 181 |
static void print_help(void) |
| 182 |
{ |
| 183 |
printf("lc15bts-mgr [-nsD] [-d cat]\n"); |
| 184 |
printf(" -n Do not write to ROM\n"); |
| 185 |
printf(" -s Disable color\n"); |
| 186 |
printf(" -d CAT enable debugging\n"); |
| 187 |
printf(" -D daemonize\n"); |
| 188 |
printf(" -c Specify the filename of the config file\n"); |
| 189 |
} |
| 190 |
|
| 191 |
static int parse_options(int argc, char **argv) |
| 192 |
{ |
| 193 |
int opt; |
| 194 |
|
| 195 |
while ((opt = getopt(argc, argv, "nhsd:c:")) != -1) { |
| 196 |
switch (opt) { |
| 197 |
case 'n': |
| 198 |
no_rom_write = 1; |
| 199 |
break; |
| 200 |
case 'h': |
| 201 |
print_help(); |
| 202 |
return -1; |
| 203 |
case 's': |
| 204 |
log_set_use_color(osmo_stderr_target, 0); |
| 205 |
break; |
| 206 |
case 'd': |
| 207 |
log_parse_category_mask(osmo_stderr_target, optarg); |
| 208 |
break; |
| 209 |
case 'D': |
| 210 |
daemonize = 1; |
| 211 |
break; |
| 212 |
case 'c': |
| 213 |
manager.config_file = optarg; |
| 214 |
break; |
| 215 |
default: |
| 216 |
return -1; |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
return 0; |
| 221 |
} |
| 222 |
|
| 223 |
static void signal_handler(int signum) |
| 224 |
{ |
| 225 |
fprintf(stderr, "signal %u received\n", signum); |
| 226 |
|
| 227 |
switch (signum) { |
| 228 |
case SIGINT: |
| 229 |
case SIGTERM: |
| 230 |
lc15bts_check_temp(no_rom_write); |
| 231 |
lc15bts_check_power(no_rom_write); |
| 232 |
lc15bts_check_vswr(no_rom_write); |
| 233 |
lc15bts_update_hours(no_rom_write); |
| 234 |
exit(0); |
| 235 |
break; |
| 236 |
case SIGABRT: |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
talloc_report_full(tall_mgr_ctx, stderr); |
| 244 |
signal(SIGABRT, SIG_DFL); |
| 245 |
raise(SIGABRT); |
| 246 |
break; |
| 247 |
case SIGUSR1: |
| 248 |
case SIGUSR2: |
| 249 |
talloc_report_full(tall_mgr_ctx, stderr); |
| 250 |
break; |
| 251 |
default: |
| 252 |
break; |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
static struct log_info_cat mgr_log_info_cat[] = { |
| 257 |
[DTEMP] = { |
| 258 |
.name = "DTEMP", |
| 259 |
.description = "Temperature monitoring", |
| 260 |
.color = "\033[1;35m", |
| 261 |
.enabled = 1, .loglevel = LOGL_NOTICE, |
| 262 |
}, |
| 263 |
[DFW] = { |
| 264 |
.name = "DFW", |
| 265 |
.description = "Firmware management", |
| 266 |
.color = "\033[1;36m", |
| 267 |
.enabled = 1, .loglevel = LOGL_NOTICE, |
| 268 |
}, |
| 269 |
[DFIND] = { |
| 270 |
.name = "DFIND", |
| 271 |
.description = "ipaccess-find handling", |
| 272 |
.color = "\033[1;37m", |
| 273 |
.enabled = 1, .loglevel = LOGL_NOTICE, |
| 274 |
}, |
| 275 |
[DCALIB] = { |
| 276 |
.name = "DCALIB", |
| 277 |
.description = "Calibration handling", |
| 278 |
.color = "\033[1;37m", |
| 279 |
.enabled = 1, .loglevel = LOGL_NOTICE, |
| 280 |
}, |
| 281 |
[DSWD] = { |
| 282 |
.name = "DSWD", |
| 283 |
.description = "Software Watchdog", |
| 284 |
.color = "\033[1;37m", |
| 285 |
.enabled = 1, .loglevel = LOGL_NOTICE, |
| 286 |
}, |
| 287 |
}; |
| 288 |
|
| 289 |
static const struct log_info mgr_log_info = { |
| 290 |
.cat = mgr_log_info_cat, |
| 291 |
.num_cat = ARRAY_SIZE(mgr_log_info_cat), |
| 292 |
}; |
| 293 |
|
| 294 |
int main(int argc, char **argv) |
| 295 |
{ |
| 296 |
int rc; |
| 297 |
|
| 298 |
tall_mgr_ctx = talloc_named_const(NULL, 1, "bts manager"); |
| 299 |
msgb_talloc_ctx_init(tall_mgr_ctx, 0); |
| 300 |
|
| 301 |
osmo_init_logging2(tall_mgr_ctx, &mgr_log_info); |
| 302 |
|
| 303 |
osmo_init_ignore_signals(); |
| 304 |
signal(SIGINT, &signal_handler); |
| 305 |
signal(SIGTERM, &signal_handler); |
| 306 |
signal(SIGABRT, &signal_handler); |
| 307 |
signal(SIGUSR1, &signal_handler); |
| 308 |
signal(SIGUSR2, &signal_handler); |
| 309 |
|
| 310 |
rc = parse_options(argc, argv); |
| 311 |
if (rc < 0) |
| 312 |
exit(2); |
| 313 |
|
| 314 |
lc15bts_mgr_vty_init(); |
| 315 |
logging_vty_add_cmds(); |
| 316 |
rc = lc15bts_mgr_parse_config(&manager); |
| 317 |
if (rc < 0) { |
| 318 |
LOGP(DFIND, LOGL_FATAL, "Cannot parse config file\n"); |
| 319 |
exit(1); |
| 320 |
} |
| 321 |
|
| 322 |
rc = telnet_init_default(tall_mgr_ctx, NULL, OSMO_VTY_PORT_BTSMGR); |
| 323 |
if (rc < 0) { |
| 324 |
fprintf(stderr, "Error initializing telnet\n"); |
| 325 |
exit(1); |
| 326 |
} |
| 327 |
|
| 328 |
INIT_LLIST_HEAD(&manager.lc15bts_leds.list); |
| 329 |
INIT_LLIST_HEAD(&manager.alarms.list); |
| 330 |
|
| 331 |
|
| 332 |
if (lc15bts_swd_init(&manager, (int)(SWD_LAST)) != 0) |
| 333 |
exit(3); |
| 334 |
|
| 335 |
|
| 336 |
sensor_timer.cb = check_sensor_timer_cb; |
| 337 |
check_sensor_timer_cb(NULL); |
| 338 |
|
| 339 |
|
| 340 |
hours_timer.cb = hours_timer_cb; |
| 341 |
hours_timer_cb(NULL); |
| 342 |
|
| 343 |
|
| 344 |
rc = lc15bts_power_set(LC15BTS_POWER_PA0, 1); |
| 345 |
if (rc < 0) { |
| 346 |
exit(3); |
| 347 |
} |
| 348 |
|
| 349 |
rc = lc15bts_power_set(LC15BTS_POWER_PA1, 1); |
| 350 |
if (rc < 0) { |
| 351 |
exit(3); |
| 352 |
} |
| 353 |
|
| 354 |
|
| 355 |
if (lc15bts_mgr_nl_init() != 0) |
| 356 |
exit(3); |
| 357 |
|
| 358 |
|
| 359 |
lc15bts_mgr_sensor_init(&manager); |
| 360 |
|
| 361 |
if (lc15bts_mgr_calib_init(&manager) != 0) |
| 362 |
exit(3); |
| 363 |
|
| 364 |
if (daemonize) { |
| 365 |
rc = osmo_daemonize(); |
| 366 |
if (rc < 0) { |
| 367 |
perror("Error during daemonize"); |
| 368 |
exit(1); |
| 369 |
} |
| 370 |
} |
| 371 |
|
| 372 |
while (1) { |
| 373 |
log_reset_context(); |
| 374 |
osmo_select_main(0); |
| 375 |
lc15bts_swd_event(&manager, SWD_MAINLOOP); |
| 376 |
} |
| 377 |
} |