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>
|
2008-12-23 20:25:15 +00:00
|
|
|
|
2010-12-01 20:07:29 +00:00
|
|
|
void *tall_sub_req_ctx;
|
|
|
|
|
2012-12-25 17:58:34 +00:00
|
|
|
extern struct llist_head *subscr_bsc_active_subscribers(void);
|
2008-12-27 21:34:06 +00:00
|
|
|
|
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);
|
|
|
|
|
2010-12-01 20:07:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Struct for pending channel requests. This is managed in the
|
|
|
|
* llist_head requests of each subscriber. The reference counting
|
|
|
|
* should work in such a way that a subscriber with a pending request
|
|
|
|
* remains in memory.
|
|
|
|
*/
|
|
|
|
struct subscr_request {
|
|
|
|
struct llist_head entry;
|
|
|
|
|
|
|
|
/* the callback data */
|
|
|
|
gsm_cbfn *cbfn;
|
|
|
|
void *param;
|
|
|
|
};
|
|
|
|
|
2014-12-03 08:28:24 +00:00
|
|
|
static struct gsm_subscriber *get_subscriber(struct gsm_subscriber_group *sgrp,
|
2013-10-04 06:35:11 +00:00
|
|
|
int type, const char *ident)
|
|
|
|
{
|
|
|
|
struct gsm_subscriber *subscr = db_get_subscriber(type, ident);
|
|
|
|
if (subscr)
|
2014-12-03 08:28:24 +00:00
|
|
|
subscr->group = sgrp;
|
2013-10-04 06:35:11 +00:00
|
|
|
return subscr;
|
|
|
|
}
|
|
|
|
|
2010-12-01 20:07:29 +00:00
|
|
|
/*
|
|
|
|
* We got the channel assigned and can now hand this channel
|
|
|
|
* over to one of our callbacks.
|
|
|
|
*/
|
2010-12-01 21:38:03 +00:00
|
|
|
static 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;
|
2010-12-01 21:38:03 +00:00
|
|
|
struct gsm_subscriber *subscr = param;
|
2010-12-01 22:04:03 +00:00
|
|
|
struct paging_signal_data sig_data;
|
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
|
|
|
struct bsc_subscr *bsub;
|
|
|
|
struct gsm_network *net;
|
2010-12-01 20:07:29 +00:00
|
|
|
|
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
|
|
|
OSMO_ASSERT(subscr && subscr->is_paging);
|
|
|
|
net = subscr->group->net;
|
2010-12-01 20:07:29 +00:00
|
|
|
|
2015-08-03 09:18:23 +00:00
|
|
|
/*
|
|
|
|
* Stop paging on all other BTS. E.g. if this is
|
|
|
|
* the first timeout on a BTS then the others will
|
|
|
|
* timeout soon as well. Let's just stop everything
|
|
|
|
* and forget we wanted to page.
|
|
|
|
*/
|
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
|
|
|
|
|
|
|
/* TODO MSC split -- creating a BSC subscriber directly from MSC data
|
|
|
|
* structures in RAM. At some point the MSC will send a message to the
|
|
|
|
* BSC instead. */
|
|
|
|
bsub = bsc_subscr_find_or_create_by_imsi(net->bsc_subscribers,
|
|
|
|
subscr->imsi);
|
|
|
|
bsub->tmsi = subscr->tmsi;
|
|
|
|
bsub->lac = subscr->lac;
|
|
|
|
paging_request_stop(&net->bts_list, NULL, bsub, NULL, NULL);
|
|
|
|
bsc_subscr_put(bsub);
|
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 */
|
2010-12-01 22:04:03 +00:00
|
|
|
sig_data.subscr = subscr;
|
|
|
|
sig_data.bts = conn ? conn->bts : NULL;
|
|
|
|
sig_data.conn = conn;
|
2010-12-23 17:19:17 +00:00
|
|
|
sig_data.paging_result = event;
|
2011-05-06 10:12:31 +00:00
|
|
|
osmo_signal_dispatch(
|
2010-12-01 22:04:03 +00:00
|
|
|
SS_PAGING,
|
|
|
|
event == GSM_PAGING_SUCCEEDED ?
|
|
|
|
S_PAGING_SUCCEEDED : S_PAGING_EXPIRED,
|
|
|
|
&sig_data
|
|
|
|
);
|
|
|
|
|
2015-04-06 10:03:45 +00:00
|
|
|
llist_for_each_entry_safe(request, tmp, &subscr->requests, entry) {
|
|
|
|
llist_del(&request->entry);
|
|
|
|
request->cbfn(hooknum, event, msg, data, request->param);
|
|
|
|
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 */
|
2015-08-03 09:34:35 +00:00
|
|
|
subscr->is_paging = 0;
|
2010-12-01 20:07:29 +00:00
|
|
|
subscr_put(subscr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-01 21:38:03 +00:00
|
|
|
static int subscr_paging_sec_cb(unsigned int hooknum, unsigned int event,
|
|
|
|
struct msgb *msg, void *data, void *param)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case GSM_SECURITY_AUTH_FAILED:
|
|
|
|
/* Dispatch as paging failure */
|
|
|
|
rc = subscr_paging_dispatch(
|
|
|
|
GSM_HOOK_RR_PAGING, GSM_PAGING_EXPIRED,
|
|
|
|
msg, data, param);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSM_SECURITY_NOAVAIL:
|
|
|
|
case GSM_SECURITY_SUCCEEDED:
|
|
|
|
/* Dispatch as paging failure */
|
|
|
|
rc = subscr_paging_dispatch(
|
|
|
|
GSM_HOOK_RR_PAGING, GSM_PAGING_SUCCEEDED,
|
|
|
|
msg, data, param);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rc = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int subscr_paging_cb(unsigned int hooknum, unsigned int event,
|
|
|
|
struct msgb *msg, void *data, void *param)
|
|
|
|
{
|
|
|
|
struct gsm_subscriber_connection *conn = data;
|
|
|
|
struct gsm48_hdr *gh;
|
|
|
|
struct gsm48_pag_resp *pr;
|
|
|
|
|
|
|
|
/* Other cases mean problem, dispatch direclty */
|
|
|
|
if (event != GSM_PAGING_SUCCEEDED)
|
|
|
|
return subscr_paging_dispatch(hooknum, event, msg, data, param);
|
|
|
|
|
|
|
|
/* Get paging response */
|
|
|
|
gh = msgb_l3(msg);
|
|
|
|
pr = (struct gsm48_pag_resp *)gh->data;
|
|
|
|
|
|
|
|
/* We _really_ have a channel, secure it now ! */
|
|
|
|
return gsm48_secure_channel(conn, pr->key_seq, subscr_paging_sec_cb, param);
|
|
|
|
}
|
|
|
|
|
2015-04-06 10:03:45 +00:00
|
|
|
struct subscr_request *subscr_request_channel(struct gsm_subscriber *subscr,
|
|
|
|
int channel_type, gsm_cbfn *cbfn, void *param)
|
2010-12-01 20:07:29 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct subscr_request *request;
|
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
|
|
|
struct bsc_subscr *bsub;
|
|
|
|
struct gsm_network *net = subscr->group->net;
|
2010-12-01 20:07:29 +00:00
|
|
|
|
2015-04-06 10:03:45 +00:00
|
|
|
/* Start paging.. we know it is async so we can do it before */
|
|
|
|
if (!subscr->is_paging) {
|
|
|
|
LOGP(DMM, LOGL_DEBUG, "Subscriber %s not paged yet.\n",
|
|
|
|
subscr_name(subscr));
|
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
|
|
|
/* TODO MSC split -- creating a BSC subscriber directly from
|
|
|
|
* MSC data structures in RAM. At some point the MSC will send
|
|
|
|
* a message to the BSC instead. */
|
|
|
|
bsub = bsc_subscr_find_or_create_by_imsi(net->bsc_subscribers,
|
|
|
|
subscr->imsi);
|
|
|
|
bsub->tmsi = subscr->tmsi;
|
|
|
|
bsub->lac = subscr->lac;
|
|
|
|
rc = paging_request(net, bsub, channel_type, subscr_paging_cb,
|
|
|
|
subscr);
|
|
|
|
bsc_subscr_put(bsub);
|
2015-04-06 10:03:45 +00:00
|
|
|
if (rc <= 0) {
|
|
|
|
LOGP(DMM, LOGL_ERROR, "Subscriber %s paging failed: %d\n",
|
|
|
|
subscr_name(subscr), rc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* reduced on the first paging callback */
|
|
|
|
subscr_get(subscr);
|
|
|
|
subscr->is_paging = 1;
|
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 */
|
|
|
|
request = talloc_zero(subscr, struct subscr_request);
|
|
|
|
if (!request)
|
|
|
|
return NULL;
|
|
|
|
|
2010-12-01 20:07:29 +00:00
|
|
|
request->cbfn = cbfn;
|
|
|
|
request->param = param;
|
2015-04-06 10:03:45 +00:00
|
|
|
llist_add_tail(&request->entry, &subscr->requests);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-12-03 08:28:24 +00:00
|
|
|
struct gsm_subscriber *subscr_create_subscriber(struct gsm_subscriber_group *sgrp,
|
2016-06-30 08:25:49 +00:00
|
|
|
const char *imsi)
|
2013-10-04 06:35:11 +00:00
|
|
|
{
|
2016-06-30 08:25:49 +00:00
|
|
|
struct gsm_subscriber *subscr = db_create_subscriber(imsi,
|
|
|
|
sgrp->net->ext_min,
|
|
|
|
sgrp->net->ext_max,
|
|
|
|
sgrp->net->auto_assign_exten);
|
2013-10-04 06:35:11 +00:00
|
|
|
if (subscr)
|
2014-12-03 08:28:24 +00:00
|
|
|
subscr->group = sgrp;
|
2013-10-04 06:35:11 +00:00
|
|
|
return subscr;
|
|
|
|
}
|
2010-12-01 20:07:29 +00:00
|
|
|
|
2014-12-03 08:28:24 +00:00
|
|
|
struct gsm_subscriber *subscr_get_by_tmsi(struct gsm_subscriber_group *sgrp,
|
2011-04-18 15:04:00 +00:00
|
|
|
uint32_t tmsi)
|
2008-12-23 20:25:15 +00:00
|
|
|
{
|
2009-08-19 10:53:57 +00:00
|
|
|
char tmsi_string[14];
|
2009-01-01 18:02:05 +00:00
|
|
|
struct gsm_subscriber *subscr;
|
2008-12-27 21:34:06 +00:00
|
|
|
|
2009-01-01 18:02:05 +00:00
|
|
|
/* we might have a record in memory already */
|
2012-12-25 17:58:34 +00:00
|
|
|
llist_for_each_entry(subscr, subscr_bsc_active_subscribers(), entry) {
|
2009-08-19 10:53:57 +00:00
|
|
|
if (tmsi == subscr->tmsi)
|
2009-01-01 18:02:05 +00:00
|
|
|
return subscr_get(subscr);
|
2008-12-27 21:34:06 +00:00
|
|
|
}
|
|
|
|
|
2009-08-19 10:53:57 +00:00
|
|
|
sprintf(tmsi_string, "%u", tmsi);
|
2014-12-03 08:28:24 +00:00
|
|
|
return get_subscriber(sgrp, GSM_SUBSCRIBER_TMSI, tmsi_string);
|
2008-12-27 21:34:06 +00:00
|
|
|
}
|
|
|
|
|
2014-12-03 08:28:24 +00:00
|
|
|
struct gsm_subscriber *subscr_get_by_imsi(struct gsm_subscriber_group *sgrp,
|
2009-07-23 16:46:00 +00:00
|
|
|
const char *imsi)
|
2008-12-27 21:34:06 +00:00
|
|
|
{
|
2009-01-01 18:02:05 +00:00
|
|
|
struct gsm_subscriber *subscr;
|
2008-12-27 21:34:06 +00:00
|
|
|
|
2012-12-25 17:58:34 +00:00
|
|
|
llist_for_each_entry(subscr, subscr_bsc_active_subscribers(), entry) {
|
2009-01-01 18:02:05 +00:00
|
|
|
if (strcmp(subscr->imsi, imsi) == 0)
|
|
|
|
return subscr_get(subscr);
|
2008-12-27 21:34:06 +00:00
|
|
|
}
|
|
|
|
|
2014-12-03 08:28:24 +00:00
|
|
|
return get_subscriber(sgrp, GSM_SUBSCRIBER_IMSI, imsi);
|
2008-12-23 20:25:15 +00:00
|
|
|
}
|
|
|
|
|
2014-12-03 08:28:24 +00:00
|
|
|
struct gsm_subscriber *subscr_get_by_extension(struct gsm_subscriber_group *sgrp,
|
2009-07-23 16:46:00 +00:00
|
|
|
const char *ext)
|
2009-02-09 23:39:20 +00:00
|
|
|
{
|
|
|
|
struct gsm_subscriber *subscr;
|
|
|
|
|
2012-12-25 17:58:34 +00:00
|
|
|
llist_for_each_entry(subscr, subscr_bsc_active_subscribers(), entry) {
|
2009-02-09 23:39:20 +00:00
|
|
|
if (strcmp(subscr->extension, ext) == 0)
|
|
|
|
return subscr_get(subscr);
|
|
|
|
}
|
|
|
|
|
2014-12-03 08:28:24 +00:00
|
|
|
return get_subscriber(sgrp, GSM_SUBSCRIBER_EXTENSION, ext);
|
2009-02-09 23:39:20 +00:00
|
|
|
}
|
|
|
|
|
2014-12-03 08:28:24 +00:00
|
|
|
struct gsm_subscriber *subscr_get_by_id(struct gsm_subscriber_group *sgrp,
|
2009-08-08 14:03:15 +00:00
|
|
|
unsigned long long id)
|
|
|
|
{
|
|
|
|
struct gsm_subscriber *subscr;
|
|
|
|
char buf[32];
|
|
|
|
sprintf(buf, "%llu", id);
|
|
|
|
|
2012-12-25 17:58:34 +00:00
|
|
|
llist_for_each_entry(subscr, subscr_bsc_active_subscribers(), entry) {
|
2009-08-08 14:03:15 +00:00
|
|
|
if (subscr->id == id)
|
|
|
|
return subscr_get(subscr);
|
|
|
|
}
|
|
|
|
|
2014-12-03 08:28:24 +00:00
|
|
|
return get_subscriber(sgrp, GSM_SUBSCRIBER_ID, buf);
|
2009-08-08 14:03:15 +00:00
|
|
|
}
|
|
|
|
|
2013-06-30 13:30:47 +00:00
|
|
|
int subscr_update_expire_lu(struct gsm_subscriber *s, struct gsm_bts *bts)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
subscr_update_expire_lu(): fix (obscure) segfault
To be paranoid, catch a NULL subscriber and/or bts in
subscr_update_expire_lu(): print an error log and avoid segfault.
(I'm not sure this would really happen in a normal situation.)
During aggressive testing of Paging timeout, I came across this segfault in
msc_release_connection() when conn->expire_timer_stopped is set but
conn->subscr is NULL, at the subscr dereference after:
if (conn->expire_timer_stopped)
subscr_update_expire_lu(conn->subscr, conn->bts);
I brought this situation about by a fabricated Paging fault, i.e. in
gsm48_rx_rr_pag_resp() return 0 and don't call gsm48_handle_paging_resp() at
all. Thus conn->subscr is still NULL when expire_timer_stopped is 1.
When looking at CM Service Request handling, the conn->subscr is set before
setting expire_timer_stopped = 1, which is a saner thing to do. But without my
mad 'return 0', there is in fact no way to have a NULL subscriber there.
It looks like all other code paths already do the same, but it's not that
obvious (e.g. _gsm48_rx_mm_serv_req_sec_cb()). So rather catch this case of
NULL conn->subscr, and while at it catch NULL bts as well.
Change-Id: I430dd952b2b928bea7f8360f1e01bb3cccb0a395
2017-02-19 00:14:39 +00:00
|
|
|
if (!s) {
|
|
|
|
LOGP(DMM, LOGL_ERROR, "LU Expiration but NULL subscriber\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!bts) {
|
|
|
|
LOGP(DMM, LOGL_ERROR, "%s: LU Expiration but NULL bts\n",
|
|
|
|
subscr_name(s));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-06-30 13:30:47 +00:00
|
|
|
/* Table 10.5.33: The T3212 timeout value field is coded as the
|
|
|
|
* binary representation of the timeout value for
|
|
|
|
* periodic updating in decihours. Mark the subscriber as
|
|
|
|
* inactive if it missed two consecutive location updates.
|
|
|
|
* Timeout is twice the t3212 value plus one minute */
|
2013-07-27 19:07:57 +00:00
|
|
|
|
|
|
|
/* Is expiration handling enabled? */
|
|
|
|
if (bts->si_common.chan_desc.t3212 == 0)
|
|
|
|
s->expire_lu = GSM_SUBSCRIBER_NO_EXPIRATION;
|
|
|
|
else
|
|
|
|
s->expire_lu = time(NULL) +
|
2013-06-30 13:30:47 +00:00
|
|
|
(bts->si_common.chan_desc.t3212 * 60 * 6 * 2) + 60;
|
2013-07-27 19:07:57 +00:00
|
|
|
|
2013-06-30 13:30:47 +00:00
|
|
|
rc = db_sync_subscriber(s);
|
|
|
|
db_subscriber_update(s);
|
|
|
|
return rc;
|
|
|
|
}
|
2009-08-08 14:03:15 +00:00
|
|
|
|
2009-04-12 05:37:29 +00:00
|
|
|
int subscr_update(struct gsm_subscriber *s, struct gsm_bts *bts, int reason)
|
2008-12-23 20:25:15 +00:00
|
|
|
{
|
2010-12-25 18:40:14 +00:00
|
|
|
int rc;
|
|
|
|
|
2009-04-12 05:37:29 +00:00
|
|
|
/* FIXME: Migrate pending requests from one BSC to another */
|
|
|
|
switch (reason) {
|
|
|
|
case GSM_SUBSCRIBER_UPDATE_ATTACHED:
|
2014-12-03 08:28:24 +00:00
|
|
|
s->group = bts->network->subscr_group;
|
2009-06-02 02:54:38 +00:00
|
|
|
/* Indicate "attached to LAC" */
|
|
|
|
s->lac = bts->location_area_code;
|
2012-12-26 23:27:16 +00:00
|
|
|
|
2013-06-30 13:30:47 +00:00
|
|
|
LOGP(DMM, LOGL_INFO, "Subscriber %s ATTACHED LAC=%u\n",
|
|
|
|
subscr_name(s), s->lac);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The below will set a new expire_lu but as a side-effect
|
|
|
|
* the new lac will be saved in the database.
|
|
|
|
*/
|
|
|
|
rc = subscr_update_expire_lu(s, bts);
|
2011-05-06 10:12:31 +00:00
|
|
|
osmo_signal_dispatch(SS_SUBSCR, S_SUBSCR_ATTACHED, s);
|
2009-04-12 05:37:29 +00:00
|
|
|
break;
|
|
|
|
case GSM_SUBSCRIBER_UPDATE_DETACHED:
|
2009-06-04 14:27:39 +00:00
|
|
|
/* Only detach if we are currently in this area */
|
|
|
|
if (bts->location_area_code == s->lac)
|
2009-10-01 02:07:15 +00:00
|
|
|
s->lac = GSM_LAC_RESERVED_DETACHED;
|
2009-12-24 13:50:24 +00:00
|
|
|
LOGP(DMM, LOGL_INFO, "Subscriber %s DETACHED\n", subscr_name(s));
|
2010-12-25 18:40:14 +00:00
|
|
|
rc = db_sync_subscriber(s);
|
|
|
|
db_subscriber_update(s);
|
2011-05-06 10:12:31 +00:00
|
|
|
osmo_signal_dispatch(SS_SUBSCR, S_SUBSCR_DETACHED, s);
|
2009-04-12 05:37:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "subscr_update with unknown reason: %d\n",
|
|
|
|
reason);
|
2010-12-25 18:40:14 +00:00
|
|
|
rc = db_sync_subscriber(s);
|
|
|
|
db_subscriber_update(s);
|
2009-04-12 05:37:29 +00:00
|
|
|
break;
|
|
|
|
};
|
2010-12-25 18:40:14 +00:00
|
|
|
|
|
|
|
return rc;
|
2009-01-01 18:02:05 +00:00
|
|
|
}
|
|
|
|
|
2010-12-22 17:12:11 +00:00
|
|
|
void subscr_update_from_db(struct gsm_subscriber *sub)
|
|
|
|
{
|
|
|
|
db_subscriber_update(sub);
|
|
|
|
}
|
2010-12-28 21:12:30 +00:00
|
|
|
|
2012-12-26 23:27:16 +00:00
|
|
|
static void subscr_expire_callback(void *data, long long unsigned int id)
|
|
|
|
{
|
|
|
|
struct gsm_network *net = data;
|
2014-12-03 08:28:24 +00:00
|
|
|
struct gsm_subscriber *s = subscr_get_by_id(net->subscr_group, id);
|
2013-06-30 13:30:47 +00:00
|
|
|
struct gsm_subscriber_connection *conn = connection_for_subscr(s);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The subscriber is active and the phone stopped the timer. As
|
|
|
|
* we don't want to periodically update the database for active
|
|
|
|
* subscribers we will just do it when the subscriber was selected
|
|
|
|
* for expiration. This way on the next around another subscriber
|
|
|
|
* will be selected.
|
|
|
|
*/
|
|
|
|
if (conn && conn->expire_timer_stopped) {
|
|
|
|
LOGP(DMM, LOGL_DEBUG, "Not expiring subscriber %s (ID %llu)\n",
|
|
|
|
subscr_name(s), id);
|
|
|
|
subscr_update_expire_lu(s, conn->bts);
|
2015-08-04 09:37:30 +00:00
|
|
|
subscr_put(s);
|
2013-06-30 13:30:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-26 23:27:16 +00:00
|
|
|
|
2013-07-04 18:22:27 +00:00
|
|
|
LOGP(DMM, LOGL_NOTICE, "Expiring inactive subscriber %s (ID %llu)\n",
|
2012-12-26 23:27:16 +00:00
|
|
|
subscr_name(s), id);
|
|
|
|
s->lac = GSM_LAC_RESERVED_DETACHED;
|
|
|
|
db_sync_subscriber(s);
|
|
|
|
|
|
|
|
subscr_put(s);
|
|
|
|
}
|
|
|
|
|
2014-12-03 08:28:24 +00:00
|
|
|
void subscr_expire(struct gsm_subscriber_group *sgrp)
|
2012-12-26 23:27:16 +00:00
|
|
|
{
|
2014-12-03 08:28:24 +00:00
|
|
|
db_subscriber_expire(sgrp->net, subscr_expire_callback);
|
2012-12-26 23:27:16 +00:00
|
|
|
}
|
2016-05-10 11:56:43 +00:00
|
|
|
|
|
|
|
struct gsm_subscriber_connection *connection_for_subscr(struct gsm_subscriber *subscr)
|
|
|
|
{
|
|
|
|
/* FIXME: replace this with a backpointer in gsm_subscriber? */
|
|
|
|
struct gsm_network *net = subscr->group->net;
|
|
|
|
struct gsm_subscriber_connection *conn;
|
|
|
|
|
|
|
|
llist_for_each_entry(conn, &net->subscr_conns, entry) {
|
|
|
|
if (conn->subscr == subscr)
|
|
|
|
return conn;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|