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>
|
|
|
|
#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-02-03 23:18:46 +00:00
|
|
|
#define PAGING_TIMEOUT 1, 75000
|
2009-02-03 21:05:49 +00:00
|
|
|
#define MAX_PAGING_REQUEST 750
|
2009-01-06 23:10:57 +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;
|
|
|
|
|
|
|
|
ccch_conf = bts->chan_desc.ccch_conf;
|
|
|
|
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
|
|
|
{
|
|
|
|
/* Update the last_request if that is necessary */
|
|
|
|
if (to_be_deleted == paging_bts->last_request) {
|
|
|
|
paging_bts->last_request =
|
2009-02-06 18:54:00 +00:00
|
|
|
(struct gsm_paging_request *)paging_bts->last_request->entry.next;
|
2009-02-06 18:08:18 +00:00
|
|
|
if (&to_be_deleted->entry == &paging_bts->pending_requests)
|
|
|
|
paging_bts->last_request = NULL;
|
|
|
|
}
|
|
|
|
|
2009-02-11 01:18:42 +00:00
|
|
|
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-01-06 23:10:57 +00:00
|
|
|
free(to_be_deleted);
|
|
|
|
}
|
|
|
|
|
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 long int tmsi;
|
|
|
|
unsigned int mi_len;
|
2009-02-06 22:33:25 +00:00
|
|
|
unsigned int page_group;
|
|
|
|
|
|
|
|
DEBUGP(DPAG, "Going to send paging commands: '%s'\n",
|
|
|
|
request->subscr->imsi);
|
|
|
|
|
|
|
|
page_group = calculate_group(request->bts, request->subscr);
|
|
|
|
tmsi = strtoul(request->subscr->tmsi, NULL, 10);
|
|
|
|
mi_len = generate_mid_from_tmsi(mi, tmsi);
|
|
|
|
rsl_paging_cmd(request->bts, page_group, mi_len, mi,
|
|
|
|
request->chan_type);
|
|
|
|
}
|
|
|
|
|
2009-02-11 03:00:20 +00:00
|
|
|
static void paging_move_to_next(struct gsm_bts_paging_state *paging_bts)
|
|
|
|
{
|
|
|
|
paging_bts->last_request =
|
|
|
|
(struct gsm_paging_request *)paging_bts->last_request->entry.next;
|
|
|
|
if (&paging_bts->last_request->entry == &paging_bts->pending_requests)
|
|
|
|
paging_bts->last_request = NULL;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
if (&paging_bts->pending_requests == paging_bts->pending_requests.next) {
|
2009-01-06 23:10:57 +00:00
|
|
|
paging_bts->last_request = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-14 18:05:03 +00:00
|
|
|
if (!paging_bts->last_request)
|
2009-02-14 23:35:09 +00:00
|
|
|
paging_bts->last_request =
|
|
|
|
(struct gsm_paging_request *)paging_bts->pending_requests.next;
|
2009-02-14 18:05:03 +00:00
|
|
|
|
|
|
|
assert(paging_bts->last_request);
|
|
|
|
initial_request = paging_bts->last_request;
|
|
|
|
current_request = initial_request;
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* handle the paging request now */
|
|
|
|
page_ms(current_request);
|
|
|
|
paging_bts->available_slots--;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* move to the next item. We might wrap around
|
|
|
|
* this means last_request will be NULL and we just
|
|
|
|
* call paging_page_to_next again. It it guranteed
|
|
|
|
* that the list is not empty.
|
|
|
|
*/
|
|
|
|
paging_move_to_next(paging_bts);
|
|
|
|
if (!paging_bts->last_request)
|
2009-02-14 23:35:09 +00:00
|
|
|
paging_bts->last_request =
|
|
|
|
(struct gsm_paging_request *)paging_bts->pending_requests.next;
|
2009-02-14 18:05:03 +00:00
|
|
|
current_request = paging_bts->last_request;
|
|
|
|
} while (paging_bts->available_slots > 0
|
|
|
|
&& initial_request != current_request);
|
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-10 00:06:19 +00:00
|
|
|
|
|
|
|
/* Large number, until we get a proper message */
|
2009-02-11 01:49:15 +00:00
|
|
|
bts->paging.available_slots = 0x0;
|
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-10 17:35:04 +00:00
|
|
|
|
|
|
|
DEBUGP(DPAG, "T3113 expired for request %p (%s)\n",
|
|
|
|
req, req->subscr->imsi);
|
|
|
|
|
2009-02-14 22:51:03 +00:00
|
|
|
struct paging_signal_data sig_data = {
|
2009-02-14 22:51:10 +00:00
|
|
|
.data = {
|
|
|
|
.area = S_PAGING,
|
|
|
|
},
|
2009-02-14 22:51:03 +00:00
|
|
|
.subscr = req->subscr,
|
|
|
|
.bts = req->bts,
|
|
|
|
.lchan = NULL,
|
|
|
|
};
|
|
|
|
|
2009-02-14 22:51:10 +00:00
|
|
|
dispatch_signal(&sig_data.data);
|
2009-02-10 17:35:04 +00:00
|
|
|
paging_remove_request(&req->bts->paging, req);
|
|
|
|
}
|
|
|
|
|
2009-02-09 23:42:03 +00:00
|
|
|
void paging_request(struct gsm_bts *bts, struct gsm_subscriber *subscr, int type) {
|
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-06 18:54:00 +00:00
|
|
|
req = (struct gsm_paging_request *)malloc(sizeof(*req));
|
2009-01-27 23:38:27 +00:00
|
|
|
memset(req, 0, sizeof(*req));
|
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-10 17:35:04 +00:00
|
|
|
req->T3113.cb = paging_T3113_expired;
|
|
|
|
req->T3113.data = req;
|
|
|
|
schedule_timer(&req->T3113, T3113_VALUE);
|
2009-01-06 21:47:18 +00:00
|
|
|
|
2009-02-09 23:42:03 +00:00
|
|
|
if (!paging_pending_request(bts_entry, subscr)) {
|
2009-02-06 18:54:00 +00:00
|
|
|
llist_add_tail(&req->entry, &bts_entry->pending_requests);
|
|
|
|
} else {
|
|
|
|
DEBUGP(DPAG, "Paging request already pending\n");
|
2009-01-06 21:47:18 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-06 12:52:14 +00:00
|
|
|
|
|
|
|
/* we consciously ignore the type of the request here */
|
2009-02-09 23:42:03 +00:00
|
|
|
void paging_request_stop(struct gsm_bts *bts, struct gsm_subscriber *subscr)
|
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-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
|
|
|
|
|
|
|
void paging_update_buffer_space(struct gsm_bts *bts, u_int16_t free_slots)
|
|
|
|
{
|
|
|
|
bts->paging.available_slots = free_slots;
|
2009-02-11 01:49:15 +00:00
|
|
|
paging_handle_pending_requests(&bts->paging);
|
2009-02-10 00:06:19 +00:00
|
|
|
}
|