2016-05-10 10:50:31 +00:00
|
|
|
/* Code used by both libbsc and libmsc (common_cs means "BSC or MSC").
|
|
|
|
*
|
|
|
|
* (C) 2016 by sysmocom s.m.f.c. <info@sysmocom.de>
|
2016-05-13 22:46:29 +00:00
|
|
|
* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
|
|
|
|
* (C) 2014 by Holger Hans Peter Freyther
|
2016-05-10 10:50:31 +00:00
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
*/
|
2016-05-13 22:46:29 +00:00
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include <osmocom/gsm/gsm0480.h>
|
|
|
|
|
2017-09-04 13:04:35 +00:00
|
|
|
#include <osmocom/msc/common_cs.h>
|
|
|
|
#include <osmocom/msc/gsm_data.h>
|
|
|
|
#include <osmocom/msc/gsm_subscriber.h>
|
|
|
|
#include <osmocom/msc/gsm_data.h>
|
|
|
|
#include <osmocom/msc/gsm_04_11.h>
|
2017-09-15 09:22:30 +00:00
|
|
|
#include <osmocom/msc/gsm_04_08.h>
|
2016-05-13 22:46:29 +00:00
|
|
|
|
|
|
|
/* Warning: if bsc_network_init() is not called, some of the members of
|
|
|
|
* gsm_network are not initialized properly and must not be used! (In
|
|
|
|
* particular the llist heads and stats counters.)
|
|
|
|
* The long term aim should be to have entirely separate structs for libbsc and
|
|
|
|
* libmsc with some common general items.
|
|
|
|
*/
|
2018-02-27 11:59:45 +00:00
|
|
|
struct gsm_network *gsm_network_init(void *ctx, mncc_recv_cb_t mncc_recv)
|
2016-05-13 22:46:29 +00:00
|
|
|
{
|
|
|
|
struct gsm_network *net;
|
|
|
|
|
|
|
|
net = talloc_zero(ctx, struct gsm_network);
|
|
|
|
if (!net)
|
|
|
|
return NULL;
|
|
|
|
|
2018-02-22 03:04:54 +00:00
|
|
|
net->plmn = (struct osmo_plmn_id){ .mcc=1, .mnc=1 };
|
|
|
|
|
2017-12-23 18:30:32 +00:00
|
|
|
/* Permit a compile-time default of A5/3 and A5/1 */
|
|
|
|
net->a5_encryption_mask = (1 << 3) | (1 << 1);
|
2016-05-13 22:46:29 +00:00
|
|
|
|
mscsplit: various preparations to separate MSC from BSC
Disable large parts of the code that depend on BSC presence. The code sections
disabled by #if BEFORE_MSCSPLIT shall be modified or dropped in the course of
adding the A-interface.
Don't set msg->lchan nor msg->dst.
Don't use lchan in libmsc.
Decouple lac from bts.
Prepare entry/exit point for MSC -> BSC and MSC -> RNC communication:
Add msc_ifaces.[hc], a_iface.c, with a general msc_tx_dtap() to redirect to
different interfaces depending on the actual subscriber connection.
While iu_tx() is going to be functional fairly soon, the a_tx() is going to be
just a dummy for some time (see comment).
Add Iu specific fields in gsm_subscriber_connection: the UE connection pointer
and an indicator for the Integrity Protection status on Iu (to be fully
implemented in later commits).
Add lac member to gsm_subscriber_connection, to allow decoupling from
bts->location_area_code. The conn->lac will actually be set in iu.c in an
upcoming commit ("add iucs.[hc]").
move to libcommon-cs: gsm48_extract_mi(), gsm48_paging_extract_mi().
libmsc: duplicate gsm0808 / gsm48 functions (towards BSC).
In osmo-nitb, libmsc would directly call the functions on the BSC level, not
always via the bsc_api. When separating libmsc from libbsc, some functions are
missing from the linkage.
Hence duplicate these functions to libmsc, add an msc_ prefix for clarity, also
add a _tx to gsm0808_cipher_mode():
* add msc_gsm0808_tx_cipher_mode() (dummy/stub)
* add msc_gsm48_tx_mm_serv_ack()
* add msc_gsm48_tx_mm_serv_rej()
Call these from libmsc instead of
* gsm0808_cipher_mode()
* gsm48_tx_mm_serv_ack()
* gsm48_tx_mm_serv_rej()
Also add a comment related to msc_gsm0808_tx_cipher_mode() in two places.
Remove internal RTP streaming code; OsmoNITB supported that, but for OsmoMSC,
this will be done with an external MGCP gateway.
Remove LCHAN_MODIFY from internal MNCC state machine.
Temporarily disable all paging to be able to link libmsc without libbsc.
Skip the paging part of channel_test because the paging is now disabled.
Employ fake paging shims in order for msc_vlr_tests to still work.
msc_compl_l3(): publish in .h, tweak return value. Use new libmsc enum values
for return val, to avoid dependency on libbsc headers. Make callable from
other scopes: publish in osmo_msc.h and remove 'static' in osmo_msc.c
add gsm_encr to subscr_conn
move subscr_request to gsm_subscriber.h
subscr_request_channel() -> subscr_request_conn()
move to libmsc: osmo_stats_vty_add_cmds()
gsm_04_08: remove apply_codec_restrictions()
gsm0408_test: use NULL for root ctx
move to libbsc: gsm_bts_neighbor()
move to libbsc: lchan_next_meas_rep()
move vty config for t3212 to network level (periodic lu)
remove unneccessary linking from some tests
remove handle_abisip_signal()
abis_rsl.c: don't use libvlr from libbsc
gsm_subscriber_connection: put the LAC here, so that it is available without
accessing conn->bts. In bsc_api.c, place this lac in conn for the sake of
transition: Iu and A will use this new field to pass the LAC around, but in a
completely separate OsmoBSC this is not actually needed. It can be removed
again from osmo-bsc.git when the time has come.
Siemens MRPCI: completely drop sending the MRPCI messages for now, they shall
be added in osmo-bsc once the A-Interface code has settled. See OS#2389.
Related: OS#1845 OS#2257 OS#2389
Change-Id: Id3705236350d5f69e447046b0a764bbabc3d493c
2017-05-08 13:12:20 +00:00
|
|
|
/* Use 30 min periodic update interval as sane default */
|
|
|
|
net->t3212 = 5;
|
|
|
|
|
fix paging: add timeout to discard unsuccessful paging
Currently, if there is no reply from the BSS / RNC, a subscriber will remain as
"already paged" forever, and is never going to be paged again. Even on IMSI
Detach, the pending request will keep a ref count on the vlr_subscr.
Add a paging timeout, as gsm_network->paging_timeout and in the VTY on the
'msc' node as 'paging timeout (default|<1-65535>'. (There is a 'network' /
'T3113' in OsmoBSC, but to not confuse the two, give this a different name.)
Add test_ms_timeout_paging() test to verify the timeout works.
I hit this while testing Paging across multiple hNodeB, when a UE lost
connection to the hNodeB. I noticed that no matter how long I wait, no Paging
is sent out anymore, and found this embarrassing issue. Good grief...
The choice of 10 seconds is taken from https://osmocom.org/issues/2756
Change-Id: I2db6f1e2ad341cf9c2cc7a21ec2fca0bae5b2db5
2017-12-15 02:02:27 +00:00
|
|
|
net->paging_response_timer = MSC_PAGING_RESPONSE_TIMER_DEFAULT;
|
|
|
|
|
2016-05-13 22:46:29 +00:00
|
|
|
INIT_LLIST_HEAD(&net->trans_list);
|
|
|
|
INIT_LLIST_HEAD(&net->upqueue);
|
|
|
|
INIT_LLIST_HEAD(&net->subscr_conns);
|
|
|
|
|
|
|
|
/* init statistics */
|
|
|
|
net->msc_ctrs = rate_ctr_group_alloc(net, &msc_ctrg_desc, 0);
|
2017-07-11 22:25:51 +00:00
|
|
|
if (!net->msc_ctrs) {
|
|
|
|
talloc_free(net);
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-05-13 22:46:29 +00:00
|
|
|
net->active_calls = osmo_counter_alloc("msc.active_calls");
|
|
|
|
|
|
|
|
net->mncc_recv = mncc_recv;
|
|
|
|
|
2017-04-09 10:32:51 +00:00
|
|
|
INIT_LLIST_HEAD(&net->a.bscs);
|
|
|
|
|
2016-05-13 22:46:29 +00:00
|
|
|
return net;
|
|
|
|
}
|
2016-05-10 12:58:51 +00:00
|
|
|
|
|
|
|
struct msgb *gsm48_create_mm_serv_rej(enum gsm48_reject_value value)
|
|
|
|
{
|
|
|
|
struct msgb *msg;
|
|
|
|
struct gsm48_hdr *gh;
|
|
|
|
|
|
|
|
msg = gsm48_msgb_alloc_name("GSM 04.08 SERV REJ");
|
|
|
|
if (!msg)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
|
|
|
|
gh->proto_discr = GSM48_PDISC_MM;
|
|
|
|
gh->msg_type = GSM48_MT_MM_CM_SERV_REJ;
|
|
|
|
gh->data[0] = value;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct msgb *gsm48_create_loc_upd_rej(uint8_t cause)
|
|
|
|
{
|
|
|
|
struct gsm48_hdr *gh;
|
|
|
|
struct msgb *msg;
|
|
|
|
|
|
|
|
msg = gsm48_msgb_alloc_name("GSM 04.08 LOC UPD REJ");
|
|
|
|
if (!msg)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
|
|
|
|
gh->proto_discr = GSM48_PDISC_MM;
|
|
|
|
gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT;
|
|
|
|
gh->data[0] = cause;
|
|
|
|
return msg;
|
|
|
|
}
|
2016-05-10 11:27:32 +00:00
|
|
|
|
mscsplit: various preparations to separate MSC from BSC
Disable large parts of the code that depend on BSC presence. The code sections
disabled by #if BEFORE_MSCSPLIT shall be modified or dropped in the course of
adding the A-interface.
Don't set msg->lchan nor msg->dst.
Don't use lchan in libmsc.
Decouple lac from bts.
Prepare entry/exit point for MSC -> BSC and MSC -> RNC communication:
Add msc_ifaces.[hc], a_iface.c, with a general msc_tx_dtap() to redirect to
different interfaces depending on the actual subscriber connection.
While iu_tx() is going to be functional fairly soon, the a_tx() is going to be
just a dummy for some time (see comment).
Add Iu specific fields in gsm_subscriber_connection: the UE connection pointer
and an indicator for the Integrity Protection status on Iu (to be fully
implemented in later commits).
Add lac member to gsm_subscriber_connection, to allow decoupling from
bts->location_area_code. The conn->lac will actually be set in iu.c in an
upcoming commit ("add iucs.[hc]").
move to libcommon-cs: gsm48_extract_mi(), gsm48_paging_extract_mi().
libmsc: duplicate gsm0808 / gsm48 functions (towards BSC).
In osmo-nitb, libmsc would directly call the functions on the BSC level, not
always via the bsc_api. When separating libmsc from libbsc, some functions are
missing from the linkage.
Hence duplicate these functions to libmsc, add an msc_ prefix for clarity, also
add a _tx to gsm0808_cipher_mode():
* add msc_gsm0808_tx_cipher_mode() (dummy/stub)
* add msc_gsm48_tx_mm_serv_ack()
* add msc_gsm48_tx_mm_serv_rej()
Call these from libmsc instead of
* gsm0808_cipher_mode()
* gsm48_tx_mm_serv_ack()
* gsm48_tx_mm_serv_rej()
Also add a comment related to msc_gsm0808_tx_cipher_mode() in two places.
Remove internal RTP streaming code; OsmoNITB supported that, but for OsmoMSC,
this will be done with an external MGCP gateway.
Remove LCHAN_MODIFY from internal MNCC state machine.
Temporarily disable all paging to be able to link libmsc without libbsc.
Skip the paging part of channel_test because the paging is now disabled.
Employ fake paging shims in order for msc_vlr_tests to still work.
msc_compl_l3(): publish in .h, tweak return value. Use new libmsc enum values
for return val, to avoid dependency on libbsc headers. Make callable from
other scopes: publish in osmo_msc.h and remove 'static' in osmo_msc.c
add gsm_encr to subscr_conn
move subscr_request to gsm_subscriber.h
subscr_request_channel() -> subscr_request_conn()
move to libmsc: osmo_stats_vty_add_cmds()
gsm_04_08: remove apply_codec_restrictions()
gsm0408_test: use NULL for root ctx
move to libbsc: gsm_bts_neighbor()
move to libbsc: lchan_next_meas_rep()
move vty config for t3212 to network level (periodic lu)
remove unneccessary linking from some tests
remove handle_abisip_signal()
abis_rsl.c: don't use libvlr from libbsc
gsm_subscriber_connection: put the LAC here, so that it is available without
accessing conn->bts. In bsc_api.c, place this lac in conn for the sake of
transition: Iu and A will use this new field to pass the LAC around, but in a
completely separate OsmoBSC this is not actually needed. It can be removed
again from osmo-bsc.git when the time has come.
Siemens MRPCI: completely drop sending the MRPCI messages for now, they shall
be added in osmo-bsc once the A-Interface code has settled. See OS#2389.
Related: OS#1845 OS#2257 OS#2389
Change-Id: Id3705236350d5f69e447046b0a764bbabc3d493c
2017-05-08 13:12:20 +00:00
|
|
|
int gsm48_extract_mi(uint8_t *classmark2_lv, int length, char *mi_string, uint8_t *mi_type)
|
|
|
|
{
|
|
|
|
/* Check the size for the classmark */
|
|
|
|
if (length < 1 + *classmark2_lv)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
uint8_t *mi_lv = classmark2_lv + *classmark2_lv + 1;
|
|
|
|
if (length < 2 + *classmark2_lv + mi_lv[0])
|
|
|
|
return -2;
|
|
|
|
|
|
|
|
*mi_type = mi_lv[1] & GSM_MI_TYPE_MASK;
|
|
|
|
return gsm48_mi_to_string(mi_string, GSM48_MI_SIZE, mi_lv+1, *mi_lv);
|
|
|
|
}
|
|
|
|
|
|
|
|
int gsm48_paging_extract_mi(struct gsm48_pag_resp *resp, int length,
|
|
|
|
char *mi_string, uint8_t *mi_type)
|
|
|
|
{
|
|
|
|
static const uint32_t classmark_offset =
|
|
|
|
offsetof(struct gsm48_pag_resp, classmark2);
|
|
|
|
uint8_t *classmark2_lv = (uint8_t *) &resp->classmark2;
|
|
|
|
return gsm48_extract_mi(classmark2_lv, length - classmark_offset,
|
|
|
|
mi_string, mi_type);
|
|
|
|
}
|
|
|
|
|
2016-05-10 11:27:32 +00:00
|
|
|
uint8_t sms_next_rp_msg_ref(uint8_t *next_rp_ref)
|
|
|
|
{
|
|
|
|
const uint8_t rp_msg_ref = *next_rp_ref;
|
|
|
|
/*
|
|
|
|
* This should wrap as the valid range is 0 to 255. We only
|
|
|
|
* transfer one SMS at a time so we don't need to check if
|
|
|
|
* the id has been already assigned.
|
|
|
|
*/
|
|
|
|
*next_rp_ref += 1;
|
|
|
|
|
|
|
|
return rp_msg_ref;
|
|
|
|
}
|