| 1 |
/* Copyright (C) 2016 by NuRAN Wireless <[email protected]> |
| 2 |
* |
| 3 |
* All Rights Reserved |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU Affero General Public License as published by |
| 7 |
* the Free Software Foundation; either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU Affero General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Affero General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
* |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <sys/ioctl.h> |
| 21 |
#include <net/if.h> |
| 22 |
#include <netdb.h> |
| 23 |
#include <ifaddrs.h> |
| 24 |
#include <netinet/in.h> |
| 25 |
#include <netinet/ip.h> |
| 26 |
#include "oc2gbts_mgr.h" |
| 27 |
#include "oc2gbts_bts.h" |
| 28 |
|
| 29 |
static int check_eth_status(char *dev_name) |
| 30 |
{ |
| 31 |
int fd, rc; |
| 32 |
struct ifreq ifr; |
| 33 |
|
| 34 |
fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); |
| 35 |
if (fd < 0) |
| 36 |
return fd; |
| 37 |
|
| 38 |
memset(&ifr, 0, sizeof(ifr)); |
| 39 |
memcpy(&ifr.ifr_name, dev_name, sizeof(ifr.ifr_name)); |
| 40 |
rc = ioctl(fd, SIOCGIFFLAGS, &ifr); |
| 41 |
close(fd); |
| 42 |
|
| 43 |
if (rc < 0) |
| 44 |
return rc; |
| 45 |
|
| 46 |
if ((ifr.ifr_flags & IFF_UP) && (ifr.ifr_flags & IFF_RUNNING)) |
| 47 |
return 0; |
| 48 |
|
| 49 |
return 1; |
| 50 |
} |
| 51 |
|
| 52 |
void check_bts_led_pattern(uint8_t *led) |
| 53 |
{ |
| 54 |
FILE *fp; |
| 55 |
char str[64] = "\0"; |
| 56 |
int rc; |
| 57 |
|
| 58 |
/* check for existing of BTS state file */ |
| 59 |
if ((fp = fopen("/var/run/osmo-bts/state", "r")) == NULL) { |
| 60 |
led[BLINK_PATTERN_INIT] = 1; |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
/* check Ethernet interface status */ |
| 65 |
rc = check_eth_status("eth0"); |
| 66 |
if (rc > 0) { |
| 67 |
LOGP(DTEMP, LOGL_DEBUG,"External link is DOWN\n"); |
| 68 |
led[BLINK_PATTERN_EXT_LINK_MALFUNC] = 1; |
| 69 |
fclose(fp); |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
/* check for BTS is still alive */ |
| 74 |
if (system("pidof osmo-bts-oc2g > /dev/null")) { |
| 75 |
LOGP(DTEMP, LOGL_DEBUG,"BTS process has stopped\n"); |
| 76 |
led[BLINK_PATTERN_INT_PROC_MALFUNC] = 1; |
| 77 |
fclose(fp); |
| 78 |
return; |
| 79 |
} |
| 80 |
|
| 81 |
/* check for BTS state */ |
| 82 |
while (fgets(str, 64, fp) != NULL) { |
| 83 |
LOGP(DTEMP, LOGL_DEBUG,"BTS state is %s\n", (strstr(str, "ABIS DOWN") != NULL) ? "DOWN" : "UP"); |
| 84 |
if (strstr(str, "ABIS DOWN") != NULL) |
| 85 |
led[BLINK_PATTERN_INT_PROC_MALFUNC] = 1; |
| 86 |
} |
| 87 |
fclose(fp); |
| 88 |
|
| 89 |
return; |
| 90 |
} |
| 91 |
|
| 92 |
int check_sensor_led_pattern( struct oc2gbts_mgr_instance *mgr, uint8_t *led) |
| 93 |
{ |
| 94 |
if(mgr->alarms.temp_high == 1) |
| 95 |
led[BLINK_PATTERN_TEMP_HIGH] = 1; |
| 96 |
|
| 97 |
if(mgr->alarms.temp_max == 1) |
| 98 |
led[BLINK_PATTERN_TEMP_MAX] = 1; |
| 99 |
|
| 100 |
if(mgr->alarms.supply_low == 1) |
| 101 |
led[BLINK_PATTERN_SUPPLY_VOLT_LOW] = 1; |
| 102 |
|
| 103 |
if(mgr->alarms.supply_min == 1) |
| 104 |
led[BLINK_PATTERN_SUPPLY_VOLT_MIN] = 1; |
| 105 |
|
| 106 |
if(mgr->alarms.vswr_high == 1) |
| 107 |
led[BLINK_PATTERN_VSWR_HIGH] = 1; |
| 108 |
|
| 109 |
if(mgr->alarms.vswr_max == 1) |
| 110 |
led[BLINK_PATTERN_VSWR_MAX] = 1; |
| 111 |
|
| 112 |
if(mgr->alarms.supply_pwr_high == 1) |
| 113 |
led[BLINK_PATTERN_SUPPLY_PWR_HIGH] = 1; |
| 114 |
|
| 115 |
if(mgr->alarms.supply_pwr_max == 1) |
| 116 |
led[BLINK_PATTERN_SUPPLY_PWR_MAX] = 1; |
| 117 |
|
| 118 |
if(mgr->alarms.pa_pwr_high == 1) |
| 119 |
led[BLINK_PATTERN_PA_PWR_HIGH] = 1; |
| 120 |
|
| 121 |
if(mgr->alarms.pa_pwr_max == 1) |
| 122 |
led[BLINK_PATTERN_PA_PWR_MAX] = 1; |
| 123 |
|
| 124 |
if(mgr->alarms.gps_fix_lost == 1) |
| 125 |
led[BLINK_PATTERN_GPS_FIX_LOST] = 1; |
| 126 |
|
| 127 |
return 0; |
| 128 |
} |
| 129 |
|