Oliver Smith | d3c7591 | 2021-07-09 16:37:16 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> |
| 3 | * Author: Oliver Smith |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 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 |
| 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 |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 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/>. |
| 17 | * |
| 18 | */ |
| 19 | #include <string.h> |
| 20 | |
| 21 | #include <osmocom/core/logging.h> |
| 22 | #include <osmocom/core/talloc.h> |
| 23 | #include <osmocom/core/tdef.h> |
| 24 | #include <osmocom/core/utils.h> |
| 25 | |
| 26 | #include <gprs_debug.h> |
| 27 | #include <gprs_pcu.h> |
| 28 | #include <bts_pch_timer.h> |
Pau Espin Pedrol | 13961c9 | 2021-11-08 17:38:47 +0100 | [diff] [blame] | 29 | #include <gprs_ms.h> |
Oliver Smith | d3c7591 | 2021-07-09 16:37:16 +0200 | [diff] [blame] | 30 | |
Pau Espin Pedrol | 13961c9 | 2021-11-08 17:38:47 +0100 | [diff] [blame] | 31 | static struct bts_pch_timer *bts_pch_timer_get_by_ptmsi(struct gprs_rlcmac_bts *bts, uint32_t ptmsi) |
| 32 | { |
| 33 | struct bts_pch_timer *p; |
| 34 | OSMO_ASSERT(ptmsi != GSM_RESERVED_TMSI); |
| 35 | |
| 36 | llist_for_each_entry(p, &bts->pch_timer, entry) { |
| 37 | if (p->ptmsi != GSM_RESERVED_TMSI && p->ptmsi == ptmsi) |
| 38 | return p; |
| 39 | } |
| 40 | |
| 41 | return NULL; |
| 42 | } |
| 43 | |
Pau Espin Pedrol | ef8a730 | 2021-11-08 19:19:25 +0100 | [diff] [blame] | 44 | struct bts_pch_timer *bts_pch_timer_get_by_imsi(struct gprs_rlcmac_bts *bts, const char *imsi) |
Oliver Smith | d3c7591 | 2021-07-09 16:37:16 +0200 | [diff] [blame] | 45 | { |
| 46 | struct bts_pch_timer *p; |
| 47 | |
| 48 | llist_for_each_entry(p, &bts->pch_timer, entry) { |
| 49 | if (strcmp(p->imsi, imsi) == 0) |
| 50 | return p; |
| 51 | } |
| 52 | |
| 53 | return NULL; |
| 54 | } |
| 55 | |
| 56 | static void bts_pch_timer_remove(struct bts_pch_timer *p) |
| 57 | { |
| 58 | osmo_timer_del(&p->T3113); |
| 59 | llist_del(&p->entry); |
| 60 | |
| 61 | LOGP(DPCU, LOGL_DEBUG, "PCH paging timer stopped for IMSI=%s\n", p->imsi); |
| 62 | talloc_free(p); |
| 63 | } |
| 64 | |
| 65 | static void T3113_callback(void *data) |
| 66 | { |
| 67 | struct bts_pch_timer *p = data; |
| 68 | |
| 69 | LOGP(DPCU, LOGL_INFO, "PCH paging timeout for IMSI=%s\n", p->imsi); |
| 70 | bts_do_rate_ctr_inc(p->bts, CTR_PCH_REQUESTS_TIMEDOUT); |
| 71 | bts_pch_timer_remove(p); |
| 72 | } |
| 73 | |
Pau Espin Pedrol | 13961c9 | 2021-11-08 17:38:47 +0100 | [diff] [blame] | 74 | void bts_pch_timer_start(struct gprs_rlcmac_bts *bts, const struct osmo_mobile_identity *mi_paging, |
| 75 | const char *imsi) |
Oliver Smith | d3c7591 | 2021-07-09 16:37:16 +0200 | [diff] [blame] | 76 | { |
Pau Espin Pedrol | 13961c9 | 2021-11-08 17:38:47 +0100 | [diff] [blame] | 77 | struct bts_pch_timer *p; |
| 78 | struct osmo_tdef *tdef; |
| 79 | |
Oliver Smith | d3c7591 | 2021-07-09 16:37:16 +0200 | [diff] [blame] | 80 | p = talloc_zero(bts, struct bts_pch_timer); |
| 81 | llist_add_tail(&p->entry, &bts->pch_timer); |
Oliver Smith | d3c7591 | 2021-07-09 16:37:16 +0200 | [diff] [blame] | 82 | p->bts = bts; |
Pau Espin Pedrol | 13961c9 | 2021-11-08 17:38:47 +0100 | [diff] [blame] | 83 | OSMO_STRLCPY_ARRAY(p->imsi, imsi); |
| 84 | p->ptmsi = (mi_paging->type == GSM_MI_TYPE_TMSI) ? mi_paging->tmsi : GSM_RESERVED_TMSI; |
Oliver Smith | d3c7591 | 2021-07-09 16:37:16 +0200 | [diff] [blame] | 85 | |
Pau Espin Pedrol | 13961c9 | 2021-11-08 17:38:47 +0100 | [diff] [blame] | 86 | tdef = osmo_tdef_get_entry(the_pcu->T_defs, 3113); |
Oliver Smith | d3c7591 | 2021-07-09 16:37:16 +0200 | [diff] [blame] | 87 | OSMO_ASSERT(tdef); |
| 88 | osmo_timer_setup(&p->T3113, T3113_callback, p); |
| 89 | osmo_timer_schedule(&p->T3113, tdef->val, 0); |
| 90 | |
Pau Espin Pedrol | 13961c9 | 2021-11-08 17:38:47 +0100 | [diff] [blame] | 91 | if (log_check_level(DPCU, LOGL_DEBUG)) { |
| 92 | char str[64]; |
| 93 | osmo_mobile_identity_to_str_buf(str, sizeof(str), mi_paging); |
| 94 | LOGP(DPCU, LOGL_DEBUG, "PCH paging timer started for MI=%s IMSI=%s\n", str, p->imsi); |
| 95 | } |
Oliver Smith | d3c7591 | 2021-07-09 16:37:16 +0200 | [diff] [blame] | 96 | } |
| 97 | |
Pau Espin Pedrol | 13961c9 | 2021-11-08 17:38:47 +0100 | [diff] [blame] | 98 | void bts_pch_timer_stop(struct gprs_rlcmac_bts *bts, const struct GprsMs *ms) |
Oliver Smith | d3c7591 | 2021-07-09 16:37:16 +0200 | [diff] [blame] | 99 | { |
Pau Espin Pedrol | 13961c9 | 2021-11-08 17:38:47 +0100 | [diff] [blame] | 100 | struct bts_pch_timer *p = NULL; |
| 101 | uint32_t tlli = ms_tlli(ms); |
| 102 | const char *imsi = ms_imsi(ms); |
Oliver Smith | d3c7591 | 2021-07-09 16:37:16 +0200 | [diff] [blame] | 103 | |
Pau Espin Pedrol | 13961c9 | 2021-11-08 17:38:47 +0100 | [diff] [blame] | 104 | /* First try matching by TMSI if available in MS */ |
| 105 | if (tlli != GSM_RESERVED_TMSI) |
| 106 | p = bts_pch_timer_get_by_ptmsi(bts, tlli); |
| 107 | /* Otherwise try matching by IMSI if available in MS */ |
| 108 | if (!p && imsi[0] != '\0') |
| 109 | p = bts_pch_timer_get_by_imsi(bts, imsi); |
Oliver Smith | d3c7591 | 2021-07-09 16:37:16 +0200 | [diff] [blame] | 110 | if (p) |
| 111 | bts_pch_timer_remove(p); |
| 112 | } |
Oliver Smith | 3f79470 | 2021-08-23 14:19:21 +0200 | [diff] [blame] | 113 | |
| 114 | void bts_pch_timer_stop_all(struct gprs_rlcmac_bts *bts) |
| 115 | { |
| 116 | struct bts_pch_timer *p, *n; |
| 117 | |
| 118 | llist_for_each_entry_safe(p, n, &bts->pch_timer, entry) { |
| 119 | bts_pch_timer_remove(p); |
| 120 | } |
| 121 | } |