2010-11-03 15:40:03 +00:00
|
|
|
/* Interaction with the SCCP subsystem */
|
|
|
|
/*
|
|
|
|
* (C) 2009-2010 by Holger Hans Peter Freyther <zecke@selfish.org>
|
|
|
|
* (C) 2009-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/gsm_data.h>
|
2010-11-06 17:08:43 +00:00
|
|
|
#include <openbsc/osmo_bsc.h>
|
|
|
|
#include <openbsc/osmo_bsc_grace.h>
|
2010-11-03 15:40:03 +00:00
|
|
|
#include <openbsc/osmo_msc_data.h>
|
|
|
|
#include <openbsc/debug.h>
|
|
|
|
|
|
|
|
#include <osmocore/gsm0808.h>
|
2010-11-05 18:48:47 +00:00
|
|
|
#include <osmocore/talloc.h>
|
2010-11-03 15:40:03 +00:00
|
|
|
#include <osmocore/protocol/gsm_08_08.h>
|
|
|
|
|
|
|
|
#include <osmocom/sccp/sccp.h>
|
|
|
|
|
2010-11-06 19:23:58 +00:00
|
|
|
/* SCCP helper */
|
|
|
|
#define SCCP_IT_TIMER 60
|
|
|
|
|
2010-11-06 17:08:43 +00:00
|
|
|
static LLIST_HEAD(active_connections);
|
|
|
|
|
|
|
|
static void msc_outgoing_sccp_data(struct sccp_connection *conn,
|
|
|
|
struct msgb *msg, unsigned int len)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void msc_outgoing_sccp_state(struct sccp_connection *conn, int old_state)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-06 19:23:58 +00:00
|
|
|
static void sccp_it_timeout(void *_data)
|
|
|
|
{
|
|
|
|
struct osmo_bsc_sccp_con *data =
|
|
|
|
(struct osmo_bsc_sccp_con *) _data;
|
|
|
|
|
|
|
|
sccp_connection_send_it(data->sccp);
|
|
|
|
bsc_schedule_timer(&data->sccp_it_timeout, SCCP_IT_TIMER, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sccp_cc_timeout(void *_data)
|
|
|
|
{
|
|
|
|
struct osmo_bsc_sccp_con *data =
|
|
|
|
(struct osmo_bsc_sccp_con *) _data;
|
|
|
|
|
|
|
|
if (data->sccp->connection_state >= SCCP_CONNECTION_STATE_ESTABLISHED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "The connection was never established.\n");
|
|
|
|
|
|
|
|
|
|
|
|
if (data->conn) {
|
|
|
|
gsm0808_clear(data->conn);
|
|
|
|
subscr_con_free(data->conn);
|
|
|
|
data->conn = NULL;
|
|
|
|
}
|
|
|
|
bsc_delete_connection(data);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:40:03 +00:00
|
|
|
static void msc_sccp_write_ipa(struct sccp_connection *conn, struct msgb *msg, void *data)
|
|
|
|
{
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "Writing is not implemented.\n");
|
|
|
|
msgb_free(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int msc_sccp_accept(struct sccp_connection *connection, void *data)
|
|
|
|
{
|
|
|
|
LOGP(DMSC, LOGL_DEBUG, "Rejecting incoming SCCP connection.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int msc_sccp_read(struct msgb *msgb, unsigned int length, void *data)
|
|
|
|
{
|
|
|
|
struct bssmap_header *bs;
|
|
|
|
|
|
|
|
LOGP(DMSC, LOGL_DEBUG, "Incoming SCCP message ftom MSC: %s\n",
|
|
|
|
hexdump(msgb->l3h, length));
|
|
|
|
|
|
|
|
if (length < sizeof(*bs)) {
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "The header is too short.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bs = (struct bssmap_header *) msgb->l3h;
|
|
|
|
if (bs->length < length - sizeof(*bs))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
switch (bs->type) {
|
|
|
|
case BSSAP_MSG_BSS_MANAGEMENT:
|
2010-11-03 17:46:52 +00:00
|
|
|
LOGP(DMSC, LOGL_ERROR, "BSS management not implemented.\n");
|
2010-11-03 15:40:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "Unimplemented msg type: %d\n", bs->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-04 10:48:49 +00:00
|
|
|
int bsc_queue_for_msc(struct gsm_subscriber_connection *conn, struct msgb *msg)
|
|
|
|
{
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "Sending SCCP messages is not yet implemented.\n");
|
|
|
|
msgb_free(msg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-05 18:48:47 +00:00
|
|
|
int bsc_create_new_connection(struct gsm_subscriber_connection *conn)
|
2010-11-05 10:10:46 +00:00
|
|
|
{
|
2010-11-06 17:08:43 +00:00
|
|
|
struct gsm_network *net;
|
|
|
|
struct osmo_bsc_sccp_con *bsc_con;
|
|
|
|
struct sccp_connection *sccp;
|
|
|
|
|
|
|
|
net = conn->bts->network;
|
|
|
|
if (!net->msc_data->msc_con->is_authenticated) {
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "Not connected to a MSC. Not forwarding data.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bsc_grace_allow_new_connection(net)) {
|
|
|
|
LOGP(DMSC, LOGL_NOTICE, "BSC in grace period. No new connections.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sccp = sccp_connection_socket();
|
|
|
|
if (!sccp) {
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "Failed to allocate memory.\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
bsc_con = talloc_zero(conn->bts, struct osmo_bsc_sccp_con);
|
|
|
|
if (!bsc_con) {
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "Failed to allocate.\n");
|
|
|
|
sccp_connection_free(sccp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
sccp->state_cb = msc_outgoing_sccp_state;
|
|
|
|
sccp->data_cb = msc_outgoing_sccp_data;
|
|
|
|
sccp->data_ctx = bsc_con;
|
|
|
|
|
2010-11-06 19:23:58 +00:00
|
|
|
/* prepare the timers */
|
|
|
|
bsc_con->sccp_it_timeout.cb = sccp_it_timeout;
|
|
|
|
bsc_con->sccp_it_timeout.data = bsc_con;
|
|
|
|
bsc_con->sccp_cc_timeout.cb = sccp_cc_timeout;
|
|
|
|
bsc_con->sccp_cc_timeout.data = bsc_con;
|
|
|
|
|
2010-11-06 17:08:43 +00:00
|
|
|
bsc_con->sccp = sccp;
|
|
|
|
bsc_con->msc_con = net->msc_data->msc_con;
|
2010-11-06 19:15:17 +00:00
|
|
|
bsc_con->conn = conn;
|
2010-11-06 17:08:43 +00:00
|
|
|
llist_add(&bsc_con->entry, &active_connections);
|
|
|
|
conn->sccp_con = bsc_con;
|
|
|
|
return 0;
|
2010-11-05 10:10:46 +00:00
|
|
|
}
|
|
|
|
|
2010-11-06 19:15:17 +00:00
|
|
|
int bsc_open_connection(struct osmo_bsc_sccp_con *conn, struct msgb *msg)
|
2010-11-05 18:48:47 +00:00
|
|
|
{
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "Not implemented yet.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-11-06 19:15:17 +00:00
|
|
|
int bsc_delete_connection(struct osmo_bsc_sccp_con *sccp)
|
2010-11-05 18:48:47 +00:00
|
|
|
{
|
2010-11-06 17:08:43 +00:00
|
|
|
if (!sccp)
|
2010-11-05 18:48:47 +00:00
|
|
|
return 0;
|
|
|
|
|
2010-11-06 19:15:17 +00:00
|
|
|
if (sccp->conn)
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "Should have been cleared.\n");
|
|
|
|
|
2010-11-06 17:08:43 +00:00
|
|
|
llist_del(&sccp->entry);
|
|
|
|
bsc_del_timer(&sccp->sccp_it_timeout);
|
|
|
|
bsc_del_timer(&sccp->sccp_cc_timeout);
|
|
|
|
talloc_free(sccp);
|
2010-11-05 18:48:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:40:03 +00:00
|
|
|
int osmo_bsc_sccp_init(struct gsm_network *gsmnet)
|
|
|
|
{
|
|
|
|
sccp_set_log_area(DSCCP);
|
|
|
|
sccp_system_init(msc_sccp_write_ipa, gsmnet);
|
|
|
|
sccp_connection_set_incoming(&sccp_ssn_bssap, msc_sccp_accept, NULL);
|
|
|
|
sccp_set_read(&sccp_ssn_bssap, msc_sccp_read, NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|