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> |
| 29 | |
| 30 | static struct bts_pch_timer *bts_pch_timer_get(struct gprs_rlcmac_bts *bts, const char *imsi) |
| 31 | { |
| 32 | struct bts_pch_timer *p; |
| 33 | |
| 34 | llist_for_each_entry(p, &bts->pch_timer, entry) { |
| 35 | if (strcmp(p->imsi, imsi) == 0) |
| 36 | return p; |
| 37 | } |
| 38 | |
| 39 | return NULL; |
| 40 | } |
| 41 | |
| 42 | static void bts_pch_timer_remove(struct bts_pch_timer *p) |
| 43 | { |
| 44 | osmo_timer_del(&p->T3113); |
| 45 | llist_del(&p->entry); |
| 46 | |
| 47 | LOGP(DPCU, LOGL_DEBUG, "PCH paging timer stopped for IMSI=%s\n", p->imsi); |
| 48 | talloc_free(p); |
| 49 | } |
| 50 | |
| 51 | static void T3113_callback(void *data) |
| 52 | { |
| 53 | struct bts_pch_timer *p = data; |
| 54 | |
| 55 | LOGP(DPCU, LOGL_INFO, "PCH paging timeout for IMSI=%s\n", p->imsi); |
| 56 | bts_do_rate_ctr_inc(p->bts, CTR_PCH_REQUESTS_TIMEDOUT); |
| 57 | bts_pch_timer_remove(p); |
| 58 | } |
| 59 | |
| 60 | void bts_pch_timer_start(struct gprs_rlcmac_bts *bts, const char *imsi) |
| 61 | { |
| 62 | if (bts_pch_timer_get(bts, imsi)) |
| 63 | return; |
| 64 | |
| 65 | struct bts_pch_timer *p; |
| 66 | p = talloc_zero(bts, struct bts_pch_timer); |
| 67 | llist_add_tail(&p->entry, &bts->pch_timer); |
| 68 | osmo_strlcpy(p->imsi, imsi, sizeof(p->imsi)); |
| 69 | p->bts = bts; |
| 70 | |
| 71 | struct osmo_tdef *tdef = osmo_tdef_get_entry(the_pcu->T_defs, 3113); |
| 72 | OSMO_ASSERT(tdef); |
| 73 | osmo_timer_setup(&p->T3113, T3113_callback, p); |
| 74 | osmo_timer_schedule(&p->T3113, tdef->val, 0); |
| 75 | |
| 76 | LOGP(DPCU, LOGL_DEBUG, "PCH paging timer started for IMSI=%s\n", p->imsi); |
| 77 | } |
| 78 | |
| 79 | void bts_pch_timer_stop(struct gprs_rlcmac_bts *bts, const char *imsi) |
| 80 | { |
| 81 | struct bts_pch_timer *p = bts_pch_timer_get(bts, imsi); |
| 82 | |
| 83 | if (p) |
| 84 | bts_pch_timer_remove(p); |
| 85 | } |
Oliver Smith | 3f79470 | 2021-08-23 14:19:21 +0200 | [diff] [blame] | 86 | |
| 87 | void bts_pch_timer_stop_all(struct gprs_rlcmac_bts *bts) |
| 88 | { |
| 89 | struct bts_pch_timer *p, *n; |
| 90 | |
| 91 | llist_for_each_entry_safe(p, n, &bts->pch_timer, entry) { |
| 92 | bts_pch_timer_remove(p); |
| 93 | } |
| 94 | } |