2009-01-06 21:47:18 +00:00
|
|
|
/* Paging helper and manager.... */
|
|
|
|
/* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Relevant specs:
|
|
|
|
* 12.21:
|
|
|
|
* - 9.4.12 for CCCH Local Threshold
|
|
|
|
*
|
|
|
|
* 05.58:
|
|
|
|
* - 8.5.2 CCCH Load indication
|
|
|
|
* - 9.3.15 Paging Load
|
|
|
|
*
|
|
|
|
* Approach:
|
|
|
|
* - Send paging command to subscriber
|
|
|
|
* - On Channel Request we will remember the reason
|
|
|
|
* - After the ACK we will request the identity
|
|
|
|
* - Then we will send assign the gsm_subscriber and
|
|
|
|
* - and call a callback
|
|
|
|
*/
|
|
|
|
|
2009-01-06 23:50:39 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2009-02-14 18:05:03 +00:00
|
|
|
#include <assert.h>
|
2009-01-06 23:50:39 +00:00
|
|
|
|
2009-01-06 21:47:18 +00:00
|
|
|
#include <openbsc/paging.h>
|
split 'libosmocore' from openbsc codebase
This library is intended to collect all generic/common funcitionality
of all Osmocom.org projects, including OpenBSC but also OsmocomBB
The library currently includes the following modules:
bitvec, comp128, gsm_utils, msgb, select, signal, statistics, talloc, timer,
tlv_parse, linuxlist
msgb allocation error debugging had to be temporarily disabled as it depends on
'debug.c' functionality which at the moment remains in OpenBSC
2010-02-20 15:24:02 +00:00
|
|
|
#include <osmocore/talloc.h>
|
2009-01-06 21:47:18 +00:00
|
|
|
#include <openbsc/debug.h>
|
2009-02-14 22:51:03 +00:00
|
|
|
#include <openbsc/signal.h>
|
2009-01-06 23:50:39 +00:00
|
|
|
#include <openbsc/abis_rsl.h>
|
2009-02-06 18:54:00 +00:00
|
|
|
#include <openbsc/gsm_data.h>
|
2009-01-06 21:47:18 +00:00
|
|
|
|
2009-08-15 00:30:58 +00:00
|
|
|
void *tall_paging_ctx;
|
2009-06-20 20:36:41 +00:00
|
|
|
|
2009-02-04 02:14:45 +00:00
|
|
|
static unsigned int calculate_group(struct gsm_bts *bts, struct gsm_subscriber *subscr)
|
|
|
|
{
|
|
|
|
int ccch_conf;
|
|
|
|
int bs_cc_chans;
|
|
|
|
int blocks;
|
|
|
|
unsigned int group;
|
|
|
|
|
2009-12-01 12:34:30 +00:00
|
|
|
ccch_conf = bts->si_common.chan_desc.ccch_conf;
|
2009-02-04 02:14:45 +00:00
|
|
|
bs_cc_chans = rsl_ccch_conf_to_bs_cc_chans(ccch_conf);
|
|
|
|
/* code word + 2, as 2 channels equals 0x0 */
|
2009-02-04 13:38:26 +00:00
|
|
|
blocks = rsl_number_of_paging_subchannels(bts);
|
2009-02-04 02:14:45 +00:00
|
|
|
group = get_paging_group(str_to_imsi(subscr->imsi),
|
|
|
|
bs_cc_chans, blocks);
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
2009-01-06 23:10:57 +00:00
|
|
|
/*
|
|
|
|
* Kill one paging request update the internal list...
|
|
|
|
*/
|
2009-02-09 23:42:03 +00:00
|
|
|
static void paging_remove_request(struct gsm_bts_paging_state *paging_bts,
|
2009-02-06 18:54:00 +00:00
|
|
|
struct gsm_paging_request *to_be_deleted)
|
2009-02-06 18:08:18 +00:00
|
|
|
{
|
2009-05-23 05:22:08 +00:00
|
|
|
bsc_del_timer(&to_be_deleted->T3113);
|
2009-01-06 23:10:57 +00:00
|
|
|
llist_del(&to_be_deleted->entry);
|
2009-02-10 17:35:04 +00:00
|
|
|
subscr_put(to_be_deleted->subscr);
|
2009-06-20 20:36:41 +00:00
|
|
|
talloc_free(to_be_deleted);
|
2009-01-06 23:10:57 +00:00
|
|
|
}
|
|
|
|
|
2009-02-06 22:33:25 +00:00
|
|
|
static void page_ms(struct gsm_paging_request *request)
|
|
|
|
{
|
2009-01-06 23:50:39 +00:00
|
|
|
u_int8_t mi[128];
|
|
|
|
unsigned int mi_len;
|
2009-02-06 22:33:25 +00:00
|
|
|
unsigned int page_group;
|
|
|
|
|
2010-04-09 20:02:39 +00:00
|
|
|
LOGP(DPAG, LOGL_INFO, "Going to send paging commands: imsi: '%s' tmsi: '0x%x'\n",
|
2009-08-21 12:55:57 +00:00
|
|
|
request->subscr->imsi, request->subscr->tmsi);
|
|
|
|
|
|
|
|
if (request->subscr->tmsi == GSM_RESERVED_TMSI)
|
|
|
|
mi_len = gsm48_generate_mid_from_imsi(mi, request->subscr->imsi);
|
|
|
|
else
|
|
|
|
mi_len = gsm48_generate_mid_from_tmsi(mi, request->subscr->tmsi);
|
2009-02-06 22:33:25 +00:00
|
|
|
|
|
|
|
page_group = calculate_group(request->bts, request->subscr);
|
|
|
|
rsl_paging_cmd(request->bts, page_group, mi_len, mi,
|
|
|
|
request->chan_type);
|
|
|
|
}
|
|
|
|
|
2009-02-14 18:05:03 +00:00
|
|
|
/*
|
|
|
|
* This is kicked by the periodic PAGING LOAD Indicator
|
|
|
|
* coming from abis_rsl.c
|
|
|
|
*
|
|
|
|
* We attempt to iterate once over the list of items but
|
|
|
|
* only upto available_slots.
|
|
|
|
*/
|
2009-02-11 01:49:15 +00:00
|
|
|
static void paging_handle_pending_requests(struct gsm_bts_paging_state *paging_bts)
|
|
|
|
{
|
2009-02-14 18:05:03 +00:00
|
|
|
struct gsm_paging_request *initial_request = NULL;
|
|
|
|
struct gsm_paging_request *current_request = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine if the pending_requests list is empty and
|
|
|
|
* return then.
|
|
|
|
*/
|
2009-02-17 01:39:41 +00:00
|
|
|
if (llist_empty(&paging_bts->pending_requests)) {
|
|
|
|
/* since the list is empty, no need to reschedule the timer */
|
2009-01-06 23:10:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-09 16:38:06 +00:00
|
|
|
/*
|
|
|
|
* In case the BTS does not provide us with load indication just fill
|
|
|
|
* up our slots for this round. We should be able to page 20 subscribers
|
|
|
|
* every two seconds. So we will just give the BTS some extra credit.
|
|
|
|
* We will have to see how often we run out of this credit, so we might
|
|
|
|
* need a low watermark and then add credit or give 20 every run when
|
|
|
|
* the bts sets an option for that.
|
|
|
|
*/
|
|
|
|
if (paging_bts->available_slots == 0) {
|
|
|
|
LOGP(DPAG, LOGL_NOTICE, "No slots available on bts nr %d\n",
|
|
|
|
paging_bts->bts->nr);
|
|
|
|
paging_bts->available_slots = 20;
|
|
|
|
}
|
|
|
|
|
2010-04-09 19:53:35 +00:00
|
|
|
initial_request = llist_entry(paging_bts->pending_requests.next,
|
|
|
|
struct gsm_paging_request, entry);
|
2009-02-14 18:05:03 +00:00
|
|
|
current_request = initial_request;
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* handle the paging request now */
|
|
|
|
page_ms(current_request);
|
|
|
|
paging_bts->available_slots--;
|
|
|
|
|
2010-04-09 19:53:35 +00:00
|
|
|
/* take the current and add it to the back */
|
|
|
|
llist_del(¤t_request->entry);
|
|
|
|
llist_add_tail(¤t_request->entry, &paging_bts->pending_requests);
|
|
|
|
|
|
|
|
/* take the next request */
|
|
|
|
current_request = llist_entry(paging_bts->pending_requests.next,
|
|
|
|
struct gsm_paging_request, entry);
|
2009-02-14 18:05:03 +00:00
|
|
|
} while (paging_bts->available_slots > 0
|
|
|
|
&& initial_request != current_request);
|
2009-02-17 01:39:41 +00:00
|
|
|
|
2010-01-27 08:10:05 +00:00
|
|
|
bsc_schedule_timer(&paging_bts->work_timer, 2, 0);
|
2009-02-17 01:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void paging_worker(void *data)
|
|
|
|
{
|
|
|
|
struct gsm_bts_paging_state *paging_bts = data;
|
|
|
|
|
|
|
|
paging_handle_pending_requests(paging_bts);
|
2009-01-06 23:10:57 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 23:42:03 +00:00
|
|
|
void paging_init(struct gsm_bts *bts)
|
2009-02-06 18:54:00 +00:00
|
|
|
{
|
|
|
|
bts->paging.bts = bts;
|
|
|
|
INIT_LLIST_HEAD(&bts->paging.pending_requests);
|
2009-02-17 01:39:41 +00:00
|
|
|
bts->paging.work_timer.cb = paging_worker;
|
|
|
|
bts->paging.work_timer.data = &bts->paging;
|
2009-02-10 00:06:19 +00:00
|
|
|
|
|
|
|
/* Large number, until we get a proper message */
|
2009-02-17 01:39:41 +00:00
|
|
|
bts->paging.available_slots = 100;
|
2009-02-06 18:54:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 23:42:03 +00:00
|
|
|
static int paging_pending_request(struct gsm_bts_paging_state *bts,
|
2009-01-06 21:47:18 +00:00
|
|
|
struct gsm_subscriber *subscr) {
|
2009-02-06 18:54:00 +00:00
|
|
|
struct gsm_paging_request *req;
|
2009-01-06 21:47:18 +00:00
|
|
|
|
|
|
|
llist_for_each_entry(req, &bts->pending_requests, entry) {
|
|
|
|
if (subscr == req->subscr)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-10 17:35:04 +00:00
|
|
|
static void paging_T3113_expired(void *data)
|
|
|
|
{
|
2009-02-14 18:04:59 +00:00
|
|
|
struct gsm_paging_request *req = (struct gsm_paging_request *)data;
|
2009-02-16 22:05:44 +00:00
|
|
|
struct paging_signal_data sig_data;
|
2009-11-17 09:16:46 +00:00
|
|
|
void *cbfn_param;
|
|
|
|
gsm_cbfn *cbfn;
|
2009-02-10 17:35:04 +00:00
|
|
|
|
2010-04-09 20:02:39 +00:00
|
|
|
LOGP(DPAG, LOGL_INFO, "T3113 expired for request %p (%s)\n",
|
2009-02-10 17:35:04 +00:00
|
|
|
req, req->subscr->imsi);
|
|
|
|
|
2009-08-20 04:15:21 +00:00
|
|
|
sig_data.subscr = req->subscr;
|
|
|
|
sig_data.bts = req->bts;
|
|
|
|
sig_data.lchan = NULL;
|
2009-02-16 22:05:44 +00:00
|
|
|
|
2009-11-17 09:16:46 +00:00
|
|
|
/* must be destroyed before calling cbfn, to prevent double free */
|
2010-04-08 14:48:46 +00:00
|
|
|
counter_inc(req->bts->network->stats.paging.expired);
|
2009-11-17 09:16:46 +00:00
|
|
|
cbfn_param = req->cbfn_param;
|
|
|
|
cbfn = req->cbfn;
|
2009-02-10 17:35:04 +00:00
|
|
|
paging_remove_request(&req->bts->paging, req);
|
2009-11-17 09:16:46 +00:00
|
|
|
|
2009-12-21 23:41:05 +00:00
|
|
|
|
2009-12-19 11:38:10 +00:00
|
|
|
dispatch_signal(SS_PAGING, S_PAGING_EXPIRED, &sig_data);
|
2009-11-17 09:16:46 +00:00
|
|
|
if (cbfn)
|
|
|
|
cbfn(GSM_HOOK_RR_PAGING, GSM_PAGING_EXPIRED, NULL, NULL,
|
|
|
|
cbfn_param);
|
2009-02-10 17:35:04 +00:00
|
|
|
}
|
|
|
|
|
2009-08-15 01:16:17 +00:00
|
|
|
static int _paging_request(struct gsm_bts *bts, struct gsm_subscriber *subscr,
|
2009-06-10 00:45:42 +00:00
|
|
|
int type, gsm_cbfn *cbfn, void *data)
|
2009-02-16 22:52:23 +00:00
|
|
|
{
|
2009-02-06 18:54:00 +00:00
|
|
|
struct gsm_bts_paging_state *bts_entry = &bts->paging;
|
|
|
|
struct gsm_paging_request *req;
|
2009-01-06 21:47:18 +00:00
|
|
|
|
2009-02-14 23:53:20 +00:00
|
|
|
if (paging_pending_request(bts_entry, subscr)) {
|
2010-04-09 20:02:39 +00:00
|
|
|
LOGP(DPAG, LOGL_INFO, "Paging request already pending for %s\n", subscr->imsi);
|
2009-08-15 01:16:17 +00:00
|
|
|
return -EEXIST;
|
2009-02-14 23:53:20 +00:00
|
|
|
}
|
|
|
|
|
2010-04-09 20:02:39 +00:00
|
|
|
LOGP(DPAG, LOGL_DEBUG, "Start paging of subscriber %llu on bts %d.\n",
|
2009-08-08 13:08:19 +00:00
|
|
|
subscr->id, bts->nr);
|
2009-06-26 18:25:23 +00:00
|
|
|
req = talloc_zero(tall_paging_ctx, struct gsm_paging_request);
|
2009-01-06 21:47:18 +00:00
|
|
|
req->subscr = subscr_get(subscr);
|
|
|
|
req->bts = bts;
|
2009-01-06 23:10:57 +00:00
|
|
|
req->chan_type = type;
|
2009-02-16 22:52:23 +00:00
|
|
|
req->cbfn = cbfn;
|
|
|
|
req->cbfn_param = data;
|
2009-02-10 17:35:04 +00:00
|
|
|
req->T3113.cb = paging_T3113_expired;
|
|
|
|
req->T3113.data = req;
|
2009-11-21 20:48:53 +00:00
|
|
|
bsc_schedule_timer(&req->T3113, bts->network->T3113, 0);
|
2009-02-14 23:53:20 +00:00
|
|
|
llist_add_tail(&req->entry, &bts_entry->pending_requests);
|
2009-02-17 01:39:41 +00:00
|
|
|
|
2009-05-23 05:22:08 +00:00
|
|
|
if (!bsc_timer_pending(&bts_entry->work_timer))
|
2010-01-27 08:10:05 +00:00
|
|
|
bsc_schedule_timer(&bts_entry->work_timer, 2, 0);
|
2009-08-15 01:16:17 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-01-06 21:47:18 +00:00
|
|
|
}
|
2009-02-06 12:52:14 +00:00
|
|
|
|
2009-08-15 01:16:17 +00:00
|
|
|
int paging_request(struct gsm_network *network, struct gsm_subscriber *subscr,
|
|
|
|
int type, gsm_cbfn *cbfn, void *data)
|
2009-06-10 00:45:42 +00:00
|
|
|
{
|
|
|
|
struct gsm_bts *bts = NULL;
|
2009-08-15 09:25:45 +00:00
|
|
|
int num_pages = 0;
|
2009-06-10 00:45:42 +00:00
|
|
|
|
2009-12-22 18:07:32 +00:00
|
|
|
counter_inc(network->stats.paging.attempted);
|
2009-12-21 23:41:05 +00:00
|
|
|
|
2009-08-01 17:31:47 +00:00
|
|
|
/* start paging subscriber on all BTS within Location Area */
|
2009-06-10 00:45:42 +00:00
|
|
|
do {
|
2009-08-15 09:25:45 +00:00
|
|
|
int rc;
|
|
|
|
|
2009-03-31 02:35:19 +00:00
|
|
|
bts = gsm_bts_by_lac(network, subscr->lac, bts);
|
2009-06-10 00:45:42 +00:00
|
|
|
if (!bts)
|
|
|
|
break;
|
2009-12-28 15:36:28 +00:00
|
|
|
|
|
|
|
/* skip all currently inactive TRX */
|
|
|
|
if (!trx_is_usable(bts->c0))
|
|
|
|
continue;
|
|
|
|
|
2009-08-15 09:25:45 +00:00
|
|
|
num_pages++;
|
2009-06-10 00:45:42 +00:00
|
|
|
|
2009-08-15 01:16:17 +00:00
|
|
|
/* Trigger paging, pass any error to caller */
|
|
|
|
rc = _paging_request(bts, subscr, type, cbfn, data);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
2009-06-10 00:45:42 +00:00
|
|
|
} while (1);
|
2009-08-15 01:16:17 +00:00
|
|
|
|
2009-12-21 23:41:05 +00:00
|
|
|
if (num_pages == 0)
|
2009-12-22 18:07:32 +00:00
|
|
|
counter_inc(network->stats.paging.detached);
|
2009-12-21 23:41:05 +00:00
|
|
|
|
2009-08-15 09:25:45 +00:00
|
|
|
return num_pages;
|
2009-06-10 00:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-06 12:52:14 +00:00
|
|
|
/* we consciously ignore the type of the request here */
|
2009-06-10 00:45:42 +00:00
|
|
|
static void _paging_request_stop(struct gsm_bts *bts, struct gsm_subscriber *subscr,
|
|
|
|
struct gsm_lchan *lchan)
|
2009-02-06 12:52:14 +00:00
|
|
|
{
|
2009-02-06 18:54:00 +00:00
|
|
|
struct gsm_bts_paging_state *bts_entry = &bts->paging;
|
|
|
|
struct gsm_paging_request *req, *req2;
|
2009-02-06 12:52:14 +00:00
|
|
|
|
|
|
|
llist_for_each_entry_safe(req, req2, &bts_entry->pending_requests,
|
|
|
|
entry) {
|
2009-02-06 18:08:18 +00:00
|
|
|
if (req->subscr == subscr) {
|
2009-06-10 15:11:52 +00:00
|
|
|
if (lchan && req->cbfn) {
|
2010-04-09 20:02:39 +00:00
|
|
|
LOGP(DPAG, LOGL_DEBUG, "Stop paging on bts %d, calling cbfn.\n", bts->nr);
|
2009-02-16 22:52:23 +00:00
|
|
|
req->cbfn(GSM_HOOK_RR_PAGING, GSM_PAGING_SUCCEEDED,
|
2009-02-17 01:39:41 +00:00
|
|
|
NULL, lchan, req->cbfn_param);
|
2009-06-10 15:11:52 +00:00
|
|
|
} else
|
2010-04-09 20:02:39 +00:00
|
|
|
LOGP(DPAG, LOGL_DEBUG, "Stop paging on bts %d silently.\n", bts->nr);
|
2009-02-09 23:42:03 +00:00
|
|
|
paging_remove_request(&bts->paging, req);
|
2009-02-06 18:08:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-02-06 12:52:14 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-10 00:06:19 +00:00
|
|
|
|
2009-06-10 00:45:42 +00:00
|
|
|
/* Stop paging on all other bts' */
|
|
|
|
void paging_request_stop(struct gsm_bts *_bts, struct gsm_subscriber *subscr,
|
|
|
|
struct gsm_lchan *lchan)
|
|
|
|
{
|
|
|
|
struct gsm_bts *bts = NULL;
|
|
|
|
|
2009-08-21 03:43:44 +00:00
|
|
|
if (_bts)
|
|
|
|
_paging_request_stop(_bts, subscr, lchan);
|
2009-06-10 09:46:58 +00:00
|
|
|
|
2009-06-10 00:45:42 +00:00
|
|
|
do {
|
|
|
|
/*
|
|
|
|
* FIXME: Don't use the lac of the subscriber...
|
|
|
|
* as it might have magically changed the lac.. use the
|
|
|
|
* location area of the _bts as reconfiguration of the
|
|
|
|
* network is probably happening less often.
|
|
|
|
*/
|
2009-08-21 03:43:44 +00:00
|
|
|
bts = gsm_bts_by_lac(subscr->net, subscr->lac, bts);
|
2009-06-10 00:45:42 +00:00
|
|
|
if (!bts)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Stop paging */
|
2009-06-10 09:46:58 +00:00
|
|
|
if (bts != _bts)
|
|
|
|
_paging_request_stop(bts, subscr, NULL);
|
2009-06-10 00:45:42 +00:00
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
|
2009-02-10 00:06:19 +00:00
|
|
|
void paging_update_buffer_space(struct gsm_bts *bts, u_int16_t free_slots)
|
|
|
|
{
|
|
|
|
bts->paging.available_slots = free_slots;
|
|
|
|
}
|