blob: b731dbcfa4d4f34ca6e1f365378ed6fd8bf4b10b [file] [log] [blame]
Harald Welteb68899d2009-01-06 21:47:18 +00001/* Paging helper and manager.... */
2/* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01006 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
Harald Welteb68899d2009-01-06 21:47:18 +00008 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010013 * GNU Affero General Public License for more details.
Harald Welteb68899d2009-01-06 21:47:18 +000014 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010015 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welteb68899d2009-01-06 21:47:18 +000017 *
18 */
19
20/*
21 * Relevant specs:
22 * 12.21:
23 * - 9.4.12 for CCCH Local Threshold
24 *
25 * 05.58:
26 * - 8.5.2 CCCH Load indication
27 * - 9.3.15 Paging Load
28 *
29 * Approach:
30 * - Send paging command to subscriber
31 * - On Channel Request we will remember the reason
32 * - After the ACK we will request the identity
33 * - Then we will send assign the gsm_subscriber and
34 * - and call a callback
35 */
36
Harald Welte2f1311b2009-01-06 23:50:39 +000037#include <stdio.h>
38#include <stdlib.h>
Holger Freythere36e15e2009-02-14 18:05:03 +000039#include <assert.h>
Harald Welte2f1311b2009-01-06 23:50:39 +000040
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010041#include <osmocom/core/talloc.h>
Harald Welte457a0812011-06-26 14:21:43 +020042#include <osmocom/gsm/gsm48.h>
Harald Weltebc82f922011-06-26 14:41:58 +020043#include <osmocom/gsm/gsm0502.h>
Harald Welte457a0812011-06-26 14:21:43 +020044
45#include <openbsc/paging.h>
Harald Welteb68899d2009-01-06 21:47:18 +000046#include <openbsc/debug.h>
Holger Freyther4af2b482009-02-14 22:51:03 +000047#include <openbsc/signal.h>
Harald Welte2f1311b2009-01-06 23:50:39 +000048#include <openbsc/abis_rsl.h>
Holger Freytherceb59b72009-02-06 18:54:00 +000049#include <openbsc/gsm_data.h>
Holger Hans Peter Freytheref811782010-04-10 00:06:17 +020050#include <openbsc/chan_alloc.h>
Holger Hans Peter Freytherc6bb3c42010-06-17 16:43:24 +080051#include <openbsc/bsc_api.h>
Harald Welteb68899d2009-01-06 21:47:18 +000052
Harald Welte (local)d19e58b2009-08-15 02:30:58 +020053void *tall_paging_ctx;
Harald Welte2cf161b2009-06-20 22:36:41 +020054
Holger Hans Peter Freythereb241aa2010-09-06 10:05:23 +080055#define PAGING_TIMER 0, 500000
56
Harald Welte38c2f132009-01-06 23:10:57 +000057/*
58 * Kill one paging request update the internal list...
59 */
Holger Freyther1fd34142009-02-09 23:42:03 +000060static void paging_remove_request(struct gsm_bts_paging_state *paging_bts,
Holger Freytherceb59b72009-02-06 18:54:00 +000061 struct gsm_paging_request *to_be_deleted)
Holger Freyther3d949242009-02-06 18:08:18 +000062{
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +020063 osmo_timer_del(&to_be_deleted->T3113);
Harald Welte38c2f132009-01-06 23:10:57 +000064 llist_del(&to_be_deleted->entry);
Harald Welte51cce1e2009-02-10 17:35:04 +000065 subscr_put(to_be_deleted->subscr);
Harald Welte2cf161b2009-06-20 22:36:41 +020066 talloc_free(to_be_deleted);
Harald Welte38c2f132009-01-06 23:10:57 +000067}
68
Holger Freyther33ba7522009-02-06 22:33:25 +000069static void page_ms(struct gsm_paging_request *request)
70{
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020071 uint8_t mi[128];
Harald Welte2f1311b2009-01-06 23:50:39 +000072 unsigned int mi_len;
Holger Freyther33ba7522009-02-06 22:33:25 +000073 unsigned int page_group;
Harald Welte1cf43ec2011-06-26 14:43:46 +020074 struct gsm_bts *bts = request->bts;
Holger Freyther33ba7522009-02-06 22:33:25 +000075
Holger Hans Peter Freyther10049bc2012-12-22 19:27:27 +010076 /* the bts is down.. we will just wait for the paging to expire */
77 if (!bts->oml_link)
78 return;
79
Holger Hans Peter Freytherc50b8362010-04-09 22:02:39 +020080 LOGP(DPAG, LOGL_INFO, "Going to send paging commands: imsi: '%s' tmsi: '0x%x'\n",
Holger Hans Peter Freytherb28285d2009-08-21 14:55:57 +020081 request->subscr->imsi, request->subscr->tmsi);
82
83 if (request->subscr->tmsi == GSM_RESERVED_TMSI)
84 mi_len = gsm48_generate_mid_from_imsi(mi, request->subscr->imsi);
85 else
86 mi_len = gsm48_generate_mid_from_tmsi(mi, request->subscr->tmsi);
Holger Freyther33ba7522009-02-06 22:33:25 +000087
Harald Welte1cf43ec2011-06-26 14:43:46 +020088 page_group = gsm0502_calc_paging_group(&bts->si_common.chan_desc,
89 str_to_imsi(request->subscr->imsi));
90 gsm0808_page(bts, page_group, mi_len, mi, request->chan_type);
Holger Freyther33ba7522009-02-06 22:33:25 +000091}
92
Holger Hans Peter Freythereb241aa2010-09-06 10:05:23 +080093static void paging_schedule_if_needed(struct gsm_bts_paging_state *paging_bts)
94{
95 if (llist_empty(&paging_bts->pending_requests))
96 return;
97
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +020098 if (!osmo_timer_pending(&paging_bts->work_timer))
99 osmo_timer_schedule(&paging_bts->work_timer, PAGING_TIMER);
Holger Hans Peter Freythereb241aa2010-09-06 10:05:23 +0800100}
101
102
Holger Hans Peter Freyther78fab292010-04-20 10:59:33 +0800103static void paging_handle_pending_requests(struct gsm_bts_paging_state *paging_bts);
Holger Hans Peter Freyther6410d932010-04-19 19:41:26 +0800104static void paging_give_credit(void *data)
105{
106 struct gsm_bts_paging_state *paging_bts = data;
107
108 LOGP(DPAG, LOGL_NOTICE, "No slots available on bts nr %d\n", paging_bts->bts->nr);
109 paging_bts->available_slots = 20;
Holger Hans Peter Freyther78fab292010-04-20 10:59:33 +0800110 paging_handle_pending_requests(paging_bts);
Holger Hans Peter Freyther6410d932010-04-19 19:41:26 +0800111}
112
Holger Hans Peter Freythere66bf1f2010-09-06 10:11:25 +0800113static int can_send_pag_req(struct gsm_bts *bts, int rsl_type)
114{
115 struct pchan_load pl;
116 int count;
117
118 memset(&pl, 0, sizeof(pl));
119 bts_chan_load(&pl, bts);
120
121 switch (rsl_type) {
122 case RSL_CHANNEED_TCH_F:
Holger Hans Peter Freythere66bf1f2010-09-06 10:11:25 +0800123 case RSL_CHANNEED_TCH_ForH:
Holger Hans Peter Freyther2e4447b2010-04-20 17:15:21 +0800124 goto count_tch;
Holger Hans Peter Freythere66bf1f2010-09-06 10:11:25 +0800125 break;
126 case RSL_CHANNEED_SDCCH:
127 goto count_sdcch;
128 break;
129 case RSL_CHANNEED_ANY:
130 default:
131 if (bts->network->pag_any_tch)
Holger Hans Peter Freyther2e4447b2010-04-20 17:15:21 +0800132 goto count_tch;
Holger Hans Peter Freythere66bf1f2010-09-06 10:11:25 +0800133 else
134 goto count_sdcch;
135 break;
136 }
137
138 return 0;
139
140 /* could available SDCCH */
141count_sdcch:
142 count = 0;
143 count += pl.pchan[GSM_PCHAN_SDCCH8_SACCH8C].total
144 - pl.pchan[GSM_PCHAN_SDCCH8_SACCH8C].used;
145 count += pl.pchan[GSM_PCHAN_CCCH_SDCCH4].total
146 - pl.pchan[GSM_PCHAN_CCCH_SDCCH4].used;
147 return bts->paging.free_chans_need > count;
Holger Hans Peter Freyther2e4447b2010-04-20 17:15:21 +0800148
149count_tch:
150 count = 0;
151 count += pl.pchan[GSM_PCHAN_TCH_F].total
152 - pl.pchan[GSM_PCHAN_TCH_F].used;
153 if (bts->network->neci)
154 count += pl.pchan[GSM_PCHAN_TCH_H].total
155 - pl.pchan[GSM_PCHAN_TCH_H].used;
156 return bts->paging.free_chans_need > count;
Holger Hans Peter Freythere66bf1f2010-09-06 10:11:25 +0800157}
158
Holger Freythere36e15e2009-02-14 18:05:03 +0000159/*
160 * This is kicked by the periodic PAGING LOAD Indicator
161 * coming from abis_rsl.c
162 *
163 * We attempt to iterate once over the list of items but
164 * only upto available_slots.
165 */
Holger Freytherb1ffbb62009-02-11 01:49:15 +0000166static void paging_handle_pending_requests(struct gsm_bts_paging_state *paging_bts)
167{
Holger Hans Peter Freythereb241aa2010-09-06 10:05:23 +0800168 struct gsm_paging_request *request = NULL;
Harald Welte38c2f132009-01-06 23:10:57 +0000169
Holger Freythere36e15e2009-02-14 18:05:03 +0000170 /*
171 * Determine if the pending_requests list is empty and
172 * return then.
173 */
Harald Welte75a1fa82009-02-17 01:39:41 +0000174 if (llist_empty(&paging_bts->pending_requests)) {
Harald Welte75a1fa82009-02-17 01:39:41 +0000175 /* since the list is empty, no need to reschedule the timer */
Harald Welte38c2f132009-01-06 23:10:57 +0000176 return;
177 }
178
Holger Hans Peter Freyther19722d42010-04-09 18:38:06 +0200179 /*
Holger Hans Peter Freyther6410d932010-04-19 19:41:26 +0800180 * In case the BTS does not provide us with load indication and we
181 * ran out of slots, call an autofill routine. It might be that the
182 * BTS did not like our paging messages and then we have counted down
183 * to zero and we do not get any messages.
Holger Hans Peter Freyther19722d42010-04-09 18:38:06 +0200184 */
185 if (paging_bts->available_slots == 0) {
Holger Hans Peter Freyther6410d932010-04-19 19:41:26 +0800186 paging_bts->credit_timer.cb = paging_give_credit;
187 paging_bts->credit_timer.data = paging_bts;
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200188 osmo_timer_schedule(&paging_bts->credit_timer, 5, 0);
Holger Hans Peter Freyther6410d932010-04-19 19:41:26 +0800189 return;
Holger Hans Peter Freyther19722d42010-04-09 18:38:06 +0200190 }
191
Holger Hans Peter Freythereb241aa2010-09-06 10:05:23 +0800192 request = llist_entry(paging_bts->pending_requests.next,
193 struct gsm_paging_request, entry);
Holger Freythere36e15e2009-02-14 18:05:03 +0000194
Holger Hans Peter Freythere66bf1f2010-09-06 10:11:25 +0800195 /* we need to determine the number of free channels */
196 if (paging_bts->free_chans_need != -1) {
197 if (can_send_pag_req(request->bts, request->chan_type) != 0)
198 goto skip_paging;
199 }
200
Holger Hans Peter Freythereb241aa2010-09-06 10:05:23 +0800201 /* handle the paging request now */
202 page_ms(request);
203 paging_bts->available_slots--;
Holger Hans Peter Freytherd3baf412010-12-23 18:19:17 +0100204 request->attempts++;
Holger Freythere36e15e2009-02-14 18:05:03 +0000205
Holger Hans Peter Freythereb241aa2010-09-06 10:05:23 +0800206 /* take the current and add it to the back */
207 llist_del(&request->entry);
208 llist_add_tail(&request->entry, &paging_bts->pending_requests);
Holger Hans Peter Freyther754e8012010-04-09 21:53:35 +0200209
Holger Hans Peter Freythere66bf1f2010-09-06 10:11:25 +0800210skip_paging:
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200211 osmo_timer_schedule(&paging_bts->work_timer, PAGING_TIMER);
Harald Welte75a1fa82009-02-17 01:39:41 +0000212}
213
214static void paging_worker(void *data)
215{
216 struct gsm_bts_paging_state *paging_bts = data;
217
218 paging_handle_pending_requests(paging_bts);
Harald Welte38c2f132009-01-06 23:10:57 +0000219}
220
Holger Hans Peter Freyther5a081bb2011-04-26 15:44:57 +0200221static void paging_init_if_needed(struct gsm_bts *bts)
Holger Freytherceb59b72009-02-06 18:54:00 +0000222{
Holger Hans Peter Freyther5a081bb2011-04-26 15:44:57 +0200223 if (bts->paging.bts)
224 return;
225
Holger Freytherceb59b72009-02-06 18:54:00 +0000226 bts->paging.bts = bts;
227 INIT_LLIST_HEAD(&bts->paging.pending_requests);
Harald Welte75a1fa82009-02-17 01:39:41 +0000228 bts->paging.work_timer.cb = paging_worker;
229 bts->paging.work_timer.data = &bts->paging;
Holger Freyther392209c2009-02-10 00:06:19 +0000230
231 /* Large number, until we get a proper message */
Holger Hans Peter Freyther14696002010-04-09 22:55:55 +0200232 bts->paging.available_slots = 20;
Holger Freytherceb59b72009-02-06 18:54:00 +0000233}
234
Holger Freyther1fd34142009-02-09 23:42:03 +0000235static int paging_pending_request(struct gsm_bts_paging_state *bts,
Harald Welteb68899d2009-01-06 21:47:18 +0000236 struct gsm_subscriber *subscr) {
Holger Freytherceb59b72009-02-06 18:54:00 +0000237 struct gsm_paging_request *req;
Harald Welteb68899d2009-01-06 21:47:18 +0000238
239 llist_for_each_entry(req, &bts->pending_requests, entry) {
240 if (subscr == req->subscr)
241 return 1;
242 }
243
244 return 0;
245}
246
Harald Welte51cce1e2009-02-10 17:35:04 +0000247static void paging_T3113_expired(void *data)
248{
Holger Freyther83e44b02009-02-14 18:04:59 +0000249 struct gsm_paging_request *req = (struct gsm_paging_request *)data;
Holger Hans Peter Freytherfe9da822009-11-17 10:16:46 +0100250 void *cbfn_param;
251 gsm_cbfn *cbfn;
Holger Hans Peter Freytherd3baf412010-12-23 18:19:17 +0100252 int msg;
Harald Welte51cce1e2009-02-10 17:35:04 +0000253
Holger Hans Peter Freytherc50b8362010-04-09 22:02:39 +0200254 LOGP(DPAG, LOGL_INFO, "T3113 expired for request %p (%s)\n",
Harald Welte51cce1e2009-02-10 17:35:04 +0000255 req, req->subscr->imsi);
Holger Freyther4af2b482009-02-14 22:51:03 +0000256
Holger Hans Peter Freytherfe9da822009-11-17 10:16:46 +0100257 /* must be destroyed before calling cbfn, to prevent double free */
Pablo Neira Ayusodfb342c2011-05-06 12:13:10 +0200258 osmo_counter_inc(req->bts->network->stats.paging.expired);
Holger Hans Peter Freytherfe9da822009-11-17 10:16:46 +0100259 cbfn_param = req->cbfn_param;
260 cbfn = req->cbfn;
Holger Hans Peter Freytherd3baf412010-12-23 18:19:17 +0100261
262 /* did we ever manage to page the subscriber */
263 msg = req->attempts > 0 ? GSM_PAGING_EXPIRED : GSM_PAGING_BUSY;
264
265 /* destroy it now. Do not access req afterwards */
Harald Welte51cce1e2009-02-10 17:35:04 +0000266 paging_remove_request(&req->bts->paging, req);
Holger Hans Peter Freytherfe9da822009-11-17 10:16:46 +0100267
Holger Hans Peter Freytherfe9da822009-11-17 10:16:46 +0100268 if (cbfn)
Holger Hans Peter Freytherd3baf412010-12-23 18:19:17 +0100269 cbfn(GSM_HOOK_RR_PAGING, msg, NULL, NULL,
Holger Hans Peter Freytherfe9da822009-11-17 10:16:46 +0100270 cbfn_param);
Harald Welte51cce1e2009-02-10 17:35:04 +0000271}
272
Harald Weltee903edf2009-08-15 03:16:17 +0200273static int _paging_request(struct gsm_bts *bts, struct gsm_subscriber *subscr,
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200274 int type, gsm_cbfn *cbfn, void *data)
Harald Welte09e38af2009-02-16 22:52:23 +0000275{
Holger Freytherceb59b72009-02-06 18:54:00 +0000276 struct gsm_bts_paging_state *bts_entry = &bts->paging;
277 struct gsm_paging_request *req;
Harald Welteb68899d2009-01-06 21:47:18 +0000278
Holger Freyther49314f62009-02-14 23:53:20 +0000279 if (paging_pending_request(bts_entry, subscr)) {
Holger Hans Peter Freytherc50b8362010-04-09 22:02:39 +0200280 LOGP(DPAG, LOGL_INFO, "Paging request already pending for %s\n", subscr->imsi);
Harald Weltee903edf2009-08-15 03:16:17 +0200281 return -EEXIST;
Holger Freyther49314f62009-02-14 23:53:20 +0000282 }
283
Holger Hans Peter Freytherc50b8362010-04-09 22:02:39 +0200284 LOGP(DPAG, LOGL_DEBUG, "Start paging of subscriber %llu on bts %d.\n",
Harald Weltef6cea1d2009-08-08 15:08:19 +0200285 subscr->id, bts->nr);
Harald Welte470ec292009-06-26 20:25:23 +0200286 req = talloc_zero(tall_paging_ctx, struct gsm_paging_request);
Harald Welteb68899d2009-01-06 21:47:18 +0000287 req->subscr = subscr_get(subscr);
288 req->bts = bts;
Harald Welte38c2f132009-01-06 23:10:57 +0000289 req->chan_type = type;
Harald Welte09e38af2009-02-16 22:52:23 +0000290 req->cbfn = cbfn;
291 req->cbfn_param = data;
Harald Welte51cce1e2009-02-10 17:35:04 +0000292 req->T3113.cb = paging_T3113_expired;
293 req->T3113.data = req;
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200294 osmo_timer_schedule(&req->T3113, bts->network->T3113, 0);
Holger Freyther49314f62009-02-14 23:53:20 +0000295 llist_add_tail(&req->entry, &bts_entry->pending_requests);
Holger Hans Peter Freythereb241aa2010-09-06 10:05:23 +0800296 paging_schedule_if_needed(bts_entry);
Harald Weltee903edf2009-08-15 03:16:17 +0200297
298 return 0;
Harald Welteb68899d2009-01-06 21:47:18 +0000299}
Harald Welte763da002009-02-06 12:52:14 +0000300
Harald Weltee903edf2009-08-15 03:16:17 +0200301int paging_request(struct gsm_network *network, struct gsm_subscriber *subscr,
302 int type, gsm_cbfn *cbfn, void *data)
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200303{
304 struct gsm_bts *bts = NULL;
Harald Welte (local)0abaf332009-08-15 11:25:45 +0200305 int num_pages = 0;
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200306
Pablo Neira Ayusodfb342c2011-05-06 12:13:10 +0200307 osmo_counter_inc(network->stats.paging.attempted);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100308
Harald Weltea1b28582009-08-01 19:31:47 +0200309 /* start paging subscriber on all BTS within Location Area */
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200310 do {
Harald Welte (local)0abaf332009-08-15 11:25:45 +0200311 int rc;
312
Holger Freyther04866d42009-03-31 04:35:19 +0200313 bts = gsm_bts_by_lac(network, subscr->lac, bts);
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200314 if (!bts)
315 break;
Harald Welte (local)82ff3972009-12-28 16:36:28 +0100316
317 /* skip all currently inactive TRX */
318 if (!trx_is_usable(bts->c0))
319 continue;
320
Holger Hans Peter Freyther5a081bb2011-04-26 15:44:57 +0200321 /* maybe it is the first time we use it */
322 paging_init_if_needed(bts);
323
Harald Welte (local)0abaf332009-08-15 11:25:45 +0200324 num_pages++;
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200325
Harald Weltee903edf2009-08-15 03:16:17 +0200326 /* Trigger paging, pass any error to caller */
327 rc = _paging_request(bts, subscr, type, cbfn, data);
328 if (rc < 0)
329 return rc;
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200330 } while (1);
Harald Weltee903edf2009-08-15 03:16:17 +0200331
Harald Welte24ff6ee2009-12-22 00:41:05 +0100332 if (num_pages == 0)
Pablo Neira Ayusodfb342c2011-05-06 12:13:10 +0200333 osmo_counter_inc(network->stats.paging.detached);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100334
Harald Welte (local)0abaf332009-08-15 11:25:45 +0200335 return num_pages;
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200336}
337
338
Harald Welte763da002009-02-06 12:52:14 +0000339/* we consciously ignore the type of the request here */
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200340static void _paging_request_stop(struct gsm_bts *bts, struct gsm_subscriber *subscr,
Sylvain Munautc7ff2572010-12-01 21:41:35 +0100341 struct gsm_subscriber_connection *conn,
342 struct msgb *msg)
Harald Welte763da002009-02-06 12:52:14 +0000343{
Holger Freytherceb59b72009-02-06 18:54:00 +0000344 struct gsm_bts_paging_state *bts_entry = &bts->paging;
345 struct gsm_paging_request *req, *req2;
Harald Welte763da002009-02-06 12:52:14 +0000346
Holger Hans Peter Freyther5a081bb2011-04-26 15:44:57 +0200347 paging_init_if_needed(bts);
348
Harald Welte763da002009-02-06 12:52:14 +0000349 llist_for_each_entry_safe(req, req2, &bts_entry->pending_requests,
350 entry) {
Holger Freyther3d949242009-02-06 18:08:18 +0000351 if (req->subscr == subscr) {
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +0800352 if (conn && req->cbfn) {
Holger Hans Peter Freytherc50b8362010-04-09 22:02:39 +0200353 LOGP(DPAG, LOGL_DEBUG, "Stop paging on bts %d, calling cbfn.\n", bts->nr);
Harald Welte09e38af2009-02-16 22:52:23 +0000354 req->cbfn(GSM_HOOK_RR_PAGING, GSM_PAGING_SUCCEEDED,
Sylvain Munautc7ff2572010-12-01 21:41:35 +0100355 msg, conn, req->cbfn_param);
Harald Welte4bfdfe72009-06-10 23:11:52 +0800356 } else
Holger Hans Peter Freytherc50b8362010-04-09 22:02:39 +0200357 LOGP(DPAG, LOGL_DEBUG, "Stop paging on bts %d silently.\n", bts->nr);
Holger Freyther1fd34142009-02-09 23:42:03 +0000358 paging_remove_request(&bts->paging, req);
Holger Freyther3d949242009-02-06 18:08:18 +0000359 break;
360 }
Harald Welte763da002009-02-06 12:52:14 +0000361 }
362}
Holger Freyther392209c2009-02-10 00:06:19 +0000363
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200364/* Stop paging on all other bts' */
365void paging_request_stop(struct gsm_bts *_bts, struct gsm_subscriber *subscr,
Sylvain Munautc7ff2572010-12-01 21:41:35 +0100366 struct gsm_subscriber_connection *conn,
367 struct msgb *msg)
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200368{
369 struct gsm_bts *bts = NULL;
370
Holger Hans Peter Freyther927f0562009-08-21 05:43:44 +0200371 if (_bts)
Sylvain Munautc7ff2572010-12-01 21:41:35 +0100372 _paging_request_stop(_bts, subscr, conn, msg);
Holger Hans Peter Freytherfdac4cc2009-06-10 11:46:58 +0200373
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200374 do {
375 /*
376 * FIXME: Don't use the lac of the subscriber...
377 * as it might have magically changed the lac.. use the
378 * location area of the _bts as reconfiguration of the
379 * network is probably happening less often.
380 */
Holger Hans Peter Freyther927f0562009-08-21 05:43:44 +0200381 bts = gsm_bts_by_lac(subscr->net, subscr->lac, bts);
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200382 if (!bts)
383 break;
384
385 /* Stop paging */
Holger Hans Peter Freythera5811362010-04-30 13:32:05 +0800386 if (bts != _bts)
Sylvain Munautc7ff2572010-12-01 21:41:35 +0100387 _paging_request_stop(bts, subscr, NULL, NULL);
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200388 } while (1);
389}
390
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200391void paging_update_buffer_space(struct gsm_bts *bts, uint16_t free_slots)
Holger Freyther392209c2009-02-10 00:06:19 +0000392{
Holger Hans Peter Freyther5a081bb2011-04-26 15:44:57 +0200393 paging_init_if_needed(bts);
394
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200395 osmo_timer_del(&bts->paging.credit_timer);
Holger Freyther392209c2009-02-10 00:06:19 +0000396 bts->paging.available_slots = free_slots;
Holger Hans Peter Freythereb241aa2010-09-06 10:05:23 +0800397 paging_schedule_if_needed(&bts->paging);
Holger Freyther392209c2009-02-10 00:06:19 +0000398}
Holger Hans Peter Freyther66e14cd2011-04-26 15:52:34 +0200399
400unsigned int paging_pending_requests_nr(struct gsm_bts *bts)
401{
402 unsigned int requests = 0;
403 struct gsm_paging_request *req;
404
405 paging_init_if_needed(bts);
406
407 llist_for_each_entry(req, &bts->paging.pending_requests, entry)
408 ++requests;
409
410 return requests;
411}
Holger Hans Peter Freyther31f5f712011-06-07 19:53:29 +0200412
413/**
414 * Find any paging data for the given subscriber at the given BTS.
415 */
416void *paging_get_data(struct gsm_bts *bts, struct gsm_subscriber *subscr)
417{
418 struct gsm_paging_request *req;
419
420 llist_for_each_entry(req, &bts->paging.pending_requests, entry)
421 if (req->subscr == subscr)
422 return req->cbfn_param;
423
424 return NULL;
425}