bsc: Add the osmo_bsc_grace from the on-waves/bsc-master branch

The grace code will decide if a given connection is allowed to
be made or if it is going to be rejected. For active connections
it is going to send a USSD message.
This commit is contained in:
Holger Hans Peter Freyther 2010-09-16 00:20:56 +08:00
parent 0ab63d73c1
commit bd76fab9cb
4 changed files with 139 additions and 1 deletions

View File

@ -11,7 +11,7 @@ noinst_HEADERS = abis_nm.h abis_rsl.h db.h gsm_04_08.h gsm_data.h \
gb_proxy.h gprs_sgsn.h gsm_04_08_gprs.h sgsn.h \
gprs_ns_frgre.h auth.h osmo_msc.h bsc_msc.h bsc_nat.h \
osmo_bsc_rf.h osmo_bsc.h network_listen.h bsc_nat_sccp.h \
osmo_msc_data.h
osmo_msc_data.h osmo_bsc_grace.h
openbsc_HEADERS = gsm_04_08.h meas_rep.h bsc_api.h
openbscdir = $(includedir)/openbsc

View File

@ -0,0 +1,29 @@
/*
* (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 General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#ifndef OSMO_BSC_GRACE_H
#define OSMO_BSC_GRACE_H
#include "gsm_data.h"
int bsc_grace_allow_new_connection(struct gsm_network *network);
#endif

View File

@ -6,6 +6,7 @@ bin_PROGRAMS = osmo-bsc
osmo_bsc_SOURCES = osmo_bsc_main.c osmo_bsc_rf.c osmo_bsc_vty.c osmo_bsc_api.c \
osmo_bsc_grace.c \
$(top_srcdir)/src/debug.c $(top_srcdir)/src/bsc_msc.c \
$(top_srcdir)/src/bsc_init.c
osmo_bsc_LDADD = $(top_builddir)/src/libvty.a \

View File

@ -0,0 +1,108 @@
/*
* (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 General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#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->ussd_grace_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->ussd_grace_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);
}