ctrl: Allow to query if the OML link is connected or not

Related: SYS#798
diff --git a/openbsc/src/libbsc/bsc_ctrl_commands.c b/openbsc/src/libbsc/bsc_ctrl_commands.c
index a93b8e0..36eda35 100644
--- a/openbsc/src/libbsc/bsc_ctrl_commands.c
+++ b/openbsc/src/libbsc/bsc_ctrl_commands.c
@@ -271,6 +271,32 @@
 }
 CTRL_CMD_DEFINE(bts_chan_load, "channel-load");
 
+static int verify_bts_oml_conn(struct ctrl_cmd *cmd, const char *value, void *_data)
+{
+	struct gsm_bts *bts = cmd->node;
+
+	if (!is_ipaccess_bts(bts)) {
+		cmd->reply = "";
+		return -1;
+	}
+	return 0;
+}
+
+static int get_bts_oml_conn(struct ctrl_cmd *cmd, void *data)
+{
+	struct gsm_bts *bts = cmd->node;
+
+	cmd->reply = bts->oml_link ? "connected" : "disconnected";
+	return CTRL_CMD_REPLY;
+}
+
+static int set_bts_oml_conn(struct ctrl_cmd *cmd, void *data)
+{
+	cmd->reply = "Read only attribute";
+	return CTRL_CMD_ERROR;
+}
+CTRL_CMD_DEFINE(bts_oml_conn, "oml-connection-state");
+
 /* TRX related commands below here */
 CTRL_HELPER_GET_INT(trx_max_power, struct gsm_bts_trx, max_power_red);
 static int verify_trx_max_power(struct ctrl_cmd *cmd, const char *value, void *_data)
@@ -327,6 +353,7 @@
 	rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_apply_config);
 	rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_si);
 	rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_chan_load);
+	rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_oml_conn);
 
 	rc |= ctrl_cmd_install(CTRL_NODE_TRX, &cmd_trx_max_power);
 	rc |= ctrl_cmd_install(CTRL_NODE_TRX, &cmd_trx_arfcn);
diff --git a/openbsc/tests/ctrl_test_runner.py b/openbsc/tests/ctrl_test_runner.py
index d875d46..3238a1b 100644
--- a/openbsc/tests/ctrl_test_runner.py
+++ b/openbsc/tests/ctrl_test_runner.py
@@ -236,6 +236,17 @@
         self.assertEquals(r['mtype'], 'GET_REPLY')
         self.assertEquals(r['value'], 'CCCH+SDCCH4,0,0 TCH/F,0,0 TCH/H,0,0 SDCCH8,0,0 TCH/F_PDCH,0,0')
 
+    def testBtsOmlConnectionState(self):
+        """Check OML state. It will not be connected"""
+        r = self.do_set('bts.0.oml-connection-state', '1')
+        self.assertEquals(r['mtype'], 'ERROR')
+        self.assertEquals(r['error'], 'Read only attribute')
+
+        # No RSL link so everything is 0
+        r = self.do_get('bts.0.oml-connection-state')
+        self.assertEquals(r['mtype'], 'GET_REPLY')
+        self.assertEquals(r['value'], 'disconnected')
+
     def testTrxPowerRed(self):
         r = self.do_get('bts.0.trx.0.max-power-reduction')
         self.assertEquals(r['mtype'], 'GET_REPLY')