blob: 55d1a8541717d8d04cb3cd605811c3893a8b0b46 [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 Welte1cf43ec2011-06-26 14:43:46 +020057static unsigned int
58gsm0502_calc_paging_group(struct gsm48_control_channel_descr *chan_desc, uint64_t imsi)
Holger Freyther3aa8d6c2009-02-04 02:14:45 +000059{
60 int ccch_conf;
61 int bs_cc_chans;
62 int blocks;
63 unsigned int group;
64
Harald Welte1cf43ec2011-06-26 14:43:46 +020065 ccch_conf = chan_desc->ccch_conf;
Holger Freyther3aa8d6c2009-02-04 02:14:45 +000066 bs_cc_chans = rsl_ccch_conf_to_bs_cc_chans(ccch_conf);
67 /* code word + 2, as 2 channels equals 0x0 */
Harald Welte1cf43ec2011-06-26 14:43:46 +020068 blocks = gsm48_number_of_paging_subchannels(chan_desc);
69 group = gsm0502_get_paging_group(imsi, bs_cc_chans, blocks);
70
Holger Freyther3aa8d6c2009-02-04 02:14:45 +000071 return group;
72}
73
Harald Welte38c2f132009-01-06 23:10:57 +000074/*
75 * Kill one paging request update the internal list...
76 */
Holger Freyther1fd34142009-02-09 23:42:03 +000077static void paging_remove_request(struct gsm_bts_paging_state *paging_bts,
Holger Freytherceb59b72009-02-06 18:54:00 +000078 struct gsm_paging_request *to_be_deleted)
Holger Freyther3d949242009-02-06 18:08:18 +000079{
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +020080 osmo_timer_del(&to_be_deleted->T3113);
Harald Welte38c2f132009-01-06 23:10:57 +000081 llist_del(&to_be_deleted->entry);
Harald Welte51cce1e2009-02-10 17:35:04 +000082 subscr_put(to_be_deleted->subscr);
Harald Welte2cf161b2009-06-20 22:36:41 +020083 talloc_free(to_be_deleted);
Harald Welte38c2f132009-01-06 23:10:57 +000084}
85
Holger Freyther33ba7522009-02-06 22:33:25 +000086static void page_ms(struct gsm_paging_request *request)
87{
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020088 uint8_t mi[128];
Harald Welte2f1311b2009-01-06 23:50:39 +000089 unsigned int mi_len;
Holger Freyther33ba7522009-02-06 22:33:25 +000090 unsigned int page_group;
Harald Welte1cf43ec2011-06-26 14:43:46 +020091 struct gsm_bts *bts = request->bts;
Holger Freyther33ba7522009-02-06 22:33:25 +000092
Holger Hans Peter Freytherc50b8362010-04-09 22:02:39 +020093 LOGP(DPAG, LOGL_INFO, "Going to send paging commands: imsi: '%s' tmsi: '0x%x'\n",
Holger Hans Peter Freytherb28285d2009-08-21 14:55:57 +020094 request->subscr->imsi, request->subscr->tmsi);
95
96 if (request->subscr->tmsi == GSM_RESERVED_TMSI)
97 mi_len = gsm48_generate_mid_from_imsi(mi, request->subscr->imsi);
98 else
99 mi_len = gsm48_generate_mid_from_tmsi(mi, request->subscr->tmsi);
Holger Freyther33ba7522009-02-06 22:33:25 +0000100
Harald Welte1cf43ec2011-06-26 14:43:46 +0200101 page_group = gsm0502_calc_paging_group(&bts->si_common.chan_desc,
102 str_to_imsi(request->subscr->imsi));
103 gsm0808_page(bts, page_group, mi_len, mi, request->chan_type);
Holger Freyther33ba7522009-02-06 22:33:25 +0000104}
105
Holger Hans Peter Freythereb241aa2010-09-06 10:05:23 +0800106static void paging_schedule_if_needed(struct gsm_bts_paging_state *paging_bts)
107{
108 if (llist_empty(&paging_bts->pending_requests))
109 return;
110
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200111 if (!osmo_timer_pending(&paging_bts->work_timer))
112 osmo_timer_schedule(&paging_bts->work_timer, PAGING_TIMER);
Holger Hans Peter Freythereb241aa2010-09-06 10:05:23 +0800113}
114
115
Holger Hans Peter Freyther78fab292010-04-20 10:59:33 +0800116static void paging_handle_pending_requests(struct gsm_bts_paging_state *paging_bts);
Holger Hans Peter Freyther6410d932010-04-19 19:41:26 +0800117static void paging_give_credit(void *data)
118{
119 struct gsm_bts_paging_state *paging_bts = data;
120
121 LOGP(DPAG, LOGL_NOTICE, "No slots available on bts nr %d\n", paging_bts->bts->nr);
122 paging_bts->available_slots = 20;
Holger Hans Peter Freyther78fab292010-04-20 10:59:33 +0800123 paging_handle_pending_requests(paging_bts);
Holger Hans Peter Freyther6410d932010-04-19 19:41:26 +0800124}
125
Holger Hans Peter Freythere66bf1f2010-09-06 10:11:25 +0800126static int can_send_pag_req(struct gsm_bts *bts, int rsl_type)
127{
128 struct pchan_load pl;
129 int count;
130
131 memset(&pl, 0, sizeof(pl));
132 bts_chan_load(&pl, bts);
133
134 switch (rsl_type) {
135 case RSL_CHANNEED_TCH_F:
Holger Hans Peter Freythere66bf1f2010-09-06 10:11:25 +0800136 case RSL_CHANNEED_TCH_ForH:
Holger Hans Peter Freyther2e4447b2010-04-20 17:15:21 +0800137 goto count_tch;
Holger Hans Peter Freythere66bf1f2010-09-06 10:11:25 +0800138 break;
139 case RSL_CHANNEED_SDCCH:
140 goto count_sdcch;
141 break;
142 case RSL_CHANNEED_ANY:
143 default:
144 if (bts->network->pag_any_tch)
Holger Hans Peter Freyther2e4447b2010-04-20 17:15:21 +0800145 goto count_tch;
Holger Hans Peter Freythere66bf1f2010-09-06 10:11:25 +0800146 else
147 goto count_sdcch;
148 break;
149 }
150
151 return 0;
152
153 /* could available SDCCH */
154count_sdcch:
155 count = 0;
156 count += pl.pchan[GSM_PCHAN_SDCCH8_SACCH8C].total
157 - pl.pchan[GSM_PCHAN_SDCCH8_SACCH8C].used;
158 count += pl.pchan[GSM_PCHAN_CCCH_SDCCH4].total
159 - pl.pchan[GSM_PCHAN_CCCH_SDCCH4].used;
160 return bts->paging.free_chans_need > count;
Holger Hans Peter Freyther2e4447b2010-04-20 17:15:21 +0800161
162count_tch:
163 count = 0;
164 count += pl.pchan[GSM_PCHAN_TCH_F].total
165 - pl.pchan[GSM_PCHAN_TCH_F].used;
166 if (bts->network->neci)
167 count += pl.pchan[GSM_PCHAN_TCH_H].total
168 - pl.pchan[GSM_PCHAN_TCH_H].used;
169 return bts->paging.free_chans_need > count;
Holger Hans Peter Freythere66bf1f2010-09-06 10:11:25 +0800170}
171
Holger Freythere36e15e2009-02-14 18:05:03 +0000172/*
173 * This is kicked by the periodic PAGING LOAD Indicator
174 * coming from abis_rsl.c
175 *
176 * We attempt to iterate once over the list of items but
177 * only upto available_slots.
178 */
Holger Freytherb1ffbb62009-02-11 01:49:15 +0000179static void paging_handle_pending_requests(struct gsm_bts_paging_state *paging_bts)
180{
Holger Hans Peter Freythereb241aa2010-09-06 10:05:23 +0800181 struct gsm_paging_request *request = NULL;
Harald Welte38c2f132009-01-06 23:10:57 +0000182
Holger Freythere36e15e2009-02-14 18:05:03 +0000183 /*
184 * Determine if the pending_requests list is empty and
185 * return then.
186 */
Harald Welte75a1fa82009-02-17 01:39:41 +0000187 if (llist_empty(&paging_bts->pending_requests)) {
Harald Welte75a1fa82009-02-17 01:39:41 +0000188 /* since the list is empty, no need to reschedule the timer */
Harald Welte38c2f132009-01-06 23:10:57 +0000189 return;
190 }
191
Holger Hans Peter Freyther19722d42010-04-09 18:38:06 +0200192 /*
Holger Hans Peter Freyther6410d932010-04-19 19:41:26 +0800193 * In case the BTS does not provide us with load indication and we
194 * ran out of slots, call an autofill routine. It might be that the
195 * BTS did not like our paging messages and then we have counted down
196 * to zero and we do not get any messages.
Holger Hans Peter Freyther19722d42010-04-09 18:38:06 +0200197 */
198 if (paging_bts->available_slots == 0) {
Holger Hans Peter Freyther6410d932010-04-19 19:41:26 +0800199 paging_bts->credit_timer.cb = paging_give_credit;
200 paging_bts->credit_timer.data = paging_bts;
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200201 osmo_timer_schedule(&paging_bts->credit_timer, 5, 0);
Holger Hans Peter Freyther6410d932010-04-19 19:41:26 +0800202 return;
Holger Hans Peter Freyther19722d42010-04-09 18:38:06 +0200203 }
204
Holger Hans Peter Freythereb241aa2010-09-06 10:05:23 +0800205 request = llist_entry(paging_bts->pending_requests.next,
206 struct gsm_paging_request, entry);
Holger Freythere36e15e2009-02-14 18:05:03 +0000207
Holger Hans Peter Freythere66bf1f2010-09-06 10:11:25 +0800208 /* we need to determine the number of free channels */
209 if (paging_bts->free_chans_need != -1) {
210 if (can_send_pag_req(request->bts, request->chan_type) != 0)
211 goto skip_paging;
212 }
213
Holger Hans Peter Freythereb241aa2010-09-06 10:05:23 +0800214 /* handle the paging request now */
215 page_ms(request);
216 paging_bts->available_slots--;
Holger Hans Peter Freytherd3baf412010-12-23 18:19:17 +0100217 request->attempts++;
Holger Freythere36e15e2009-02-14 18:05:03 +0000218
Holger Hans Peter Freythereb241aa2010-09-06 10:05:23 +0800219 /* take the current and add it to the back */
220 llist_del(&request->entry);
221 llist_add_tail(&request->entry, &paging_bts->pending_requests);
Holger Hans Peter Freyther754e8012010-04-09 21:53:35 +0200222
Holger Hans Peter Freythere66bf1f2010-09-06 10:11:25 +0800223skip_paging:
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200224 osmo_timer_schedule(&paging_bts->work_timer, PAGING_TIMER);
Harald Welte75a1fa82009-02-17 01:39:41 +0000225}
226
227static void paging_worker(void *data)
228{
229 struct gsm_bts_paging_state *paging_bts = data;
230
231 paging_handle_pending_requests(paging_bts);
Harald Welte38c2f132009-01-06 23:10:57 +0000232}
233
Holger Hans Peter Freyther5a081bb2011-04-26 15:44:57 +0200234static void paging_init_if_needed(struct gsm_bts *bts)
Holger Freytherceb59b72009-02-06 18:54:00 +0000235{
Holger Hans Peter Freyther5a081bb2011-04-26 15:44:57 +0200236 if (bts->paging.bts)
237 return;
238
Holger Freytherceb59b72009-02-06 18:54:00 +0000239 bts->paging.bts = bts;
240 INIT_LLIST_HEAD(&bts->paging.pending_requests);
Harald Welte75a1fa82009-02-17 01:39:41 +0000241 bts->paging.work_timer.cb = paging_worker;
242 bts->paging.work_timer.data = &bts->paging;
Holger Freyther392209c2009-02-10 00:06:19 +0000243
244 /* Large number, until we get a proper message */
Holger Hans Peter Freyther14696002010-04-09 22:55:55 +0200245 bts->paging.available_slots = 20;
Holger Freytherceb59b72009-02-06 18:54:00 +0000246}
247
Holger Freyther1fd34142009-02-09 23:42:03 +0000248static int paging_pending_request(struct gsm_bts_paging_state *bts,
Harald Welteb68899d2009-01-06 21:47:18 +0000249 struct gsm_subscriber *subscr) {
Holger Freytherceb59b72009-02-06 18:54:00 +0000250 struct gsm_paging_request *req;
Harald Welteb68899d2009-01-06 21:47:18 +0000251
252 llist_for_each_entry(req, &bts->pending_requests, entry) {
253 if (subscr == req->subscr)
254 return 1;
255 }
256
257 return 0;
258}
259
Harald Welte51cce1e2009-02-10 17:35:04 +0000260static void paging_T3113_expired(void *data)
261{
Holger Freyther83e44b02009-02-14 18:04:59 +0000262 struct gsm_paging_request *req = (struct gsm_paging_request *)data;
Holger Hans Peter Freytherfe9da822009-11-17 10:16:46 +0100263 void *cbfn_param;
264 gsm_cbfn *cbfn;
Holger Hans Peter Freytherd3baf412010-12-23 18:19:17 +0100265 int msg;
Harald Welte51cce1e2009-02-10 17:35:04 +0000266
Holger Hans Peter Freytherc50b8362010-04-09 22:02:39 +0200267 LOGP(DPAG, LOGL_INFO, "T3113 expired for request %p (%s)\n",
Harald Welte51cce1e2009-02-10 17:35:04 +0000268 req, req->subscr->imsi);
Holger Freyther4af2b482009-02-14 22:51:03 +0000269
Holger Hans Peter Freytherfe9da822009-11-17 10:16:46 +0100270 /* must be destroyed before calling cbfn, to prevent double free */
Pablo Neira Ayusodfb342c2011-05-06 12:13:10 +0200271 osmo_counter_inc(req->bts->network->stats.paging.expired);
Holger Hans Peter Freytherfe9da822009-11-17 10:16:46 +0100272 cbfn_param = req->cbfn_param;
273 cbfn = req->cbfn;
Holger Hans Peter Freytherd3baf412010-12-23 18:19:17 +0100274
275 /* did we ever manage to page the subscriber */
276 msg = req->attempts > 0 ? GSM_PAGING_EXPIRED : GSM_PAGING_BUSY;
277
278 /* destroy it now. Do not access req afterwards */
Harald Welte51cce1e2009-02-10 17:35:04 +0000279 paging_remove_request(&req->bts->paging, req);
Holger Hans Peter Freytherfe9da822009-11-17 10:16:46 +0100280
Holger Hans Peter Freytherfe9da822009-11-17 10:16:46 +0100281 if (cbfn)
Holger Hans Peter Freytherd3baf412010-12-23 18:19:17 +0100282 cbfn(GSM_HOOK_RR_PAGING, msg, NULL, NULL,
Holger Hans Peter Freytherfe9da822009-11-17 10:16:46 +0100283 cbfn_param);
Harald Welte51cce1e2009-02-10 17:35:04 +0000284}
285
Harald Weltee903edf2009-08-15 03:16:17 +0200286static int _paging_request(struct gsm_bts *bts, struct gsm_subscriber *subscr,
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200287 int type, gsm_cbfn *cbfn, void *data)
Harald Welte09e38af2009-02-16 22:52:23 +0000288{
Holger Freytherceb59b72009-02-06 18:54:00 +0000289 struct gsm_bts_paging_state *bts_entry = &bts->paging;
290 struct gsm_paging_request *req;
Harald Welteb68899d2009-01-06 21:47:18 +0000291
Holger Freyther49314f62009-02-14 23:53:20 +0000292 if (paging_pending_request(bts_entry, subscr)) {
Holger Hans Peter Freytherc50b8362010-04-09 22:02:39 +0200293 LOGP(DPAG, LOGL_INFO, "Paging request already pending for %s\n", subscr->imsi);
Harald Weltee903edf2009-08-15 03:16:17 +0200294 return -EEXIST;
Holger Freyther49314f62009-02-14 23:53:20 +0000295 }
296
Holger Hans Peter Freytherc50b8362010-04-09 22:02:39 +0200297 LOGP(DPAG, LOGL_DEBUG, "Start paging of subscriber %llu on bts %d.\n",
Harald Weltef6cea1d2009-08-08 15:08:19 +0200298 subscr->id, bts->nr);
Harald Welte470ec292009-06-26 20:25:23 +0200299 req = talloc_zero(tall_paging_ctx, struct gsm_paging_request);
Harald Welteb68899d2009-01-06 21:47:18 +0000300 req->subscr = subscr_get(subscr);
301 req->bts = bts;
Harald Welte38c2f132009-01-06 23:10:57 +0000302 req->chan_type = type;
Harald Welte09e38af2009-02-16 22:52:23 +0000303 req->cbfn = cbfn;
304 req->cbfn_param = data;
Harald Welte51cce1e2009-02-10 17:35:04 +0000305 req->T3113.cb = paging_T3113_expired;
306 req->T3113.data = req;
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200307 osmo_timer_schedule(&req->T3113, bts->network->T3113, 0);
Holger Freyther49314f62009-02-14 23:53:20 +0000308 llist_add_tail(&req->entry, &bts_entry->pending_requests);
Holger Hans Peter Freythereb241aa2010-09-06 10:05:23 +0800309 paging_schedule_if_needed(bts_entry);
Harald Weltee903edf2009-08-15 03:16:17 +0200310
311 return 0;
Harald Welteb68899d2009-01-06 21:47:18 +0000312}
Harald Welte763da002009-02-06 12:52:14 +0000313
Harald Weltee903edf2009-08-15 03:16:17 +0200314int paging_request(struct gsm_network *network, struct gsm_subscriber *subscr,
315 int type, gsm_cbfn *cbfn, void *data)
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200316{
317 struct gsm_bts *bts = NULL;
Harald Welte (local)0abaf332009-08-15 11:25:45 +0200318 int num_pages = 0;
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200319
Pablo Neira Ayusodfb342c2011-05-06 12:13:10 +0200320 osmo_counter_inc(network->stats.paging.attempted);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100321
Harald Weltea1b28582009-08-01 19:31:47 +0200322 /* start paging subscriber on all BTS within Location Area */
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200323 do {
Harald Welte (local)0abaf332009-08-15 11:25:45 +0200324 int rc;
325
Holger Freyther04866d42009-03-31 04:35:19 +0200326 bts = gsm_bts_by_lac(network, subscr->lac, bts);
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200327 if (!bts)
328 break;
Harald Welte (local)82ff3972009-12-28 16:36:28 +0100329
330 /* skip all currently inactive TRX */
331 if (!trx_is_usable(bts->c0))
332 continue;
333
Holger Hans Peter Freyther5a081bb2011-04-26 15:44:57 +0200334 /* maybe it is the first time we use it */
335 paging_init_if_needed(bts);
336
Harald Welte (local)0abaf332009-08-15 11:25:45 +0200337 num_pages++;
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200338
Harald Weltee903edf2009-08-15 03:16:17 +0200339 /* Trigger paging, pass any error to caller */
340 rc = _paging_request(bts, subscr, type, cbfn, data);
341 if (rc < 0)
342 return rc;
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200343 } while (1);
Harald Weltee903edf2009-08-15 03:16:17 +0200344
Harald Welte24ff6ee2009-12-22 00:41:05 +0100345 if (num_pages == 0)
Pablo Neira Ayusodfb342c2011-05-06 12:13:10 +0200346 osmo_counter_inc(network->stats.paging.detached);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100347
Harald Welte (local)0abaf332009-08-15 11:25:45 +0200348 return num_pages;
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200349}
350
351
Harald Welte763da002009-02-06 12:52:14 +0000352/* we consciously ignore the type of the request here */
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200353static void _paging_request_stop(struct gsm_bts *bts, struct gsm_subscriber *subscr,
Sylvain Munautc7ff2572010-12-01 21:41:35 +0100354 struct gsm_subscriber_connection *conn,
355 struct msgb *msg)
Harald Welte763da002009-02-06 12:52:14 +0000356{
Holger Freytherceb59b72009-02-06 18:54:00 +0000357 struct gsm_bts_paging_state *bts_entry = &bts->paging;
358 struct gsm_paging_request *req, *req2;
Harald Welte763da002009-02-06 12:52:14 +0000359
Holger Hans Peter Freyther5a081bb2011-04-26 15:44:57 +0200360 paging_init_if_needed(bts);
361
Harald Welte763da002009-02-06 12:52:14 +0000362 llist_for_each_entry_safe(req, req2, &bts_entry->pending_requests,
363 entry) {
Holger Freyther3d949242009-02-06 18:08:18 +0000364 if (req->subscr == subscr) {
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +0800365 if (conn && req->cbfn) {
Holger Hans Peter Freytherc50b8362010-04-09 22:02:39 +0200366 LOGP(DPAG, LOGL_DEBUG, "Stop paging on bts %d, calling cbfn.\n", bts->nr);
Harald Welte09e38af2009-02-16 22:52:23 +0000367 req->cbfn(GSM_HOOK_RR_PAGING, GSM_PAGING_SUCCEEDED,
Sylvain Munautc7ff2572010-12-01 21:41:35 +0100368 msg, conn, req->cbfn_param);
Harald Welte4bfdfe72009-06-10 23:11:52 +0800369 } else
Holger Hans Peter Freytherc50b8362010-04-09 22:02:39 +0200370 LOGP(DPAG, LOGL_DEBUG, "Stop paging on bts %d silently.\n", bts->nr);
Holger Freyther1fd34142009-02-09 23:42:03 +0000371 paging_remove_request(&bts->paging, req);
Holger Freyther3d949242009-02-06 18:08:18 +0000372 break;
373 }
Harald Welte763da002009-02-06 12:52:14 +0000374 }
375}
Holger Freyther392209c2009-02-10 00:06:19 +0000376
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200377/* Stop paging on all other bts' */
378void paging_request_stop(struct gsm_bts *_bts, struct gsm_subscriber *subscr,
Sylvain Munautc7ff2572010-12-01 21:41:35 +0100379 struct gsm_subscriber_connection *conn,
380 struct msgb *msg)
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200381{
382 struct gsm_bts *bts = NULL;
383
Holger Hans Peter Freyther927f0562009-08-21 05:43:44 +0200384 if (_bts)
Sylvain Munautc7ff2572010-12-01 21:41:35 +0100385 _paging_request_stop(_bts, subscr, conn, msg);
Holger Hans Peter Freytherfdac4cc2009-06-10 11:46:58 +0200386
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200387 do {
388 /*
389 * FIXME: Don't use the lac of the subscriber...
390 * as it might have magically changed the lac.. use the
391 * location area of the _bts as reconfiguration of the
392 * network is probably happening less often.
393 */
Holger Hans Peter Freyther927f0562009-08-21 05:43:44 +0200394 bts = gsm_bts_by_lac(subscr->net, subscr->lac, bts);
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200395 if (!bts)
396 break;
397
398 /* Stop paging */
Holger Hans Peter Freythera5811362010-04-30 13:32:05 +0800399 if (bts != _bts)
Sylvain Munautc7ff2572010-12-01 21:41:35 +0100400 _paging_request_stop(bts, subscr, NULL, NULL);
Holger Hans Peter Freyther2c451232009-06-10 02:45:42 +0200401 } while (1);
402}
403
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200404void paging_update_buffer_space(struct gsm_bts *bts, uint16_t free_slots)
Holger Freyther392209c2009-02-10 00:06:19 +0000405{
Holger Hans Peter Freyther5a081bb2011-04-26 15:44:57 +0200406 paging_init_if_needed(bts);
407
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200408 osmo_timer_del(&bts->paging.credit_timer);
Holger Freyther392209c2009-02-10 00:06:19 +0000409 bts->paging.available_slots = free_slots;
Holger Hans Peter Freythereb241aa2010-09-06 10:05:23 +0800410 paging_schedule_if_needed(&bts->paging);
Holger Freyther392209c2009-02-10 00:06:19 +0000411}
Holger Hans Peter Freyther66e14cd2011-04-26 15:52:34 +0200412
413unsigned int paging_pending_requests_nr(struct gsm_bts *bts)
414{
415 unsigned int requests = 0;
416 struct gsm_paging_request *req;
417
418 paging_init_if_needed(bts);
419
420 llist_for_each_entry(req, &bts->paging.pending_requests, entry)
421 ++requests;
422
423 return requests;
424}