lcls: do not LCLS call legs with different codecs

It is theoretically possible to LCLS two legs that use different
codecs. However, this requires transcoding capabilities on the
local MGW. If the local MGW lacks transcoding features such a
local circuit should be avoided. Enabeling LCLS under such
coditions should be optional (VTY)

- Add check to avoid LCLS on different codec/rate
- Add VTY-Option to optionally override the check
  (MGW is able to transcode)

Change-Id: I157549129a40c64364dc126f67195759e5f1d60f
Related: OS#1602
diff --git a/include/osmocom/bsc/bsc_msc_data.h b/include/osmocom/bsc/bsc_msc_data.h
index 79d2eca..7ec3442 100644
--- a/include/osmocom/bsc/bsc_msc_data.h
+++ b/include/osmocom/bsc/bsc_msc_data.h
@@ -87,6 +87,7 @@
 	struct gsm_audio_support **audio_support;
 	int audio_length;
 	enum bsc_lcls_mode lcls_mode;
+	bool lcls_codec_mismatch_allow;
 
 	/* ussd welcome text */
 	char *ussd_welcome_txt;
diff --git a/src/osmo-bsc/osmo_bsc_lcls.c b/src/osmo-bsc/osmo_bsc_lcls.c
index 4639c4e..6aeccb3 100644
--- a/src/osmo-bsc/osmo_bsc_lcls.c
+++ b/src/osmo-bsc/osmo_bsc_lcls.c
@@ -274,6 +274,18 @@
 		return false;
 	}
 
+	if (conn->user_plane.full_rate != conn->lcls.other->user_plane.full_rate
+	    && conn->sccp.msc->lcls_codec_mismatch_allow == false) {
+		LOGPFSM(conn->lcls.fi, "Not enabling LS due to codec mismiatch (channel rate)\n");
+		return false;
+	}
+
+	if (conn->user_plane.chan_mode != conn->lcls.other->user_plane.chan_mode
+	    && conn->sccp.msc->lcls_codec_mismatch_allow == false) {
+		LOGPFSM(conn->lcls.fi, "Not enabling LS due to codec mismiatch (channel mode)\n");
+		return false;
+	}
+
 	return true;
 }
 
diff --git a/src/osmo-bsc/osmo_bsc_vty.c b/src/osmo-bsc/osmo_bsc_vty.c
index f6f1b8a..efa12e0 100644
--- a/src/osmo-bsc/osmo_bsc_vty.c
+++ b/src/osmo-bsc/osmo_bsc_vty.c
@@ -184,6 +184,11 @@
 	vty_out(vty, " lcls-mode %s%s", get_value_string(bsc_lcls_mode_names, msc->lcls_mode),
 		VTY_NEWLINE);
 
+	if (msc->lcls_codec_mismatch_allow)
+		vty_out(vty, " lcls-codec-mismatch allowed%s", VTY_NEWLINE);
+	else
+		vty_out(vty, " lcls-codec-mismatch forbidden%s", VTY_NEWLINE);
+
 	/* write MGW configuration */
 	mgcp_client_config_write(vty, " ");
 }
@@ -650,6 +655,23 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(cfg_net_msc_lcls_mismtch,
+      cfg_net_msc_lcls_mismtch_cmd,
+      "lcls-codec-mismatch (allowed|forbidden)",
+      "Allow 3GPP LCLS (Local Call, Local Switch) when call legs use different codec/rate\n"
+      "Allow LCLS only only for calls that use the same codec/rate on both legs\n"
+      "Do not Allow LCLS for calls that use a different codec/rate on both legs\n")
+{
+	struct bsc_msc_data *data = bsc_msc_data(vty);
+
+	if (strcmp(argv[0], "allowed") == 0)
+		data->lcls_codec_mismatch_allow = true;
+	else
+		data->lcls_codec_mismatch_allow = false;
+
+	return CMD_SUCCESS;
+}
+
 DEFUN(cfg_net_bsc_mid_call_text,
       cfg_net_bsc_mid_call_text_cmd,
       "mid-call-text .TEXT",
@@ -938,6 +960,7 @@
 	install_element(MSC_NODE, &cfg_net_msc_amr_5_15_cmd);
 	install_element(MSC_NODE, &cfg_net_msc_amr_4_75_cmd);
 	install_element(MSC_NODE, &cfg_net_msc_lcls_mode_cmd);
+	install_element(MSC_NODE, &cfg_net_msc_lcls_mismtch_cmd);
 	install_element(MSC_NODE, &cfg_msc_acc_lst_name_cmd);
 	install_element(MSC_NODE, &cfg_msc_no_acc_lst_name_cmd);
 	install_element(MSC_NODE, &cfg_msc_cs7_bsc_addr_cmd);