aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/osmo-bsc/osmo_bsc_grace.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2011-03-03 23:29:05 +0100
committerHarald Welte <laforge@gnumonks.org>2011-03-03 23:29:05 +0100
commit31c00f7d6fa63937f2c973157d196a427f6eef95 (patch)
tree6b7c81d92b6a8b83d0588b2b59d47fd0cca7a052 /openbsc/src/osmo-bsc/osmo_bsc_grace.c
parent9349d7ff7c5866110a1f2421ccc68a487e4030be (diff)
re-structure the OpenBSC directory layout
The new structure divides the code into a number of libraries for the BSC core functionality, MSC core functionality, Abis transport, TRAU and other bits. This doesn't introduce any functional code change but simply moves around files and alters Makefile.am accordingly. Next step would be to disentangle a lot of the inter-library dependencies and make the individual bits of code more independent.
Diffstat (limited to 'openbsc/src/osmo-bsc/osmo_bsc_grace.c')
-rw-r--r--openbsc/src/osmo-bsc/osmo_bsc_grace.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/openbsc/src/osmo-bsc/osmo_bsc_grace.c b/openbsc/src/osmo-bsc/osmo_bsc_grace.c
new file mode 100644
index 000000000..f699cf39c
--- /dev/null
+++ b/openbsc/src/osmo-bsc/osmo_bsc_grace.c
@@ -0,0 +1,107 @@
+/*
+ * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2010 by On-Waves
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <openbsc/osmo_bsc_grace.h>
+#include <openbsc/osmo_bsc_rf.h>
+#include <openbsc/osmo_msc_data.h>
+#include <openbsc/gsm_04_80.h>
+#include <openbsc/signal.h>
+
+int bsc_grace_allow_new_connection(struct gsm_network *network)
+{
+ if (!network->msc_data->rf_ctl)
+ return 1;
+ return network->msc_data->rf_ctl->policy == S_RF_ON;
+}
+
+static int handle_sub(struct gsm_lchan *lchan, const char *text)
+{
+ struct gsm_subscriber_connection *conn;
+
+ /* only send it to TCH */
+ if (lchan->type != GSM_LCHAN_TCH_H && lchan->type != GSM_LCHAN_TCH_F)
+ return -1;
+
+ /* only send on the primary channel */
+ conn = lchan->conn;
+ if (!conn)
+ return -1;
+
+ if (conn->lchan != lchan)
+ return -1;
+
+ /* only when active */
+ if (lchan->state != LCHAN_S_ACTIVE)
+ return -1;
+
+ gsm0480_send_ussdNotify(conn, 0, text);
+ gsm0480_send_releaseComplete(conn);
+
+ return 0;
+}
+
+/*
+ * The place to handle the grace mode. Right now we will send
+ * USSD messages to the subscriber, in the future we might start
+ * a timer to have different modes for the grace period.
+ */
+static int handle_grace(struct gsm_network *network)
+{
+ int ts_nr, lchan_nr;
+ struct gsm_bts *bts;
+ struct gsm_bts_trx *trx;
+
+ if (!network->msc_data->mid_call_txt)
+ return 0;
+
+ llist_for_each_entry(bts, &network->bts_list, list) {
+ llist_for_each_entry(trx, &bts->trx_list, list) {
+ for (ts_nr = 0; ts_nr < TRX_NR_TS; ++ts_nr) {
+ struct gsm_bts_trx_ts *ts = &trx->ts[ts_nr];
+ for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN; ++lchan_nr) {
+ handle_sub(&ts->lchan[lchan_nr],
+ network->msc_data->mid_call_txt);
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+static int handle_rf_signal(unsigned int subsys, unsigned int signal,
+ void *handler_data, void *signal_data)
+{
+ struct rf_signal_data *sig;
+
+ if (subsys != SS_RF)
+ return -1;
+
+ sig = signal_data;
+
+ if (signal == S_RF_GRACE)
+ handle_grace(sig->net);
+
+ return 0;
+}
+
+static __attribute__((constructor)) void on_dso_load_grace(void)
+{
+ register_signal_handler(SS_RF, handle_rf_signal, NULL);
+}