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>
|
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;
|
|
|
|
|
|
|
|
/* back reference */
|
|
|
|
struct gsm_subscriber *subscr;
|
|
|
|
|
|
|
|
/* the requested channel type */
|
|
|
|
int channel_type;
|
|
|
|
|
2010-12-29 08:33:34 +00:00
|
|
|
/* what did we do */
|
|
|
|
int state;
|
|
|
|
|
2010-12-01 20:07:29 +00:00
|
|
|
/* the callback data */
|
|
|
|
gsm_cbfn *cbfn;
|
|
|
|
void *param;
|
|
|
|
};
|
|
|
|
|
2010-12-29 08:33:34 +00:00
|
|
|
enum {
|
|
|
|
REQ_STATE_INITIAL,
|
|
|
|
REQ_STATE_QUEUED,
|
|
|
|
REQ_STATE_PAGED,
|
|
|
|
REQ_STATE_FAILED_START,
|
|
|
|
REQ_STATE_DISPATCHED,
|
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
|
|
|
struct subscr_request *request;
|
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;
|
2010-12-01 20:07:29 +00:00
|
|
|
|
|
|
|
/* There is no request anymore... */
|
|
|
|
if (llist_empty(&subscr->requests))
|
|
|
|
return -1;
|
|
|
|
|
2010-12-01 22:04:03 +00:00
|
|
|
/* Dispatch signal */
|
|
|
|
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
|
|
|
|
);
|
|
|
|
|
2010-12-01 20:07:29 +00:00
|
|
|
/*
|
|
|
|
* FIXME: What to do with paging requests coming during
|
|
|
|
* this callback? We must be sure to not start paging when
|
|
|
|
* we have an active connection to a subscriber and to make
|
|
|
|
* the subscr_put_channel work as required...
|
|
|
|
*/
|
|
|
|
request = (struct subscr_request *)subscr->requests.next;
|
2010-12-29 08:33:34 +00:00
|
|
|
request->state = REQ_STATE_DISPATCHED;
|
2010-12-01 20:07:29 +00:00
|
|
|
llist_del(&request->entry);
|
|
|
|
subscr->in_callback = 1;
|
|
|
|
request->cbfn(hooknum, event, msg, data, request->param);
|
|
|
|
subscr->in_callback = 0;
|
|
|
|
|
2010-12-28 16:47:43 +00:00
|
|
|
if (event != GSM_PAGING_SUCCEEDED) {
|
|
|
|
/*
|
|
|
|
* This is a workaround for a bigger issue. We have
|
|
|
|
* issued paging that might involve multiple BTSes
|
|
|
|
* and one of them have failed now. We will stop the
|
|
|
|
* other paging requests as well as the next timeout
|
|
|
|
* would work on the next paging request and the queue
|
|
|
|
* will do bad things. This should be fixed by counting
|
|
|
|
* the outstanding results.
|
|
|
|
*/
|
|
|
|
paging_request_stop(NULL, subscr, NULL, NULL);
|
2010-12-28 16:27:05 +00:00
|
|
|
subscr_put_channel(subscr);
|
2010-12-28 16:47:43 +00:00
|
|
|
}
|
2010-12-28 16:27:05 +00:00
|
|
|
|
2010-12-01 20:07:29 +00:00
|
|
|
subscr_put(subscr);
|
|
|
|
talloc_free(request);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-01 20:07:29 +00:00
|
|
|
static void subscr_send_paging_request(struct gsm_subscriber *subscr)
|
|
|
|
{
|
|
|
|
struct subscr_request *request;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
assert(!llist_empty(&subscr->requests));
|
|
|
|
|
|
|
|
request = (struct subscr_request *)subscr->requests.next;
|
2010-12-29 08:33:34 +00:00
|
|
|
request->state = REQ_STATE_PAGED;
|
2010-12-01 20:07:29 +00:00
|
|
|
rc = paging_request(subscr->net, subscr, request->channel_type,
|
|
|
|
subscr_paging_cb, subscr);
|
|
|
|
|
|
|
|
/* paging failed, quit now */
|
|
|
|
if (rc <= 0) {
|
2010-12-29 08:33:34 +00:00
|
|
|
request->state = REQ_STATE_FAILED_START;
|
2010-12-23 17:19:17 +00:00
|
|
|
subscr_paging_cb(GSM_HOOK_RR_PAGING, GSM_PAGING_BUSY,
|
2010-12-01 20:07:29 +00:00
|
|
|
NULL, NULL, subscr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void subscr_get_channel(struct gsm_subscriber *subscr,
|
|
|
|
int type, gsm_cbfn *cbfn, void *param)
|
|
|
|
{
|
|
|
|
struct subscr_request *request;
|
|
|
|
|
|
|
|
request = talloc(tall_sub_req_ctx, struct subscr_request);
|
|
|
|
if (!request) {
|
|
|
|
if (cbfn)
|
|
|
|
cbfn(GSM_HOOK_RR_PAGING, GSM_PAGING_OOM,
|
|
|
|
NULL, NULL, param);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(request, 0, sizeof(*request));
|
|
|
|
request->subscr = subscr_get(subscr);
|
|
|
|
request->channel_type = type;
|
|
|
|
request->cbfn = cbfn;
|
|
|
|
request->param = param;
|
2010-12-29 08:33:34 +00:00
|
|
|
request->state = REQ_STATE_INITIAL;
|
2010-12-01 20:07:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: We might be able to assign more than one
|
|
|
|
* channel, e.g. voice and SMS submit at the same
|
|
|
|
* time.
|
|
|
|
*/
|
|
|
|
if (!subscr->in_callback && llist_empty(&subscr->requests)) {
|
|
|
|
/* add to the list, send a request */
|
|
|
|
llist_add_tail(&request->entry, &subscr->requests);
|
|
|
|
subscr_send_paging_request(subscr);
|
|
|
|
} else {
|
|
|
|
/* this will be picked up later, from subscr_put_channel */
|
|
|
|
llist_add_tail(&request->entry, &subscr->requests);
|
2010-12-29 08:33:34 +00:00
|
|
|
request->state = REQ_STATE_QUEUED;
|
2010-12-01 20:07:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-27 21:43:28 +00:00
|
|
|
void subscr_put_channel(struct gsm_subscriber *subscr)
|
2010-12-01 20:07:29 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* FIXME: Continue with other requests now... by checking
|
|
|
|
* the gsm_subscriber inside the gsm_lchan. Drop the ref count
|
|
|
|
* of the lchan after having asked the next requestee to handle
|
|
|
|
* the channel.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* FIXME: is the lchan is of a different type we could still
|
|
|
|
* issue an immediate assignment for another channel and then
|
|
|
|
* close this one.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Currently we will drop the last ref of the lchan which
|
|
|
|
* will result in a channel release on RSL and we will start
|
|
|
|
* the paging. This should work most of the time as the MS
|
|
|
|
* will listen to the paging requests before we timeout
|
|
|
|
*/
|
|
|
|
|
2010-12-27 21:43:28 +00:00
|
|
|
if (subscr && !llist_empty(&subscr->requests))
|
|
|
|
subscr_send_paging_request(subscr);
|
2010-12-01 20:07:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-23 16:46:00 +00:00
|
|
|
struct gsm_subscriber *subscr_get_by_tmsi(struct gsm_network *net,
|
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);
|
|
|
|
return db_get_subscriber(net, GSM_SUBSCRIBER_TMSI, tmsi_string);
|
2008-12-27 21:34:06 +00:00
|
|
|
}
|
|
|
|
|
2009-07-23 16:46:00 +00:00
|
|
|
struct gsm_subscriber *subscr_get_by_imsi(struct gsm_network *net,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-07-23 16:46:00 +00:00
|
|
|
return db_get_subscriber(net, GSM_SUBSCRIBER_IMSI, imsi);
|
2008-12-23 20:25:15 +00:00
|
|
|
}
|
|
|
|
|
2009-07-23 16:46:00 +00:00
|
|
|
struct gsm_subscriber *subscr_get_by_extension(struct gsm_network *net,
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-07-23 16:46:00 +00:00
|
|
|
return db_get_subscriber(net, GSM_SUBSCRIBER_EXTENSION, ext);
|
2009-02-09 23:39:20 +00:00
|
|
|
}
|
|
|
|
|
2009-08-08 14:03:15 +00:00
|
|
|
struct gsm_subscriber *subscr_get_by_id(struct gsm_network *net,
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return db_get_subscriber(net, GSM_SUBSCRIBER_ID, buf);
|
|
|
|
}
|
|
|
|
|
2013-06-30 13:30:47 +00:00
|
|
|
int subscr_update_expire_lu(struct gsm_subscriber *s, struct gsm_bts *bts)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* 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:
|
2009-07-23 16:56:43 +00:00
|
|
|
s->net = bts->network;
|
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;
|
2013-06-30 13:30:47 +00:00
|
|
|
struct gsm_subscriber *s = subscr_get_by_id(net, id);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void subscr_expire(struct gsm_network *net)
|
|
|
|
{
|
|
|
|
db_subscriber_expire(net, subscr_expire_callback);
|
|
|
|
}
|
|
|
|
|
2010-12-28 21:12:30 +00:00
|
|
|
int subscr_pending_requests(struct gsm_subscriber *sub)
|
|
|
|
{
|
|
|
|
struct subscr_request *req;
|
|
|
|
int pending = 0;
|
|
|
|
|
|
|
|
llist_for_each_entry(req, &sub->requests, entry)
|
|
|
|
pending += 1;
|
|
|
|
|
|
|
|
return pending;
|
|
|
|
}
|
2010-12-28 21:21:55 +00:00
|
|
|
|
|
|
|
int subscr_pending_clear(struct gsm_subscriber *sub)
|
|
|
|
{
|
|
|
|
int deleted = 0;
|
|
|
|
struct subscr_request *req, *tmp;
|
|
|
|
|
|
|
|
llist_for_each_entry_safe(req, tmp, &sub->requests, entry) {
|
|
|
|
subscr_put(req->subscr);
|
|
|
|
llist_del(&req->entry);
|
|
|
|
talloc_free(req);
|
|
|
|
deleted += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return deleted;
|
|
|
|
}
|
2010-12-29 10:07:22 +00:00
|
|
|
|
|
|
|
int subscr_pending_dump(struct gsm_subscriber *sub, struct vty *vty)
|
|
|
|
{
|
|
|
|
struct subscr_request *req;
|
|
|
|
|
|
|
|
vty_out(vty, "Pending Requests for Subscriber %llu.%s", sub->id, VTY_NEWLINE);
|
|
|
|
llist_for_each_entry(req, &sub->requests, entry) {
|
|
|
|
vty_out(vty, "Channel type: %d State: %d Sub: %llu.%s",
|
|
|
|
req->channel_type, req->state, req->subscr->id, VTY_NEWLINE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-12-29 12:45:49 +00:00
|
|
|
|
|
|
|
int subscr_pending_kick(struct gsm_subscriber *sub)
|
|
|
|
{
|
|
|
|
subscr_put_channel(sub);
|
|
|
|
return 0;
|
|
|
|
}
|