commit cd129c545bcd9f1ed423a5da2bd66fd84e1343bc
Author: Andreas Eversberg <andreas@eversberg.eu>
Date:   Thu Dec 5 13:25:06 2013 +0100

    Add VTY option for Nokia BTS that does not send RELease CONFirm message
    
    This option is a workarround for a bug found in Nokia InSite BTS firmware
    version 3.0.0. There is no RELease CONFirm message for local end release.
    Nokia MetroSite with firmware version 4.178.16 is not affected.
    
    TS 04.06 Chapter 5.4.4.4 "Local end release procedure" states that a
    confirm must be sent by layer 2 when receiving a local end release
    request.
    
    In order to correctly switch a channel (handover or assignment), local
    end release is required.

diff --git a/openbsc/include/openbsc/gsm_data.h b/openbsc/include/openbsc/gsm_data.h
index 8741505..7c3ca84 100644
--- a/openbsc/include/openbsc/gsm_data.h
+++ b/openbsc/include/openbsc/gsm_data.h
@@ -370,6 +370,18 @@ static inline int is_siemens_bts(struct gsm_bts *bts)
 	return 0;
 }
 
+static inline int is_nokia_bts(struct gsm_bts *bts)
+{
+	switch (bts->type) {
+	case GSM_BTS_TYPE_NOKIA_SITE:
+		return 1;
+	default:
+		break;
+	}
+
+	return 0;
+}
+
 enum gsm_auth_policy gsm_auth_policy_parse(const char *arg);
 const char *gsm_auth_policy_name(enum gsm_auth_policy policy);
 
