2009-06-12 05:08:13 +00:00
|
|
|
/* The concept of a subscriber for the MSC, roughly HLR/VLR functionality */
|
2008-12-23 20:25:15 +00:00
|
|
|
|
|
|
|
/* (C) 2008 by Harald Welte <laforge@gnumonks.org>
|
2013-06-30 13:30:47 +00:00
|
|
|
* (C) 2009,2013 by Holger Hans Peter Freyther <zecke@selfish.org>
|
2008-12-25 23:28:35 +00:00
|
|
|
*
|
2008-12-23 20:25:15 +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
|
2008-12-23 20:25:15 +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.
|
2008-12-23 20:25:15 +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/>.
|
2008-12-23 20:25:15 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-12-27 21:34:06 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2009-04-18 11:48:55 +00:00
|
|
|
#include <assert.h>
|
2012-12-26 23:27:16 +00:00
|
|
|
#include <time.h>
|
2016-06-30 08:25:49 +00:00
|
|
|
#include <stdbool.h>
|
2008-12-23 20:25:15 +00:00
|
|
|
|
2011-03-22 15:47:59 +00:00
|
|
|
#include <osmocom/core/talloc.h>
|
2010-12-01 20:07:29 +00:00
|
|
|
|
2010-12-29 10:07:22 +00:00
|
|
|
#include <osmocom/vty/vty.h>
|
|
|
|
|
2008-12-25 23:28:35 +00:00
|
|
|
#include <openbsc/gsm_subscriber.h>
|
2010-12-01 21:38:03 +00:00
|
|
|
#include <openbsc/gsm_04_08.h>
|
2009-06-02 02:54:48 +00:00
|
|
|
#include <openbsc/debug.h>
|
2010-12-01 20:07:29 +00:00
|
|
|
#include <openbsc/paging.h>
|
2009-07-29 21:14:15 +00:00
|
|
|
#include <openbsc/signal.h>
|
2008-12-27 21:34:06 +00:00
|
|
|
#include <openbsc/db.h>
|
2013-06-30 13:30:47 +00:00
|
|
|
#include <openbsc/chan_alloc.h>
|
2016-06-19 16:06:02 +00:00
|
|
|
#include <openbsc/vlr.h>
|
2016-05-20 19:59:55 +00:00
|
|
|
#include <openbsc/iu.h>
|
|
|
|
#include <openbsc/osmo_msc.h>
|
|
|
|
#include <openbsc/msc_ifaces.h>
|
2017-06-12 10:52:35 +00:00
|
|
|
#include <openbsc/a_iface.h>
|
2008-12-23 20:25:15 +00:00
|
|
|
|
2010-12-01 20:07:29 +00:00
|
|
|
void *tall_sub_req_ctx;
|
|
|
|
|
2010-12-01 21:38:03 +00:00
|
|
|
int gsm48_secure_channel(struct gsm_subscriber_connection *conn, int key_seq,
|
|
|
|
gsm_cbfn *cb, void *cb_data);
|
|
|
|
|
2016-05-20 19:59:55 +00:00
|
|
|
/* A connection is established and the paging callbacks may run now. */
|
2016-06-19 16:06:02 +00:00
|
|
|
int subscr_paging_dispatch(unsigned int hooknum, unsigned int event,
|
|
|
|
struct msgb *msg, void *data, void *param)
|
2010-12-01 20:07:29 +00:00
|
|
|
{
|
2015-04-06 10:03:45 +00:00
|
|
|
struct subscr_request *request, *tmp;
|
2010-12-01 22:04:03 +00:00
|
|
|
struct gsm_subscriber_connection *conn = data;
|
2016-06-19 16:06:02 +00:00
|
|
|
struct vlr_subscr *vsub = param;
|
2010-12-01 22:04:03 +00:00
|
|
|
struct paging_signal_data sig_data;
|
2010-12-01 20:07:29 +00:00
|
|
|
|
2016-05-20 19:59:55 +00:00
|
|
|
OSMO_ASSERT(vsub);
|
|
|
|
OSMO_ASSERT(hooknum == GSM_HOOK_RR_PAGING);
|
|
|
|
OSMO_ASSERT(!(conn && (conn->vsub != vsub)));
|
|
|
|
OSMO_ASSERT(!((event == GSM_PAGING_SUCCEEDED) && !conn));
|
|
|
|
|
|
|
|
LOGP(DPAG, LOGL_DEBUG, "Paging %s for %s (event=%d)\n",
|
|
|
|
event == GSM_PAGING_SUCCEEDED ? "success" : "failure",
|
|
|
|
vlr_subscr_name(vsub), event);
|
2010-12-01 20:07:29 +00:00
|
|
|
|
2016-05-20 19:59:55 +00:00
|
|
|
if (!vsub->cs.is_paging) {
|
|
|
|
LOGP(DPAG, LOGL_ERROR,
|
|
|
|
"Paging Response received for subscriber"
|
|
|
|
" that is not paging.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
add struct bsc_subscr, separating libbsc from gsm_subscriber
In a future commit, gsm_subscriber will be replaced by vlr_subscr, and it will
not make sense to use vlr_subscr in libbsc. Thus we need a dedicated BSC
subscriber: struct bsc_subscr.
Add rf_policy arg to bsc_grace_paging_request() because the bsc_subscr will no
longer have a backpointer to gsm_network (used to be via subscr->group).
Create a separate logging filter for the new BSC subscriber. The implementation
of adjusting the filter context is added in libbsc to not introduce
bsc_subscr_get/_put() dependencies to libcommon.
During Paging Response, fetch a bsc_subscr from the mobile identity, like we do
for the gsm_subscriber. It looks like a duplication now, but will make sense
for the VLR as well as for future MSC split patches.
Naming: it was requested to not name the new struct bsc_sub, because 'sub' is
too ambiguous. At the same time it would be fine to have 'bsc_sub_' as function
prefix. Instead of struct bsc_subscriber and bsc_sub_ prefix, I decided to
match both up as struct bsc_subscr and bsc_subscr_ function prefix. It's fast
to type, relatively short, unambiguous, and the naming is consistent.
Add bsc_subscr unit test.
Related: OS#1592, OS#1594
Change-Id: Ia61cc00e8bb186b976939a4fc8f7cf9ce6aa3d8e
2017-02-18 21:20:46 +00:00
|
|
|
|
2016-05-20 19:59:55 +00:00
|
|
|
if (event == GSM_PAGING_SUCCEEDED)
|
|
|
|
msc_stop_paging(vsub);
|
2015-08-03 09:18:23 +00:00
|
|
|
|
2015-04-06 10:03:45 +00:00
|
|
|
/* Inform parts of the system we don't know */
|
2016-05-20 19:59:55 +00:00
|
|
|
sig_data.vsub = vsub;
|
|
|
|
sig_data.conn = conn;
|
2010-12-23 17:19:17 +00:00
|
|
|
sig_data.paging_result = event;
|
2016-05-20 19:59:55 +00:00
|
|
|
osmo_signal_dispatch(SS_PAGING,
|
|
|
|
event == GSM_PAGING_SUCCEEDED ?
|
|
|
|
S_PAGING_SUCCEEDED : S_PAGING_EXPIRED,
|
|
|
|
&sig_data);
|
2010-12-01 22:04:03 +00:00
|
|
|
|
2016-06-19 16:06:02 +00:00
|
|
|
llist_for_each_entry_safe(request, tmp, &vsub->cs.requests, entry) {
|
2015-04-06 10:03:45 +00:00
|
|
|
llist_del(&request->entry);
|
2016-05-20 19:59:55 +00:00
|
|
|
if (request->cbfn) {
|
|
|
|
LOGP(DPAG, LOGL_DEBUG, "Calling paging cbfn.\n");
|
|
|
|
request->cbfn(hooknum, event, msg, data, request->param);
|
|
|
|
} else
|
|
|
|
LOGP(DPAG, LOGL_DEBUG, "Paging without action.\n");
|
2015-04-06 10:03:45 +00:00
|
|
|
talloc_free(request);
|
2010-12-28 16:47:43 +00:00
|
|
|
}
|
2010-12-28 16:27:05 +00:00
|
|
|
|
2015-04-06 10:03:45 +00:00
|
|
|
/* balanced with the moment we start paging */
|
2016-06-19 16:06:02 +00:00
|
|
|
vsub->cs.is_paging = false;
|
|
|
|
vlr_subscr_put(vsub);
|
2010-12-01 20:07:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-20 19:59:55 +00:00
|
|
|
int msc_paging_request(struct vlr_subscr *vsub)
|
|
|
|
{
|
|
|
|
/* The subscriber was last seen in subscr->lac. Find out which
|
|
|
|
* BSCs/RNCs are responsible and send them a paging request via open
|
|
|
|
* SCCP connections (if any). */
|
|
|
|
/* TODO Implementing only RNC paging, since this is code on the iu branch.
|
|
|
|
* Need to add BSC paging at some point. */
|
|
|
|
switch (vsub->cs.attached_via_ran) {
|
|
|
|
case RAN_GERAN_A:
|
2017-06-12 10:52:35 +00:00
|
|
|
return a_iface_tx_paging(vsub->imsi, vsub->tmsi, vsub->lac);
|
2016-05-20 19:59:55 +00:00
|
|
|
case RAN_UTRAN_IU:
|
|
|
|
return iu_page_cs(vsub->imsi,
|
|
|
|
vsub->tmsi == GSM_RESERVED_TMSI?
|
|
|
|
NULL : &vsub->tmsi,
|
|
|
|
vsub->lac);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGP(DPAG, LOGL_ERROR, "%s: Cannot page, subscriber not attached\n",
|
|
|
|
vlr_subscr_name(vsub));
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Start a paging request for vsub, call cbfn(param) when done.
|
|
|
|
* \param vsub subscriber to page.
|
|
|
|
* \param cbfn function to call when the conn is established.
|
|
|
|
* \param param caller defined param to pass to cbfn().
|
|
|
|
* \param label human readable label of the request kind used for logging.
|
|
|
|
*/
|
|
|
|
struct subscr_request *subscr_request_conn(struct vlr_subscr *vsub,
|
|
|
|
gsm_cbfn *cbfn, void *param,
|
|
|
|
const char *label)
|
2010-12-01 20:07:29 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct subscr_request *request;
|
|
|
|
|
2015-04-06 10:03:45 +00:00
|
|
|
/* Start paging.. we know it is async so we can do it before */
|
2016-06-19 16:06:02 +00:00
|
|
|
if (!vsub->cs.is_paging) {
|
2016-05-20 19:59:55 +00:00
|
|
|
LOGP(DMM, LOGL_DEBUG, "Subscriber %s not paged yet, start paging.\n",
|
2016-06-19 16:06:02 +00:00
|
|
|
vlr_subscr_name(vsub));
|
2016-05-20 19:59:55 +00:00
|
|
|
rc = msc_paging_request(vsub);
|
2015-04-06 10:03:45 +00:00
|
|
|
if (rc <= 0) {
|
|
|
|
LOGP(DMM, LOGL_ERROR, "Subscriber %s paging failed: %d\n",
|
2016-06-19 16:06:02 +00:00
|
|
|
vlr_subscr_name(vsub), rc);
|
2015-04-06 10:03:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* reduced on the first paging callback */
|
2016-06-19 16:06:02 +00:00
|
|
|
vlr_subscr_get(vsub);
|
|
|
|
vsub->cs.is_paging = true;
|
2016-05-20 19:59:55 +00:00
|
|
|
} else {
|
|
|
|
LOGP(DMM, LOGL_DEBUG, "Subscriber %s already paged.\n",
|
|
|
|
vlr_subscr_name(vsub));
|
2010-12-01 20:07:29 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 10:03:45 +00:00
|
|
|
/* TODO: Stop paging in case of memory allocation failure */
|
2016-06-19 16:06:02 +00:00
|
|
|
request = talloc_zero(vsub, struct subscr_request);
|
2015-04-06 10:03:45 +00:00
|
|
|
if (!request)
|
|
|
|
return NULL;
|
|
|
|
|
2010-12-01 20:07:29 +00:00
|
|
|
request->cbfn = cbfn;
|
|
|
|
request->param = param;
|
2016-06-19 16:06:02 +00:00
|
|
|
llist_add_tail(&request->entry, &vsub->cs.requests);
|
2015-04-06 10:03:45 +00:00
|
|
|
return request;
|
2010-12-01 20:07:29 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 10:03:45 +00:00
|
|
|
void subscr_remove_request(struct subscr_request *request)
|
2010-12-01 20:07:29 +00:00
|
|
|
{
|
2015-04-06 10:03:45 +00:00
|
|
|
llist_del(&request->entry);
|
|
|
|
talloc_free(request);
|
2010-12-01 20:07:29 +00:00
|
|
|
}
|
|
|
|
|
2016-06-19 16:06:02 +00:00
|
|
|
struct gsm_subscriber_connection *connection_for_subscr(struct vlr_subscr *vsub)
|
2016-05-10 11:56:43 +00:00
|
|
|
{
|
2016-06-19 16:06:02 +00:00
|
|
|
struct gsm_network *net = vsub->vlr->user_ctx;
|
2016-05-10 11:56:43 +00:00
|
|
|
struct gsm_subscriber_connection *conn;
|
|
|
|
|
|
|
|
llist_for_each_entry(conn, &net->subscr_conns, entry) {
|
2016-06-19 16:06:02 +00:00
|
|
|
if (conn->vsub == vsub)
|
2016-05-10 11:56:43 +00:00
|
|
|
return conn;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|