Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 1 | /* Copied from gprs_bssgp_pcu.cpp |
| 2 | * |
| 3 | * Copyright (C) 2012 Ivan Klyuchnikov |
Holger Hans Peter Freyther | 8692128 | 2013-08-24 21:26:42 +0200 | [diff] [blame] | 4 | * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu> |
Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 5 | * Copyright (C) 2013 by Holger Hans Peter Freyther |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version 2 |
| 10 | * of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 16 | */ |
| 17 | |
Pau Espin Pedrol | a0cbde7 | 2020-03-26 15:56:15 +0100 | [diff] [blame] | 18 | #include <new> |
Pau Espin Pedrol | cd6c466 | 2020-09-22 13:41:00 +0200 | [diff] [blame] | 19 | #include <sstream> |
Pau Espin Pedrol | a0cbde7 | 2020-03-26 15:56:15 +0100 | [diff] [blame] | 20 | |
Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 21 | #include <bts.h> |
Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 22 | #include <tbf.h> |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 23 | #include <tbf_dl.h> |
| 24 | #include <tbf_ul.h> |
Holger Hans Peter Freyther | d11290b | 2013-10-26 17:32:04 +0200 | [diff] [blame] | 25 | #include <rlc.h> |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 26 | #include <encoding.h> |
Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 27 | #include <gprs_rlcmac.h> |
| 28 | #include <gprs_debug.h> |
Jacob Erlbeck | fecece0 | 2015-05-08 12:13:08 +0200 | [diff] [blame] | 29 | #include <gprs_ms.h> |
Jacob Erlbeck | 36df774 | 2016-01-19 15:53:30 +0100 | [diff] [blame] | 30 | #include <pcu_utils.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 31 | #include <gprs_ms_storage.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 32 | #include <sba.h> |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 33 | #include <pdch.h> |
Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 34 | |
| 35 | extern "C" { |
| 36 | #include <osmocom/core/msgb.h> |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 37 | #include <osmocom/core/utils.h> |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 38 | #include <osmocom/core/talloc.h> |
sivasankari | 5395073 | 2016-12-08 17:15:17 +0530 | [diff] [blame] | 39 | #include <osmocom/core/stats.h> |
Max | 467f633 | 2017-12-20 18:13:29 +0100 | [diff] [blame] | 40 | #include <osmocom/core/logging.h> |
Stefan Sperling | f0f7df1 | 2018-05-25 15:12:30 +0200 | [diff] [blame] | 41 | #include <osmocom/core/timer_compat.h> |
Pau Espin Pedrol | 980ef1e | 2020-03-26 15:06:11 +0100 | [diff] [blame] | 42 | #include <osmocom/core/bitvec.h> |
| 43 | #include <osmocom/core/rate_ctr.h> |
| 44 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
Pau Espin Pedrol | b2653fe | 2020-03-26 15:14:01 +0100 | [diff] [blame] | 45 | |
| 46 | #include "gsm_rlcmac.h" |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 47 | #include "coding_scheme.h" |
Pau Espin Pedrol | 952cb3d | 2021-02-01 14:52:48 +0100 | [diff] [blame] | 48 | #include "nacc_fsm.h" |
Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | #include <errno.h> |
| 52 | #include <string.h> |
| 53 | |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 54 | extern void *tall_pcu_ctx; |
| 55 | |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 56 | unsigned int next_tbf_ctr_group_id = 0; /* Incrementing group id */ |
Pau Espin Pedrol | 0926901 | 2018-07-10 15:44:47 +0200 | [diff] [blame] | 57 | |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 58 | static const struct value_string tbf_counters_names[] = { |
| 59 | OSMO_VALUE_STRING(N3101), |
| 60 | OSMO_VALUE_STRING(N3103), |
| 61 | OSMO_VALUE_STRING(N3105), |
| 62 | { 0, NULL } |
| 63 | }; |
| 64 | |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 65 | static const struct value_string tbf_timers_names[] = { |
Pau Espin Pedrol | 4b6f0bf | 2021-05-10 18:54:52 +0200 | [diff] [blame] | 66 | OSMO_VALUE_STRING(T3141), |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 67 | OSMO_VALUE_STRING(T3191), |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 68 | { 0, NULL } |
| 69 | }; |
| 70 | |
sivasankari | 5395073 | 2016-12-08 17:15:17 +0530 | [diff] [blame] | 71 | static const struct rate_ctr_desc tbf_ctr_description[] = { |
Pau Espin Pedrol | 218ee98 | 2018-07-10 15:16:49 +0200 | [diff] [blame] | 72 | { "rlc:nacked", "RLC Nacked " }, |
sivasankari | 5395073 | 2016-12-08 17:15:17 +0530 | [diff] [blame] | 73 | }; |
| 74 | |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 75 | const struct rate_ctr_group_desc tbf_ctrg_desc = { |
Pau Espin Pedrol | 218ee98 | 2018-07-10 15:16:49 +0200 | [diff] [blame] | 76 | "pcu:tbf", |
sivasankari | 5395073 | 2016-12-08 17:15:17 +0530 | [diff] [blame] | 77 | "TBF Statistics", |
| 78 | OSMO_STATS_CLASS_SUBSCRIBER, |
| 79 | ARRAY_SIZE(tbf_ctr_description), |
| 80 | tbf_ctr_description, |
| 81 | }; |
| 82 | |
Jacob Erlbeck | b6b3c7e | 2015-08-28 12:07:14 +0200 | [diff] [blame] | 83 | gprs_rlcmac_tbf::Meas::Meas() : |
| 84 | rssi_sum(0), |
| 85 | rssi_num(0) |
| 86 | { |
Stefan Sperling | f0f7df1 | 2018-05-25 15:12:30 +0200 | [diff] [blame] | 87 | timespecclear(&rssi_tv); |
Jacob Erlbeck | b6b3c7e | 2015-08-28 12:07:14 +0200 | [diff] [blame] | 88 | } |
| 89 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 90 | gprs_rlcmac_tbf::gprs_rlcmac_tbf(struct gprs_rlcmac_bts *bts_, GprsMs *ms, gprs_rlcmac_tbf_direction dir) : |
Jacob Erlbeck | 6835cea | 2015-08-21 15:24:02 +0200 | [diff] [blame] | 91 | direction(dir), |
Jacob Erlbeck | b6b3c7e | 2015-08-28 12:07:14 +0200 | [diff] [blame] | 92 | trx(NULL), |
Pau Espin Pedrol | d3d46de | 2021-11-08 13:07:35 +0100 | [diff] [blame] | 93 | first_ts(TBF_TS_UNSET), |
| 94 | first_common_ts(TBF_TS_UNSET), |
| 95 | control_ts(TBF_TS_UNSET), |
Jacob Erlbeck | b6b3c7e | 2015-08-28 12:07:14 +0200 | [diff] [blame] | 96 | fT(0), |
| 97 | num_fT_exp(0), |
Pau Espin Pedrol | 907f037 | 2021-07-29 16:34:04 +0200 | [diff] [blame] | 98 | upgrade_to_multislot(false), |
Jacob Erlbeck | b6b3c7e | 2015-08-28 12:07:14 +0200 | [diff] [blame] | 99 | bts(bts_), |
Pau Espin Pedrol | a02f945 | 2021-11-08 13:09:29 +0100 | [diff] [blame] | 100 | m_tfi(TBF_TFI_UNSET), |
Jacob Erlbeck | b6b3c7e | 2015-08-28 12:07:14 +0200 | [diff] [blame] | 101 | m_created_ts(0), |
Neels Hofmeyr | d34646a | 2017-02-08 17:07:40 +0100 | [diff] [blame] | 102 | m_ctrs(NULL), |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 103 | m_ms(ms), |
Neels Hofmeyr | d34646a | 2017-02-08 17:07:40 +0100 | [diff] [blame] | 104 | m_egprs_enabled(false) |
Jacob Erlbeck | 444bc82 | 2015-08-20 17:49:03 +0200 | [diff] [blame] | 105 | { |
Jacob Erlbeck | b6b3c7e | 2015-08-28 12:07:14 +0200 | [diff] [blame] | 106 | /* The classes of these members do not have proper constructors yet. |
| 107 | * Just set them to 0 like talloc_zero did */ |
Jacob Erlbeck | b6b3c7e | 2015-08-28 12:07:14 +0200 | [diff] [blame] | 108 | memset(&pdch, 0, sizeof(pdch)); |
Pau Espin Pedrol | ef1fe58 | 2019-09-05 14:40:24 +0200 | [diff] [blame] | 109 | memset(&Tarr, 0, sizeof(Tarr)); |
| 110 | memset(&Narr, 0, sizeof(Narr)); |
Jacob Erlbeck | b6b3c7e | 2015-08-28 12:07:14 +0200 | [diff] [blame] | 111 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 112 | memset(&m_ms_list, 0, sizeof(m_ms_list)); |
| 113 | m_ms_list.entry = this; |
| 114 | |
Pau Espin Pedrol | 1a1557a | 2021-05-13 18:39:36 +0200 | [diff] [blame] | 115 | memset(&m_trx_list, 0, sizeof(m_trx_list)); |
| 116 | m_trx_list.entry = this; |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 117 | |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 118 | memset(&ul_ass_fsm, 0, sizeof(ul_ass_fsm)); |
| 119 | ul_ass_fsm.tbf = this; |
| 120 | ul_ass_fsm.fi = osmo_fsm_inst_alloc(&tbf_ul_ass_fsm, this, &ul_ass_fsm, LOGL_INFO, NULL); |
Pau Espin Pedrol | b5bad20 | 2021-10-09 17:03:25 +0200 | [diff] [blame] | 121 | OSMO_ASSERT(ul_ass_fsm.fi); |
Pau Espin Pedrol | 49a2f40 | 2021-07-27 17:33:07 +0200 | [diff] [blame] | 122 | memset(&dl_ass_fsm, 0, sizeof(dl_ass_fsm)); |
| 123 | dl_ass_fsm.tbf = this; |
| 124 | dl_ass_fsm.fi = osmo_fsm_inst_alloc(&tbf_dl_ass_fsm, this, &dl_ass_fsm, LOGL_INFO, NULL); |
Pau Espin Pedrol | b5bad20 | 2021-10-09 17:03:25 +0200 | [diff] [blame] | 125 | OSMO_ASSERT(dl_ass_fsm.fi); |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 126 | |
Pau Espin Pedrol | 0b0748a | 2018-05-16 15:20:39 +0200 | [diff] [blame] | 127 | m_rlc.init(); |
Pau Espin Pedrol | 4f8384b | 2022-03-31 19:36:12 +0200 | [diff] [blame] | 128 | llc_init(&m_llc); |
Jacob Erlbeck | b6b3c7e | 2015-08-28 12:07:14 +0200 | [diff] [blame] | 129 | |
| 130 | m_name_buf[0] = '\0'; |
Pau Espin Pedrol | de0eeaf | 2021-11-08 12:54:49 +0100 | [diff] [blame] | 131 | |
| 132 | m_created_ts = time(NULL); |
Jacob Erlbeck | 444bc82 | 2015-08-20 17:49:03 +0200 | [diff] [blame] | 133 | } |
| 134 | |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 135 | |
| 136 | gprs_rlcmac_tbf::~gprs_rlcmac_tbf() |
| 137 | { |
Pau Espin Pedrol | f197f15 | 2022-11-17 20:18:46 +0100 | [diff] [blame] | 138 | osmo_fsm_inst_free(state_fi); |
| 139 | state_fi = NULL; |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 140 | |
| 141 | osmo_fsm_inst_free(ul_ass_fsm.fi); |
| 142 | ul_ass_fsm.fi = NULL; |
Pau Espin Pedrol | 49a2f40 | 2021-07-27 17:33:07 +0200 | [diff] [blame] | 143 | osmo_fsm_inst_free(dl_ass_fsm.fi); |
| 144 | dl_ass_fsm.fi = NULL; |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 145 | |
Pau Espin Pedrol | 131deb0 | 2021-07-26 18:24:14 +0200 | [diff] [blame] | 146 | rate_ctr_group_free(m_ctrs); |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 147 | } |
| 148 | |
Jacob Erlbeck | 8759735 | 2015-05-18 11:56:50 +0200 | [diff] [blame] | 149 | uint32_t gprs_rlcmac_tbf::tlli() const |
| 150 | { |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 151 | return m_ms ? ms_tlli(m_ms) : GSM_RESERVED_TMSI; |
Jacob Erlbeck | 8759735 | 2015-05-18 11:56:50 +0200 | [diff] [blame] | 152 | } |
| 153 | |
Jacob Erlbeck | b0e5eaf | 2015-05-21 11:07:16 +0200 | [diff] [blame] | 154 | const char *gprs_rlcmac_tbf::imsi() const |
Holger Hans Peter Freyther | d868928 | 2013-08-24 20:51:06 +0200 | [diff] [blame] | 155 | { |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 156 | return ms_imsi(m_ms); |
Holger Hans Peter Freyther | d868928 | 2013-08-24 20:51:06 +0200 | [diff] [blame] | 157 | } |
| 158 | |
Jacob Erlbeck | 9200ce6 | 2015-05-22 17:48:04 +0200 | [diff] [blame] | 159 | uint8_t gprs_rlcmac_tbf::ta() const |
| 160 | { |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 161 | return ms_ta(m_ms); |
Jacob Erlbeck | 9200ce6 | 2015-05-22 17:48:04 +0200 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | void gprs_rlcmac_tbf::set_ta(uint8_t ta) |
| 165 | { |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 166 | ms_set_ta(m_ms, ta); |
Jacob Erlbeck | 9200ce6 | 2015-05-22 17:48:04 +0200 | [diff] [blame] | 167 | } |
| 168 | |
Jacob Erlbeck | befc760 | 2015-06-02 12:33:30 +0200 | [diff] [blame] | 169 | uint8_t gprs_rlcmac_tbf::ms_class() const |
| 170 | { |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 171 | return ms_ms_class(m_ms); |
Jacob Erlbeck | befc760 | 2015-06-02 12:33:30 +0200 | [diff] [blame] | 172 | } |
| 173 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 174 | enum CodingScheme gprs_rlcmac_tbf::current_cs() const |
Jacob Erlbeck | a700dd9 | 2015-06-02 16:00:41 +0200 | [diff] [blame] | 175 | { |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 176 | enum CodingScheme cs; |
Pau Espin Pedrol | fc46493 | 2021-01-25 12:05:32 +0100 | [diff] [blame] | 177 | enum mcs_kind req_mcs_kind = is_egprs_enabled() ? EGPRS : GPRS; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 178 | |
Jacob Erlbeck | a700dd9 | 2015-06-02 16:00:41 +0200 | [diff] [blame] | 179 | if (direction == GPRS_RLCMAC_UL_TBF) |
Pau Espin Pedrol | 2238228 | 2021-01-25 11:37:19 +0100 | [diff] [blame] | 180 | cs = ms_current_cs_ul(m_ms); |
Jacob Erlbeck | a700dd9 | 2015-06-02 16:00:41 +0200 | [diff] [blame] | 181 | else |
Pau Espin Pedrol | fc46493 | 2021-01-25 12:05:32 +0100 | [diff] [blame] | 182 | cs = ms_current_cs_dl(m_ms, req_mcs_kind); |
Jacob Erlbeck | a700dd9 | 2015-06-02 16:00:41 +0200 | [diff] [blame] | 183 | |
Jacob Erlbeck | cb72890 | 2016-01-05 15:33:03 +0100 | [diff] [blame] | 184 | return cs; |
Jacob Erlbeck | a700dd9 | 2015-06-02 16:00:41 +0200 | [diff] [blame] | 185 | } |
| 186 | |
Jacob Erlbeck | 489a2b3 | 2015-05-28 19:07:01 +0200 | [diff] [blame] | 187 | gprs_llc_queue *gprs_rlcmac_tbf::llc_queue() |
| 188 | { |
Pau Espin Pedrol | 2238228 | 2021-01-25 11:37:19 +0100 | [diff] [blame] | 189 | return ms_llc_queue(m_ms); |
Jacob Erlbeck | 489a2b3 | 2015-05-28 19:07:01 +0200 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | const gprs_llc_queue *gprs_rlcmac_tbf::llc_queue() const |
| 193 | { |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 194 | return ms_llc_queue(m_ms); |
Alexander Couzens | d38b92e | 2016-08-21 19:38:30 +0200 | [diff] [blame] | 195 | } |
| 196 | |
Jacob Erlbeck | fecece0 | 2015-05-08 12:13:08 +0200 | [diff] [blame] | 197 | void gprs_rlcmac_tbf::set_ms(GprsMs *ms) |
| 198 | { |
| 199 | if (m_ms == ms) |
| 200 | return; |
| 201 | |
Pau Espin Pedrol | affd6a7 | 2021-10-18 16:44:19 +0200 | [diff] [blame] | 202 | if (m_ms) |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 203 | ms_detach_tbf(m_ms, this); |
Jacob Erlbeck | fecece0 | 2015-05-08 12:13:08 +0200 | [diff] [blame] | 204 | |
| 205 | m_ms = ms; |
| 206 | |
| 207 | if (m_ms) |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 208 | ms_attach_tbf(m_ms, this); |
Jacob Erlbeck | fecece0 | 2015-05-08 12:13:08 +0200 | [diff] [blame] | 209 | } |
| 210 | |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 211 | static void tbf_unlink_pdch(struct gprs_rlcmac_tbf *tbf) |
| 212 | { |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 213 | int ts; |
| 214 | |
Pau Espin Pedrol | b9fede7 | 2021-10-12 19:52:02 +0200 | [diff] [blame] | 215 | /* During assignment (state=ASSIGN), tbf may be temporarily using |
| 216 | * tbf->control_ts from a previous TBF/SBA to transmit the UL/DL |
Pau Espin Pedrol | b0aba59 | 2021-10-14 19:27:49 +0200 | [diff] [blame] | 217 | * Assignment, which may not be necessarily be a TS where the current TBF |
| 218 | * is attached to. This will be the case until a TBF receives proper |
| 219 | * confirmation from the MS and goes through the FLOW state. Hence, we |
| 220 | * may have ULC pollings ongoing and we need to make sure we drop all |
| 221 | * reserved nodes there: */ |
Pau Espin Pedrol | d3d46de | 2021-11-08 13:07:35 +0100 | [diff] [blame] | 222 | if (tbf->control_ts != TBF_TS_UNSET && !tbf->pdch[tbf->control_ts]) |
Pau Espin Pedrol | b9fede7 | 2021-10-12 19:52:02 +0200 | [diff] [blame] | 223 | pdch_ulc_release_tbf(tbf->trx->pdch[tbf->control_ts].ulc, tbf); |
| 224 | |
| 225 | /* Now simply detach from all attached PDCHs */ |
Jacob Erlbeck | ccc34e4 | 2015-06-29 13:45:05 +0200 | [diff] [blame] | 226 | for (ts = 0; ts < 8; ts++) { |
| 227 | if (!tbf->pdch[ts]) |
| 228 | continue; |
| 229 | |
| 230 | tbf->pdch[ts]->detach_tbf(tbf); |
| 231 | tbf->pdch[ts] = NULL; |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | |
| 235 | void tbf_free(struct gprs_rlcmac_tbf *tbf) |
| 236 | { |
Jacob Erlbeck | 0316dc6 | 2016-01-21 20:12:04 +0100 | [diff] [blame] | 237 | /* update counters */ |
Pau Espin Pedrol | b5fece9 | 2021-08-23 16:58:04 +0200 | [diff] [blame] | 238 | if (tbf->direction == GPRS_RLCMAC_UL_TBF) { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 239 | bts_do_rate_ctr_inc(tbf->bts, CTR_TBF_UL_FREED); |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 240 | if (tbf->state_is(TBF_ST_FLOW)) |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 241 | bts_do_rate_ctr_inc(tbf->bts, CTR_TBF_UL_ABORTED); |
Pau Espin Pedrol | b5fece9 | 2021-08-23 16:58:04 +0200 | [diff] [blame] | 242 | } else { |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 243 | gprs_rlcmac_dl_tbf *dl_tbf = tbf_as_dl_tbf(tbf); |
Pau Espin Pedrol | 284711d | 2021-07-26 18:32:36 +0200 | [diff] [blame] | 244 | gprs_rlc_dl_window *win = static_cast<gprs_rlc_dl_window *>(dl_tbf->window()); |
| 245 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 246 | bts_do_rate_ctr_inc(tbf->bts, CTR_TBF_DL_FREED); |
Pau Espin Pedrol | 284711d | 2021-07-26 18:32:36 +0200 | [diff] [blame] | 247 | if (tbf->state_is(TBF_ST_FLOW)) { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 248 | bts_do_rate_ctr_inc(tbf->bts, CTR_TBF_DL_ABORTED); |
Pau Espin Pedrol | 284711d | 2021-07-26 18:32:36 +0200 | [diff] [blame] | 249 | /* range V(A)..V(S)-1 */ |
| 250 | uint16_t lost = win->count_unacked(); |
| 251 | /* report all outstanding packets as lost */ |
| 252 | gprs_rlcmac_received_lost(dl_tbf, 0, lost); |
| 253 | /* TODO: Reschedule all LLC frames starting with the one that is |
| 254 | * (partly) encoded in chunk 1 of block V(A). (optional) */ |
| 255 | } |
Pau Espin Pedrol | 284711d | 2021-07-26 18:32:36 +0200 | [diff] [blame] | 256 | /* reset rlc states */ |
| 257 | win->reset(); |
Daniel Willmann | 418a423 | 2014-08-08 11:21:04 +0200 | [diff] [blame] | 258 | } |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 259 | |
Max | c21f007 | 2017-12-15 17:36:45 +0100 | [diff] [blame] | 260 | LOGPTBF(tbf, LOGL_INFO, "free\n"); |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 261 | tbf->stop_timers("freeing TBF"); |
Max | 5a6bcfb | 2017-09-01 14:36:44 +0200 | [diff] [blame] | 262 | /* TODO: Could/Should generate bssgp_tx_llc_discarded */ |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 263 | tbf_unlink_pdch(tbf); |
Pau Espin Pedrol | 1a1557a | 2021-05-13 18:39:36 +0200 | [diff] [blame] | 264 | llist_del(tbf_trx_list(tbf)); |
Holger Hans Peter Freyther | 1587764 | 2013-10-27 09:50:15 +0100 | [diff] [blame] | 265 | |
Jacob Erlbeck | fecece0 | 2015-05-08 12:13:08 +0200 | [diff] [blame] | 266 | if (tbf->ms()) |
| 267 | tbf->set_ms(NULL); |
| 268 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 269 | LOGP(DTBF, LOGL_DEBUG, "********** %s-TBF ends here **********\n", |
Max | c21f007 | 2017-12-15 17:36:45 +0100 | [diff] [blame] | 270 | (tbf->direction != GPRS_RLCMAC_UL_TBF) ? "DL" : "UL"); |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 271 | talloc_free(tbf); |
| 272 | } |
| 273 | |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 274 | uint16_t egprs_window_size(const struct gprs_rlcmac_bts *bts, uint8_t slots) |
Max | 9d7357e | 2017-12-14 15:02:33 +0100 | [diff] [blame] | 275 | { |
| 276 | uint8_t num_pdch = pcu_bitcount(slots); |
| 277 | |
| 278 | return OSMO_MIN((num_pdch != 1) ? (128 * num_pdch) : 192, |
Pau Espin Pedrol | 519d071 | 2021-01-14 14:30:03 +0100 | [diff] [blame] | 279 | OSMO_MAX(64, (the_pcu->vty.ws_base + num_pdch * the_pcu->vty.ws_pdch) / 32 * 32)); |
Max | 9d7357e | 2017-12-14 15:02:33 +0100 | [diff] [blame] | 280 | } |
| 281 | |
Jacob Erlbeck | e0c734d | 2015-07-03 14:03:33 +0200 | [diff] [blame] | 282 | int gprs_rlcmac_tbf::update() |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 283 | { |
Jacob Erlbeck | e0c734d | 2015-07-03 14:03:33 +0200 | [diff] [blame] | 284 | int rc; |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 285 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 286 | LOGP(DTBF, LOGL_DEBUG, "********** DL-TBF update **********\n"); |
Pau Espin Pedrol | 8a9eec3 | 2021-10-18 16:11:31 +0200 | [diff] [blame] | 287 | OSMO_ASSERT(direction == GPRS_RLCMAC_DL_TBF); |
Max | c21f007 | 2017-12-15 17:36:45 +0100 | [diff] [blame] | 288 | |
Holger Hans Peter Freyther | aa9c326 | 2013-10-26 17:49:36 +0200 | [diff] [blame] | 289 | tbf_unlink_pdch(this); |
Pau Espin Pedrol | c85e093 | 2021-02-25 18:08:10 +0100 | [diff] [blame] | 290 | rc = the_pcu->alloc_algorithm(bts, this, false, -1); |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 291 | /* if no resource */ |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 292 | if (rc < 0) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 293 | LOGPTBF(this, LOGL_ERROR, "No resource after update???\n"); |
Pau Espin Pedrol | 4e1c9ad | 2021-02-25 17:21:32 +0100 | [diff] [blame] | 294 | bts_do_rate_ctr_inc(bts, CTR_TBF_ALLOC_FAIL); |
Pau Espin Pedrol | e50b5f1 | 2021-10-18 16:13:30 +0200 | [diff] [blame] | 295 | return rc; |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 296 | } |
| 297 | |
Aravind Sirsikar | 0ee31cf | 2016-09-15 17:54:46 +0530 | [diff] [blame] | 298 | if (is_egprs_enabled()) { |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 299 | gprs_rlcmac_dl_tbf *dl_tbf = tbf_as_dl_tbf(this); |
Aravind Sirsikar | 0ee31cf | 2016-09-15 17:54:46 +0530 | [diff] [blame] | 300 | if (dl_tbf) |
Max | 9d7357e | 2017-12-14 15:02:33 +0100 | [diff] [blame] | 301 | dl_tbf->set_window_size(); |
Aravind Sirsikar | 0ee31cf | 2016-09-15 17:54:46 +0530 | [diff] [blame] | 302 | } |
| 303 | |
Pau Espin Pedrol | a2ef802 | 2021-10-18 14:14:20 +0200 | [diff] [blame] | 304 | tbf_update_state_fsm_name(this); |
| 305 | |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 306 | return 0; |
| 307 | } |
| 308 | |
Pau Espin Pedrol | 32744c8 | 2021-10-12 19:36:40 +0200 | [diff] [blame] | 309 | void tbf_assign_control_ts(struct gprs_rlcmac_tbf *tbf) |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 310 | { |
Pau Espin Pedrol | d3d46de | 2021-11-08 13:07:35 +0100 | [diff] [blame] | 311 | if (tbf->control_ts == TBF_TS_UNSET) |
Max | c21f007 | 2017-12-15 17:36:45 +0100 | [diff] [blame] | 312 | LOGPTBF(tbf, LOGL_INFO, "Setting Control TS %d\n", |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 313 | tbf->first_common_ts); |
| 314 | else if (tbf->control_ts != tbf->first_common_ts) |
Pau Espin Pedrol | 7fd9a29 | 2020-11-30 12:18:38 +0100 | [diff] [blame] | 315 | LOGPTBF(tbf, LOGL_INFO, "Changing Control TS %d -> %d\n", |
| 316 | tbf->control_ts, tbf->first_common_ts); |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 317 | tbf->control_ts = tbf->first_common_ts; |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 318 | } |
| 319 | |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 320 | void gprs_rlcmac_tbf::n_reset(enum tbf_counters n) |
| 321 | { |
| 322 | if (n >= N_MAX) { |
| 323 | LOGPTBF(this, LOGL_ERROR, "attempting to reset unknown counter %s\n", |
| 324 | get_value_string(tbf_counters_names, n)); |
| 325 | return; |
| 326 | } |
| 327 | |
Pau Espin Pedrol | ef1fe58 | 2019-09-05 14:40:24 +0200 | [diff] [blame] | 328 | Narr[n] = 0; |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | /* Increment counter and check for MAX value (return true if we hit it) */ |
| 332 | bool gprs_rlcmac_tbf::n_inc(enum tbf_counters n) |
| 333 | { |
| 334 | uint8_t chk; |
| 335 | |
| 336 | if (n >= N_MAX) { |
| 337 | LOGPTBF(this, LOGL_ERROR, "attempting to increment unknown counter %s\n", |
| 338 | get_value_string(tbf_counters_names, n)); |
| 339 | return true; |
| 340 | } |
| 341 | |
Pau Espin Pedrol | ef1fe58 | 2019-09-05 14:40:24 +0200 | [diff] [blame] | 342 | Narr[n]++; |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 343 | |
| 344 | switch(n) { |
| 345 | case N3101: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 346 | chk = bts->n3101; |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 347 | break; |
| 348 | case N3103: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 349 | chk = bts->n3103; |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 350 | break; |
| 351 | case N3105: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 352 | chk = bts->n3105; |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 353 | break; |
| 354 | default: |
| 355 | LOGPTBF(this, LOGL_ERROR, "unhandled counter %s\n", |
| 356 | get_value_string(tbf_counters_names, n)); |
| 357 | return true; |
| 358 | } |
| 359 | |
Pau Espin Pedrol | ef1fe58 | 2019-09-05 14:40:24 +0200 | [diff] [blame] | 360 | if (Narr[n] == chk) { |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 361 | LOGPTBF(this, LOGL_NOTICE, "%s exceeded MAX (%u)\n", |
| 362 | get_value_string(tbf_counters_names, n), chk); |
| 363 | return true; |
Pau Espin Pedrol | 58fdc54 | 2021-03-04 14:10:52 +0100 | [diff] [blame] | 364 | } else { |
| 365 | LOGPTBF(this, LOGL_DEBUG, "%s %" PRIu8 " => %" PRIu8 " (< MAX %" PRIu8 ")\n", |
| 366 | get_value_string(tbf_counters_names, n), Narr[n] - 1, Narr[n], chk); |
| 367 | return false; |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 368 | } |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 369 | } |
| 370 | |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 371 | void gprs_rlcmac_tbf::t_stop(enum tbf_timers t, const char *reason) |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 372 | { |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 373 | if (t >= T_MAX) { |
| 374 | LOGPTBF(this, LOGL_ERROR, "attempting to stop unknown timer %s [%s]\n", |
| 375 | get_value_string(tbf_timers_names, t), reason); |
Max | 0bc982e | 2017-12-21 18:58:50 +0100 | [diff] [blame] | 376 | return; |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 377 | } |
| 378 | |
Pau Espin Pedrol | ef1fe58 | 2019-09-05 14:40:24 +0200 | [diff] [blame] | 379 | if (osmo_timer_pending(&Tarr[t])) { |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 380 | LOGPTBF(this, LOGL_DEBUG, "stopping timer %s [%s]\n", |
| 381 | get_value_string(tbf_timers_names, t), reason); |
Pau Espin Pedrol | ef1fe58 | 2019-09-05 14:40:24 +0200 | [diff] [blame] | 382 | osmo_timer_del(&Tarr[t]); |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
| 386 | /* check if any of T31xx timer(s) are pending */ |
| 387 | bool gprs_rlcmac_tbf::timers_pending(enum tbf_timers t) |
| 388 | { |
| 389 | uint8_t i; |
| 390 | |
| 391 | if (t != T_MAX) |
Pau Espin Pedrol | ef1fe58 | 2019-09-05 14:40:24 +0200 | [diff] [blame] | 392 | return osmo_timer_pending(&Tarr[t]); |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 393 | |
Pau Espin Pedrol | 4b6f0bf | 2021-05-10 18:54:52 +0200 | [diff] [blame] | 394 | for (i = T3141; i < T_MAX; i++) |
Pau Espin Pedrol | ef1fe58 | 2019-09-05 14:40:24 +0200 | [diff] [blame] | 395 | if (osmo_timer_pending(&Tarr[i])) |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 396 | return true; |
| 397 | |
| 398 | return false; |
| 399 | } |
| 400 | |
| 401 | void gprs_rlcmac_tbf::stop_timers(const char *reason) |
| 402 | { |
| 403 | uint8_t i; |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 404 | for (i = T3141; i < T_MAX; i++) |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 405 | t_stop((enum tbf_timers)i, reason); |
Holger Hans Peter Freyther | 86300bb | 2013-10-26 18:01:35 +0200 | [diff] [blame] | 406 | } |
| 407 | |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 408 | static inline void tbf_timeout_free(struct gprs_rlcmac_tbf *tbf, enum tbf_timers t, bool run_diag) |
| 409 | { |
Pau Espin Pedrol | cd6c466 | 2020-09-22 13:41:00 +0200 | [diff] [blame] | 410 | if (run_diag) { |
| 411 | LOGPTBF(tbf, LOGL_NOTICE, "%s timeout expired, freeing TBF: %s\n", |
Pau Espin Pedrol | ab8fba3 | 2021-07-27 16:35:00 +0200 | [diff] [blame] | 412 | get_value_string(tbf_timers_names, t), tbf_rlcmac_diag(tbf)); |
Pau Espin Pedrol | cd6c466 | 2020-09-22 13:41:00 +0200 | [diff] [blame] | 413 | } else { |
| 414 | LOGPTBF(tbf, LOGL_NOTICE, "%s timeout expired, freeing TBF\n", |
| 415 | get_value_string(tbf_timers_names, t)); |
| 416 | } |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 417 | |
| 418 | tbf_free(tbf); |
| 419 | } |
| 420 | |
| 421 | #define T_CBACK(t, diag) static void cb_##t(void *_tbf) { tbf_timeout_free((struct gprs_rlcmac_tbf *)_tbf, t, diag); } |
| 422 | |
Pau Espin Pedrol | 4b6f0bf | 2021-05-10 18:54:52 +0200 | [diff] [blame] | 423 | /* 3GPP TS 44.018 sec 3.5.2.1.5: On the network side, if timer T3141 elapses |
| 424 | * before a successful contention resolution procedure is completed, the newly |
| 425 | * allocated temporary block flow is released as specified in 3GPP TS 44.060 and |
| 426 | * the packet access is forgotten.*/ |
| 427 | T_CBACK(T3141, true) |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 428 | T_CBACK(T3191, true) |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 429 | |
Pau Espin Pedrol | 28f160e | 2019-09-05 14:48:35 +0200 | [diff] [blame] | 430 | void gprs_rlcmac_tbf::t_start(enum tbf_timers t, int T, const char *reason, bool force, |
Max | 467f633 | 2017-12-20 18:13:29 +0100 | [diff] [blame] | 431 | const char *file, unsigned line) |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 432 | { |
Pau Espin Pedrol | 4a5209d | 2021-01-18 14:05:40 +0100 | [diff] [blame] | 433 | int current_fn = bts_current_frame_number(bts); |
Pau Espin Pedrol | 28f160e | 2019-09-05 14:48:35 +0200 | [diff] [blame] | 434 | int sec; |
| 435 | int microsec; |
| 436 | struct osmo_tdef *tdef; |
Philipp Maier | 33c52b6 | 2018-04-10 14:21:11 +0200 | [diff] [blame] | 437 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 438 | if (!(tdef = osmo_tdef_get_entry(bts->T_defs_bts, T))) |
Pau Espin Pedrol | 924aaad | 2021-01-14 12:01:42 +0100 | [diff] [blame] | 439 | tdef = osmo_tdef_get_entry(bts->pcu->T_defs, T); |
Pau Espin Pedrol | 28f160e | 2019-09-05 14:48:35 +0200 | [diff] [blame] | 440 | |
| 441 | if (t >= T_MAX || !tdef) { |
Philipp Maier | 33c52b6 | 2018-04-10 14:21:11 +0200 | [diff] [blame] | 442 | LOGPSRC(DTBF, LOGL_ERROR, file, line, "%s attempting to start unknown timer %s [%s], cur_fn=%d\n", |
| 443 | tbf_name(this), get_value_string(tbf_timers_names, t), reason, current_fn); |
Max | 0bc982e | 2017-12-21 18:58:50 +0100 | [diff] [blame] | 444 | return; |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 445 | } |
| 446 | |
Pau Espin Pedrol | ef1fe58 | 2019-09-05 14:40:24 +0200 | [diff] [blame] | 447 | if (!force && osmo_timer_pending(&Tarr[t])) |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 448 | return; |
| 449 | |
Pau Espin Pedrol | 28f160e | 2019-09-05 14:48:35 +0200 | [diff] [blame] | 450 | switch (tdef->unit) { |
| 451 | case OSMO_TDEF_MS: |
| 452 | sec = 0; |
| 453 | microsec = tdef->val * 1000; |
| 454 | break; |
| 455 | case OSMO_TDEF_S: |
| 456 | sec = tdef->val; |
| 457 | microsec = 0; |
| 458 | break; |
| 459 | default: |
| 460 | /* so far only timers using MS and S */ |
| 461 | OSMO_ASSERT(false); |
| 462 | } |
| 463 | |
Philipp Maier | 33c52b6 | 2018-04-10 14:21:11 +0200 | [diff] [blame] | 464 | LOGPSRC(DTBF, LOGL_DEBUG, file, line, "%s %sstarting timer %s [%s] with %u sec. %u microsec, cur_fn=%d\n", |
Pau Espin Pedrol | ef1fe58 | 2019-09-05 14:40:24 +0200 | [diff] [blame] | 465 | tbf_name(this), osmo_timer_pending(&Tarr[t]) ? "re" : "", |
Philipp Maier | 33c52b6 | 2018-04-10 14:21:11 +0200 | [diff] [blame] | 466 | get_value_string(tbf_timers_names, t), reason, sec, microsec, current_fn); |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 467 | |
Pau Espin Pedrol | ef1fe58 | 2019-09-05 14:40:24 +0200 | [diff] [blame] | 468 | Tarr[t].data = this; |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 469 | |
| 470 | switch(t) { |
Pau Espin Pedrol | 4b6f0bf | 2021-05-10 18:54:52 +0200 | [diff] [blame] | 471 | case T3141: |
| 472 | Tarr[t].cb = cb_T3141; |
| 473 | break; |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 474 | case T3191: |
Pau Espin Pedrol | ef1fe58 | 2019-09-05 14:40:24 +0200 | [diff] [blame] | 475 | Tarr[t].cb = cb_T3191; |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 476 | break; |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 477 | default: |
Philipp Maier | 33c52b6 | 2018-04-10 14:21:11 +0200 | [diff] [blame] | 478 | LOGPSRC(DTBF, LOGL_ERROR, file, line, "%s attempting to set callback for unknown timer %s [%s], cur_fn=%d\n", |
| 479 | tbf_name(this), get_value_string(tbf_timers_names, t), reason, current_fn); |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 480 | } |
| 481 | |
Pau Espin Pedrol | ef1fe58 | 2019-09-05 14:40:24 +0200 | [diff] [blame] | 482 | osmo_timer_schedule(&Tarr[t], sec, microsec); |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 483 | } |
| 484 | |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 485 | int gprs_rlcmac_tbf::check_polling(uint32_t fn, uint8_t ts, |
Pau Espin Pedrol | 57dcde4 | 2021-02-01 18:14:23 +0100 | [diff] [blame] | 486 | uint32_t *poll_fn_, unsigned int *rrbp_) const |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 487 | { |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 488 | int rc; |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 489 | if (!is_control_ts(ts)) { |
Max | c21f007 | 2017-12-15 17:36:45 +0100 | [diff] [blame] | 490 | LOGPTBF(this, LOGL_DEBUG, "Polling cannot be " |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 491 | "scheduled in this TS %d (first control TS %d)\n", |
| 492 | ts, control_ts); |
| 493 | return -EINVAL; |
| 494 | } |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 495 | |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 496 | if ((rc = pdch_ulc_get_next_free_rrbp_fn(trx->pdch[ts].ulc, fn, poll_fn_, rrbp_)) < 0) { |
Pau Espin Pedrol | b6babc3 | 2021-11-08 12:04:43 +0100 | [diff] [blame] | 497 | LOGPTBF(this, LOGL_NOTICE, |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 498 | "(bts=%u,trx=%u,ts=%u) FN=%u No suitable free RRBP offset found!\n", |
| 499 | trx->bts->nr, trx->trx_no, ts, fn); |
| 500 | return rc; |
| 501 | } |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 502 | |
| 503 | return 0; |
| 504 | } |
| 505 | |
Pau Espin Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 506 | void gprs_rlcmac_tbf::set_polling(uint32_t new_poll_fn, uint8_t ts, enum pdch_ulc_tbf_poll_reason reason) |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 507 | { |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 508 | /* schedule polling */ |
Pau Espin Pedrol | a161bf4 | 2021-07-30 13:42:06 +0200 | [diff] [blame] | 509 | if (pdch_ulc_reserve_tbf_poll(trx->pdch[ts].ulc, new_poll_fn, this, reason) < 0) |
Pau Espin Pedrol | bd1f01f | 2022-10-27 15:19:39 +0200 | [diff] [blame] | 510 | LOGPTBF(this, LOGL_ERROR, "Failed scheduling poll on PACCH (FN=%d, TS=%d)\n", |
Pau Espin Pedrol | a161bf4 | 2021-07-30 13:42:06 +0200 | [diff] [blame] | 511 | new_poll_fn, ts); |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 512 | } |
| 513 | |
Pau Espin Pedrol | 16e1678 | 2021-03-29 19:10:19 +0200 | [diff] [blame] | 514 | void gprs_rlcmac_tbf::poll_timeout(struct gprs_rlcmac_pdch *pdch, uint32_t poll_fn, enum pdch_ulc_tbf_poll_reason reason) |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 515 | { |
Pau Espin Pedrol | d72f46f | 2021-09-28 13:10:03 +0200 | [diff] [blame] | 516 | gprs_rlcmac_ul_tbf *ul_tbf; |
| 517 | gprs_rlcmac_dl_tbf *dl_tbf; |
Max | fd13f6c | 2017-07-07 14:29:36 +0200 | [diff] [blame] | 518 | |
Max | c21f007 | 2017-12-15 17:36:45 +0100 | [diff] [blame] | 519 | LOGPTBF(this, LOGL_NOTICE, "poll timeout for FN=%d, TS=%d (curr FN %d)\n", |
Pau Espin Pedrol | 16e1678 | 2021-03-29 19:10:19 +0200 | [diff] [blame] | 520 | poll_fn, pdch->ts_no, bts_current_frame_number(bts)); |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 521 | |
Pau Espin Pedrol | d72f46f | 2021-09-28 13:10:03 +0200 | [diff] [blame] | 522 | switch (reason) { |
| 523 | case PDCH_ULC_POLL_UL_ACK: |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 524 | ul_tbf = tbf_as_ul_tbf(this); |
Pau Espin Pedrol | d72f46f | 2021-09-28 13:10:03 +0200 | [diff] [blame] | 525 | OSMO_ASSERT(ul_tbf); |
| 526 | if (!tbf_ul_ack_exp_ctrl_ack(ul_tbf, poll_fn, pdch->ts_no)) { |
| 527 | LOGPTBF(this, LOGL_NOTICE, "FN=%d, TS=%d (curr FN %d): POLL_UL_ACK not expected!\n", |
| 528 | poll_fn, pdch->ts_no, bts_current_frame_number(bts)); |
| 529 | return; |
| 530 | } |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 531 | bts_do_rate_ctr_inc(bts, CTR_RLC_ACK_TIMEDOUT); |
| 532 | bts_do_rate_ctr_inc(bts, CTR_PUAN_POLL_TIMEDOUT); |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 533 | if (state_is(TBF_ST_FINISHED)) { |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 534 | if (ul_tbf->n_inc(N3103)) { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 535 | bts_do_rate_ctr_inc(bts, CTR_PUAN_POLL_FAILED); |
Pau Espin Pedrol | f197f15 | 2022-11-17 20:18:46 +0100 | [diff] [blame] | 536 | osmo_fsm_inst_dispatch(this->state_fi, TBF_EV_MAX_N3103, NULL); |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 537 | return; |
| 538 | } |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 539 | } |
Pau Espin Pedrol | ea8dbdd | 2021-07-29 18:39:16 +0200 | [diff] [blame] | 540 | osmo_fsm_inst_dispatch(ul_tbf->ul_ack_fsm.fi, TBF_UL_ACK_EV_POLL_TIMEOUT, NULL); |
Pau Espin Pedrol | d72f46f | 2021-09-28 13:10:03 +0200 | [diff] [blame] | 541 | break; |
| 542 | |
| 543 | case PDCH_ULC_POLL_UL_ASS: |
| 544 | if (!ul_ass_state_is(TBF_UL_ASS_WAIT_ACK)) { |
| 545 | LOGPTBF(this, LOGL_NOTICE, "FN=%d, TS=%d (curr FN %d): POLL_UL_ASS not expected! state is %s\n", |
| 546 | poll_fn, pdch->ts_no, bts_current_frame_number(bts), |
| 547 | osmo_fsm_inst_state_name(tbf_ul_ass_fi(this))); |
| 548 | return; |
| 549 | } |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 550 | bts_do_rate_ctr_inc(bts, CTR_RLC_ASS_TIMEDOUT); |
| 551 | bts_do_rate_ctr_inc(bts, CTR_PUA_POLL_TIMEDOUT); |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 552 | if (n_inc(N3105)) { |
Pau Espin Pedrol | f197f15 | 2022-11-17 20:18:46 +0100 | [diff] [blame] | 553 | osmo_fsm_inst_dispatch(this->state_fi, TBF_EV_MAX_N3105, NULL); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 554 | bts_do_rate_ctr_inc(bts, CTR_RLC_ASS_FAILED); |
| 555 | bts_do_rate_ctr_inc(bts, CTR_PUA_POLL_FAILED); |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 556 | return; |
| 557 | } |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 558 | /* Signal timeout to FSM to reschedule UL assignment */ |
| 559 | osmo_fsm_inst_dispatch(this->ul_ass_fsm.fi, TBF_UL_ASS_EV_ASS_POLL_TIMEOUT, NULL); |
Pau Espin Pedrol | d72f46f | 2021-09-28 13:10:03 +0200 | [diff] [blame] | 560 | break; |
| 561 | |
| 562 | case PDCH_ULC_POLL_DL_ASS: |
| 563 | if (!dl_ass_state_is(TBF_DL_ASS_WAIT_ACK)) { |
| 564 | LOGPTBF(this, LOGL_NOTICE, "FN=%d, TS=%d (curr FN %d): POLL_DL_ASS not expected! state is %s\n", |
| 565 | poll_fn, pdch->ts_no, bts_current_frame_number(bts), |
| 566 | osmo_fsm_inst_state_name(tbf_dl_ass_fi(this))); |
| 567 | return; |
| 568 | } |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 569 | bts_do_rate_ctr_inc(bts, CTR_RLC_ASS_TIMEDOUT); |
| 570 | bts_do_rate_ctr_inc(bts, CTR_PDA_POLL_TIMEDOUT); |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 571 | if (n_inc(N3105)) { |
Pau Espin Pedrol | f197f15 | 2022-11-17 20:18:46 +0100 | [diff] [blame] | 572 | osmo_fsm_inst_dispatch(this->state_fi, TBF_EV_MAX_N3105, NULL); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 573 | bts_do_rate_ctr_inc(bts, CTR_RLC_ASS_FAILED); |
| 574 | bts_do_rate_ctr_inc(bts, CTR_PDA_POLL_FAILED); |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 575 | return; |
| 576 | } |
Pau Espin Pedrol | 49a2f40 | 2021-07-27 17:33:07 +0200 | [diff] [blame] | 577 | /* Signal timeout to FSM to reschedule DL assignment */ |
| 578 | osmo_fsm_inst_dispatch(this->dl_ass_fsm.fi, TBF_DL_ASS_EV_ASS_POLL_TIMEOUT, NULL); |
Pau Espin Pedrol | d72f46f | 2021-09-28 13:10:03 +0200 | [diff] [blame] | 579 | break; |
| 580 | |
| 581 | case PDCH_ULC_POLL_CELL_CHG_CONTINUE: |
| 582 | if (!m_ms->nacc || !nacc_fsm_exp_ctrl_ack(m_ms->nacc, poll_fn, pdch->ts_no)) { |
| 583 | LOGPTBF(this, LOGL_NOTICE, "FN=%d, TS=%d (curr FN %d): POLL_CELL_CHG_CONTINUE not expected!\n", |
| 584 | poll_fn, pdch->ts_no, bts_current_frame_number(bts)); |
| 585 | return; |
| 586 | } |
Pau Espin Pedrol | 952cb3d | 2021-02-01 14:52:48 +0100 | [diff] [blame] | 587 | /* Timeout waiting for CTRL ACK acking Pkt Cell Change Continue */ |
| 588 | osmo_fsm_inst_dispatch(m_ms->nacc->fi, NACC_EV_TIMEOUT_CELL_CHG_CONTINUE, NULL); |
Pau Espin Pedrol | d72f46f | 2021-09-28 13:10:03 +0200 | [diff] [blame] | 589 | break; |
Pau Espin Pedrol | b5fece9 | 2021-08-23 16:58:04 +0200 | [diff] [blame] | 590 | |
Pau Espin Pedrol | d72f46f | 2021-09-28 13:10:03 +0200 | [diff] [blame] | 591 | case PDCH_ULC_POLL_DL_ACK: |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 592 | dl_tbf = tbf_as_dl_tbf(this); |
Pau Espin Pedrol | d72f46f | 2021-09-28 13:10:03 +0200 | [diff] [blame] | 593 | /* POLL Timeout expecting DL ACK/NACK: implies direction == GPRS_RLCMAC_DL_TBF */ |
| 594 | OSMO_ASSERT(dl_tbf); |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 595 | if (!(dl_tbf->state_fsm.state_flags & (1 << GPRS_RLCMAC_FLAG_TO_DL_ACK))) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 596 | LOGPTBF(this, LOGL_NOTICE, |
Pau Espin Pedrol | cd6c466 | 2020-09-22 13:41:00 +0200 | [diff] [blame] | 597 | "Timeout for polling PACKET DOWNLINK ACK: %s\n", |
Pau Espin Pedrol | ab8fba3 | 2021-07-27 16:35:00 +0200 | [diff] [blame] | 598 | tbf_rlcmac_diag(dl_tbf)); |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 599 | dl_tbf->state_fsm.state_flags |= (1 << GPRS_RLCMAC_FLAG_TO_DL_ACK); |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 600 | } |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 601 | if (dl_tbf->state_is(TBF_ST_RELEASING)) |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 602 | bts_do_rate_ctr_inc(bts, CTR_RLC_REL_TIMEDOUT); |
Mrinal Mishra | f86307e | 2016-11-10 18:16:30 +0530 | [diff] [blame] | 603 | else { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 604 | bts_do_rate_ctr_inc(bts, CTR_RLC_ACK_TIMEDOUT); |
| 605 | bts_do_rate_ctr_inc(bts, CTR_PDAN_POLL_TIMEDOUT); |
Mrinal Mishra | f86307e | 2016-11-10 18:16:30 +0530 | [diff] [blame] | 606 | } |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 607 | if (dl_tbf->n_inc(N3105)) { |
Pau Espin Pedrol | f197f15 | 2022-11-17 20:18:46 +0100 | [diff] [blame] | 608 | osmo_fsm_inst_dispatch(this->state_fi, TBF_EV_MAX_N3105, NULL); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 609 | bts_do_rate_ctr_inc(bts, CTR_PDAN_POLL_FAILED); |
| 610 | bts_do_rate_ctr_inc(bts, CTR_RLC_ACK_FAILED); |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 611 | return; |
| 612 | } |
| 613 | /* resend IMM.ASS on CCCH on timeout */ |
Pau Espin Pedrol | f197f15 | 2022-11-17 20:18:46 +0100 | [diff] [blame] | 614 | osmo_fsm_inst_dispatch(this->state_fi, TBF_EV_DL_ACKNACK_MISS, NULL); |
Pau Espin Pedrol | d72f46f | 2021-09-28 13:10:03 +0200 | [diff] [blame] | 615 | break; |
| 616 | |
| 617 | default: |
| 618 | LOGPTBF(this, LOGL_ERROR, "Poll Timeout, reason %s unhandled!\n", |
| 619 | get_value_string(pdch_ulc_tbf_poll_reason_names, reason)); |
| 620 | } |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 621 | } |
| 622 | |
Pau Espin Pedrol | e9f77d3 | 2020-10-23 18:41:40 +0200 | [diff] [blame] | 623 | int gprs_rlcmac_tbf::setup(int8_t use_trx, bool single_slot) |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 624 | { |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 625 | int rc; |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 626 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 627 | if (ms_mode(m_ms) != GPRS) |
Pau Espin Pedrol | e9f77d3 | 2020-10-23 18:41:40 +0200 | [diff] [blame] | 628 | enable_egprs(); |
Daniel Willmann | 1b3864f | 2014-07-30 13:25:19 +0200 | [diff] [blame] | 629 | |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 630 | /* select algorithm */ |
Pau Espin Pedrol | c85e093 | 2021-02-25 18:08:10 +0100 | [diff] [blame] | 631 | rc = the_pcu->alloc_algorithm(bts, this, single_slot, use_trx); |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 632 | /* if no resource */ |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 633 | if (rc < 0) { |
Pau Espin Pedrol | 7c9a4a4 | 2021-02-25 17:21:10 +0100 | [diff] [blame] | 634 | LOGPTBF(this, LOGL_NOTICE, |
| 635 | "Timeslot Allocation failed: trx = %d, single_slot = %d\n", |
| 636 | use_trx, single_slot); |
Pau Espin Pedrol | 4e1c9ad | 2021-02-25 17:21:32 +0100 | [diff] [blame] | 637 | bts_do_rate_ctr_inc(bts, CTR_TBF_ALLOC_FAIL); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 638 | return -1; |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 639 | } |
Pau Espin Pedrol | 32744c8 | 2021-10-12 19:36:40 +0200 | [diff] [blame] | 640 | /* assign initial control ts */ |
| 641 | tbf_assign_control_ts(this); |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 642 | |
| 643 | /* set timestamp */ |
Pau Espin Pedrol | e9f77d3 | 2020-10-23 18:41:40 +0200 | [diff] [blame] | 644 | osmo_clock_gettime(CLOCK_MONOTONIC, &meas.rssi_tv); |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 645 | |
Pau Espin Pedrol | e9f77d3 | 2020-10-23 18:41:40 +0200 | [diff] [blame] | 646 | LOGPTBF(this, LOGL_INFO, |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 647 | "Allocated: trx = %d, ul_slots = %02x, dl_slots = %02x\n", |
Pau Espin Pedrol | e9f77d3 | 2020-10-23 18:41:40 +0200 | [diff] [blame] | 648 | this->trx->trx_no, ul_slots(), dl_slots()); |
Jacob Erlbeck | 5879c64 | 2015-07-10 10:41:36 +0200 | [diff] [blame] | 649 | |
Pau Espin Pedrol | e9f77d3 | 2020-10-23 18:41:40 +0200 | [diff] [blame] | 650 | m_ctrs = rate_ctr_group_alloc(this, &tbf_ctrg_desc, next_tbf_ctr_group_id++); |
| 651 | if (!m_ctrs) { |
| 652 | LOGPTBF(this, LOGL_ERROR, "Couldn't allocate TBF counters\n"); |
Harald Welte | 9530a40 | 2017-07-12 00:46:36 +0200 | [diff] [blame] | 653 | return -1; |
| 654 | } |
sivasankari | 5395073 | 2016-12-08 17:15:17 +0530 | [diff] [blame] | 655 | |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 656 | tbf_update_state_fsm_name(this); |
| 657 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 658 | ms_attach_tbf(m_ms, this); |
Pau Espin Pedrol | e9f77d3 | 2020-10-23 18:41:40 +0200 | [diff] [blame] | 659 | |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 660 | return 0; |
| 661 | } |
| 662 | |
Pau Espin Pedrol | 57dcde4 | 2021-02-01 18:14:23 +0100 | [diff] [blame] | 663 | const char *tbf_name(const gprs_rlcmac_tbf *tbf) |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 664 | { |
Alexander Couzens | e04fd0c | 2016-05-31 13:18:01 +0200 | [diff] [blame] | 665 | return tbf ? tbf->name() : "(no TBF)"; |
Jacob Erlbeck | adcdf15 | 2015-03-03 14:45:55 +0100 | [diff] [blame] | 666 | } |
| 667 | |
Pau Espin Pedrol | 57843c5 | 2022-11-03 13:35:19 +0100 | [diff] [blame] | 668 | const char *gprs_rlcmac_tbf::name(bool enclousure) const |
Jacob Erlbeck | adcdf15 | 2015-03-03 14:45:55 +0100 | [diff] [blame] | 669 | { |
Pau Espin Pedrol | 57843c5 | 2022-11-03 13:35:19 +0100 | [diff] [blame] | 670 | struct osmo_strbuf sb = { .buf = m_name_buf, .len = sizeof(m_name_buf) }; |
| 671 | |
| 672 | if (enclousure) |
| 673 | OSMO_STRBUF_PRINTF(sb, "TBF("); |
| 674 | OSMO_STRBUF_PRINTF(sb, "%s", direction == GPRS_RLCMAC_UL_TBF ? "UL" : "DL"); |
| 675 | if (this->trx) { /* This may not be available during TBF alloc func time */ |
| 676 | int8_t tfi = (m_tfi == TBF_TS_UNSET) ? -1 : m_tfi; |
| 677 | OSMO_STRBUF_PRINTF(sb, ":TFI-%u-%u-%d", |
| 678 | this->trx->bts->nr, this->trx->trx_no, tfi); |
| 679 | } |
| 680 | OSMO_STRBUF_PRINTF(sb, ":STATE-%s:%sGPRS", |
| 681 | state_name(), is_egprs_enabled() ? "E" : ""); |
| 682 | if (m_ms) { |
| 683 | uint32_t tlli = ms_tlli(m_ms); |
| 684 | if (ms_imsi_is_valid(m_ms)) |
| 685 | OSMO_STRBUF_PRINTF(sb, ":IMSI-%s", ms_imsi(m_ms)); |
| 686 | if (tlli != GSM_RESERVED_TMSI) |
| 687 | OSMO_STRBUF_PRINTF(sb, ":TLLI-0x%08x", tlli); |
| 688 | } |
| 689 | if (enclousure) |
| 690 | OSMO_STRBUF_PRINTF(sb, ")"); |
Jacob Erlbeck | adcdf15 | 2015-03-03 14:45:55 +0100 | [diff] [blame] | 691 | return m_name_buf; |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 692 | } |
Holger Hans Peter Freyther | 758dc12 | 2013-11-06 20:39:45 +0100 | [diff] [blame] | 693 | |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 694 | void tbf_update_state_fsm_name(struct gprs_rlcmac_tbf *tbf) |
| 695 | { |
Pau Espin Pedrol | 57843c5 | 2022-11-03 13:35:19 +0100 | [diff] [blame] | 696 | const char *buf = tbf->name(false); |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 697 | |
Pau Espin Pedrol | f197f15 | 2022-11-17 20:18:46 +0100 | [diff] [blame] | 698 | osmo_fsm_inst_update_id(tbf->state_fi, buf); |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 699 | osmo_fsm_inst_update_id(tbf->ul_ass_fsm.fi, buf); |
Pau Espin Pedrol | 49a2f40 | 2021-07-27 17:33:07 +0200 | [diff] [blame] | 700 | osmo_fsm_inst_update_id(tbf->dl_ass_fsm.fi, buf); |
Pau Espin Pedrol | ea8dbdd | 2021-07-29 18:39:16 +0200 | [diff] [blame] | 701 | |
| 702 | if (tbf_direction(tbf) == GPRS_RLCMAC_UL_TBF) { |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 703 | struct gprs_rlcmac_ul_tbf *ul_tbf = tbf_as_ul_tbf(tbf); |
Pau Espin Pedrol | ea8dbdd | 2021-07-29 18:39:16 +0200 | [diff] [blame] | 704 | osmo_fsm_inst_update_id(ul_tbf->ul_ack_fsm.fi, buf); |
| 705 | } |
| 706 | |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 707 | } |
| 708 | |
Holger Hans Peter Freyther | 7a5f3c2 | 2013-11-26 13:08:12 +0100 | [diff] [blame] | 709 | void gprs_rlcmac_tbf::rotate_in_list() |
| 710 | { |
Pau Espin Pedrol | 1a1557a | 2021-05-13 18:39:36 +0200 | [diff] [blame] | 711 | llist_del(tbf_trx_list((struct gprs_rlcmac_tbf *)this)); |
Holger Hans Peter Freyther | 7a5f3c2 | 2013-11-26 13:08:12 +0100 | [diff] [blame] | 712 | if (direction == GPRS_RLCMAC_UL_TBF) |
Pau Espin Pedrol | 1a1557a | 2021-05-13 18:39:36 +0200 | [diff] [blame] | 713 | llist_add(tbf_trx_list((struct gprs_rlcmac_tbf *)this), &trx->ul_tbfs); |
Holger Hans Peter Freyther | 7a5f3c2 | 2013-11-26 13:08:12 +0100 | [diff] [blame] | 714 | else |
Pau Espin Pedrol | 1a1557a | 2021-05-13 18:39:36 +0200 | [diff] [blame] | 715 | llist_add(tbf_trx_list((struct gprs_rlcmac_tbf *)this), &trx->dl_tbfs); |
Holger Hans Peter Freyther | 7a5f3c2 | 2013-11-26 13:08:12 +0100 | [diff] [blame] | 716 | } |
Holger Hans Peter Freyther | 8f399de | 2013-12-25 20:22:35 +0100 | [diff] [blame] | 717 | |
Jacob Erlbeck | 617c712 | 2015-06-30 09:18:30 +0200 | [diff] [blame] | 718 | uint8_t gprs_rlcmac_tbf::dl_slots() const |
| 719 | { |
| 720 | uint8_t slots = 0; |
| 721 | size_t i; |
| 722 | |
| 723 | if (direction == GPRS_RLCMAC_UL_TBF) |
| 724 | return 0; |
| 725 | |
| 726 | for (i = 0; i < ARRAY_SIZE(pdch); i += 1) |
| 727 | if (pdch[i]) |
| 728 | slots |= 1 << i; |
| 729 | |
| 730 | return slots; |
| 731 | } |
| 732 | |
| 733 | uint8_t gprs_rlcmac_tbf::ul_slots() const |
| 734 | { |
| 735 | uint8_t slots = 0; |
| 736 | size_t i; |
| 737 | |
| 738 | if (direction == GPRS_RLCMAC_DL_TBF) { |
| 739 | if (control_ts < 8) |
| 740 | slots |= 1 << control_ts; |
| 741 | if (first_common_ts < 8) |
| 742 | slots |= 1 << first_common_ts; |
| 743 | |
| 744 | return slots; |
| 745 | } |
| 746 | |
| 747 | for (i = 0; i < ARRAY_SIZE(pdch); i += 1) |
| 748 | if (pdch[i]) |
| 749 | slots |= 1 << i; |
| 750 | |
| 751 | return slots; |
| 752 | } |
Jacob Erlbeck | 646da1b | 2016-01-22 17:41:33 +0100 | [diff] [blame] | 753 | |
| 754 | bool gprs_rlcmac_tbf::is_control_ts(uint8_t ts) const |
| 755 | { |
| 756 | return ts == control_ts; |
| 757 | } |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 758 | |
Oliver Smith | 402451b | 2021-09-08 09:33:24 +0200 | [diff] [blame] | 759 | void gprs_rlcmac_tbf::enable_egprs() |
| 760 | { |
| 761 | /* Decrease GPRS TBF count of attached PDCHs */ |
| 762 | for (size_t ts = 0; ts < ARRAY_SIZE(pdch); ts++) { |
| 763 | if (pdch[ts]) |
| 764 | pdch[ts]->num_tbfs_update(this, false); |
| 765 | } |
| 766 | |
| 767 | m_egprs_enabled = true; |
| 768 | window()->set_sns(RLC_EGPRS_SNS); |
| 769 | |
| 770 | /* Increase EGPRS TBF count of attached PDCHs */ |
| 771 | for (size_t ts = 0; ts < ARRAY_SIZE(pdch); ts++) { |
| 772 | if (pdch[ts]) |
| 773 | pdch[ts]->num_tbfs_update(this, true); |
| 774 | } |
| 775 | } |
| 776 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 777 | /* C API */ |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 778 | enum tbf_fsm_states tbf_state(const struct gprs_rlcmac_tbf *tbf) |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 779 | { |
Pau Espin Pedrol | f197f15 | 2022-11-17 20:18:46 +0100 | [diff] [blame] | 780 | return (enum tbf_fsm_states)tbf->state_fi->state; |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 781 | } |
| 782 | |
Pau Espin Pedrol | 9438613 | 2022-10-28 19:50:09 +0200 | [diff] [blame] | 783 | struct osmo_fsm_inst *tbf_state_fi(const struct gprs_rlcmac_tbf *tbf) |
| 784 | { |
Pau Espin Pedrol | f197f15 | 2022-11-17 20:18:46 +0100 | [diff] [blame] | 785 | return tbf->state_fi; |
Pau Espin Pedrol | 9438613 | 2022-10-28 19:50:09 +0200 | [diff] [blame] | 786 | } |
| 787 | |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 788 | struct osmo_fsm_inst *tbf_ul_ass_fi(const struct gprs_rlcmac_tbf *tbf) |
| 789 | { |
| 790 | return tbf->ul_ass_fsm.fi; |
| 791 | } |
| 792 | |
Pau Espin Pedrol | 49a2f40 | 2021-07-27 17:33:07 +0200 | [diff] [blame] | 793 | struct osmo_fsm_inst *tbf_dl_ass_fi(const struct gprs_rlcmac_tbf *tbf) |
| 794 | { |
| 795 | return tbf->dl_ass_fsm.fi; |
| 796 | } |
| 797 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 798 | enum gprs_rlcmac_tbf_direction tbf_direction(const struct gprs_rlcmac_tbf *tbf) |
| 799 | { |
| 800 | return tbf->direction; |
| 801 | } |
| 802 | |
| 803 | void tbf_set_ms(struct gprs_rlcmac_tbf *tbf, GprsMs *ms) |
| 804 | { |
| 805 | tbf->set_ms(ms); |
| 806 | } |
| 807 | |
| 808 | struct llist_head *tbf_ms_list(struct gprs_rlcmac_tbf *tbf) |
| 809 | { |
| 810 | return &tbf->m_ms_list.list; |
| 811 | } |
| 812 | |
Pau Espin Pedrol | 1a1557a | 2021-05-13 18:39:36 +0200 | [diff] [blame] | 813 | struct llist_head *tbf_trx_list(struct gprs_rlcmac_tbf *tbf) |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 814 | { |
Pau Espin Pedrol | 1a1557a | 2021-05-13 18:39:36 +0200 | [diff] [blame] | 815 | return &tbf->m_trx_list.list; |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 816 | } |
| 817 | |
Pau Espin Pedrol | 1e77ca8 | 2021-01-27 13:22:03 +0100 | [diff] [blame] | 818 | struct GprsMs *tbf_ms(const struct gprs_rlcmac_tbf *tbf) |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 819 | { |
| 820 | return tbf->ms(); |
| 821 | } |
| 822 | |
| 823 | bool tbf_timers_pending(struct gprs_rlcmac_tbf *tbf, enum tbf_timers t) |
| 824 | { |
| 825 | return tbf->timers_pending(t); |
| 826 | } |
| 827 | |
| 828 | struct gprs_llc *tbf_llc(struct gprs_rlcmac_tbf *tbf) |
| 829 | { |
| 830 | return &tbf->m_llc; |
| 831 | } |
| 832 | |
| 833 | uint8_t tbf_first_common_ts(const struct gprs_rlcmac_tbf *tbf) |
| 834 | { |
| 835 | return tbf->first_common_ts; |
| 836 | } |
| 837 | |
| 838 | uint8_t tbf_dl_slots(const struct gprs_rlcmac_tbf *tbf) |
| 839 | { |
| 840 | return tbf->dl_slots(); |
| 841 | } |
| 842 | uint8_t tbf_ul_slots(const struct gprs_rlcmac_tbf *tbf) |
| 843 | { |
| 844 | return tbf->ul_slots(); |
| 845 | } |
| 846 | |
| 847 | bool tbf_is_tfi_assigned(const struct gprs_rlcmac_tbf *tbf) |
| 848 | { |
Pau Espin Pedrol | c6e4aef | 2022-11-17 21:00:24 +0100 | [diff] [blame] | 849 | const struct gprs_rlcmac_dl_tbf *dl_tbf; |
| 850 | |
| 851 | /* The TBF is established: */ |
| 852 | if (tbf->state_fi->state > TBF_ST_ASSIGN) |
| 853 | return true; |
| 854 | |
| 855 | /* The DL TBF has been assigned by a IMM.ASS: */ |
| 856 | dl_tbf = tbf_as_dl_tbf_const(tbf); |
| 857 | if (tbf->state_fi->state == TBF_ST_ASSIGN && dl_tbf && |
| 858 | (dl_tbf->state_fsm.state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH))) |
| 859 | return true; |
| 860 | |
| 861 | return false; |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 862 | } |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 863 | |
| 864 | uint8_t tbf_tfi(const struct gprs_rlcmac_tbf *tbf) |
| 865 | { |
| 866 | return tbf->tfi(); |
| 867 | } |
Pau Espin Pedrol | 952cb3d | 2021-02-01 14:52:48 +0100 | [diff] [blame] | 868 | |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 869 | bool tbf_is_egprs_enabled(const struct gprs_rlcmac_tbf *tbf) |
| 870 | { |
| 871 | return tbf->is_egprs_enabled(); |
| 872 | } |
| 873 | |
Pau Espin Pedrol | 952cb3d | 2021-02-01 14:52:48 +0100 | [diff] [blame] | 874 | int tbf_check_polling(const struct gprs_rlcmac_tbf *tbf, uint32_t fn, uint8_t ts, uint32_t *poll_fn, unsigned int *rrbp) |
| 875 | { |
| 876 | return tbf->check_polling(fn, ts, poll_fn, rrbp); |
| 877 | } |
| 878 | |
Pau Espin Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 879 | void tbf_set_polling(struct gprs_rlcmac_tbf *tbf, uint32_t new_poll_fn, uint8_t ts, enum pdch_ulc_tbf_poll_reason t) |
Pau Espin Pedrol | 952cb3d | 2021-02-01 14:52:48 +0100 | [diff] [blame] | 880 | { |
| 881 | return tbf->set_polling(new_poll_fn, ts, t); |
| 882 | } |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 883 | |
Pau Espin Pedrol | 16e1678 | 2021-03-29 19:10:19 +0200 | [diff] [blame] | 884 | void tbf_poll_timeout(struct gprs_rlcmac_tbf *tbf, struct gprs_rlcmac_pdch *pdch, uint32_t poll_fn, enum pdch_ulc_tbf_poll_reason reason) |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 885 | { |
Pau Espin Pedrol | 16e1678 | 2021-03-29 19:10:19 +0200 | [diff] [blame] | 886 | tbf->poll_timeout(pdch, poll_fn, reason); |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 887 | } |
Pau Espin Pedrol | ab8fba3 | 2021-07-27 16:35:00 +0200 | [diff] [blame] | 888 | |
Pau Espin Pedrol | 49a2f40 | 2021-07-27 17:33:07 +0200 | [diff] [blame] | 889 | bool tbf_is_control_ts(const struct gprs_rlcmac_tbf *tbf, uint8_t ts) |
| 890 | { |
| 891 | return tbf->is_control_ts(ts); |
| 892 | } |
| 893 | |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 894 | bool tbf_can_upgrade_to_multislot(const struct gprs_rlcmac_tbf *tbf) |
| 895 | { |
| 896 | return tbf->upgrade_to_multislot; |
| 897 | } |
| 898 | |
| 899 | int tbf_update(struct gprs_rlcmac_tbf *tbf) |
| 900 | { |
| 901 | return tbf->update(); |
| 902 | } |
| 903 | |
Pau Espin Pedrol | ab8fba3 | 2021-07-27 16:35:00 +0200 | [diff] [blame] | 904 | const char* tbf_rlcmac_diag(const struct gprs_rlcmac_tbf *tbf) |
| 905 | { |
| 906 | static char buf[256]; |
| 907 | struct osmo_strbuf sb = { .buf = buf, .len = sizeof(buf) }; |
| 908 | |
| 909 | OSMO_STRBUF_PRINTF(sb, "|"); |
Pau Espin Pedrol | c65c9e5 | 2021-07-28 18:22:00 +0200 | [diff] [blame] | 910 | if (tbf->direction == GPRS_RLCMAC_UL_TBF) { |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 911 | const struct gprs_rlcmac_ul_tbf *ul_tbf = tbf_as_ul_tbf_const(tbf); |
| 912 | if (ul_tbf->state_fsm.state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH)) |
| 913 | OSMO_STRBUF_PRINTF(sb, "Assignment was on CCCH|"); |
| 914 | if (ul_tbf->state_fsm.state_flags & (1 << GPRS_RLCMAC_FLAG_PACCH)) |
| 915 | OSMO_STRBUF_PRINTF(sb, "Assignment was on PACCH|"); |
Pau Espin Pedrol | c65c9e5 | 2021-07-28 18:22:00 +0200 | [diff] [blame] | 916 | if (ul_tbf->m_rx_counter) |
| 917 | OSMO_STRBUF_PRINTF(sb, "Uplink data was received|"); |
| 918 | else |
| 919 | OSMO_STRBUF_PRINTF(sb, "No uplink data received yet|"); |
| 920 | } else { |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 921 | const struct gprs_rlcmac_dl_tbf *dl_tbf = tbf_as_dl_tbf_const(tbf); |
| 922 | if (dl_tbf->state_fsm.state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH)) |
| 923 | OSMO_STRBUF_PRINTF(sb, "Assignment was on CCCH|"); |
| 924 | if (dl_tbf->state_fsm.state_flags & (1 << GPRS_RLCMAC_FLAG_PACCH)) |
| 925 | OSMO_STRBUF_PRINTF(sb, "Assignment was on PACCH|"); |
| 926 | if (dl_tbf->state_fsm.state_flags & (1 << GPRS_RLCMAC_FLAG_DL_ACK)) |
Pau Espin Pedrol | c65c9e5 | 2021-07-28 18:22:00 +0200 | [diff] [blame] | 927 | OSMO_STRBUF_PRINTF(sb, "Downlink ACK was received|"); |
| 928 | else |
| 929 | OSMO_STRBUF_PRINTF(sb, "No downlink ACK received yet|"); |
| 930 | } |
Pau Espin Pedrol | ab8fba3 | 2021-07-27 16:35:00 +0200 | [diff] [blame] | 931 | |
| 932 | return buf; |
| 933 | } |
Pau Espin Pedrol | 14beef6 | 2022-10-26 19:44:07 +0200 | [diff] [blame] | 934 | |
Pau Espin Pedrol | 22b26d8 | 2022-10-26 15:44:14 +0200 | [diff] [blame] | 935 | struct gprs_rlcmac_trx *tbf_get_trx(struct gprs_rlcmac_tbf *tbf) |
| 936 | { |
| 937 | return tbf->trx; |
| 938 | } |
Pau Espin Pedrol | ee35008 | 2022-10-28 17:35:03 +0200 | [diff] [blame] | 939 | |
| 940 | void tbf_stop_timers(struct gprs_rlcmac_tbf *tbf, const char *reason) |
| 941 | { |
| 942 | tbf->stop_timers(reason); |
| 943 | } |