diff --git a/openbsc/include/openbsc/gsm_data_shared.h b/openbsc/include/openbsc/gsm_data_shared.h
index 4a41498..3bf05e4 100644
--- a/openbsc/include/openbsc/gsm_data_shared.h
+++ b/openbsc/include/openbsc/gsm_data_shared.h
@@ -113,6 +113,7 @@ struct gsm_abis_mo {
 #define LCHAN_SAPI_UNUSED	0
 #define LCHAN_SAPI_MS		1
 #define LCHAN_SAPI_NET		2
+#define LCHAN_SAPI_REL		3
 
 /* state of a logical channel */
 enum gsm_lchan_state {
@@ -237,6 +238,7 @@ struct gsm_lchan {
 	struct osmo_timer_list T3111;
 	struct osmo_timer_list error_timer;
 	struct osmo_timer_list act_timer;
+	struct osmo_timer_list rel_work;
 	uint8_t error_cause;
 
 	/* table of neighbor cell measurements */
@@ -640,6 +642,7 @@ struct gsm_bts {
 			uint8_t bts_type;
 			unsigned int configured:1,
 				skip_reset:1,
+				no_loc_rel_cnf:1,
 				did_reset:1,
 				wait_reset:1;
 			struct osmo_timer_list reset_timer;
diff --git a/openbsc/src/libbsc/abis_rsl.c b/openbsc/src/libbsc/abis_rsl.c
index 41bfcdc..f53ba84 100644
--- a/openbsc/src/libbsc/abis_rsl.c
+++ b/openbsc/src/libbsc/abis_rsl.c
@@ -867,6 +867,22 @@ int rsl_establish_request(struct gsm_lchan *lchan, uint8_t link_id)
 	return abis_rsl_sendmsg(msg);
 }
 
+static void rsl_handle_release(struct gsm_lchan *lchan);
+
+/* Special work handler to handle missing RSL_MT_REL_CONF message from
+ * Nokia InSite BTS */
+static void lchan_rel_work_cb(void *data)
+{
+	struct gsm_lchan *lchan = data;
+	int sapi;
+
+	for (sapi = 0; sapi < ARRAY_SIZE(lchan->sapis); ++sapi) {
+		if (lchan->sapis[sapi] == LCHAN_SAPI_REL)
+			lchan->sapis[sapi] = LCHAN_SAPI_UNUSED;
+	}
+	rsl_handle_release(lchan);
+}
+
 /* Chapter 8.3.7 Request the release of multiframe mode of RLL connection.
    This is what higher layers should call.  The BTS then responds with
    RELEASE CONFIRM, which we in turn use to trigger RSL CHANNEL RELEASE,
@@ -890,7 +906,20 @@ int rsl_release_request(struct gsm_lchan *lchan, uint8_t link_id,
 	DEBUGP(DRLL, "%s RSL RLL RELEASE REQ (link_id=0x%02x, reason=%u)\n",
 		gsm_lchan_name(lchan), link_id, release_mode);
 
-	return abis_rsl_sendmsg(msg);
+	abis_rsl_sendmsg(msg);
+
+	/* Do not wait for Nokia BTS to send the confirm. */
+	if (is_nokia_bts(lchan->ts->trx->bts)
+	 && lchan->ts->trx->bts->nokia.no_loc_rel_cnf
+	 && release_mode == RSL_REL_LOCAL_END) {
+		DEBUGP(DRLL, "Scheduling release, becasuse Nokia InSite BTS does not send a RELease CONFirm.\n");
+		lchan->sapis[link_id & 0x7] = LCHAN_SAPI_REL;
+		lchan->rel_work.cb = lchan_rel_work_cb;
+		lchan->rel_work.data = lchan;
+		osmo_timer_schedule(&lchan->rel_work, 0, 0);
+	}
+
+	return 0;
 }
 
 int rsl_lchan_set_state(struct gsm_lchan *lchan, int state)
diff --git a/openbsc/src/libbsc/bsc_vty.c b/openbsc/src/libbsc/bsc_vty.c
index 1bc0ea1..17b5223 100644
--- a/openbsc/src/libbsc/bsc_vty.c
+++ b/openbsc/src/libbsc/bsc_vty.c
@@ -601,6 +601,8 @@ static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts)
 		break;
 	case GSM_BTS_TYPE_NOKIA_SITE:
 		vty_out(vty, "  nokia_site skip-reset %d%s", bts->nokia.skip_reset, VTY_NEWLINE);
+		vty_out(vty, "  nokia_site no-local-rel-conf %d%s",
+			bts->nokia.no_loc_rel_cnf, VTY_NEWLINE);
 		/* fall through: Nokia requires "oml e1" parameters also */
 	default:
 		config_write_e1_link(vty, &bts->oml_e1_link, "  oml ");
@@ -1758,11 +1760,12 @@ DEFUN(cfg_bts_rsl_ip,
 	return CMD_SUCCESS;
 }
 
+#define NOKIA_STR "Nokia *Site related commands\n"
 
 DEFUN(cfg_bts_nokia_site_skip_reset,
       cfg_bts_nokia_site_skip_reset_cmd,
       "nokia_site skip-reset (0|1)",
-      "Nokia *Site related commands\n"
+      NOKIA_STR
       "Skip the reset step during bootstrap process of this BTS\n"
       "Do NOT skip the reset\n" "Skip the reset\n")
 {
@@ -1778,6 +1781,26 @@ DEFUN(cfg_bts_nokia_site_skip_reset,
 	return CMD_SUCCESS;
 }
 
+DEFUN(cfg_bts_nokia_site_no_loc_rel_cnf,
+      cfg_bts_nokia_site_no_loc_rel_cnf_cmd,
+      "nokia_site no-local-rel-conf (0|1)",
+      NOKIA_STR
+      "Do not wait for RELease CONFirm message when releasing channel locally\n"
+      "Wait for RELease CONFirm\n" "Do not wait for RELease CONFirm\n")
+{
+	struct gsm_bts *bts = vty->index;
+
+	if (!is_nokia_bts(bts)) {
+		vty_out(vty, "%% BTS is not of Nokia *Site type%s",
+			VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	bts->nokia.no_loc_rel_cnf = atoi(argv[0]);
+
+	return CMD_SUCCESS;
+}
+
 #define OML_STR	"Organization & Maintenance Link\n"
 #define IPA_STR "A-bis/IP Specific Options\n"
 
@@ -3255,6 +3278,7 @@ int bsc_vty_init(const struct log_info *cat)
 	install_element(BTS_NODE, &cfg_bts_timezone_dst_cmd);
 	install_element(BTS_NODE, &cfg_bts_no_timezone_cmd);
 	install_element(BTS_NODE, &cfg_bts_nokia_site_skip_reset_cmd);
+	install_element(BTS_NODE, &cfg_bts_nokia_site_no_loc_rel_cnf_cmd);
 	install_element(BTS_NODE, &cfg_bts_stream_id_cmd);
 	install_element(BTS_NODE, &cfg_bts_oml_e1_cmd);
 	install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd);
