msc: Separate the BSC and MSC link completly...

Make the msc_conn responsible for creating the link to
the core network and reopening it, make the BTS code just
call the msc methods and the MSC will throw away data in
case it can not be forwarded.

This avoids a problem that we start a reconnect timer
while we have a connection in progress and then add the
same file descriptor twice. This is mostly a speculative
fix to the problem.
diff --git a/include/bsc_data.h b/include/bsc_data.h
index 1427db5..f24af5d 100644
--- a/include/bsc_data.h
+++ b/include/bsc_data.h
@@ -109,7 +109,6 @@
 
 /* msc related functions */
 int msc_init(struct bsc_data *bsc);
-void msc_schedule_reconnect(struct bsc_data *bsc);
 void msc_send_rlc(struct bsc_data *bsc, struct sccp_source_reference *src, struct sccp_source_reference *dest);
 void msc_send_reset(struct bsc_data *bsc);
 void msc_send_msg(struct bsc_data *bsc, int rc, struct sccp_parse_result *, struct msgb *msg);
diff --git a/src/main.c b/src/main.c
index bb15ed9..5d63ff4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -272,7 +272,6 @@
 void bsc_resources_released(struct bsc_data *bsc)
 {
 	bsc_del_timer(&bsc->reset_timeout);
-	msc_schedule_reconnect(bsc);
 }
 
 static void bsc_reset_timeout(void *_data)
@@ -376,11 +375,8 @@
 	/* clear pending messages from the MSC */
 	msc_clear_queue(data->bsc);
 
-	/* for the case the link is going down while we are trying to reset */
-	if (data->bsc->msc_link_down)
-		msc_schedule_reconnect(data->bsc);
-	else if (was_up)
-		msc_send_reset(data->bsc);
+	/* If we have an A link send a reset to the MSC */
+	msc_send_reset(data->bsc);
 }
 
 void bsc_link_up(struct link_data *data)
diff --git a/src/msc_conn.c b/src/msc_conn.c
index 19394f8..aabd151 100644
--- a/src/msc_conn.c
+++ b/src/msc_conn.c
@@ -44,6 +44,7 @@
 
 static void msc_send_id_response(struct bsc_data *bsc);
 static void msc_send(struct bsc_data *bsc, struct msgb *msg, int proto);
+static void msc_schedule_reconnect(struct bsc_data *bsc);
 
 void mtp_link_slta_recv(struct mtp_link *link)
 {
@@ -83,6 +84,7 @@
 	release_bsc_resources(bsc);
 	bsc_del_timer(&bsc->ping_timeout);
 	bsc_del_timer(&bsc->pong_timeout);
+	msc_schedule_reconnect(bsc);
 }
 
 static void msc_connect_timeout(void *_bsc_data)
@@ -377,7 +379,7 @@
 	bsc_schedule_timer(&bsc->msc_timeout, bsc->msc_time, 0);
 }
 
-void msc_schedule_reconnect(struct bsc_data *bsc)
+static void msc_schedule_reconnect(struct bsc_data *bsc)
 {
 	bsc_schedule_timer(&bsc->reconnect_timer, RECONNECT_TIME);
 }
@@ -519,11 +521,20 @@
 	/* create MGCP port */
 	if (mgcp_create_port(bsc) != 0)
 		return -1;
+
+	/* now connect to the BSC */
+	msc_schedule_reconnect(bsc);
 	return 0;
 }
 
 static void msc_send(struct bsc_data *bsc, struct msgb *msg, int proto)
 {
+	if (bsc->msc_link_down) {
+		LOGP(DMSC, LOGL_NOTICE, "Dropping data due lack of MSC connection.\n");
+		msgb_free(msg);
+		return;
+	}
+
 	ipaccess_prepend_header(msg, proto);
 
 	if (write_queue_enqueue(&bsc->msc_connection, msg) != 0) {