| 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 |
#include <inttypes.h> |
| 26 |
#include "misc/lc15bts_mgr.h" |
| 27 |
#include "misc/lc15bts_misc.h" |
| 28 |
#include "misc/lc15bts_temp.h" |
| 29 |
#include "misc/lc15bts_power.h" |
| 30 |
#include "misc/lc15bts_led.h" |
| 31 |
#include "misc/lc15bts_swd.h" |
| 32 |
#include "limits.h" |
| 33 |
|
| 34 |
#include <osmo-bts/logging.h> |
| 35 |
|
| 36 |
#include <osmocom/core/timer.h> |
| 37 |
#include <osmocom/core/utils.h> |
| 38 |
#include <osmocom/core/linuxlist.h> |
| 39 |
|
| 40 |
struct lc15bts_mgr_instance *s_mgr; |
| 41 |
static struct osmo_timer_list sensor_ctrl_timer; |
| 42 |
|
| 43 |
static const struct value_string state_names[] = { |
| 44 |
{ STATE_NORMAL, "NORMAL" }, |
| 45 |
{ STATE_WARNING_HYST, "WARNING (HYST)" }, |
| 46 |
{ STATE_WARNING, "WARNING" }, |
| 47 |
{ STATE_CRITICAL, "CRITICAL" }, |
| 48 |
{ 0, NULL } |
| 49 |
}; |
| 50 |
|
| 51 |
const char *lc15bts_mgr_sensor_get_state(enum lc15bts_sensor_state state) |
| 52 |
{ |
| 53 |
return get_value_string(state_names, state); |
| 54 |
} |
| 55 |
|
| 56 |
static int next_state(enum lc15bts_sensor_state current_state, int critical, int warning) |
| 57 |
{ |
| 58 |
int next_state = -1; |
| 59 |
switch (current_state) { |
| 60 |
case STATE_NORMAL: |
| 61 |
if (critical) |
| 62 |
next_state = STATE_CRITICAL; |
| 63 |
else if (warning) |
| 64 |
next_state = STATE_WARNING; |
| 65 |
break; |
| 66 |
case STATE_WARNING_HYST: |
| 67 |
if (critical) |
| 68 |
next_state = STATE_CRITICAL; |
| 69 |
else if (warning) |
| 70 |
next_state = STATE_WARNING; |
| 71 |
else |
| 72 |
next_state = STATE_NORMAL; |
| 73 |
break; |
| 74 |
case STATE_WARNING: |
| 75 |
if (critical) |
| 76 |
next_state = STATE_CRITICAL; |
| 77 |
else if (!warning) |
| 78 |
next_state = STATE_WARNING_HYST; |
| 79 |
break; |
| 80 |
case STATE_CRITICAL: |
| 81 |
if (!critical && !warning) |
| 82 |
next_state = STATE_WARNING; |
| 83 |
break; |
| 84 |
}; |
| 85 |
|
| 86 |
return next_state; |
| 87 |
} |
| 88 |
|
| 89 |
static void handle_normal_actions(int actions) |
| 90 |
{ |
| 91 |
|
| 92 |
if (actions & SENSOR_ACT_NORM_PA0_ON) { |
| 93 |
if (lc15bts_power_set(LC15BTS_POWER_PA0, 1) != 0) { |
| 94 |
LOGP(DTEMP, LOGL_ERROR, |
| 95 |
"Failed to switch on the PA #0\n"); |
| 96 |
} else { |
| 97 |
LOGP(DTEMP, LOGL_NOTICE, |
| 98 |
"Switched on the PA #0 as normal action.\n"); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
if (actions & SENSOR_ACT_NORM_PA1_ON) { |
| 103 |
if (lc15bts_power_set(LC15BTS_POWER_PA1, 1) != 0) { |
| 104 |
LOGP(DTEMP, LOGL_ERROR, |
| 105 |
"Failed to switch on the PA #1\n"); |
| 106 |
} else { |
| 107 |
LOGP(DTEMP, LOGL_NOTICE, |
| 108 |
"Switched on the PA #1 as normal action.\n"); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
if (actions & SENSOR_ACT_NORM_BTS_SRV_ON) { |
| 113 |
LOGP(DTEMP, LOGL_NOTICE, |
| 114 |
"Going to switch on the BTS service\n"); |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
system("/bin/systemctl start osmo-bts.service"); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
static void handle_actions(int actions) |
| 125 |
{ |
| 126 |
|
| 127 |
if (actions & SENSOR_ACT_PA1_OFF) { |
| 128 |
if (lc15bts_power_set(LC15BTS_POWER_PA1, 0) != 0) { |
| 129 |
LOGP(DTEMP, LOGL_ERROR, |
| 130 |
"Failed to switch off the PA #1. Stop BTS?\n"); |
| 131 |
} else { |
| 132 |
LOGP(DTEMP, LOGL_NOTICE, |
| 133 |
"Switched off the PA #1 due temperature.\n"); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
if (actions & SENSOR_ACT_PA0_OFF) { |
| 138 |
if (lc15bts_power_set(LC15BTS_POWER_PA0, 0) != 0) { |
| 139 |
LOGP(DTEMP, LOGL_ERROR, |
| 140 |
"Failed to switch off the PA #0. Stop BTS?\n"); |
| 141 |
} else { |
| 142 |
LOGP(DTEMP, LOGL_NOTICE, |
| 143 |
"Switched off the PA #0 due temperature.\n"); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
if (actions & SENSOR_ACT_BTS_SRV_OFF) { |
| 148 |
LOGP(DTEMP, LOGL_NOTICE, |
| 149 |
"Going to switch off the BTS service\n"); |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
system("/bin/systemctl stop osmo-bts.service"); |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
static void execute_normal_act(struct lc15bts_mgr_instance *manager) |
| 167 |
{ |
| 168 |
LOGP(DTEMP, LOGL_NOTICE, "System is back to normal state.\n"); |
| 169 |
handle_normal_actions(manager->state.action_norm); |
| 170 |
} |
| 171 |
|
| 172 |
static void execute_warning_act(struct lc15bts_mgr_instance *manager) |
| 173 |
{ |
| 174 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning state.\n"); |
| 175 |
handle_actions(manager->state.action_warn); |
| 176 |
} |
| 177 |
|
| 178 |
static void execute_critical_act(struct lc15bts_mgr_instance *manager) |
| 179 |
{ |
| 180 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached critical warning.\n"); |
| 181 |
handle_actions(manager->state.action_crit); |
| 182 |
} |
| 183 |
|
| 184 |
static void lc15bts_mgr_sensor_handle(struct lc15bts_mgr_instance *manager, |
| 185 |
int critical, int warning) |
| 186 |
{ |
| 187 |
int new_state = next_state(manager->state.state, critical, warning); |
| 188 |
|
| 189 |
|
| 190 |
if (new_state < 0) |
| 191 |
return; |
| 192 |
|
| 193 |
LOGP(DTEMP, LOGL_NOTICE, "Moving from state %s to %s.\n", |
| 194 |
get_value_string(state_names, manager->state.state), |
| 195 |
get_value_string(state_names, new_state)); |
| 196 |
manager->state.state = new_state; |
| 197 |
switch (manager->state.state) { |
| 198 |
case STATE_NORMAL: |
| 199 |
execute_normal_act(manager); |
| 200 |
break; |
| 201 |
case STATE_WARNING_HYST: |
| 202 |
|
| 203 |
break; |
| 204 |
case STATE_WARNING: |
| 205 |
execute_warning_act(manager); |
| 206 |
break; |
| 207 |
case STATE_CRITICAL: |
| 208 |
execute_critical_act(manager); |
| 209 |
break; |
| 210 |
}; |
| 211 |
} |
| 212 |
|
| 213 |
static void sensor_ctrl_check(struct lc15bts_mgr_instance *mgr) |
| 214 |
{ |
| 215 |
int rc; |
| 216 |
int temp = 0; |
| 217 |
int warn_thresh_passed = 0; |
| 218 |
int crit_thresh_passed = 0; |
| 219 |
|
| 220 |
LOGP(DTEMP, LOGL_DEBUG, "Going to check the temperature.\n"); |
| 221 |
|
| 222 |
|
| 223 |
rc = lc15bts_temp_get(LC15BTS_TEMP_SUPPLY, &temp); |
| 224 |
if (rc < 0) { |
| 225 |
LOGP(DTEMP, LOGL_ERROR, |
| 226 |
"Failed to read the supply temperature. rc=%d\n", rc); |
| 227 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 228 |
} else { |
| 229 |
temp = temp / 1000; |
| 230 |
if (temp > mgr->temp.supply_temp_limit.thresh_warn_max) |
| 231 |
warn_thresh_passed = 1; |
| 232 |
if (temp > mgr->temp.supply_temp_limit.thresh_crit_max) |
| 233 |
crit_thresh_passed = 1; |
| 234 |
LOGP(DTEMP, LOGL_DEBUG, "Supply temperature is: %d\n", temp); |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
rc = lc15bts_temp_get(LC15BTS_TEMP_SOC, &temp); |
| 239 |
if (rc < 0) { |
| 240 |
LOGP(DTEMP, LOGL_ERROR, |
| 241 |
"Failed to read the SoC temperature. rc=%d\n", rc); |
| 242 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 243 |
} else { |
| 244 |
temp = temp / 1000; |
| 245 |
if (temp > mgr->temp.soc_temp_limit.thresh_warn_max) |
| 246 |
warn_thresh_passed = 1; |
| 247 |
if (temp > mgr->temp.soc_temp_limit.thresh_crit_max) |
| 248 |
crit_thresh_passed = 1; |
| 249 |
LOGP(DTEMP, LOGL_DEBUG, "SoC temperature is: %d\n", temp); |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
rc = lc15bts_temp_get(LC15BTS_TEMP_FPGA, &temp); |
| 254 |
if (rc < 0) { |
| 255 |
LOGP(DTEMP, LOGL_ERROR, |
| 256 |
"Failed to read the fpga temperature. rc=%d\n", rc); |
| 257 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 258 |
} else { |
| 259 |
temp = temp / 1000; |
| 260 |
if (temp > mgr->temp.fpga_temp_limit.thresh_warn_max) |
| 261 |
warn_thresh_passed = 1; |
| 262 |
if (temp > mgr->temp.fpga_temp_limit.thresh_crit_max) |
| 263 |
crit_thresh_passed = 1; |
| 264 |
LOGP(DTEMP, LOGL_DEBUG, "FPGA temperature is: %d\n", temp); |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
rc = lc15bts_temp_get(LC15BTS_TEMP_RMSDET, &temp); |
| 269 |
if (rc < 0) { |
| 270 |
LOGP(DTEMP, LOGL_ERROR, |
| 271 |
"Failed to read the RMS detector temperature. rc=%d\n", rc); |
| 272 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 273 |
} else { |
| 274 |
temp = temp / 1000; |
| 275 |
if (temp > mgr->temp.rmsdet_temp_limit.thresh_warn_max) |
| 276 |
warn_thresh_passed = 1; |
| 277 |
if (temp > mgr->temp.rmsdet_temp_limit.thresh_crit_max) |
| 278 |
crit_thresh_passed = 1; |
| 279 |
LOGP(DTEMP, LOGL_DEBUG, "RMS detector temperature is: %d\n", temp); |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
rc = lc15bts_temp_get(LC15BTS_TEMP_OCXO, &temp); |
| 284 |
if (rc < 0) { |
| 285 |
LOGP(DTEMP, LOGL_ERROR, |
| 286 |
"Failed to read the OCXO temperature. rc=%d\n", rc); |
| 287 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 288 |
} else { |
| 289 |
temp = temp / 1000; |
| 290 |
if (temp > mgr->temp.ocxo_temp_limit.thresh_warn_max) |
| 291 |
warn_thresh_passed = 1; |
| 292 |
if (temp > mgr->temp.ocxo_temp_limit.thresh_crit_max) |
| 293 |
crit_thresh_passed = 1; |
| 294 |
LOGP(DTEMP, LOGL_DEBUG, "OCXO temperature is: %d\n", temp); |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
rc = lc15bts_temp_get(LC15BTS_TEMP_TX0, &temp); |
| 299 |
if (rc < 0) { |
| 300 |
LOGP(DTEMP, LOGL_ERROR, |
| 301 |
"Failed to read the TX #0 temperature. rc=%d\n", rc); |
| 302 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 303 |
} else { |
| 304 |
temp = temp / 1000; |
| 305 |
if (temp > mgr->temp.tx0_temp_limit.thresh_warn_max) |
| 306 |
warn_thresh_passed = 1; |
| 307 |
if (temp > mgr->temp.tx0_temp_limit.thresh_crit_max) |
| 308 |
crit_thresh_passed = 1; |
| 309 |
LOGP(DTEMP, LOGL_DEBUG, "TX #0 temperature is: %d\n", temp); |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
rc = lc15bts_temp_get(LC15BTS_TEMP_TX1, &temp); |
| 314 |
if (rc < 0) { |
| 315 |
LOGP(DTEMP, LOGL_ERROR, |
| 316 |
"Failed to read the TX #1 temperature. rc=%d\n", rc); |
| 317 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 318 |
} else { |
| 319 |
temp = temp / 1000; |
| 320 |
if (temp > mgr->temp.tx1_temp_limit.thresh_warn_max) |
| 321 |
warn_thresh_passed = 1; |
| 322 |
if (temp > mgr->temp.tx1_temp_limit.thresh_crit_max) |
| 323 |
crit_thresh_passed = 1; |
| 324 |
LOGP(DTEMP, LOGL_DEBUG, "TX #1 temperature is: %d\n", temp); |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
rc = lc15bts_temp_get(LC15BTS_TEMP_PA0, &temp); |
| 329 |
if (rc < 0) { |
| 330 |
LOGP(DTEMP, LOGL_ERROR, |
| 331 |
"Failed to read the PA #0 temperature. rc=%d\n", rc); |
| 332 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 333 |
} else { |
| 334 |
temp = temp / 1000; |
| 335 |
if (temp > mgr->temp.pa0_temp_limit.thresh_warn_max) |
| 336 |
warn_thresh_passed = 1; |
| 337 |
if (temp > mgr->temp.pa0_temp_limit.thresh_crit_max) |
| 338 |
crit_thresh_passed = 1; |
| 339 |
LOGP(DTEMP, LOGL_DEBUG, "PA #0 temperature is: %d\n", temp); |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
rc = lc15bts_temp_get(LC15BTS_TEMP_PA1, &temp); |
| 344 |
if (rc < 0) { |
| 345 |
LOGP(DTEMP, LOGL_ERROR, |
| 346 |
"Failed to read the PA #1 temperature. rc=%d\n", rc); |
| 347 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 348 |
} else { |
| 349 |
temp = temp / 1000; |
| 350 |
if (temp > mgr->temp.pa1_temp_limit.thresh_warn_max) |
| 351 |
warn_thresh_passed = 1; |
| 352 |
if (temp > mgr->temp.pa1_temp_limit.thresh_crit_max) |
| 353 |
crit_thresh_passed = 1; |
| 354 |
LOGP(DTEMP, LOGL_DEBUG, "PA #1 temperature is: %d\n", temp); |
| 355 |
} |
| 356 |
|
| 357 |
lc15bts_mgr_sensor_handle(mgr, crit_thresh_passed, warn_thresh_passed); |
| 358 |
} |
| 359 |
|
| 360 |
static void sensor_ctrl_check_cb(void *_data) |
| 361 |
{ |
| 362 |
struct lc15bts_mgr_instance *mgr = _data; |
| 363 |
sensor_ctrl_check(mgr); |
| 364 |
|
| 365 |
osmo_timer_schedule(&sensor_ctrl_timer, LC15BTS_SENSOR_TIMER_DURATION, 0); |
| 366 |
LOGP(DTEMP, LOGL_DEBUG,"Check sensors timer expired\n"); |
| 367 |
|
| 368 |
lc15bts_swd_event(mgr, SWD_CHECK_TEMP_SENSOR); |
| 369 |
} |
| 370 |
|
| 371 |
int lc15bts_mgr_sensor_init(struct lc15bts_mgr_instance *mgr) |
| 372 |
{ |
| 373 |
s_mgr = mgr; |
| 374 |
sensor_ctrl_timer.cb = sensor_ctrl_check_cb; |
| 375 |
sensor_ctrl_timer.data = s_mgr; |
| 376 |
sensor_ctrl_check_cb(s_mgr); |
| 377 |
return 0; |
| 378 |
} |