@@ -39,6 +39,7 @@
#include <osmocom/vty/telnet_interface.h>
#include <osmocom/vty/logging.h>
#include <osmocom/gsm/protocol/ipaccess.h>
+#include <osmocom/gsm/abis_nm.h>
#include <osmo-bts/gsm_data.h>
#include <osmo-bts/logging.h>
@@ -54,11 +55,14 @@
#define IPA_OML_PROTO 0xFF
+#define TEMP_TIMER_SECS ((6 * 3600) + 1)
+
#include "utils.h"
#include "eeprom.h"
#include "l1_if.h"
#include "hw_misc.h"
#include "btsconfig.h"
+#include <misc/sysmobts_misc.h>
/* FIXME: read from real hardware */
const uint8_t abis_mac[6] = { 0,1,2,3,4,5 };
@@ -297,6 +301,60 @@ static int write_pid_file(char *procname)
}
#ifdef BUILD_SBTS2050
+static int init_max_power_red;
+static int new_max_power_red;
+static int status_change_power_red = 0;
+
+enum {
+ SBTS2050_DISABLE_CHANGE_POWER = 0,
+ SBTS2050_ENABLE_CHANGE_POWER,
+};
+
+#define oml_tlv_parse(dec, buf, len) \
+ tlv_parse(dec, &abis_nm_att_tlvdef, buf, len, 0, 0)
+
+/* size of the struct plus 1 Bytes of tag and 2 Bytes for the length */
+#define TLV_ADD_INFO_LEN (sizeof(struct sbts2050_config_info) + 3)
+
+static struct osmo_timer_list power_timer;
+static void change_max_power_red_cb(void *data)
+{
+ struct gsm_bts *bts = data;
+
+ if (status_change_power_red == SBTS2050_ENABLE_CHANGE_POWER) {
+ if (bts->c0->max_power_red != new_max_power_red) {
+ init_max_power_red = bts->c0->max_power_red;
+ bts->c0->max_power_red = new_max_power_red;
+ }
+ status_change_power_red = SBTS2050_DISABLE_CHANGE_POWER;
+ osmo_timer_schedule(&power_timer, TEMP_TIMER_SECS, 0);
+ } else if (status_change_power_red == SBTS2050_DISABLE_CHANGE_POWER)
+ bts->c0->max_power_red = init_max_power_red;
+}
+
+static int take_max_power_red(struct msgb *msg)
+{
+ struct sbts2050_config_info *config_info;
+ struct tlv_parsed tlv_out;
+ int rc;
+
+ rc = oml_tlv_parse(&tlv_out, msg->tail - TLV_ADD_INFO_LEN,
+ TLV_ADD_INFO_LEN);
+
+ if (rc < 0)
+ return -1;
+
+ config_info =
+ (struct sbts2050_config_info *) TLVP_VAL(&tlv_out, NM_ATT_ADD_INFO);
+
+ new_max_power_red = config_info->max_power_red;
+
+ status_change_power_red = SBTS2050_ENABLE_CHANGE_POWER;
+ change_max_power_red_cb(bts);
+
+ return 0;
+}
+
static int test_recv_msg(struct msgb *msg)
{
struct ipaccess_head *hh;
@@ -392,6 +450,11 @@ static int read_sock(struct osmo_fd *fd, unsigned int what)
goto err;
}
+ if (take_max_power_red(msg) < 0) {
+ LOGP(DL1C, LOGL_ERROR, "Failed Add_info: Malformed message\n");
+ goto err;
+ }
+
mo = &bts->mo;
msg->trx = mo->bts->c0;
@@ -441,6 +504,9 @@ static int sbts2050_sock_unix_init(struct osmo_fd *accept, struct osmo_fd *read)
read->fd = -1;
accept->data = read;
+ power_timer.cb = change_max_power_red_cb;
+ power_timer.data = bts;
+
rc = osmo_sock_unix_init_ofd(accept, SOCK_SEQPACKET, 0, SOCKET_PATH,
OSMO_SOCK_F_BIND | OSMO_SOCK_F_NONBLOCK);
return rc;