2015-04-05 18:53:42 +00:00
|
|
|
/* (C) 2009-2015 by Holger Hans Peter Freyther <zecke@selfish.org>
|
2011-08-15 13:53:00 +00:00
|
|
|
* (C) 2009-2011 by On-Waves
|
2010-07-05 08:02:04 +00:00
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2011-01-01 14:25:50 +00:00
|
|
|
* 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
|
2010-07-05 08:02:04 +00:00
|
|
|
* (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
|
2011-01-01 14:25:50 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
2010-07-05 08:02:04 +00:00
|
|
|
*
|
2011-01-01 14:25:50 +00:00
|
|
|
* 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/>.
|
2010-07-05 08:02:04 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <openbsc/osmo_bsc.h>
|
2010-11-05 18:48:47 +00:00
|
|
|
#include <openbsc/osmo_msc_data.h>
|
2010-11-03 18:03:35 +00:00
|
|
|
#include <openbsc/debug.h>
|
|
|
|
|
2013-09-11 08:46:55 +00:00
|
|
|
#include <openbsc/gsm_04_80.h>
|
|
|
|
|
2011-03-23 17:26:56 +00:00
|
|
|
#include <osmocom/gsm/protocol/gsm_08_08.h>
|
|
|
|
#include <osmocom/gsm/gsm0808.h>
|
2010-11-04 10:59:41 +00:00
|
|
|
|
2011-06-09 12:44:47 +00:00
|
|
|
#include <osmocom/sccp/sccp.h>
|
|
|
|
|
2010-11-03 18:03:35 +00:00
|
|
|
#define return_when_not_connected(conn) \
|
|
|
|
if (!conn->sccp_con) {\
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "MSC Connection not present.\n"); \
|
|
|
|
return; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define return_when_not_connected_val(conn, ret) \
|
|
|
|
if (!conn->sccp_con) {\
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "MSC Connection not present.\n"); \
|
|
|
|
return ret; \
|
|
|
|
}
|
2010-07-05 08:02:04 +00:00
|
|
|
|
2010-11-05 10:02:28 +00:00
|
|
|
#define queue_msg_or_return(resp) \
|
|
|
|
if (!resp) { \
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "Failed to allocate response.\n"); \
|
|
|
|
return; \
|
|
|
|
} \
|
2010-11-10 08:31:41 +00:00
|
|
|
bsc_queue_for_msc(conn->sccp_con, resp);
|
2010-11-05 10:02:28 +00:00
|
|
|
|
2011-06-09 15:37:04 +00:00
|
|
|
static int bsc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause);
|
|
|
|
static int complete_layer3(struct gsm_subscriber_connection *conn,
|
|
|
|
struct msgb *msg, struct osmo_msc_data *msc);
|
|
|
|
|
2011-06-04 12:51:51 +00:00
|
|
|
static uint16_t get_network_code_for_msc(struct osmo_msc_data *msc)
|
2010-11-05 18:48:47 +00:00
|
|
|
{
|
2015-07-13 09:06:10 +00:00
|
|
|
if (msc->core_mnc != -1)
|
|
|
|
return msc->core_mnc;
|
2011-06-04 12:51:51 +00:00
|
|
|
return msc->network->network_code;
|
2010-11-05 18:48:47 +00:00
|
|
|
}
|
|
|
|
|
2011-06-04 12:51:51 +00:00
|
|
|
static uint16_t get_country_code_for_msc(struct osmo_msc_data *msc)
|
2010-11-05 18:48:47 +00:00
|
|
|
{
|
2011-06-04 12:51:51 +00:00
|
|
|
if (msc->core_mcc != -1)
|
|
|
|
return msc->core_mcc;
|
|
|
|
return msc->network->country_code;
|
2010-11-05 18:48:47 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 16:15:48 +00:00
|
|
|
static uint16_t get_lac_for_msc(struct osmo_msc_data *msc, struct gsm_bts *bts)
|
|
|
|
{
|
|
|
|
if (msc->core_lac != -1)
|
|
|
|
return msc->core_lac;
|
|
|
|
return bts->location_area_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint16_t get_ci_for_msc(struct osmo_msc_data *msc, struct gsm_bts *bts)
|
|
|
|
{
|
|
|
|
if (msc->core_ci != -1)
|
|
|
|
return msc->core_ci;
|
|
|
|
return bts->cell_identity;
|
|
|
|
}
|
|
|
|
|
2015-04-05 20:45:32 +00:00
|
|
|
static void bsc_maybe_lu_reject(struct gsm_subscriber_connection *conn, int con_type, int cause)
|
|
|
|
{
|
|
|
|
struct msgb *msg;
|
|
|
|
|
|
|
|
/* ignore cm service request or such */
|
|
|
|
if (con_type != FLT_CON_TYPE_LU)
|
|
|
|
return;
|
|
|
|
|
|
|
|
msg = gsm48_create_loc_upd_rej(cause);
|
|
|
|
if (!msg) {
|
|
|
|
LOGP(DMM, LOGL_ERROR, "Failed to create msg for LOCATION UPDATING REJECT.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg->lchan = conn->lchan;
|
|
|
|
gsm0808_submit_dtap(conn, msg, 0, 0);
|
|
|
|
}
|
|
|
|
|
2015-04-05 18:53:42 +00:00
|
|
|
static int bsc_filter_initial(struct osmo_bsc_data *bsc,
|
|
|
|
struct osmo_msc_data *msc,
|
|
|
|
struct gsm_subscriber_connection *conn,
|
2015-04-05 20:45:32 +00:00
|
|
|
struct msgb *msg, char **imsi, int *con_type,
|
|
|
|
int *lu_cause)
|
2015-04-05 18:53:42 +00:00
|
|
|
{
|
|
|
|
struct bsc_filter_request req;
|
|
|
|
struct bsc_filter_reject_cause cause;
|
|
|
|
struct gsm48_hdr *gh = msgb_l3(msg);
|
2015-04-05 20:45:32 +00:00
|
|
|
int rc;
|
2015-04-05 18:53:42 +00:00
|
|
|
|
|
|
|
req.ctx = conn;
|
|
|
|
req.black_list = NULL;
|
|
|
|
req.access_lists = bsc_access_lists();
|
|
|
|
req.local_lst_name = msc->acc_lst_name;
|
|
|
|
req.global_lst_name = conn->bts->network->bsc_data->acc_lst_name;
|
|
|
|
req.bsc_nr = 0;
|
|
|
|
|
2015-04-05 20:45:32 +00:00
|
|
|
rc = bsc_msg_filter_initial(gh, msgb_l3len(msg), &req,
|
|
|
|
con_type, imsi, &cause);
|
|
|
|
*lu_cause = cause.lu_reject_cause;
|
|
|
|
return rc;
|
2015-04-05 18:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int bsc_filter_data(struct gsm_subscriber_connection *conn,
|
2015-04-05 20:45:32 +00:00
|
|
|
struct msgb *msg, int *lu_cause)
|
2015-04-05 18:53:42 +00:00
|
|
|
{
|
|
|
|
struct bsc_filter_request req;
|
|
|
|
struct gsm48_hdr *gh = msgb_l3(msg);
|
|
|
|
struct bsc_filter_reject_cause cause;
|
2015-04-05 20:45:32 +00:00
|
|
|
int rc;
|
2015-04-05 18:53:42 +00:00
|
|
|
|
|
|
|
req.ctx = conn;
|
|
|
|
req.black_list = NULL;
|
|
|
|
req.access_lists = bsc_access_lists();
|
|
|
|
req.local_lst_name = conn->sccp_con->msc->acc_lst_name;
|
|
|
|
req.global_lst_name = conn->bts->network->bsc_data->acc_lst_name;
|
|
|
|
req.bsc_nr = 0;
|
|
|
|
|
2015-04-05 20:45:32 +00:00
|
|
|
rc = bsc_msg_filter_data(gh, msgb_l3len(msg), &req,
|
2015-04-05 18:53:42 +00:00
|
|
|
&conn->sccp_con->filter_state,
|
|
|
|
&cause);
|
2015-04-05 20:45:32 +00:00
|
|
|
*lu_cause = cause.lu_reject_cause;
|
|
|
|
return rc;
|
2015-04-05 18:53:42 +00:00
|
|
|
}
|
2015-04-01 16:15:48 +00:00
|
|
|
|
2010-09-16 09:26:35 +00:00
|
|
|
static void bsc_sapi_n_reject(struct gsm_subscriber_connection *conn, int dlci)
|
|
|
|
{
|
2010-11-04 11:28:32 +00:00
|
|
|
struct msgb *resp;
|
2010-11-03 18:03:35 +00:00
|
|
|
return_when_not_connected(conn);
|
2010-11-04 11:28:32 +00:00
|
|
|
|
2011-07-11 22:05:11 +00:00
|
|
|
LOGP(DMSC, LOGL_NOTICE, "Tx MSC SAPI N REJECT DLCI=0x%02x\n", dlci);
|
|
|
|
|
2010-11-04 11:28:32 +00:00
|
|
|
resp = gsm0808_create_sapi_reject(dlci);
|
2010-11-05 10:02:28 +00:00
|
|
|
queue_msg_or_return(resp);
|
2010-09-16 09:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bsc_cipher_mode_compl(struct gsm_subscriber_connection *conn,
|
|
|
|
struct msgb *msg, uint8_t chosen_encr)
|
|
|
|
{
|
2010-11-04 10:59:41 +00:00
|
|
|
struct msgb *resp;
|
2010-11-03 18:03:35 +00:00
|
|
|
return_when_not_connected(conn);
|
2010-11-04 10:59:41 +00:00
|
|
|
|
|
|
|
LOGP(DMSC, LOGL_DEBUG, "CIPHER MODE COMPLETE from MS, forwarding to MSC\n");
|
|
|
|
resp = gsm0808_create_cipher_complete(msg, chosen_encr);
|
2010-11-05 10:02:28 +00:00
|
|
|
queue_msg_or_return(resp);
|
2010-09-16 09:26:35 +00:00
|
|
|
}
|
|
|
|
|
2013-10-31 14:36:43 +00:00
|
|
|
static void bsc_send_ussd_no_srv(struct gsm_subscriber_connection *conn,
|
|
|
|
struct msgb *msg, const char *text)
|
2013-09-11 08:46:55 +00:00
|
|
|
{
|
|
|
|
struct gsm48_hdr *gh;
|
|
|
|
int8_t pdisc;
|
|
|
|
uint8_t mtype;
|
|
|
|
int drop_message = 1;
|
|
|
|
|
|
|
|
if (!text)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!msg || msgb_l3len(msg) < sizeof(*gh))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gh = msgb_l3(msg);
|
2016-03-14 15:13:24 +00:00
|
|
|
pdisc = gsm48_hdr_pdisc(gh);
|
|
|
|
mtype = gsm48_hdr_msg_type(gh);
|
2013-09-11 08:46:55 +00:00
|
|
|
|
|
|
|
/* Is CM service request? */
|
|
|
|
if (pdisc == GSM48_PDISC_MM && mtype == GSM48_MT_MM_CM_SERV_REQ) {
|
|
|
|
struct gsm48_service_request *cm;
|
|
|
|
|
|
|
|
cm = (struct gsm48_service_request *) &gh->data[0];
|
|
|
|
|
|
|
|
/* Is type SMS or call? */
|
|
|
|
if (cm->cm_service_type == GSM48_CMSERV_SMS)
|
|
|
|
drop_message = 0;
|
|
|
|
else if (cm->cm_service_type == GSM48_CMSERV_MO_CALL_PACKET)
|
|
|
|
drop_message = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drop_message) {
|
2013-10-31 12:35:28 +00:00
|
|
|
LOGP(DMSC, LOGL_DEBUG, "Skipping (not sending) USSD message: '%s'\n", text);
|
2013-09-11 08:46:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-31 14:36:42 +00:00
|
|
|
LOGP(DMSC, LOGL_INFO, "Sending CM Service Accept\n");
|
|
|
|
gsm48_tx_mm_serv_ack(conn);
|
|
|
|
|
2013-09-11 08:46:55 +00:00
|
|
|
LOGP(DMSC, LOGL_INFO, "Sending USSD message: '%s'\n", text);
|
|
|
|
gsm0480_send_ussdNotify(conn, 1, text);
|
|
|
|
gsm0480_send_releaseComplete(conn);
|
|
|
|
}
|
|
|
|
|
2010-11-05 18:48:47 +00:00
|
|
|
/*
|
|
|
|
* Instruct to reserve data for a new connectiom, create the complete
|
|
|
|
* layer three message, send it to open the connection.
|
|
|
|
*/
|
2010-09-16 09:26:35 +00:00
|
|
|
static int bsc_compl_l3(struct gsm_subscriber_connection *conn, struct msgb *msg,
|
|
|
|
uint16_t chosen_channel)
|
|
|
|
{
|
2011-06-07 09:40:20 +00:00
|
|
|
struct osmo_msc_data *msc;
|
2010-11-05 18:48:47 +00:00
|
|
|
|
2011-07-11 22:05:11 +00:00
|
|
|
LOGP(DMSC, LOGL_INFO, "Tx MSC COMPL L3\n");
|
|
|
|
|
2011-06-07 09:40:20 +00:00
|
|
|
/* find the MSC link we want to use */
|
2011-06-07 17:57:02 +00:00
|
|
|
msc = bsc_find_msc(conn, msg);
|
2011-06-07 09:40:20 +00:00
|
|
|
if (!msc) {
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "Failed to find a MSC for a connection.\n");
|
2013-10-31 14:36:43 +00:00
|
|
|
bsc_send_ussd_no_srv(conn, msg,
|
|
|
|
conn->bts->network->bsc_data->ussd_no_msc_txt);
|
2011-06-07 09:40:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-06-09 15:37:04 +00:00
|
|
|
return complete_layer3(conn, msg, msc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int complete_layer3(struct gsm_subscriber_connection *conn,
|
|
|
|
struct msgb *msg, struct osmo_msc_data *msc)
|
|
|
|
{
|
2015-04-05 20:45:32 +00:00
|
|
|
int con_type, rc, lu_cause;
|
2015-04-05 18:53:42 +00:00
|
|
|
char *imsi = NULL;
|
2014-09-02 15:28:40 +00:00
|
|
|
struct timeval tv;
|
2011-06-09 15:37:04 +00:00
|
|
|
struct msgb *resp;
|
|
|
|
uint16_t network_code;
|
|
|
|
uint16_t country_code;
|
2015-04-01 16:15:48 +00:00
|
|
|
uint16_t lac;
|
|
|
|
uint16_t ci;
|
2013-09-11 08:46:55 +00:00
|
|
|
enum bsc_con ret;
|
2014-09-02 15:28:40 +00:00
|
|
|
int send_ping = msc->advanced_ping;
|
|
|
|
|
|
|
|
/* Advanced ping/pong handling */
|
|
|
|
if (osmo_timer_pending(&msc->pong_timer))
|
|
|
|
send_ping = 0;
|
2014-10-29 09:06:15 +00:00
|
|
|
if (msc->ping_timeout <= 0)
|
2014-09-02 15:28:40 +00:00
|
|
|
send_ping = 0;
|
|
|
|
if (send_ping && osmo_timer_remaining(&msc->ping_timer, NULL, &tv) == -1)
|
|
|
|
send_ping = 0;
|
2011-06-09 15:37:04 +00:00
|
|
|
|
2015-04-05 18:53:42 +00:00
|
|
|
/* Check the filter */
|
2015-04-05 20:45:32 +00:00
|
|
|
rc = bsc_filter_initial(msc->network->bsc_data, msc, conn, msg,
|
|
|
|
&imsi, &con_type, &lu_cause);
|
|
|
|
if (rc < 0) {
|
|
|
|
bsc_maybe_lu_reject(conn, con_type, lu_cause);
|
2015-04-05 18:53:42 +00:00
|
|
|
return BSC_API_CONN_POL_REJECT;
|
2015-04-05 20:45:32 +00:00
|
|
|
}
|
2015-04-05 18:53:42 +00:00
|
|
|
|
2010-11-05 18:48:47 +00:00
|
|
|
/* allocate resource for a new connection */
|
2014-09-02 15:28:40 +00:00
|
|
|
ret = bsc_create_new_connection(conn, msc, send_ping);
|
2013-09-11 08:46:55 +00:00
|
|
|
|
|
|
|
if (ret != BSC_CON_SUCCESS) {
|
|
|
|
/* allocation has failed */
|
|
|
|
if (ret == BSC_CON_REJECT_NO_LINK)
|
2013-10-31 14:36:43 +00:00
|
|
|
bsc_send_ussd_no_srv(conn, msg, msc->ussd_msc_lost_txt);
|
2013-09-11 08:46:55 +00:00
|
|
|
else if (ret == BSC_CON_REJECT_RF_GRACE)
|
2013-10-31 14:36:43 +00:00
|
|
|
bsc_send_ussd_no_srv(conn, msg, msc->ussd_grace_txt);
|
2013-09-11 08:46:55 +00:00
|
|
|
|
2010-11-05 18:48:47 +00:00
|
|
|
return BSC_API_CONN_POL_REJECT;
|
2013-09-11 08:46:55 +00:00
|
|
|
}
|
|
|
|
|
2015-04-05 18:53:42 +00:00
|
|
|
if (imsi)
|
|
|
|
conn->sccp_con->filter_state.imsi = talloc_steal(conn, imsi);
|
2015-04-05 20:45:32 +00:00
|
|
|
conn->sccp_con->filter_state.con_type = con_type;
|
2015-04-05 18:53:42 +00:00
|
|
|
|
2013-09-11 08:46:55 +00:00
|
|
|
/* check return value, if failed check msg for and send USSD */
|
2010-11-05 18:48:47 +00:00
|
|
|
|
2011-06-04 12:51:51 +00:00
|
|
|
network_code = get_network_code_for_msc(conn->sccp_con->msc);
|
|
|
|
country_code = get_country_code_for_msc(conn->sccp_con->msc);
|
2015-04-01 16:15:48 +00:00
|
|
|
lac = get_lac_for_msc(conn->sccp_con->msc, conn->bts);
|
|
|
|
ci = get_ci_for_msc(conn->sccp_con->msc, conn->bts);
|
2011-06-04 12:51:51 +00:00
|
|
|
|
2010-11-05 18:48:47 +00:00
|
|
|
bsc_scan_bts_msg(conn, msg);
|
2015-04-05 19:03:49 +00:00
|
|
|
|
2015-04-01 16:15:48 +00:00
|
|
|
resp = gsm0808_create_layer3(msg, network_code, country_code, lac, ci);
|
2010-11-05 18:48:47 +00:00
|
|
|
if (!resp) {
|
|
|
|
LOGP(DMSC, LOGL_DEBUG, "Failed to create layer3 message.\n");
|
2011-06-09 12:44:47 +00:00
|
|
|
sccp_connection_free(conn->sccp_con->sccp);
|
2010-11-06 19:15:17 +00:00
|
|
|
bsc_delete_connection(conn->sccp_con);
|
2010-11-05 18:48:47 +00:00
|
|
|
return BSC_API_CONN_POL_REJECT;
|
|
|
|
}
|
|
|
|
|
2010-11-06 19:15:17 +00:00
|
|
|
if (bsc_open_connection(conn->sccp_con, resp) != 0) {
|
2011-06-09 12:44:47 +00:00
|
|
|
sccp_connection_free(conn->sccp_con->sccp);
|
2010-11-06 19:15:17 +00:00
|
|
|
bsc_delete_connection(conn->sccp_con);
|
2010-11-05 18:48:47 +00:00
|
|
|
msgb_free(resp);
|
|
|
|
return BSC_API_CONN_POL_REJECT;
|
2010-11-05 10:21:18 +00:00
|
|
|
}
|
|
|
|
|
2010-11-05 18:48:47 +00:00
|
|
|
return BSC_API_CONN_POL_ACCEPT;
|
2010-09-16 09:26:35 +00:00
|
|
|
}
|
|
|
|
|
2011-06-09 15:37:04 +00:00
|
|
|
/*
|
|
|
|
* Plastic surgery... we want to give up the current connection
|
|
|
|
*/
|
|
|
|
static int move_to_msc(struct gsm_subscriber_connection *_conn,
|
|
|
|
struct msgb *msg, struct osmo_msc_data *msc)
|
|
|
|
{
|
|
|
|
struct osmo_bsc_sccp_con *old_con = _conn->sccp_con;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1. Give up the old connection.
|
|
|
|
* This happens by sending a clear request to the MSC,
|
|
|
|
* it should end with the MSC releasing the connection.
|
|
|
|
*/
|
|
|
|
old_con->conn = NULL;
|
|
|
|
bsc_clear_request(_conn, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 2. Attempt to create a new connection to the local
|
|
|
|
* MSC. If it fails the caller will need to handle this
|
|
|
|
* properly.
|
|
|
|
*/
|
|
|
|
_conn->sccp_con = NULL;
|
|
|
|
if (complete_layer3(_conn, msg, msc) != BSC_API_CONN_POL_ACCEPT) {
|
|
|
|
gsm0808_clear(_conn);
|
|
|
|
subscr_con_free(_conn);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int handle_cc_setup(struct gsm_subscriber_connection *conn,
|
|
|
|
struct msgb *msg)
|
|
|
|
{
|
|
|
|
struct gsm48_hdr *gh = msgb_l3(msg);
|
2016-03-14 15:13:24 +00:00
|
|
|
uint8_t pdisc = gsm48_hdr_pdisc(gh);
|
|
|
|
uint8_t mtype = gsm48_hdr_msg_type(gh);
|
2011-06-09 15:37:04 +00:00
|
|
|
|
|
|
|
struct osmo_msc_data *msc;
|
|
|
|
struct gsm_mncc_number called;
|
|
|
|
struct tlv_parsed tp;
|
|
|
|
unsigned payload_len;
|
|
|
|
|
|
|
|
char _dest_nr[35];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do we have a setup message here? if not return fast.
|
|
|
|
*/
|
|
|
|
if (pdisc != GSM48_PDISC_CC || mtype != GSM48_MT_CC_SETUP)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
payload_len = msgb_l3len(msg) - sizeof(*gh);
|
|
|
|
|
|
|
|
tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
|
|
|
|
if (!TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD)) {
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "Called BCD not present in setup.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&called, 0, sizeof(called));
|
|
|
|
gsm48_decode_called(&called,
|
|
|
|
TLVP_VAL(&tp, GSM48_IE_CALLED_BCD) - 1);
|
|
|
|
|
2011-09-30 14:24:27 +00:00
|
|
|
if (called.plan != 1 && called.plan != 0)
|
2011-06-09 15:37:04 +00:00
|
|
|
return 0;
|
|
|
|
|
2011-09-30 14:24:27 +00:00
|
|
|
if (called.plan == 1 && called.type == 1) {
|
2011-06-09 15:37:04 +00:00
|
|
|
_dest_nr[0] = _dest_nr[1] = '0';
|
|
|
|
memcpy(_dest_nr + 2, called.number, sizeof(called.number));
|
|
|
|
} else
|
|
|
|
memcpy(_dest_nr, called.number, sizeof(called.number));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the connection should be moved...
|
|
|
|
*/
|
|
|
|
llist_for_each_entry(msc, &conn->bts->network->bsc_data->mscs, entry) {
|
|
|
|
if (msc->type != MSC_CON_TYPE_LOCAL)
|
|
|
|
continue;
|
|
|
|
if (!msc->local_pref)
|
|
|
|
continue;
|
|
|
|
if (regexec(&msc->local_pref_reg, _dest_nr, 0, NULL, 0) != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return move_to_msc(conn, msg, msc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-04 11:18:00 +00:00
|
|
|
static void bsc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct msgb *msg)
|
2010-09-16 09:26:35 +00:00
|
|
|
{
|
2015-04-05 20:45:32 +00:00
|
|
|
int lu_cause;
|
2010-11-04 11:24:05 +00:00
|
|
|
struct msgb *resp;
|
2010-11-03 18:03:35 +00:00
|
|
|
return_when_not_connected(conn);
|
2010-11-04 11:24:05 +00:00
|
|
|
|
2011-07-11 22:05:11 +00:00
|
|
|
LOGP(DMSC, LOGL_INFO, "Tx MSC DTAP LINK_ID=0x%02x\n", link_id);
|
|
|
|
|
2011-06-09 15:37:04 +00:00
|
|
|
/*
|
|
|
|
* We might want to move this connection to a new MSC. Ask someone
|
|
|
|
* to handle it. If it was handled we will return.
|
|
|
|
*/
|
2011-06-27 19:29:03 +00:00
|
|
|
if (handle_cc_setup(conn, msg) >= 1)
|
2011-06-09 15:37:04 +00:00
|
|
|
return;
|
|
|
|
|
2015-04-05 18:53:42 +00:00
|
|
|
/* Check the filter */
|
2015-04-05 20:45:32 +00:00
|
|
|
if (bsc_filter_data(conn, msg, &lu_cause) < 0) {
|
|
|
|
bsc_maybe_lu_reject(conn,
|
|
|
|
conn->sccp_con->filter_state.con_type,
|
|
|
|
lu_cause);
|
2015-04-05 18:53:42 +00:00
|
|
|
bsc_clear_request(conn, 0);
|
|
|
|
return;
|
|
|
|
}
|
2011-06-09 15:37:04 +00:00
|
|
|
|
2015-04-05 18:53:42 +00:00
|
|
|
bsc_scan_bts_msg(conn, msg);
|
2011-06-09 15:37:04 +00:00
|
|
|
|
2010-11-04 11:24:05 +00:00
|
|
|
resp = gsm0808_create_dtap(msg, link_id);
|
2010-11-05 10:02:28 +00:00
|
|
|
queue_msg_or_return(resp);
|
2010-09-16 09:26:35 +00:00
|
|
|
}
|
|
|
|
|
2010-11-04 11:06:57 +00:00
|
|
|
static void bsc_assign_compl(struct gsm_subscriber_connection *conn, uint8_t rr_cause,
|
|
|
|
uint8_t chosen_channel, uint8_t encr_alg_id,
|
|
|
|
uint8_t speech_model)
|
2010-09-16 09:26:35 +00:00
|
|
|
{
|
2010-11-04 11:09:45 +00:00
|
|
|
struct msgb *resp;
|
2010-11-03 18:03:35 +00:00
|
|
|
return_when_not_connected(conn);
|
2010-11-04 11:09:45 +00:00
|
|
|
|
2011-07-11 22:05:11 +00:00
|
|
|
LOGP(DMSC, LOGL_INFO, "Tx MSC ASSIGN COMPL\n");
|
|
|
|
|
2010-11-04 11:09:45 +00:00
|
|
|
resp = gsm0808_create_assignment_completed(rr_cause, chosen_channel,
|
|
|
|
encr_alg_id, speech_model);
|
2010-11-05 10:02:28 +00:00
|
|
|
queue_msg_or_return(resp);
|
2010-09-16 09:26:35 +00:00
|
|
|
}
|
|
|
|
|
2010-11-05 09:37:17 +00:00
|
|
|
static void bsc_assign_fail(struct gsm_subscriber_connection *conn,
|
|
|
|
uint8_t cause, uint8_t *rr_cause)
|
2010-09-16 09:26:35 +00:00
|
|
|
{
|
2010-11-05 09:59:45 +00:00
|
|
|
struct msgb *resp;
|
2010-11-03 18:03:35 +00:00
|
|
|
return_when_not_connected(conn);
|
2010-11-05 09:59:45 +00:00
|
|
|
|
2011-07-11 22:05:11 +00:00
|
|
|
LOGP(DMSC, LOGL_INFO, "Tx MSC ASSIGN FAIL\n");
|
|
|
|
|
2010-11-05 09:59:45 +00:00
|
|
|
resp = gsm0808_create_assignment_failure(cause, rr_cause);
|
2010-11-05 10:02:28 +00:00
|
|
|
queue_msg_or_return(resp);
|
2010-09-16 09:26:35 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 18:01:58 +00:00
|
|
|
static int bsc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause)
|
2010-09-16 09:26:35 +00:00
|
|
|
{
|
2011-08-06 12:52:56 +00:00
|
|
|
struct osmo_bsc_sccp_con *sccp;
|
2010-11-04 11:47:06 +00:00
|
|
|
struct msgb *resp;
|
2010-11-03 18:03:35 +00:00
|
|
|
return_when_not_connected_val(conn, 1);
|
2010-11-04 11:47:06 +00:00
|
|
|
|
2011-07-11 22:05:11 +00:00
|
|
|
LOGP(DMSC, LOGL_INFO, "Tx MSC CLEAR REQUEST\n");
|
|
|
|
|
2011-08-06 12:52:56 +00:00
|
|
|
/*
|
|
|
|
* Remove the connection from BSC<->SCCP part, the SCCP part
|
|
|
|
* will either be cleared by channel release or MSC disconnect
|
|
|
|
*/
|
|
|
|
sccp = conn->sccp_con;
|
|
|
|
sccp->conn = NULL;
|
|
|
|
conn->sccp_con = NULL;
|
|
|
|
|
2010-11-04 11:47:06 +00:00
|
|
|
resp = gsm0808_create_clear_rqst(GSM0808_CAUSE_RADIO_INTERFACE_FAILURE);
|
|
|
|
if (!resp) {
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "Failed to allocate response.\n");
|
2011-08-06 12:52:56 +00:00
|
|
|
return 1;
|
2010-11-04 11:47:06 +00:00
|
|
|
}
|
|
|
|
|
2011-08-06 12:52:56 +00:00
|
|
|
bsc_queue_for_msc(sccp, resp);
|
|
|
|
return 1;
|
2010-09-16 09:26:35 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 09:28:35 +00:00
|
|
|
static void bsc_cm_update(struct gsm_subscriber_connection *conn,
|
|
|
|
const uint8_t *cm2, uint8_t cm2_len,
|
|
|
|
const uint8_t *cm3, uint8_t cm3_len)
|
|
|
|
{
|
|
|
|
struct msgb *resp;
|
2012-03-16 10:49:46 +00:00
|
|
|
return_when_not_connected(conn);
|
2012-01-23 09:28:35 +00:00
|
|
|
|
|
|
|
resp = gsm0808_create_classmark_update(cm2, cm2_len, cm3, cm3_len);
|
|
|
|
|
|
|
|
queue_msg_or_return(resp);
|
|
|
|
}
|
|
|
|
|
2011-08-06 05:00:52 +00:00
|
|
|
static void bsc_mr_config(struct gsm_subscriber_connection *conn,
|
2015-09-24 14:26:01 +00:00
|
|
|
struct gsm_lchan *lchan, int full_rate)
|
2011-08-06 05:00:52 +00:00
|
|
|
{
|
|
|
|
struct osmo_msc_data *msc;
|
2015-09-24 14:26:01 +00:00
|
|
|
struct gsm48_multi_rate_conf *ms_conf, *bts_conf;
|
2011-08-06 05:00:52 +00:00
|
|
|
|
|
|
|
if (!conn->sccp_con) {
|
|
|
|
LOGP(DMSC, LOGL_ERROR,
|
|
|
|
"No msc data available on conn %p. Audio will be broken.\n",
|
|
|
|
conn);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
msc = conn->sccp_con->msc;
|
|
|
|
|
2015-09-24 14:26:01 +00:00
|
|
|
/* initialize the data structure */
|
|
|
|
lchan->mr_ms_lv[0] = sizeof(*ms_conf);
|
|
|
|
lchan->mr_bts_lv[0] = sizeof(*bts_conf);
|
|
|
|
ms_conf = (struct gsm48_multi_rate_conf *) &lchan->mr_ms_lv[1];
|
|
|
|
bts_conf = (struct gsm48_multi_rate_conf *) &lchan->mr_bts_lv[1];
|
|
|
|
memset(ms_conf, 0, sizeof(*ms_conf));
|
|
|
|
memset(bts_conf, 0, sizeof(*bts_conf));
|
|
|
|
|
|
|
|
bts_conf->ver = ms_conf->ver = 1;
|
|
|
|
bts_conf->icmi = ms_conf->icmi = 1;
|
2011-08-06 05:00:52 +00:00
|
|
|
|
|
|
|
/* maybe gcc see's it is copy of _one_ byte */
|
2015-09-24 14:26:01 +00:00
|
|
|
bts_conf->m4_75 = ms_conf->m4_75 = msc->amr_conf.m4_75;
|
|
|
|
bts_conf->m5_15 = ms_conf->m5_15 = msc->amr_conf.m5_15;
|
|
|
|
bts_conf->m5_90 = ms_conf->m5_90 = msc->amr_conf.m5_90;
|
|
|
|
bts_conf->m6_70 = ms_conf->m6_70 = msc->amr_conf.m6_70;
|
|
|
|
bts_conf->m7_40 = ms_conf->m7_40 = msc->amr_conf.m7_40;
|
|
|
|
bts_conf->m7_95 = ms_conf->m7_95 = msc->amr_conf.m7_95;
|
|
|
|
if (full_rate) {
|
|
|
|
bts_conf->m10_2 = ms_conf->m10_2 = msc->amr_conf.m10_2;
|
|
|
|
bts_conf->m12_2 = ms_conf->m12_2 = msc->amr_conf.m12_2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now copy this into the bts structure */
|
|
|
|
memcpy(lchan->mr_bts_lv, lchan->mr_ms_lv, sizeof(lchan->mr_ms_lv));
|
2011-08-06 05:00:52 +00:00
|
|
|
}
|
|
|
|
|
2010-09-16 09:26:35 +00:00
|
|
|
static struct bsc_api bsc_handler = {
|
|
|
|
.sapi_n_reject = bsc_sapi_n_reject,
|
|
|
|
.cipher_mode_compl = bsc_cipher_mode_compl,
|
|
|
|
.compl_l3 = bsc_compl_l3,
|
|
|
|
.dtap = bsc_dtap,
|
|
|
|
.assign_compl = bsc_assign_compl,
|
|
|
|
.assign_fail = bsc_assign_fail,
|
|
|
|
.clear_request = bsc_clear_request,
|
2012-01-23 09:28:35 +00:00
|
|
|
.classmark_chg = bsc_cm_update,
|
2011-08-06 05:00:52 +00:00
|
|
|
.mr_config = bsc_mr_config,
|
2010-09-16 09:26:35 +00:00
|
|
|
};
|
|
|
|
|
2010-07-05 08:02:04 +00:00
|
|
|
struct bsc_api *osmo_bsc_api()
|
|
|
|
{
|
2010-09-16 09:26:35 +00:00
|
|
|
return &bsc_handler;
|
2010-07-05 08:02:04 +00:00
|
|
|
}
|