Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1 | /* 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 Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 6 | * 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 Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 8 | * (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 Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 13 | * GNU Affero General Public License for more details. |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 14 | * |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * 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 Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 17 | * |
| 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 | |
| 37 | #include <stdio.h> |
| 38 | #include <stdlib.h> |
| 39 | #include <assert.h> |
| 40 | |
| 41 | #include <openbsc/paging.h> |
Harald Welte | f4625b1 | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 42 | #include <osmocore/talloc.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 43 | #include <openbsc/debug.h> |
| 44 | #include <openbsc/signal.h> |
| 45 | #include <openbsc/abis_rsl.h> |
| 46 | #include <openbsc/gsm_data.h> |
Holger Hans Peter Freyther | 8ecec25 | 2010-04-10 00:06:17 +0200 | [diff] [blame] | 47 | #include <openbsc/chan_alloc.h> |
Holger Hans Peter Freyther | 710157a | 2010-06-17 16:43:24 +0800 | [diff] [blame] | 48 | #include <openbsc/bsc_api.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 49 | |
Harald Welte (local) | 8751ee9 | 2009-08-15 02:30:58 +0200 | [diff] [blame] | 50 | void *tall_paging_ctx; |
Harald Welte | a837977 | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 51 | |
Holger Hans Peter Freyther | c814ae9 | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 52 | #define PAGING_TIMER 0, 500000 |
| 53 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 54 | static unsigned int calculate_group(struct gsm_bts *bts, struct gsm_subscriber *subscr) |
| 55 | { |
| 56 | int ccch_conf; |
| 57 | int bs_cc_chans; |
| 58 | int blocks; |
| 59 | unsigned int group; |
| 60 | |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 61 | ccch_conf = bts->si_common.chan_desc.ccch_conf; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 62 | bs_cc_chans = rsl_ccch_conf_to_bs_cc_chans(ccch_conf); |
| 63 | /* code word + 2, as 2 channels equals 0x0 */ |
| 64 | blocks = rsl_number_of_paging_subchannels(bts); |
| 65 | group = get_paging_group(str_to_imsi(subscr->imsi), |
| 66 | bs_cc_chans, blocks); |
| 67 | return group; |
| 68 | } |
| 69 | |
| 70 | /* |
| 71 | * Kill one paging request update the internal list... |
| 72 | */ |
| 73 | static void paging_remove_request(struct gsm_bts_paging_state *paging_bts, |
| 74 | struct gsm_paging_request *to_be_deleted) |
| 75 | { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 76 | bsc_del_timer(&to_be_deleted->T3113); |
| 77 | llist_del(&to_be_deleted->entry); |
| 78 | subscr_put(to_be_deleted->subscr); |
Harald Welte | a837977 | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 79 | talloc_free(to_be_deleted); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static void page_ms(struct gsm_paging_request *request) |
| 83 | { |
| 84 | u_int8_t mi[128]; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 85 | unsigned int mi_len; |
| 86 | unsigned int page_group; |
| 87 | |
Holger Hans Peter Freyther | b6a3394 | 2010-04-09 22:02:39 +0200 | [diff] [blame] | 88 | LOGP(DPAG, LOGL_INFO, "Going to send paging commands: imsi: '%s' tmsi: '0x%x'\n", |
Holger Hans Peter Freyther | 9b7911e | 2009-08-21 14:55:57 +0200 | [diff] [blame] | 89 | request->subscr->imsi, request->subscr->tmsi); |
| 90 | |
| 91 | if (request->subscr->tmsi == GSM_RESERVED_TMSI) |
| 92 | mi_len = gsm48_generate_mid_from_imsi(mi, request->subscr->imsi); |
| 93 | else |
| 94 | mi_len = gsm48_generate_mid_from_tmsi(mi, request->subscr->tmsi); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 95 | |
| 96 | page_group = calculate_group(request->bts, request->subscr); |
Holger Hans Peter Freyther | 897ad9a | 2010-06-16 14:10:45 +0800 | [diff] [blame] | 97 | gsm0808_page(request->bts, page_group, mi_len, mi, request->chan_type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 98 | } |
| 99 | |
Holger Hans Peter Freyther | c814ae9 | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 100 | static void paging_schedule_if_needed(struct gsm_bts_paging_state *paging_bts) |
| 101 | { |
| 102 | if (llist_empty(&paging_bts->pending_requests)) |
| 103 | return; |
| 104 | |
| 105 | if (!bsc_timer_pending(&paging_bts->work_timer)) |
| 106 | bsc_schedule_timer(&paging_bts->work_timer, PAGING_TIMER); |
| 107 | } |
| 108 | |
| 109 | |
Holger Hans Peter Freyther | e791d95 | 2010-04-20 10:59:33 +0800 | [diff] [blame] | 110 | static void paging_handle_pending_requests(struct gsm_bts_paging_state *paging_bts); |
Holger Hans Peter Freyther | e7be13c | 2010-04-19 19:41:26 +0800 | [diff] [blame] | 111 | static void paging_give_credit(void *data) |
| 112 | { |
| 113 | struct gsm_bts_paging_state *paging_bts = data; |
| 114 | |
| 115 | LOGP(DPAG, LOGL_NOTICE, "No slots available on bts nr %d\n", paging_bts->bts->nr); |
| 116 | paging_bts->available_slots = 20; |
Holger Hans Peter Freyther | e791d95 | 2010-04-20 10:59:33 +0800 | [diff] [blame] | 117 | paging_handle_pending_requests(paging_bts); |
Holger Hans Peter Freyther | e7be13c | 2010-04-19 19:41:26 +0800 | [diff] [blame] | 118 | } |
| 119 | |
Holger Hans Peter Freyther | 3112f67 | 2010-09-06 10:11:25 +0800 | [diff] [blame] | 120 | static int can_send_pag_req(struct gsm_bts *bts, int rsl_type) |
| 121 | { |
| 122 | struct pchan_load pl; |
| 123 | int count; |
| 124 | |
| 125 | memset(&pl, 0, sizeof(pl)); |
| 126 | bts_chan_load(&pl, bts); |
| 127 | |
| 128 | switch (rsl_type) { |
| 129 | case RSL_CHANNEED_TCH_F: |
Holger Hans Peter Freyther | 3112f67 | 2010-09-06 10:11:25 +0800 | [diff] [blame] | 130 | case RSL_CHANNEED_TCH_ForH: |
Holger Hans Peter Freyther | 343b945 | 2010-04-20 17:15:21 +0800 | [diff] [blame] | 131 | goto count_tch; |
Holger Hans Peter Freyther | 3112f67 | 2010-09-06 10:11:25 +0800 | [diff] [blame] | 132 | break; |
| 133 | case RSL_CHANNEED_SDCCH: |
| 134 | goto count_sdcch; |
| 135 | break; |
| 136 | case RSL_CHANNEED_ANY: |
| 137 | default: |
| 138 | if (bts->network->pag_any_tch) |
Holger Hans Peter Freyther | 343b945 | 2010-04-20 17:15:21 +0800 | [diff] [blame] | 139 | goto count_tch; |
Holger Hans Peter Freyther | 3112f67 | 2010-09-06 10:11:25 +0800 | [diff] [blame] | 140 | else |
| 141 | goto count_sdcch; |
| 142 | break; |
| 143 | } |
| 144 | |
| 145 | return 0; |
| 146 | |
| 147 | /* could available SDCCH */ |
| 148 | count_sdcch: |
| 149 | count = 0; |
| 150 | count += pl.pchan[GSM_PCHAN_SDCCH8_SACCH8C].total |
| 151 | - pl.pchan[GSM_PCHAN_SDCCH8_SACCH8C].used; |
| 152 | count += pl.pchan[GSM_PCHAN_CCCH_SDCCH4].total |
| 153 | - pl.pchan[GSM_PCHAN_CCCH_SDCCH4].used; |
| 154 | return bts->paging.free_chans_need > count; |
Holger Hans Peter Freyther | 343b945 | 2010-04-20 17:15:21 +0800 | [diff] [blame] | 155 | |
| 156 | count_tch: |
| 157 | count = 0; |
| 158 | count += pl.pchan[GSM_PCHAN_TCH_F].total |
| 159 | - pl.pchan[GSM_PCHAN_TCH_F].used; |
| 160 | if (bts->network->neci) |
| 161 | count += pl.pchan[GSM_PCHAN_TCH_H].total |
| 162 | - pl.pchan[GSM_PCHAN_TCH_H].used; |
| 163 | return bts->paging.free_chans_need > count; |
Holger Hans Peter Freyther | 3112f67 | 2010-09-06 10:11:25 +0800 | [diff] [blame] | 164 | } |
| 165 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 166 | /* |
| 167 | * This is kicked by the periodic PAGING LOAD Indicator |
| 168 | * coming from abis_rsl.c |
| 169 | * |
| 170 | * We attempt to iterate once over the list of items but |
| 171 | * only upto available_slots. |
| 172 | */ |
| 173 | static void paging_handle_pending_requests(struct gsm_bts_paging_state *paging_bts) |
| 174 | { |
Holger Hans Peter Freyther | c814ae9 | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 175 | struct gsm_paging_request *request = NULL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 176 | |
| 177 | /* |
| 178 | * Determine if the pending_requests list is empty and |
| 179 | * return then. |
| 180 | */ |
| 181 | if (llist_empty(&paging_bts->pending_requests)) { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 182 | /* since the list is empty, no need to reschedule the timer */ |
| 183 | return; |
| 184 | } |
| 185 | |
Holger Hans Peter Freyther | 5fd943c | 2010-04-09 18:38:06 +0200 | [diff] [blame] | 186 | /* |
Holger Hans Peter Freyther | e7be13c | 2010-04-19 19:41:26 +0800 | [diff] [blame] | 187 | * In case the BTS does not provide us with load indication and we |
| 188 | * ran out of slots, call an autofill routine. It might be that the |
| 189 | * BTS did not like our paging messages and then we have counted down |
| 190 | * to zero and we do not get any messages. |
Holger Hans Peter Freyther | 5fd943c | 2010-04-09 18:38:06 +0200 | [diff] [blame] | 191 | */ |
| 192 | if (paging_bts->available_slots == 0) { |
Holger Hans Peter Freyther | e7be13c | 2010-04-19 19:41:26 +0800 | [diff] [blame] | 193 | paging_bts->credit_timer.cb = paging_give_credit; |
| 194 | paging_bts->credit_timer.data = paging_bts; |
| 195 | bsc_schedule_timer(&paging_bts->credit_timer, 5, 0); |
| 196 | return; |
Holger Hans Peter Freyther | 5fd943c | 2010-04-09 18:38:06 +0200 | [diff] [blame] | 197 | } |
| 198 | |
Holger Hans Peter Freyther | c814ae9 | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 199 | request = llist_entry(paging_bts->pending_requests.next, |
| 200 | struct gsm_paging_request, entry); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 201 | |
Holger Hans Peter Freyther | 3112f67 | 2010-09-06 10:11:25 +0800 | [diff] [blame] | 202 | /* we need to determine the number of free channels */ |
| 203 | if (paging_bts->free_chans_need != -1) { |
| 204 | if (can_send_pag_req(request->bts, request->chan_type) != 0) |
| 205 | goto skip_paging; |
| 206 | } |
| 207 | |
Holger Hans Peter Freyther | c814ae9 | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 208 | /* handle the paging request now */ |
| 209 | page_ms(request); |
| 210 | paging_bts->available_slots--; |
Holger Hans Peter Freyther | ab2a933 | 2010-12-23 18:19:17 +0100 | [diff] [blame] | 211 | request->attempts++; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 212 | |
Holger Hans Peter Freyther | c814ae9 | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 213 | /* take the current and add it to the back */ |
| 214 | llist_del(&request->entry); |
| 215 | llist_add_tail(&request->entry, &paging_bts->pending_requests); |
Holger Hans Peter Freyther | 5ded191 | 2010-04-09 21:53:35 +0200 | [diff] [blame] | 216 | |
Holger Hans Peter Freyther | 3112f67 | 2010-09-06 10:11:25 +0800 | [diff] [blame] | 217 | skip_paging: |
Holger Hans Peter Freyther | c814ae9 | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 218 | bsc_schedule_timer(&paging_bts->work_timer, PAGING_TIMER); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static void paging_worker(void *data) |
| 222 | { |
| 223 | struct gsm_bts_paging_state *paging_bts = data; |
| 224 | |
| 225 | paging_handle_pending_requests(paging_bts); |
| 226 | } |
| 227 | |
| 228 | void paging_init(struct gsm_bts *bts) |
| 229 | { |
| 230 | bts->paging.bts = bts; |
| 231 | INIT_LLIST_HEAD(&bts->paging.pending_requests); |
| 232 | bts->paging.work_timer.cb = paging_worker; |
| 233 | bts->paging.work_timer.data = &bts->paging; |
| 234 | |
| 235 | /* Large number, until we get a proper message */ |
Holger Hans Peter Freyther | c13d32f | 2010-04-09 22:55:55 +0200 | [diff] [blame] | 236 | bts->paging.available_slots = 20; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | static int paging_pending_request(struct gsm_bts_paging_state *bts, |
| 240 | struct gsm_subscriber *subscr) { |
| 241 | struct gsm_paging_request *req; |
| 242 | |
| 243 | llist_for_each_entry(req, &bts->pending_requests, entry) { |
| 244 | if (subscr == req->subscr) |
| 245 | return 1; |
| 246 | } |
| 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | static void paging_T3113_expired(void *data) |
| 252 | { |
| 253 | struct gsm_paging_request *req = (struct gsm_paging_request *)data; |
Holger Hans Peter Freyther | 353e9b6 | 2009-11-17 10:16:46 +0100 | [diff] [blame] | 254 | void *cbfn_param; |
| 255 | gsm_cbfn *cbfn; |
Holger Hans Peter Freyther | ab2a933 | 2010-12-23 18:19:17 +0100 | [diff] [blame] | 256 | int msg; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 257 | |
Holger Hans Peter Freyther | b6a3394 | 2010-04-09 22:02:39 +0200 | [diff] [blame] | 258 | LOGP(DPAG, LOGL_INFO, "T3113 expired for request %p (%s)\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 259 | req, req->subscr->imsi); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 260 | |
Holger Hans Peter Freyther | 353e9b6 | 2009-11-17 10:16:46 +0100 | [diff] [blame] | 261 | /* must be destroyed before calling cbfn, to prevent double free */ |
Holger Hans Peter Freyther | fad51da | 2010-04-08 16:48:46 +0200 | [diff] [blame] | 262 | counter_inc(req->bts->network->stats.paging.expired); |
Holger Hans Peter Freyther | 353e9b6 | 2009-11-17 10:16:46 +0100 | [diff] [blame] | 263 | cbfn_param = req->cbfn_param; |
| 264 | cbfn = req->cbfn; |
Holger Hans Peter Freyther | ab2a933 | 2010-12-23 18:19:17 +0100 | [diff] [blame] | 265 | |
| 266 | /* did we ever manage to page the subscriber */ |
| 267 | msg = req->attempts > 0 ? GSM_PAGING_EXPIRED : GSM_PAGING_BUSY; |
| 268 | |
| 269 | /* destroy it now. Do not access req afterwards */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 270 | paging_remove_request(&req->bts->paging, req); |
Holger Hans Peter Freyther | 353e9b6 | 2009-11-17 10:16:46 +0100 | [diff] [blame] | 271 | |
Holger Hans Peter Freyther | 353e9b6 | 2009-11-17 10:16:46 +0100 | [diff] [blame] | 272 | if (cbfn) |
Holger Hans Peter Freyther | ab2a933 | 2010-12-23 18:19:17 +0100 | [diff] [blame] | 273 | cbfn(GSM_HOOK_RR_PAGING, msg, NULL, NULL, |
Holger Hans Peter Freyther | 353e9b6 | 2009-11-17 10:16:46 +0100 | [diff] [blame] | 274 | cbfn_param); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 275 | } |
| 276 | |
Harald Welte | d363c95 | 2009-08-15 03:16:17 +0200 | [diff] [blame] | 277 | static int _paging_request(struct gsm_bts *bts, struct gsm_subscriber *subscr, |
Holger Hans Peter Freyther | 13d472d | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 278 | int type, gsm_cbfn *cbfn, void *data) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 279 | { |
| 280 | struct gsm_bts_paging_state *bts_entry = &bts->paging; |
| 281 | struct gsm_paging_request *req; |
| 282 | |
| 283 | if (paging_pending_request(bts_entry, subscr)) { |
Holger Hans Peter Freyther | b6a3394 | 2010-04-09 22:02:39 +0200 | [diff] [blame] | 284 | LOGP(DPAG, LOGL_INFO, "Paging request already pending for %s\n", subscr->imsi); |
Harald Welte | d363c95 | 2009-08-15 03:16:17 +0200 | [diff] [blame] | 285 | return -EEXIST; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 286 | } |
| 287 | |
Holger Hans Peter Freyther | b6a3394 | 2010-04-09 22:02:39 +0200 | [diff] [blame] | 288 | LOGP(DPAG, LOGL_DEBUG, "Start paging of subscriber %llu on bts %d.\n", |
Harald Welte | cd97c21 | 2009-08-08 15:08:19 +0200 | [diff] [blame] | 289 | subscr->id, bts->nr); |
Harald Welte | 857e00d | 2009-06-26 20:25:23 +0200 | [diff] [blame] | 290 | req = talloc_zero(tall_paging_ctx, struct gsm_paging_request); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 291 | req->subscr = subscr_get(subscr); |
| 292 | req->bts = bts; |
| 293 | req->chan_type = type; |
| 294 | req->cbfn = cbfn; |
| 295 | req->cbfn_param = data; |
| 296 | req->T3113.cb = paging_T3113_expired; |
| 297 | req->T3113.data = req; |
Holger Hans Peter Freyther | 4b9042a | 2009-11-21 21:48:53 +0100 | [diff] [blame] | 298 | bsc_schedule_timer(&req->T3113, bts->network->T3113, 0); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 299 | llist_add_tail(&req->entry, &bts_entry->pending_requests); |
Holger Hans Peter Freyther | c814ae9 | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 300 | paging_schedule_if_needed(bts_entry); |
Harald Welte | d363c95 | 2009-08-15 03:16:17 +0200 | [diff] [blame] | 301 | |
| 302 | return 0; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 303 | } |
| 304 | |
Harald Welte | d363c95 | 2009-08-15 03:16:17 +0200 | [diff] [blame] | 305 | int paging_request(struct gsm_network *network, struct gsm_subscriber *subscr, |
| 306 | int type, gsm_cbfn *cbfn, void *data) |
Holger Hans Peter Freyther | 13d472d | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 307 | { |
| 308 | struct gsm_bts *bts = NULL; |
Harald Welte (local) | dec08ee | 2009-08-15 11:25:45 +0200 | [diff] [blame] | 309 | int num_pages = 0; |
Holger Hans Peter Freyther | 13d472d | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 310 | |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 311 | counter_inc(network->stats.paging.attempted); |
Harald Welte | 3edc5a9 | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 312 | |
Harald Welte | 2a3a81b | 2009-08-01 19:31:47 +0200 | [diff] [blame] | 313 | /* start paging subscriber on all BTS within Location Area */ |
Holger Hans Peter Freyther | 13d472d | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 314 | do { |
Harald Welte (local) | dec08ee | 2009-08-15 11:25:45 +0200 | [diff] [blame] | 315 | int rc; |
| 316 | |
Holger Freyther | 93795ac | 2009-03-31 04:35:19 +0200 | [diff] [blame] | 317 | bts = gsm_bts_by_lac(network, subscr->lac, bts); |
Holger Hans Peter Freyther | 13d472d | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 318 | if (!bts) |
| 319 | break; |
Harald Welte (local) | 43db2bf | 2009-12-28 16:36:28 +0100 | [diff] [blame] | 320 | |
| 321 | /* skip all currently inactive TRX */ |
| 322 | if (!trx_is_usable(bts->c0)) |
| 323 | continue; |
| 324 | |
Harald Welte (local) | dec08ee | 2009-08-15 11:25:45 +0200 | [diff] [blame] | 325 | num_pages++; |
Holger Hans Peter Freyther | 13d472d | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 326 | |
Harald Welte | d363c95 | 2009-08-15 03:16:17 +0200 | [diff] [blame] | 327 | /* Trigger paging, pass any error to caller */ |
| 328 | rc = _paging_request(bts, subscr, type, cbfn, data); |
| 329 | if (rc < 0) |
| 330 | return rc; |
Holger Hans Peter Freyther | 13d472d | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 331 | } while (1); |
Harald Welte | d363c95 | 2009-08-15 03:16:17 +0200 | [diff] [blame] | 332 | |
Harald Welte | 3edc5a9 | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 333 | if (num_pages == 0) |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 334 | counter_inc(network->stats.paging.detached); |
Harald Welte | 3edc5a9 | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 335 | |
Harald Welte (local) | dec08ee | 2009-08-15 11:25:45 +0200 | [diff] [blame] | 336 | return num_pages; |
Holger Hans Peter Freyther | 13d472d | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 340 | /* we consciously ignore the type of the request here */ |
Holger Hans Peter Freyther | 13d472d | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 341 | static void _paging_request_stop(struct gsm_bts *bts, struct gsm_subscriber *subscr, |
Sylvain Munaut | b7b6e78 | 2010-12-01 21:41:35 +0100 | [diff] [blame] | 342 | struct gsm_subscriber_connection *conn, |
| 343 | struct msgb *msg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 344 | { |
| 345 | struct gsm_bts_paging_state *bts_entry = &bts->paging; |
| 346 | struct gsm_paging_request *req, *req2; |
| 347 | |
| 348 | llist_for_each_entry_safe(req, req2, &bts_entry->pending_requests, |
| 349 | entry) { |
| 350 | if (req->subscr == subscr) { |
Holger Hans Peter Freyther | d3aaf66 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 351 | if (conn && req->cbfn) { |
Holger Hans Peter Freyther | b6a3394 | 2010-04-09 22:02:39 +0200 | [diff] [blame] | 352 | LOGP(DPAG, LOGL_DEBUG, "Stop paging on bts %d, calling cbfn.\n", bts->nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 353 | req->cbfn(GSM_HOOK_RR_PAGING, GSM_PAGING_SUCCEEDED, |
Sylvain Munaut | b7b6e78 | 2010-12-01 21:41:35 +0100 | [diff] [blame] | 354 | msg, conn, req->cbfn_param); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 355 | } else |
Holger Hans Peter Freyther | b6a3394 | 2010-04-09 22:02:39 +0200 | [diff] [blame] | 356 | LOGP(DPAG, LOGL_DEBUG, "Stop paging on bts %d silently.\n", bts->nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 357 | paging_remove_request(&bts->paging, req); |
| 358 | break; |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
Holger Hans Peter Freyther | 13d472d | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 363 | /* Stop paging on all other bts' */ |
| 364 | void paging_request_stop(struct gsm_bts *_bts, struct gsm_subscriber *subscr, |
Sylvain Munaut | b7b6e78 | 2010-12-01 21:41:35 +0100 | [diff] [blame] | 365 | struct gsm_subscriber_connection *conn, |
| 366 | struct msgb *msg) |
Holger Hans Peter Freyther | 13d472d | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 367 | { |
| 368 | struct gsm_bts *bts = NULL; |
| 369 | |
Holger Hans Peter Freyther | b78507a | 2009-08-21 05:43:44 +0200 | [diff] [blame] | 370 | if (_bts) |
Sylvain Munaut | b7b6e78 | 2010-12-01 21:41:35 +0100 | [diff] [blame] | 371 | _paging_request_stop(_bts, subscr, conn, msg); |
Holger Hans Peter Freyther | c51e333 | 2009-06-10 11:46:58 +0200 | [diff] [blame] | 372 | |
Holger Hans Peter Freyther | 13d472d | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 373 | do { |
| 374 | /* |
| 375 | * FIXME: Don't use the lac of the subscriber... |
| 376 | * as it might have magically changed the lac.. use the |
| 377 | * location area of the _bts as reconfiguration of the |
| 378 | * network is probably happening less often. |
| 379 | */ |
Holger Hans Peter Freyther | b78507a | 2009-08-21 05:43:44 +0200 | [diff] [blame] | 380 | bts = gsm_bts_by_lac(subscr->net, subscr->lac, bts); |
Holger Hans Peter Freyther | 13d472d | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 381 | if (!bts) |
| 382 | break; |
| 383 | |
| 384 | /* Stop paging */ |
Holger Hans Peter Freyther | 8c99434 | 2010-04-30 13:32:05 +0800 | [diff] [blame] | 385 | if (bts != _bts) |
Sylvain Munaut | b7b6e78 | 2010-12-01 21:41:35 +0100 | [diff] [blame] | 386 | _paging_request_stop(bts, subscr, NULL, NULL); |
Holger Hans Peter Freyther | 13d472d | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 387 | } while (1); |
| 388 | } |
| 389 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 390 | void paging_update_buffer_space(struct gsm_bts *bts, u_int16_t free_slots) |
| 391 | { |
Holger Hans Peter Freyther | e7be13c | 2010-04-19 19:41:26 +0800 | [diff] [blame] | 392 | bsc_del_timer(&bts->paging.credit_timer); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 393 | bts->paging.available_slots = free_slots; |
Holger Hans Peter Freyther | c814ae9 | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 394 | paging_schedule_if_needed(&bts->paging); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 395 | } |