Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 1 | /* Paging helper and manager.... */ |
Holger Hans Peter Freyther | dc03096 | 2013-01-07 17:30:13 +0100 | [diff] [blame] | 2 | /* (C) 2009,2013 by Holger Hans Peter Freyther <zecke@selfish.org> |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 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 | b68899d | 2009-01-06 21:47:18 +0000 | [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 | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 13 | * GNU Affero General Public License for more details. |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 14 | * |
Harald Welte | 9af6ddf | 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 | b68899d | 2009-01-06 21:47:18 +0000 | [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 | |
Harald Welte | 2f1311b | 2009-01-06 23:50:39 +0000 | [diff] [blame] | 37 | #include <stdio.h> |
| 38 | #include <stdlib.h> |
Holger Freyther | e36e15e | 2009-02-14 18:05:03 +0000 | [diff] [blame] | 39 | #include <assert.h> |
Harald Welte | 2f1311b | 2009-01-06 23:50:39 +0000 | [diff] [blame] | 40 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 41 | #include <osmocom/core/talloc.h> |
Harald Welte | 457a081 | 2011-06-26 14:21:43 +0200 | [diff] [blame] | 42 | #include <osmocom/gsm/gsm48.h> |
Harald Welte | bc82f92 | 2011-06-26 14:41:58 +0200 | [diff] [blame] | 43 | #include <osmocom/gsm/gsm0502.h> |
Harald Welte | 457a081 | 2011-06-26 14:21:43 +0200 | [diff] [blame] | 44 | |
| 45 | #include <openbsc/paging.h> |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 46 | #include <openbsc/debug.h> |
Holger Freyther | 4af2b48 | 2009-02-14 22:51:03 +0000 | [diff] [blame] | 47 | #include <openbsc/signal.h> |
Harald Welte | 2f1311b | 2009-01-06 23:50:39 +0000 | [diff] [blame] | 48 | #include <openbsc/abis_rsl.h> |
Holger Freyther | ceb59b7 | 2009-02-06 18:54:00 +0000 | [diff] [blame] | 49 | #include <openbsc/gsm_data.h> |
Holger Hans Peter Freyther | ef81178 | 2010-04-10 00:06:17 +0200 | [diff] [blame] | 50 | #include <openbsc/chan_alloc.h> |
Holger Hans Peter Freyther | c6bb3c4 | 2010-06-17 16:43:24 +0800 | [diff] [blame] | 51 | #include <openbsc/bsc_api.h> |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 52 | |
Harald Welte (local) | d19e58b | 2009-08-15 02:30:58 +0200 | [diff] [blame] | 53 | void *tall_paging_ctx; |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 54 | |
Holger Hans Peter Freyther | eb241aa | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 55 | #define PAGING_TIMER 0, 500000 |
| 56 | |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 57 | /* |
| 58 | * Kill one paging request update the internal list... |
| 59 | */ |
Holger Freyther | 1fd3414 | 2009-02-09 23:42:03 +0000 | [diff] [blame] | 60 | static void paging_remove_request(struct gsm_bts_paging_state *paging_bts, |
Holger Freyther | ceb59b7 | 2009-02-06 18:54:00 +0000 | [diff] [blame] | 61 | struct gsm_paging_request *to_be_deleted) |
Holger Freyther | 3d94924 | 2009-02-06 18:08:18 +0000 | [diff] [blame] | 62 | { |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 63 | osmo_timer_del(&to_be_deleted->T3113); |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 64 | llist_del(&to_be_deleted->entry); |
Harald Welte | 51cce1e | 2009-02-10 17:35:04 +0000 | [diff] [blame] | 65 | subscr_put(to_be_deleted->subscr); |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 66 | talloc_free(to_be_deleted); |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Holger Freyther | 33ba752 | 2009-02-06 22:33:25 +0000 | [diff] [blame] | 69 | static void page_ms(struct gsm_paging_request *request) |
| 70 | { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 71 | uint8_t mi[128]; |
Harald Welte | 2f1311b | 2009-01-06 23:50:39 +0000 | [diff] [blame] | 72 | unsigned int mi_len; |
Holger Freyther | 33ba752 | 2009-02-06 22:33:25 +0000 | [diff] [blame] | 73 | unsigned int page_group; |
Harald Welte | 1cf43ec | 2011-06-26 14:43:46 +0200 | [diff] [blame] | 74 | struct gsm_bts *bts = request->bts; |
Holger Freyther | 33ba752 | 2009-02-06 22:33:25 +0000 | [diff] [blame] | 75 | |
Holger Hans Peter Freyther | 10049bc | 2012-12-22 19:27:27 +0100 | [diff] [blame] | 76 | /* the bts is down.. we will just wait for the paging to expire */ |
| 77 | if (!bts->oml_link) |
| 78 | return; |
| 79 | |
Neels Hofmeyr | f13b3c9 | 2017-02-17 17:05:40 +0100 | [diff] [blame^] | 80 | log_set_context(LOGGING_CTX_VLR_SUBSCR, request->subscr); |
Holger Hans Peter Freyther | b7ccac4 | 2014-12-28 15:00:36 +0100 | [diff] [blame] | 81 | |
Max | 8dc8f23 | 2017-02-09 19:13:02 +0100 | [diff] [blame] | 82 | LOGP(DPAG, LOGL_INFO, "Going to send paging commands: imsi: %s tmsi: " |
| 83 | "0x%x for ch. type %d (attempt %d)\n", request->subscr->imsi, |
| 84 | request->subscr->tmsi, request->chan_type, request->attempts); |
Holger Hans Peter Freyther | b28285d | 2009-08-21 14:55:57 +0200 | [diff] [blame] | 85 | |
| 86 | if (request->subscr->tmsi == GSM_RESERVED_TMSI) |
| 87 | mi_len = gsm48_generate_mid_from_imsi(mi, request->subscr->imsi); |
| 88 | else |
| 89 | mi_len = gsm48_generate_mid_from_tmsi(mi, request->subscr->tmsi); |
Holger Freyther | 33ba752 | 2009-02-06 22:33:25 +0000 | [diff] [blame] | 90 | |
Harald Welte | 1cf43ec | 2011-06-26 14:43:46 +0200 | [diff] [blame] | 91 | page_group = gsm0502_calc_paging_group(&bts->si_common.chan_desc, |
| 92 | str_to_imsi(request->subscr->imsi)); |
| 93 | gsm0808_page(bts, page_group, mi_len, mi, request->chan_type); |
Neels Hofmeyr | f13b3c9 | 2017-02-17 17:05:40 +0100 | [diff] [blame^] | 94 | log_set_context(LOGGING_CTX_VLR_SUBSCR, NULL); |
Holger Freyther | 33ba752 | 2009-02-06 22:33:25 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Holger Hans Peter Freyther | eb241aa | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 97 | static void paging_schedule_if_needed(struct gsm_bts_paging_state *paging_bts) |
| 98 | { |
| 99 | if (llist_empty(&paging_bts->pending_requests)) |
| 100 | return; |
| 101 | |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 102 | if (!osmo_timer_pending(&paging_bts->work_timer)) |
| 103 | osmo_timer_schedule(&paging_bts->work_timer, PAGING_TIMER); |
Holger Hans Peter Freyther | eb241aa | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | |
Holger Hans Peter Freyther | 78fab29 | 2010-04-20 10:59:33 +0800 | [diff] [blame] | 107 | static void paging_handle_pending_requests(struct gsm_bts_paging_state *paging_bts); |
Holger Hans Peter Freyther | 6410d93 | 2010-04-19 19:41:26 +0800 | [diff] [blame] | 108 | static void paging_give_credit(void *data) |
| 109 | { |
| 110 | struct gsm_bts_paging_state *paging_bts = data; |
| 111 | |
| 112 | LOGP(DPAG, LOGL_NOTICE, "No slots available on bts nr %d\n", paging_bts->bts->nr); |
| 113 | paging_bts->available_slots = 20; |
Holger Hans Peter Freyther | 78fab29 | 2010-04-20 10:59:33 +0800 | [diff] [blame] | 114 | paging_handle_pending_requests(paging_bts); |
Holger Hans Peter Freyther | 6410d93 | 2010-04-19 19:41:26 +0800 | [diff] [blame] | 115 | } |
| 116 | |
Holger Hans Peter Freyther | e66bf1f | 2010-09-06 10:11:25 +0800 | [diff] [blame] | 117 | static int can_send_pag_req(struct gsm_bts *bts, int rsl_type) |
| 118 | { |
| 119 | struct pchan_load pl; |
| 120 | int count; |
| 121 | |
| 122 | memset(&pl, 0, sizeof(pl)); |
Neels Hofmeyr | 2afffd5 | 2016-09-25 17:01:20 +0200 | [diff] [blame] | 123 | bts_chan_load(&pl, bts); |
Holger Hans Peter Freyther | e66bf1f | 2010-09-06 10:11:25 +0800 | [diff] [blame] | 124 | |
| 125 | switch (rsl_type) { |
| 126 | case RSL_CHANNEED_TCH_F: |
Holger Hans Peter Freyther | e66bf1f | 2010-09-06 10:11:25 +0800 | [diff] [blame] | 127 | case RSL_CHANNEED_TCH_ForH: |
Holger Hans Peter Freyther | 2e4447b | 2010-04-20 17:15:21 +0800 | [diff] [blame] | 128 | goto count_tch; |
Holger Hans Peter Freyther | e66bf1f | 2010-09-06 10:11:25 +0800 | [diff] [blame] | 129 | break; |
| 130 | case RSL_CHANNEED_SDCCH: |
| 131 | goto count_sdcch; |
| 132 | break; |
| 133 | case RSL_CHANNEED_ANY: |
| 134 | default: |
| 135 | if (bts->network->pag_any_tch) |
Holger Hans Peter Freyther | 2e4447b | 2010-04-20 17:15:21 +0800 | [diff] [blame] | 136 | goto count_tch; |
Holger Hans Peter Freyther | e66bf1f | 2010-09-06 10:11:25 +0800 | [diff] [blame] | 137 | else |
| 138 | goto count_sdcch; |
| 139 | break; |
| 140 | } |
| 141 | |
| 142 | return 0; |
| 143 | |
| 144 | /* could available SDCCH */ |
| 145 | count_sdcch: |
| 146 | count = 0; |
| 147 | count += pl.pchan[GSM_PCHAN_SDCCH8_SACCH8C].total |
| 148 | - pl.pchan[GSM_PCHAN_SDCCH8_SACCH8C].used; |
| 149 | count += pl.pchan[GSM_PCHAN_CCCH_SDCCH4].total |
| 150 | - pl.pchan[GSM_PCHAN_CCCH_SDCCH4].used; |
| 151 | return bts->paging.free_chans_need > count; |
Holger Hans Peter Freyther | 2e4447b | 2010-04-20 17:15:21 +0800 | [diff] [blame] | 152 | |
| 153 | count_tch: |
| 154 | count = 0; |
| 155 | count += pl.pchan[GSM_PCHAN_TCH_F].total |
| 156 | - pl.pchan[GSM_PCHAN_TCH_F].used; |
| 157 | if (bts->network->neci) |
| 158 | count += pl.pchan[GSM_PCHAN_TCH_H].total |
| 159 | - pl.pchan[GSM_PCHAN_TCH_H].used; |
| 160 | return bts->paging.free_chans_need > count; |
Holger Hans Peter Freyther | e66bf1f | 2010-09-06 10:11:25 +0800 | [diff] [blame] | 161 | } |
| 162 | |
Holger Freyther | e36e15e | 2009-02-14 18:05:03 +0000 | [diff] [blame] | 163 | /* |
| 164 | * This is kicked by the periodic PAGING LOAD Indicator |
| 165 | * coming from abis_rsl.c |
| 166 | * |
| 167 | * We attempt to iterate once over the list of items but |
| 168 | * only upto available_slots. |
| 169 | */ |
Holger Freyther | b1ffbb6 | 2009-02-11 01:49:15 +0000 | [diff] [blame] | 170 | static void paging_handle_pending_requests(struct gsm_bts_paging_state *paging_bts) |
| 171 | { |
Holger Hans Peter Freyther | eb241aa | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 172 | struct gsm_paging_request *request = NULL; |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 173 | |
Holger Freyther | e36e15e | 2009-02-14 18:05:03 +0000 | [diff] [blame] | 174 | /* |
| 175 | * Determine if the pending_requests list is empty and |
| 176 | * return then. |
| 177 | */ |
Harald Welte | 75a1fa8 | 2009-02-17 01:39:41 +0000 | [diff] [blame] | 178 | if (llist_empty(&paging_bts->pending_requests)) { |
Harald Welte | 75a1fa8 | 2009-02-17 01:39:41 +0000 | [diff] [blame] | 179 | /* since the list is empty, no need to reschedule the timer */ |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 180 | return; |
| 181 | } |
| 182 | |
Holger Hans Peter Freyther | 19722d4 | 2010-04-09 18:38:06 +0200 | [diff] [blame] | 183 | /* |
Holger Hans Peter Freyther | 6410d93 | 2010-04-19 19:41:26 +0800 | [diff] [blame] | 184 | * In case the BTS does not provide us with load indication and we |
| 185 | * ran out of slots, call an autofill routine. It might be that the |
| 186 | * BTS did not like our paging messages and then we have counted down |
| 187 | * to zero and we do not get any messages. |
Holger Hans Peter Freyther | 19722d4 | 2010-04-09 18:38:06 +0200 | [diff] [blame] | 188 | */ |
| 189 | if (paging_bts->available_slots == 0) { |
Holger Hans Peter Freyther | 6410d93 | 2010-04-19 19:41:26 +0800 | [diff] [blame] | 190 | paging_bts->credit_timer.cb = paging_give_credit; |
| 191 | paging_bts->credit_timer.data = paging_bts; |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 192 | osmo_timer_schedule(&paging_bts->credit_timer, 5, 0); |
Holger Hans Peter Freyther | 6410d93 | 2010-04-19 19:41:26 +0800 | [diff] [blame] | 193 | return; |
Holger Hans Peter Freyther | 19722d4 | 2010-04-09 18:38:06 +0200 | [diff] [blame] | 194 | } |
| 195 | |
Holger Hans Peter Freyther | eb241aa | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 196 | request = llist_entry(paging_bts->pending_requests.next, |
| 197 | struct gsm_paging_request, entry); |
Holger Freyther | e36e15e | 2009-02-14 18:05:03 +0000 | [diff] [blame] | 198 | |
Holger Hans Peter Freyther | e66bf1f | 2010-09-06 10:11:25 +0800 | [diff] [blame] | 199 | /* we need to determine the number of free channels */ |
| 200 | if (paging_bts->free_chans_need != -1) { |
| 201 | if (can_send_pag_req(request->bts, request->chan_type) != 0) |
| 202 | goto skip_paging; |
| 203 | } |
| 204 | |
Holger Hans Peter Freyther | eb241aa | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 205 | /* handle the paging request now */ |
| 206 | page_ms(request); |
| 207 | paging_bts->available_slots--; |
Holger Hans Peter Freyther | d3baf41 | 2010-12-23 18:19:17 +0100 | [diff] [blame] | 208 | request->attempts++; |
Holger Freyther | e36e15e | 2009-02-14 18:05:03 +0000 | [diff] [blame] | 209 | |
Holger Hans Peter Freyther | eb241aa | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 210 | /* take the current and add it to the back */ |
| 211 | llist_del(&request->entry); |
| 212 | llist_add_tail(&request->entry, &paging_bts->pending_requests); |
Holger Hans Peter Freyther | 754e801 | 2010-04-09 21:53:35 +0200 | [diff] [blame] | 213 | |
Holger Hans Peter Freyther | e66bf1f | 2010-09-06 10:11:25 +0800 | [diff] [blame] | 214 | skip_paging: |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 215 | osmo_timer_schedule(&paging_bts->work_timer, PAGING_TIMER); |
Harald Welte | 75a1fa8 | 2009-02-17 01:39:41 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static void paging_worker(void *data) |
| 219 | { |
| 220 | struct gsm_bts_paging_state *paging_bts = data; |
| 221 | |
| 222 | paging_handle_pending_requests(paging_bts); |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Holger Hans Peter Freyther | 5a081bb | 2011-04-26 15:44:57 +0200 | [diff] [blame] | 225 | static void paging_init_if_needed(struct gsm_bts *bts) |
Holger Freyther | ceb59b7 | 2009-02-06 18:54:00 +0000 | [diff] [blame] | 226 | { |
Holger Hans Peter Freyther | 5a081bb | 2011-04-26 15:44:57 +0200 | [diff] [blame] | 227 | if (bts->paging.bts) |
| 228 | return; |
| 229 | |
Holger Freyther | ceb59b7 | 2009-02-06 18:54:00 +0000 | [diff] [blame] | 230 | bts->paging.bts = bts; |
| 231 | INIT_LLIST_HEAD(&bts->paging.pending_requests); |
Harald Welte | 75a1fa8 | 2009-02-17 01:39:41 +0000 | [diff] [blame] | 232 | bts->paging.work_timer.cb = paging_worker; |
| 233 | bts->paging.work_timer.data = &bts->paging; |
Holger Freyther | 392209c | 2009-02-10 00:06:19 +0000 | [diff] [blame] | 234 | |
| 235 | /* Large number, until we get a proper message */ |
Holger Hans Peter Freyther | 1469600 | 2010-04-09 22:55:55 +0200 | [diff] [blame] | 236 | bts->paging.available_slots = 20; |
Holger Freyther | ceb59b7 | 2009-02-06 18:54:00 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Holger Freyther | 1fd3414 | 2009-02-09 23:42:03 +0000 | [diff] [blame] | 239 | static int paging_pending_request(struct gsm_bts_paging_state *bts, |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 240 | struct gsm_subscriber *subscr) { |
Holger Freyther | ceb59b7 | 2009-02-06 18:54:00 +0000 | [diff] [blame] | 241 | struct gsm_paging_request *req; |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 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 | |
Harald Welte | 51cce1e | 2009-02-10 17:35:04 +0000 | [diff] [blame] | 251 | static void paging_T3113_expired(void *data) |
| 252 | { |
Holger Freyther | 83e44b0 | 2009-02-14 18:04:59 +0000 | [diff] [blame] | 253 | struct gsm_paging_request *req = (struct gsm_paging_request *)data; |
Holger Hans Peter Freyther | fe9da82 | 2009-11-17 10:16:46 +0100 | [diff] [blame] | 254 | void *cbfn_param; |
| 255 | gsm_cbfn *cbfn; |
Holger Hans Peter Freyther | d3baf41 | 2010-12-23 18:19:17 +0100 | [diff] [blame] | 256 | int msg; |
Harald Welte | 51cce1e | 2009-02-10 17:35:04 +0000 | [diff] [blame] | 257 | |
Neels Hofmeyr | f13b3c9 | 2017-02-17 17:05:40 +0100 | [diff] [blame^] | 258 | log_set_context(LOGGING_CTX_VLR_SUBSCR, req->subscr); |
Holger Hans Peter Freyther | b7ccac4 | 2014-12-28 15:00:36 +0100 | [diff] [blame] | 259 | |
Holger Hans Peter Freyther | c50b836 | 2010-04-09 22:02:39 +0200 | [diff] [blame] | 260 | LOGP(DPAG, LOGL_INFO, "T3113 expired for request %p (%s)\n", |
Harald Welte | 51cce1e | 2009-02-10 17:35:04 +0000 | [diff] [blame] | 261 | req, req->subscr->imsi); |
Holger Freyther | 4af2b48 | 2009-02-14 22:51:03 +0000 | [diff] [blame] | 262 | |
Holger Hans Peter Freyther | fe9da82 | 2009-11-17 10:16:46 +0100 | [diff] [blame] | 263 | /* must be destroyed before calling cbfn, to prevent double free */ |
Alexander Couzens | b847a21 | 2016-08-02 11:34:11 +0200 | [diff] [blame] | 264 | rate_ctr_inc(&req->bts->network->bsc_ctrs->ctr[BSC_CTR_PAGING_EXPIRED]); |
Holger Hans Peter Freyther | fe9da82 | 2009-11-17 10:16:46 +0100 | [diff] [blame] | 265 | cbfn_param = req->cbfn_param; |
| 266 | cbfn = req->cbfn; |
Holger Hans Peter Freyther | d3baf41 | 2010-12-23 18:19:17 +0100 | [diff] [blame] | 267 | |
| 268 | /* did we ever manage to page the subscriber */ |
| 269 | msg = req->attempts > 0 ? GSM_PAGING_EXPIRED : GSM_PAGING_BUSY; |
| 270 | |
| 271 | /* destroy it now. Do not access req afterwards */ |
Harald Welte | 51cce1e | 2009-02-10 17:35:04 +0000 | [diff] [blame] | 272 | paging_remove_request(&req->bts->paging, req); |
Holger Hans Peter Freyther | fe9da82 | 2009-11-17 10:16:46 +0100 | [diff] [blame] | 273 | |
Holger Hans Peter Freyther | fe9da82 | 2009-11-17 10:16:46 +0100 | [diff] [blame] | 274 | if (cbfn) |
Holger Hans Peter Freyther | d3baf41 | 2010-12-23 18:19:17 +0100 | [diff] [blame] | 275 | cbfn(GSM_HOOK_RR_PAGING, msg, NULL, NULL, |
Holger Hans Peter Freyther | fe9da82 | 2009-11-17 10:16:46 +0100 | [diff] [blame] | 276 | cbfn_param); |
Holger Hans Peter Freyther | b7ccac4 | 2014-12-28 15:00:36 +0100 | [diff] [blame] | 277 | |
Harald Welte | 51cce1e | 2009-02-10 17:35:04 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Harald Welte | e903edf | 2009-08-15 03:16:17 +0200 | [diff] [blame] | 280 | static int _paging_request(struct gsm_bts *bts, struct gsm_subscriber *subscr, |
Holger Hans Peter Freyther | 2c45123 | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 281 | int type, gsm_cbfn *cbfn, void *data) |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 282 | { |
Holger Freyther | ceb59b7 | 2009-02-06 18:54:00 +0000 | [diff] [blame] | 283 | struct gsm_bts_paging_state *bts_entry = &bts->paging; |
| 284 | struct gsm_paging_request *req; |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 285 | |
Holger Freyther | 49314f6 | 2009-02-14 23:53:20 +0000 | [diff] [blame] | 286 | if (paging_pending_request(bts_entry, subscr)) { |
Holger Hans Peter Freyther | c50b836 | 2010-04-09 22:02:39 +0200 | [diff] [blame] | 287 | LOGP(DPAG, LOGL_INFO, "Paging request already pending for %s\n", subscr->imsi); |
Harald Welte | e903edf | 2009-08-15 03:16:17 +0200 | [diff] [blame] | 288 | return -EEXIST; |
Holger Freyther | 49314f6 | 2009-02-14 23:53:20 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Holger Hans Peter Freyther | c50b836 | 2010-04-09 22:02:39 +0200 | [diff] [blame] | 291 | LOGP(DPAG, LOGL_DEBUG, "Start paging of subscriber %llu on bts %d.\n", |
Harald Welte | f6cea1d | 2009-08-08 15:08:19 +0200 | [diff] [blame] | 292 | subscr->id, bts->nr); |
Harald Welte | 470ec29 | 2009-06-26 20:25:23 +0200 | [diff] [blame] | 293 | req = talloc_zero(tall_paging_ctx, struct gsm_paging_request); |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 294 | req->subscr = subscr_get(subscr); |
| 295 | req->bts = bts; |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 296 | req->chan_type = type; |
Harald Welte | 09e38af | 2009-02-16 22:52:23 +0000 | [diff] [blame] | 297 | req->cbfn = cbfn; |
| 298 | req->cbfn_param = data; |
Harald Welte | 51cce1e | 2009-02-10 17:35:04 +0000 | [diff] [blame] | 299 | req->T3113.cb = paging_T3113_expired; |
| 300 | req->T3113.data = req; |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 301 | osmo_timer_schedule(&req->T3113, bts->network->T3113, 0); |
Holger Freyther | 49314f6 | 2009-02-14 23:53:20 +0000 | [diff] [blame] | 302 | llist_add_tail(&req->entry, &bts_entry->pending_requests); |
Holger Hans Peter Freyther | eb241aa | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 303 | paging_schedule_if_needed(bts_entry); |
Harald Welte | e903edf | 2009-08-15 03:16:17 +0200 | [diff] [blame] | 304 | |
| 305 | return 0; |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 306 | } |
Harald Welte | 763da00 | 2009-02-06 12:52:14 +0000 | [diff] [blame] | 307 | |
Holger Hans Peter Freyther | dc03096 | 2013-01-07 17:30:13 +0100 | [diff] [blame] | 308 | int paging_request_bts(struct gsm_bts *bts, struct gsm_subscriber *subscr, |
| 309 | int type, gsm_cbfn *cbfn, void *data) |
| 310 | { |
| 311 | int rc; |
| 312 | |
| 313 | /* skip all currently inactive TRX */ |
| 314 | if (!trx_is_usable(bts->c0)) |
| 315 | return 0; |
| 316 | |
| 317 | /* maybe it is the first time we use it */ |
| 318 | paging_init_if_needed(bts); |
| 319 | |
| 320 | |
| 321 | /* Trigger paging, pass any error to the caller */ |
| 322 | rc = _paging_request(bts, subscr, type, cbfn, data); |
| 323 | if (rc < 0) |
| 324 | return rc; |
| 325 | return 1; |
| 326 | } |
| 327 | |
Harald Welte | e903edf | 2009-08-15 03:16:17 +0200 | [diff] [blame] | 328 | int paging_request(struct gsm_network *network, struct gsm_subscriber *subscr, |
| 329 | int type, gsm_cbfn *cbfn, void *data) |
Holger Hans Peter Freyther | 2c45123 | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 330 | { |
| 331 | struct gsm_bts *bts = NULL; |
Harald Welte (local) | 0abaf33 | 2009-08-15 11:25:45 +0200 | [diff] [blame] | 332 | int num_pages = 0; |
Holger Hans Peter Freyther | 2c45123 | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 333 | |
Alexander Couzens | b847a21 | 2016-08-02 11:34:11 +0200 | [diff] [blame] | 334 | rate_ctr_inc(&network->bsc_ctrs->ctr[BSC_CTR_PAGING_ATTEMPTED]); |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 335 | |
Harald Welte | a1b2858 | 2009-08-01 19:31:47 +0200 | [diff] [blame] | 336 | /* start paging subscriber on all BTS within Location Area */ |
Holger Hans Peter Freyther | 2c45123 | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 337 | do { |
Harald Welte (local) | 0abaf33 | 2009-08-15 11:25:45 +0200 | [diff] [blame] | 338 | int rc; |
| 339 | |
Holger Freyther | 04866d4 | 2009-03-31 04:35:19 +0200 | [diff] [blame] | 340 | bts = gsm_bts_by_lac(network, subscr->lac, bts); |
Holger Hans Peter Freyther | 2c45123 | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 341 | if (!bts) |
| 342 | break; |
Harald Welte (local) | 82ff397 | 2009-12-28 16:36:28 +0100 | [diff] [blame] | 343 | |
Holger Hans Peter Freyther | dc03096 | 2013-01-07 17:30:13 +0100 | [diff] [blame] | 344 | rc = paging_request_bts(bts, subscr, type, cbfn, data); |
Holger Hans Peter Freyther | 469f992 | 2015-08-03 11:19:35 +0200 | [diff] [blame] | 345 | if (rc < 0) { |
| 346 | paging_request_stop(NULL, subscr, NULL, NULL); |
Harald Welte | e903edf | 2009-08-15 03:16:17 +0200 | [diff] [blame] | 347 | return rc; |
Holger Hans Peter Freyther | 469f992 | 2015-08-03 11:19:35 +0200 | [diff] [blame] | 348 | } |
Holger Hans Peter Freyther | dc03096 | 2013-01-07 17:30:13 +0100 | [diff] [blame] | 349 | num_pages += rc; |
Holger Hans Peter Freyther | 2c45123 | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 350 | } while (1); |
Harald Welte | e903edf | 2009-08-15 03:16:17 +0200 | [diff] [blame] | 351 | |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 352 | if (num_pages == 0) |
Alexander Couzens | b847a21 | 2016-08-02 11:34:11 +0200 | [diff] [blame] | 353 | rate_ctr_inc(&network->bsc_ctrs->ctr[BSC_CTR_PAGING_DETACHED]); |
Harald Welte | 24ff6ee | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 354 | |
Harald Welte (local) | 0abaf33 | 2009-08-15 11:25:45 +0200 | [diff] [blame] | 355 | return num_pages; |
Holger Hans Peter Freyther | 2c45123 | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | |
Harald Welte | 763da00 | 2009-02-06 12:52:14 +0000 | [diff] [blame] | 359 | /* we consciously ignore the type of the request here */ |
Holger Hans Peter Freyther | 2c45123 | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 360 | static void _paging_request_stop(struct gsm_bts *bts, struct gsm_subscriber *subscr, |
Sylvain Munaut | c7ff257 | 2010-12-01 21:41:35 +0100 | [diff] [blame] | 361 | struct gsm_subscriber_connection *conn, |
| 362 | struct msgb *msg) |
Harald Welte | 763da00 | 2009-02-06 12:52:14 +0000 | [diff] [blame] | 363 | { |
Holger Freyther | ceb59b7 | 2009-02-06 18:54:00 +0000 | [diff] [blame] | 364 | struct gsm_bts_paging_state *bts_entry = &bts->paging; |
| 365 | struct gsm_paging_request *req, *req2; |
Harald Welte | 763da00 | 2009-02-06 12:52:14 +0000 | [diff] [blame] | 366 | |
Holger Hans Peter Freyther | 5a081bb | 2011-04-26 15:44:57 +0200 | [diff] [blame] | 367 | paging_init_if_needed(bts); |
| 368 | |
Harald Welte | 763da00 | 2009-02-06 12:52:14 +0000 | [diff] [blame] | 369 | llist_for_each_entry_safe(req, req2, &bts_entry->pending_requests, |
| 370 | entry) { |
Holger Freyther | 3d94924 | 2009-02-06 18:08:18 +0000 | [diff] [blame] | 371 | if (req->subscr == subscr) { |
Holger Hans Peter Freyther | 0ae564d | 2015-04-06 16:54:55 +0200 | [diff] [blame] | 372 | gsm_cbfn *cbfn = req->cbfn; |
| 373 | void *param = req->cbfn_param; |
| 374 | |
| 375 | /* now give up the data structure */ |
| 376 | paging_remove_request(&bts->paging, req); |
| 377 | req = NULL; |
| 378 | |
| 379 | if (conn && cbfn) { |
Max | 8dc8f23 | 2017-02-09 19:13:02 +0100 | [diff] [blame] | 380 | LOGP(DPAG, LOGL_DEBUG, "Stop paging %s on bts %d, calling cbfn.\n", subscr->imsi, bts->nr); |
Holger Hans Peter Freyther | 0ae564d | 2015-04-06 16:54:55 +0200 | [diff] [blame] | 381 | cbfn(GSM_HOOK_RR_PAGING, GSM_PAGING_SUCCEEDED, |
| 382 | msg, conn, param); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 383 | } else |
Max | 8dc8f23 | 2017-02-09 19:13:02 +0100 | [diff] [blame] | 384 | LOGP(DPAG, LOGL_DEBUG, "Stop paging %s on bts %d silently.\n", subscr->imsi, bts->nr); |
Holger Freyther | 3d94924 | 2009-02-06 18:08:18 +0000 | [diff] [blame] | 385 | break; |
| 386 | } |
Harald Welte | 763da00 | 2009-02-06 12:52:14 +0000 | [diff] [blame] | 387 | } |
| 388 | } |
Holger Freyther | 392209c | 2009-02-10 00:06:19 +0000 | [diff] [blame] | 389 | |
Holger Hans Peter Freyther | 2c45123 | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 390 | /* Stop paging on all other bts' */ |
| 391 | void paging_request_stop(struct gsm_bts *_bts, struct gsm_subscriber *subscr, |
Sylvain Munaut | c7ff257 | 2010-12-01 21:41:35 +0100 | [diff] [blame] | 392 | struct gsm_subscriber_connection *conn, |
| 393 | struct msgb *msg) |
Holger Hans Peter Freyther | 2c45123 | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 394 | { |
Holger Hans Peter Freyther | ba43365 | 2015-08-03 11:20:31 +0200 | [diff] [blame] | 395 | struct gsm_bts *bts; |
Holger Hans Peter Freyther | 2c45123 | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 396 | |
Neels Hofmeyr | f13b3c9 | 2017-02-17 17:05:40 +0100 | [diff] [blame^] | 397 | log_set_context(LOGGING_CTX_VLR_SUBSCR, subscr); |
Holger Hans Peter Freyther | b7ccac4 | 2014-12-28 15:00:36 +0100 | [diff] [blame] | 398 | |
Holger Hans Peter Freyther | ba43365 | 2015-08-03 11:20:31 +0200 | [diff] [blame] | 399 | /* Stop this first and dispatch the request */ |
Holger Hans Peter Freyther | 927f056 | 2009-08-21 05:43:44 +0200 | [diff] [blame] | 400 | if (_bts) |
Sylvain Munaut | c7ff257 | 2010-12-01 21:41:35 +0100 | [diff] [blame] | 401 | _paging_request_stop(_bts, subscr, conn, msg); |
Holger Hans Peter Freyther | fdac4cc | 2009-06-10 11:46:58 +0200 | [diff] [blame] | 402 | |
Holger Hans Peter Freyther | ba43365 | 2015-08-03 11:20:31 +0200 | [diff] [blame] | 403 | /* Make sure to cancel this everywhere else */ |
| 404 | llist_for_each_entry(bts, &subscr->group->net->bts_list, list) { |
| 405 | /* Sort of an optimization. */ |
| 406 | if (bts == _bts) |
| 407 | continue; |
| 408 | _paging_request_stop(bts, subscr, NULL, NULL); |
| 409 | } |
Holger Hans Peter Freyther | 2c45123 | 2009-06-10 02:45:42 +0200 | [diff] [blame] | 410 | } |
| 411 | |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 412 | void paging_update_buffer_space(struct gsm_bts *bts, uint16_t free_slots) |
Holger Freyther | 392209c | 2009-02-10 00:06:19 +0000 | [diff] [blame] | 413 | { |
Holger Hans Peter Freyther | 5a081bb | 2011-04-26 15:44:57 +0200 | [diff] [blame] | 414 | paging_init_if_needed(bts); |
| 415 | |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 416 | osmo_timer_del(&bts->paging.credit_timer); |
Holger Freyther | 392209c | 2009-02-10 00:06:19 +0000 | [diff] [blame] | 417 | bts->paging.available_slots = free_slots; |
Holger Hans Peter Freyther | eb241aa | 2010-09-06 10:05:23 +0800 | [diff] [blame] | 418 | paging_schedule_if_needed(&bts->paging); |
Holger Freyther | 392209c | 2009-02-10 00:06:19 +0000 | [diff] [blame] | 419 | } |
Holger Hans Peter Freyther | 66e14cd | 2011-04-26 15:52:34 +0200 | [diff] [blame] | 420 | |
| 421 | unsigned int paging_pending_requests_nr(struct gsm_bts *bts) |
| 422 | { |
| 423 | unsigned int requests = 0; |
| 424 | struct gsm_paging_request *req; |
| 425 | |
| 426 | paging_init_if_needed(bts); |
| 427 | |
| 428 | llist_for_each_entry(req, &bts->paging.pending_requests, entry) |
| 429 | ++requests; |
| 430 | |
| 431 | return requests; |
| 432 | } |
Holger Hans Peter Freyther | 31f5f71 | 2011-06-07 19:53:29 +0200 | [diff] [blame] | 433 | |
| 434 | /** |
| 435 | * Find any paging data for the given subscriber at the given BTS. |
| 436 | */ |
| 437 | void *paging_get_data(struct gsm_bts *bts, struct gsm_subscriber *subscr) |
| 438 | { |
| 439 | struct gsm_paging_request *req; |
| 440 | |
| 441 | llist_for_each_entry(req, &bts->paging.pending_requests, entry) |
| 442 | if (req->subscr == subscr) |
| 443 | return req->cbfn_param; |
| 444 | |
| 445 | return NULL; |
| 446 | } |