Holger Hans Peter Freyther | b6acfda | 2013-10-17 19:41:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 by Holger Hans Peter Freyther |
| 3 | * |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <bts.h> |
Holger Hans Peter Freyther | b78adcd | 2013-10-17 20:12:37 +0200 | [diff] [blame] | 22 | #include <poll_controller.h> |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 23 | #include <tbf.h> |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 24 | #include <tbf_ul.h> |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 25 | #include <encoding.h> |
Holger Hans Peter Freyther | d11290b | 2013-10-26 17:32:04 +0200 | [diff] [blame] | 26 | #include <decoding.h> |
| 27 | #include <rlc.h> |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 28 | #include <pcu_l1_if.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 29 | #include <gprs_ms.h> |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 30 | #include <gprs_rlcmac.h> |
Holger Hans Peter Freyther | 24e98d0 | 2013-10-19 18:15:44 +0200 | [diff] [blame] | 31 | #include <gprs_debug.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 32 | #include <cxx_linuxlist.h> |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 33 | #include <pdch.h> |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 34 | #include <gprs_ms_storage.h> |
| 35 | #include <sba.h> |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 36 | |
| 37 | extern "C" { |
| 38 | #include <osmocom/core/talloc.h> |
Holger Hans Peter Freyther | 24e98d0 | 2013-10-19 18:15:44 +0200 | [diff] [blame] | 39 | #include <osmocom/core/msgb.h> |
Holger Hans Peter Freyther | 8df447d | 2015-11-07 21:04:40 +0100 | [diff] [blame] | 40 | #include <osmocom/core/stats.h> |
Max | 9bbe160 | 2016-07-18 12:50:18 +0200 | [diff] [blame] | 41 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
Philipp Maier | 1275a3f | 2017-02-21 19:35:23 +0100 | [diff] [blame] | 42 | #include <osmocom/gsm/gsm_utils.h> |
Pau Espin Pedrol | fbfab29 | 2019-12-23 13:19:25 +0100 | [diff] [blame] | 43 | #include <osmocom/gsm/gsm48.h> |
Harald Welte | 717cdf5 | 2017-07-21 21:56:23 +0200 | [diff] [blame] | 44 | #include <osmocom/core/gsmtap_util.h> |
Harald Welte | 3e51d3e | 2017-10-29 10:57:27 +0100 | [diff] [blame] | 45 | #include <osmocom/core/application.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 46 | #include <osmocom/core/bitvec.h> |
| 47 | #include <osmocom/core/gsmtap.h> |
| 48 | #include <osmocom/core/logging.h> |
| 49 | #include <osmocom/core/utils.h> |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 50 | } |
Holger Hans Peter Freyther | b78adcd | 2013-10-17 20:12:37 +0200 | [diff] [blame] | 51 | |
Holger Hans Peter Freyther | f098489 | 2013-10-19 18:28:59 +0200 | [diff] [blame] | 52 | #include <errno.h> |
Holger Hans Peter Freyther | b6acfda | 2013-10-17 19:41:11 +0200 | [diff] [blame] | 53 | #include <string.h> |
| 54 | |
Philipp Maier | 1275a3f | 2017-02-21 19:35:23 +0100 | [diff] [blame] | 55 | #define RFN_MODULUS 42432 |
| 56 | #define RFN_THRESHOLD RFN_MODULUS / 2 |
| 57 | |
Holger Hans Peter Freyther | 24e98d0 | 2013-10-19 18:15:44 +0200 | [diff] [blame] | 58 | extern void *tall_pcu_ctx; |
| 59 | |
Harald Welte | 3e51d3e | 2017-10-29 10:57:27 +0100 | [diff] [blame] | 60 | extern "C" { |
| 61 | /* e must make sure to initialize logging before the BTS static |
| 62 | * constructors are executed below, as those call libosmocore APIs that |
| 63 | * require logging already to be initialized. */ |
Harald Welte | 0a369e5 | 2020-09-30 19:57:02 +0200 | [diff] [blame] | 64 | __attribute__((constructor (101))) static void early_init(void) |
Harald Welte | 3e51d3e | 2017-10-29 10:57:27 +0100 | [diff] [blame] | 65 | { |
Neels Hofmeyr | 42f2d61 | 2018-04-01 16:54:40 +0200 | [diff] [blame] | 66 | if (!tall_pcu_ctx) { |
| 67 | tall_pcu_ctx = talloc_named_const(NULL, 1, "Osmo-PCU context"); |
| 68 | osmo_init_logging2(tall_pcu_ctx, &gprs_log_info); |
| 69 | } |
Harald Welte | 3e51d3e | 2017-10-29 10:57:27 +0100 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
Pau Espin Pedrol | 906aafc | 2021-01-18 17:53:29 +0100 | [diff] [blame] | 73 | void bts_trx_free_all_tbf(struct gprs_rlcmac_trx *trx) |
| 74 | { |
| 75 | for (uint8_t ts = 0; ts < 8; ts++) |
| 76 | pdch_free_all_tbf(&trx->pdch[ts]); |
| 77 | } |
| 78 | |
Pau Espin Pedrol | 28f160e | 2019-09-05 14:48:35 +0200 | [diff] [blame] | 79 | static struct osmo_tdef T_defs_bts[] = { |
| 80 | { .T=3142, .default_val=20, .unit=OSMO_TDEF_S, .desc="timer (s)", .val=0 }, |
| 81 | { .T=3169, .default_val=5, .unit=OSMO_TDEF_S, .desc="Reuse of USF and TFI(s) after the MS uplink TBF assignment is invalid (s)", .val=0 }, |
| 82 | { .T=3191, .default_val=5, .unit=OSMO_TDEF_S, .desc="Reuse of TFI(s) after sending (1) last RLC Data Block on TBF(s), or (2) PACKET TBF RELEASE for an MBMS radio bearer (s)", .val=0 }, |
| 83 | { .T=3193, .default_val=100, .unit=OSMO_TDEF_MS, .desc="Reuse of TFI(s) after reception of final PACKET DOWNLINK ACK/NACK from MS for TBF (ms)", .val=0 }, |
| 84 | { .T=3195, .default_val=5, .unit=OSMO_TDEF_S, .desc="Reuse of TFI(s) upon no response from the MS (radio failure or cell change) for TBF/MBMS radio bearer (s)", .val=0 }, |
Pau Espin Pedrol | 5360ef5 | 2019-09-13 12:41:54 +0200 | [diff] [blame] | 85 | { .T=0, .default_val=0, .unit=OSMO_TDEF_S, .desc=NULL, .val=0 } /* empty item at the end */ |
Pau Espin Pedrol | 28f160e | 2019-09-05 14:48:35 +0200 | [diff] [blame] | 86 | }; |
Pau Espin Pedrol | 28f160e | 2019-09-05 14:48:35 +0200 | [diff] [blame] | 87 | |
Holger Hans Peter Freyther | f537298 | 2013-10-27 09:02:31 +0100 | [diff] [blame] | 88 | /** |
| 89 | * For gcc-4.4 compat do not use extended initializer list but keep the |
| 90 | * order from the enum here. Once we support GCC4.7 and up we can change |
| 91 | * the code below. |
| 92 | */ |
| 93 | static const struct rate_ctr_desc bts_ctr_description[] = { |
Max | a5eb67d | 2017-11-21 20:24:54 +0100 | [diff] [blame] | 94 | { "tbf:dl:alloc", "TBF DL Allocated "}, |
| 95 | { "tbf:dl:freed", "TBF DL Freed "}, |
| 96 | { "tbf:dl:aborted", "TBF DL Aborted "}, |
| 97 | { "tbf:ul:alloc", "TBF UL Allocated "}, |
| 98 | { "tbf:ul:freed", "TBF UL Freed "}, |
| 99 | { "tbf:ul:aborted", "TBF UL Aborted "}, |
| 100 | { "tbf:reused", "TBF Reused "}, |
| 101 | { "tbf:alloc:algo-a", "TBF Alloc Algo A "}, |
| 102 | { "tbf:alloc:algo-b", "TBF Alloc Algo B "}, |
Max | a5eb67d | 2017-11-21 20:24:54 +0100 | [diff] [blame] | 103 | { "rlc:sent", "RLC Sent "}, |
| 104 | { "rlc:resent", "RLC Resent "}, |
| 105 | { "rlc:restarted", "RLC Restarted "}, |
| 106 | { "rlc:stalled", "RLC Stalled "}, |
| 107 | { "rlc:nacked", "RLC Nacked "}, |
| 108 | { "rlc:final_block_resent", "RLC Final Blk resent "}, |
| 109 | { "rlc:ass:timedout", "RLC Assign Timeout "}, |
| 110 | { "rlc:ass:failed", "RLC Assign Failed "}, |
| 111 | { "rlc:ack:timedout", "RLC Ack Timeout "}, |
| 112 | { "rlc:ack:failed", "RLC Ack Failed "}, |
| 113 | { "rlc:rel:timedout", "RLC Release Timeout "}, |
| 114 | { "rlc:late-block", "RLC Late Block "}, |
| 115 | { "rlc:sent-dummy", "RLC Sent Dummy "}, |
| 116 | { "rlc:sent-control", "RLC Sent Control "}, |
| 117 | { "rlc:dl_bytes", "RLC DL Bytes "}, |
| 118 | { "rlc:dl_payload_bytes", "RLC DL Payload Bytes "}, |
| 119 | { "rlc:ul_bytes", "RLC UL Bytes "}, |
| 120 | { "rlc:ul_payload_bytes", "RLC UL Payload Bytes "}, |
| 121 | { "decode:errors", "Decode Errors "}, |
| 122 | { "sba:allocated", "SBA Allocated "}, |
| 123 | { "sba:freed", "SBA Freed "}, |
| 124 | { "sba:timedout", "SBA Timeout "}, |
| 125 | { "llc:timeout", "Timedout Frames "}, |
| 126 | { "llc:dropped", "Dropped Frames "}, |
| 127 | { "llc:scheduled", "Scheduled Frames "}, |
| 128 | { "llc:dl_bytes", "RLC encapsulated PDUs"}, |
| 129 | { "llc:ul_bytes", "full PDUs received "}, |
| 130 | { "rach:requests", "RACH requests "}, |
| 131 | { "11bit_rach:requests", "11BIT_RACH requests "}, |
| 132 | { "spb:uplink_first_segment", "First seg of UL SPB "}, |
| 133 | { "spb:uplink_second_segment", "Second seg of UL SPB "}, |
| 134 | { "spb:downlink_first_segment", "First seg of DL SPB "}, |
| 135 | { "spb:downlink_second_segment","Second seg of DL SPB "}, |
| 136 | { "immediate:assignment_UL", "Immediate Assign UL "}, |
| 137 | { "immediate:assignment_rej", "Immediate Assign Rej "}, |
| 138 | { "immediate:assignment_DL", "Immediate Assign DL "}, |
| 139 | { "channel:request_description","Channel Request Desc "}, |
| 140 | { "pkt:ul_assignment", "Packet UL Assignment "}, |
| 141 | { "pkt:access_reject", "Packet Access Reject "}, |
| 142 | { "pkt:dl_assignment", "Packet DL Assignment "}, |
| 143 | { "ul:control", "UL control Block "}, |
| 144 | { "ul:assignment_poll_timeout", "UL Assign Timeout "}, |
| 145 | { "ul:assignment_failed", "UL Assign Failed "}, |
| 146 | { "dl:assignment_timeout", "DL Assign Timeout "}, |
| 147 | { "dl:assignment_failed", "DL Assign Failed "}, |
| 148 | { "pkt:ul_ack_nack_timeout", "PUAN Poll Timeout "}, |
| 149 | { "pkt:ul_ack_nack_failed", "PUAN poll Failed "}, |
| 150 | { "pkt:dl_ack_nack_timeout", "PDAN poll Timeout "}, |
| 151 | { "pkt:dl_ack_nack_failed", "PDAN poll Failed "}, |
| 152 | { "gprs:downlink_cs1", "CS1 downlink "}, |
| 153 | { "gprs:downlink_cs2", "CS2 downlink "}, |
| 154 | { "gprs:downlink_cs3", "CS3 downlink "}, |
| 155 | { "gprs:downlink_cs4", "CS4 downlink "}, |
| 156 | { "egprs:downlink_mcs1", "MCS1 downlink "}, |
| 157 | { "egprs:downlink_mcs2", "MCS2 downlink "}, |
| 158 | { "egprs:downlink_mcs3", "MCS3 downlink "}, |
| 159 | { "egprs:downlink_mcs4", "MCS4 downlink "}, |
| 160 | { "egprs:downlink_mcs5", "MCS5 downlink "}, |
| 161 | { "egprs:downlink_mcs6", "MCS6 downlink "}, |
| 162 | { "egprs:downlink_mcs7", "MCS7 downlink "}, |
| 163 | { "egprs:downlink_mcs8", "MCS8 downlink "}, |
| 164 | { "egprs:downlink_mcs9", "MCS9 downlink "}, |
| 165 | { "gprs:uplink_cs1", "CS1 Uplink "}, |
| 166 | { "gprs:uplink_cs2", "CS2 Uplink "}, |
| 167 | { "gprs:uplink_cs3", "CS3 Uplink "}, |
| 168 | { "gprs:uplink_cs4", "CS4 Uplink "}, |
| 169 | { "egprs:uplink_mcs1", "MCS1 Uplink "}, |
| 170 | { "egprs:uplink_mcs2", "MCS2 Uplink "}, |
| 171 | { "egprs:uplink_mcs3", "MCS3 Uplink "}, |
| 172 | { "egprs:uplink_mcs4", "MCS4 Uplink "}, |
| 173 | { "egprs:uplink_mcs5", "MCS5 Uplink "}, |
| 174 | { "egprs:uplink_mcs6", "MCS6 Uplink "}, |
| 175 | { "egprs:uplink_mcs7", "MCS7 Uplink "}, |
| 176 | { "egprs:uplink_mcs8", "MCS8 Uplink "}, |
| 177 | { "egprs:uplink_mcs9", "MCS9 Uplink "}, |
Holger Hans Peter Freyther | f537298 | 2013-10-27 09:02:31 +0100 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | static const struct rate_ctr_group_desc bts_ctrg_desc = { |
| 181 | "bts", |
| 182 | "BTS Statistics", |
Holger Hans Peter Freyther | b8a5426 | 2015-11-07 21:00:00 +0100 | [diff] [blame] | 183 | OSMO_STATS_CLASS_GLOBAL, |
Holger Hans Peter Freyther | f537298 | 2013-10-27 09:02:31 +0100 | [diff] [blame] | 184 | ARRAY_SIZE(bts_ctr_description), |
| 185 | bts_ctr_description, |
| 186 | }; |
| 187 | |
Jacob Erlbeck | f5898a0 | 2015-11-27 19:05:13 +0100 | [diff] [blame] | 188 | static const struct osmo_stat_item_desc bts_stat_item_description[] = { |
| 189 | { "ms.present", "MS Present ", |
| 190 | OSMO_STAT_ITEM_NO_UNIT, 4, 0}, |
| 191 | }; |
| 192 | |
| 193 | static const struct osmo_stat_item_group_desc bts_statg_desc = { |
| 194 | "bts", |
| 195 | "BTS Statistics", |
| 196 | OSMO_STATS_CLASS_GLOBAL, |
| 197 | ARRAY_SIZE(bts_stat_item_description), |
| 198 | bts_stat_item_description, |
| 199 | }; |
| 200 | |
Pau Espin Pedrol | 289f900 | 2021-01-18 12:57:32 +0100 | [diff] [blame] | 201 | static int bts_talloc_destructor(struct gprs_rlcmac_bts* bts) |
Pau Espin Pedrol | 46fd7a0 | 2020-11-02 14:36:22 +0100 | [diff] [blame] | 202 | { |
Pau Espin Pedrol | 289f900 | 2021-01-18 12:57:32 +0100 | [diff] [blame] | 203 | /* this can cause counter updates and must not be left to the |
| 204 | * m_ms_store's destructor */ |
| 205 | bts->ms_store->cleanup(); |
| 206 | delete bts->ms_store; |
| 207 | delete bts->sba; |
| 208 | delete bts->pollController; |
| 209 | |
| 210 | if (bts->ratectrs) { |
| 211 | rate_ctr_group_free(bts->ratectrs); |
| 212 | bts->ratectrs = NULL; |
| 213 | } |
| 214 | |
| 215 | if (bts->statg) { |
| 216 | osmo_stat_item_group_free(bts->statg); |
| 217 | bts->statg = NULL; |
| 218 | } |
| 219 | |
| 220 | if (bts->app_info) { |
| 221 | msgb_free(bts->app_info); |
| 222 | bts->app_info = NULL; |
| 223 | } |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 224 | |
| 225 | llist_del(&bts->list); |
Pau Espin Pedrol | 289f900 | 2021-01-18 12:57:32 +0100 | [diff] [blame] | 226 | return 0; |
| 227 | } |
| 228 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 229 | struct gprs_rlcmac_bts* bts_alloc(struct gprs_pcu *pcu, uint8_t bts_nr) |
Pau Espin Pedrol | 289f900 | 2021-01-18 12:57:32 +0100 | [diff] [blame] | 230 | { |
| 231 | struct gprs_rlcmac_bts* bts; |
| 232 | bts = talloc_zero(pcu, struct gprs_rlcmac_bts); |
| 233 | if (!bts) |
| 234 | return bts; |
| 235 | talloc_set_destructor(bts, bts_talloc_destructor); |
| 236 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 237 | bts->pcu = pcu; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 238 | bts->nr = bts_nr; |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 239 | |
| 240 | bts->pollController = new PollController(*bts); |
| 241 | bts->sba = new SBAController(*bts); |
| 242 | bts->ms_store = new GprsMsStorage(bts); |
| 243 | |
| 244 | bts->cur_fn = 0; |
| 245 | bts->cur_blk_fn = -1; |
| 246 | bts->max_cs_dl = MAX_GPRS_CS; |
| 247 | bts->max_cs_ul = MAX_GPRS_CS; |
| 248 | bts->max_mcs_dl = MAX_EDGE_MCS; |
| 249 | bts->max_mcs_ul = MAX_EDGE_MCS; |
Pau Espin Pedrol | 46fd7a0 | 2020-11-02 14:36:22 +0100 | [diff] [blame] | 250 | bts->initial_cs_dl = bts->initial_cs_ul = 1; |
| 251 | bts->initial_mcs_dl = bts->initial_mcs_ul = 1; |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 252 | bts->cs_mask = 1 << 0; /* CS-1 always enabled by default */ |
Pau Espin Pedrol | 46fd7a0 | 2020-11-02 14:36:22 +0100 | [diff] [blame] | 253 | bts->n3101 = 10; |
| 254 | bts->n3103 = 4; |
| 255 | bts->n3105 = 8; |
Pau Espin Pedrol | 46fd7a0 | 2020-11-02 14:36:22 +0100 | [diff] [blame] | 256 | bts->si13_is_set = false; |
Pau Espin Pedrol | 46fd7a0 | 2020-11-02 14:36:22 +0100 | [diff] [blame] | 257 | |
Pau Espin Pedrol | 46fd7a0 | 2020-11-02 14:36:22 +0100 | [diff] [blame] | 258 | bts->app_info = NULL; |
Pau Espin Pedrol | 46fd7a0 | 2020-11-02 14:36:22 +0100 | [diff] [blame] | 259 | bts->T_defs_bts = T_defs_bts; |
Pau Espin Pedrol | 46fd7a0 | 2020-11-02 14:36:22 +0100 | [diff] [blame] | 260 | osmo_tdefs_reset(bts->T_defs_bts); |
Pau Espin Pedrol | 46fd7a0 | 2020-11-02 14:36:22 +0100 | [diff] [blame] | 261 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 262 | INIT_LLIST_HEAD(&bts->ul_tbfs); |
| 263 | INIT_LLIST_HEAD(&bts->dl_tbfs); |
| 264 | |
Pau Espin Pedrol | 46fd7a0 | 2020-11-02 14:36:22 +0100 | [diff] [blame] | 265 | /* initialize back pointers */ |
| 266 | for (size_t trx_no = 0; trx_no < ARRAY_SIZE(bts->trx); ++trx_no) { |
| 267 | struct gprs_rlcmac_trx *trx = &bts->trx[trx_no]; |
| 268 | trx->trx_no = trx_no; |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 269 | trx->bts = bts; |
Pau Espin Pedrol | 46fd7a0 | 2020-11-02 14:36:22 +0100 | [diff] [blame] | 270 | |
| 271 | for (size_t ts_no = 0; ts_no < ARRAY_SIZE(trx->pdch); ++ts_no) { |
| 272 | struct gprs_rlcmac_pdch *pdch = &trx->pdch[ts_no]; |
| 273 | pdch->init_ptcch_msg(); |
| 274 | pdch->ts_no = ts_no; |
| 275 | pdch->trx = trx; |
| 276 | } |
| 277 | } |
Holger Hans Peter Freyther | f537298 | 2013-10-27 09:02:31 +0100 | [diff] [blame] | 278 | |
Max | ea9968f | 2017-12-18 22:52:52 +0100 | [diff] [blame] | 279 | /* The static allocator might have already registered the counter group. |
Max | 1714aea | 2017-12-21 11:19:39 +0100 | [diff] [blame] | 280 | If this happens and we still called explicitly (in tests/ for example) |
Max | ea9968f | 2017-12-18 22:52:52 +0100 | [diff] [blame] | 281 | than just allocate the group with different index. |
| 282 | This shall be removed once weget rid of BTS singleton */ |
| 283 | if (rate_ctr_get_group_by_name_idx(bts_ctrg_desc.group_name_prefix, 0)) |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 284 | bts->ratectrs = rate_ctr_group_alloc(tall_pcu_ctx, &bts_ctrg_desc, 1); |
Max | ea9968f | 2017-12-18 22:52:52 +0100 | [diff] [blame] | 285 | else |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 286 | bts->ratectrs = rate_ctr_group_alloc(tall_pcu_ctx, &bts_ctrg_desc, 0); |
| 287 | OSMO_ASSERT(bts->ratectrs); |
Max | ea9968f | 2017-12-18 22:52:52 +0100 | [diff] [blame] | 288 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 289 | bts->statg = osmo_stat_item_group_alloc(tall_pcu_ctx, &bts_statg_desc, 0); |
| 290 | OSMO_ASSERT(bts->statg); |
Holger Hans Peter Freyther | 9b30c7f | 2013-10-17 19:59:56 +0200 | [diff] [blame] | 291 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 292 | llist_add_tail(&bts->list, &pcu->bts_list); |
| 293 | |
Pau Espin Pedrol | 289f900 | 2021-01-18 12:57:32 +0100 | [diff] [blame] | 294 | return bts; |
Holger Hans Peter Freyther | f537298 | 2013-10-27 09:02:31 +0100 | [diff] [blame] | 295 | } |
| 296 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 297 | void bts_set_current_frame_number(struct gprs_rlcmac_bts *bts, int fn) |
Holger Hans Peter Freyther | 9b30c7f | 2013-10-17 19:59:56 +0200 | [diff] [blame] | 298 | { |
Jacob Erlbeck | ac49d09 | 2015-08-27 13:18:24 +0200 | [diff] [blame] | 299 | /* The UL frame numbers lag 3 behind the DL frames and the data |
| 300 | * indication is only sent after all 4 frames of the block have been |
| 301 | * received. Sometimes there is an idle frame between the end of one |
| 302 | * and start of another frame (every 3 blocks). So the timeout should |
| 303 | * definitely be there if we're more than 8 frames past poll_fn. Let's |
Jacob Erlbeck | e77d49f | 2015-08-27 13:28:05 +0200 | [diff] [blame] | 304 | * stay on the safe side and say 13 or more. An additional delay can |
| 305 | * happen due to the block processing time in the DSP, so the delay of |
| 306 | * decoded blocks relative to the timing clock can be much larger. |
| 307 | * Values up to 50 frames have been observed under load. */ |
| 308 | const static int max_delay = 60; |
Jacob Erlbeck | ac49d09 | 2015-08-27 13:18:24 +0200 | [diff] [blame] | 309 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 310 | bts->cur_fn = fn; |
| 311 | bts->pollController->expireTimedout(bts->cur_fn, max_delay); |
Holger Hans Peter Freyther | 9b30c7f | 2013-10-17 19:59:56 +0200 | [diff] [blame] | 312 | } |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 313 | |
Max | 9dabfa2 | 2017-05-16 16:10:45 +0200 | [diff] [blame] | 314 | static inline int delta_fn(int fn, int to) |
| 315 | { |
| 316 | return (fn + GSM_MAX_FN * 3 / 2 - to) % GSM_MAX_FN - GSM_MAX_FN/2; |
| 317 | } |
| 318 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 319 | void bts_set_current_block_frame_number(struct gprs_rlcmac_bts *bts, int fn, unsigned max_delay) |
Jacob Erlbeck | 60f7703 | 2015-08-24 14:35:14 +0200 | [diff] [blame] | 320 | { |
| 321 | int delay = 0; |
| 322 | const int late_block_delay_thresh = 13; |
| 323 | const int fn_update_ok_min_delay = -500; |
| 324 | const int fn_update_ok_max_delay = 0; |
| 325 | |
| 326 | /* frame numbers in the received blocks are assumed to be strongly |
| 327 | * monotonic. */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 328 | if (bts->cur_blk_fn >= 0) { |
| 329 | int delta = delta_fn(fn, bts->cur_blk_fn); |
Jacob Erlbeck | 60f7703 | 2015-08-24 14:35:14 +0200 | [diff] [blame] | 330 | if (delta <= 0) |
| 331 | return; |
| 332 | } |
| 333 | |
| 334 | /* Check block delay vs. the current frame number */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 335 | if (bts_current_frame_number(bts) != 0) |
| 336 | delay = delta_fn(fn, bts_current_frame_number(bts)); |
Jacob Erlbeck | be4a08b | 2015-08-25 15:19:31 +0200 | [diff] [blame] | 337 | if (delay <= -late_block_delay_thresh) { |
Jacob Erlbeck | 60f7703 | 2015-08-24 14:35:14 +0200 | [diff] [blame] | 338 | LOGP(DRLCMAC, LOGL_NOTICE, |
| 339 | "Late RLC block, FN delta: %d FN: %d curFN: %d\n", |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 340 | delay, fn, bts_current_frame_number(bts)); |
| 341 | bts_do_rate_ctr_inc(bts, CTR_RLC_LATE_BLOCK); |
Jacob Erlbeck | be4a08b | 2015-08-25 15:19:31 +0200 | [diff] [blame] | 342 | } |
Jacob Erlbeck | 60f7703 | 2015-08-24 14:35:14 +0200 | [diff] [blame] | 343 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 344 | bts->cur_blk_fn = fn; |
Jacob Erlbeck | 60f7703 | 2015-08-24 14:35:14 +0200 | [diff] [blame] | 345 | if (delay < fn_update_ok_min_delay || delay > fn_update_ok_max_delay || |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 346 | bts_current_frame_number(bts) == 0) |
| 347 | bts->cur_fn = fn; |
Jacob Erlbeck | 60f7703 | 2015-08-24 14:35:14 +0200 | [diff] [blame] | 348 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 349 | bts->pollController->expireTimedout(fn, max_delay); |
Jacob Erlbeck | 60f7703 | 2015-08-24 14:35:14 +0200 | [diff] [blame] | 350 | } |
| 351 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 352 | int bts_add_paging(struct gprs_rlcmac_bts *bts, uint8_t chan_needed, const struct osmo_mobile_identity *mi) |
Holger Hans Peter Freyther | f098489 | 2013-10-19 18:28:59 +0200 | [diff] [blame] | 353 | { |
| 354 | uint8_t l, trx, ts, any_tbf = 0; |
| 355 | struct gprs_rlcmac_tbf *tbf; |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 356 | struct llist_item *pos; |
Holger Hans Peter Freyther | f098489 | 2013-10-19 18:28:59 +0200 | [diff] [blame] | 357 | uint8_t slot_mask[8]; |
| 358 | int8_t first_ts; /* must be signed */ |
| 359 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 360 | struct llist_head *tbfs_lists[] = { |
| 361 | &bts->ul_tbfs, |
| 362 | &bts->dl_tbfs, |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 363 | NULL |
| 364 | }; |
| 365 | |
Neels Hofmeyr | 0052051 | 2020-08-21 15:44:58 +0200 | [diff] [blame] | 366 | if (log_check_level(DRLCMAC, LOGL_INFO)) { |
Neels Hofmeyr | 0052051 | 2020-08-21 15:44:58 +0200 | [diff] [blame] | 367 | char str[64]; |
Neels Hofmeyr | 59fc0bd | 2020-08-21 16:21:23 +0200 | [diff] [blame] | 368 | osmo_mobile_identity_to_str_buf(str, sizeof(str), mi); |
Neels Hofmeyr | 0052051 | 2020-08-21 15:44:58 +0200 | [diff] [blame] | 369 | LOGP(DRLCMAC, LOGL_INFO, "Add RR paging: chan-needed=%d MI=%s\n", chan_needed, str); |
| 370 | } |
Holger Hans Peter Freyther | f098489 | 2013-10-19 18:28:59 +0200 | [diff] [blame] | 371 | |
| 372 | /* collect slots to page |
| 373 | * Mark slots for every TBF, but only mark one of it. |
| 374 | * Mark only the first slot found. |
| 375 | * Don't mark, if TBF uses a different slot that is already marked. */ |
| 376 | memset(slot_mask, 0, sizeof(slot_mask)); |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 377 | for (l = 0; tbfs_lists[l]; l++) { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 378 | llist_for_each_entry(pos, tbfs_lists[l], list) { |
| 379 | tbf = (struct gprs_rlcmac_tbf *)pos->entry; |
Holger Hans Peter Freyther | f098489 | 2013-10-19 18:28:59 +0200 | [diff] [blame] | 380 | first_ts = -1; |
| 381 | for (ts = 0; ts < 8; ts++) { |
| 382 | if (tbf->pdch[ts]) { |
| 383 | /* remember the first slot found */ |
| 384 | if (first_ts < 0) |
| 385 | first_ts = ts; |
| 386 | /* break, if we already marked a slot */ |
Holger Hans Peter Freyther | ec80f82 | 2013-10-27 13:44:37 +0100 | [diff] [blame] | 387 | if ((slot_mask[tbf->trx->trx_no] & (1 << ts))) |
Holger Hans Peter Freyther | f098489 | 2013-10-19 18:28:59 +0200 | [diff] [blame] | 388 | break; |
| 389 | } |
| 390 | } |
| 391 | /* mark first slot found, if none is marked already */ |
| 392 | if (ts == 8 && first_ts >= 0) { |
Max | c21f007 | 2017-12-15 17:36:45 +0100 | [diff] [blame] | 393 | LOGPTBF(tbf, LOGL_DEBUG, "uses " |
Holger Hans Peter Freyther | f098489 | 2013-10-19 18:28:59 +0200 | [diff] [blame] | 394 | "TRX=%d TS=%d, so we mark\n", |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 395 | tbf->trx->trx_no, first_ts); |
Holger Hans Peter Freyther | ec80f82 | 2013-10-27 13:44:37 +0100 | [diff] [blame] | 396 | slot_mask[tbf->trx->trx_no] |= (1 << first_ts); |
Holger Hans Peter Freyther | f098489 | 2013-10-19 18:28:59 +0200 | [diff] [blame] | 397 | } else |
Max | c21f007 | 2017-12-15 17:36:45 +0100 | [diff] [blame] | 398 | LOGPTBF(tbf, LOGL_DEBUG, "uses " |
Holger Hans Peter Freyther | f098489 | 2013-10-19 18:28:59 +0200 | [diff] [blame] | 399 | "already marked TRX=%d TS=%d\n", |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 400 | tbf->trx->trx_no, ts); |
Holger Hans Peter Freyther | f098489 | 2013-10-19 18:28:59 +0200 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
| 404 | /* Now we have a list of marked slots. Every TBF uses at least one |
| 405 | * of these slots. */ |
| 406 | |
| 407 | /* schedule paging to all marked slots */ |
| 408 | for (trx = 0; trx < 8; trx++) { |
| 409 | if (slot_mask[trx] == 0) |
| 410 | continue; |
Holger Hans Peter Freyther | f098489 | 2013-10-19 18:28:59 +0200 | [diff] [blame] | 411 | for (ts = 0; ts < 8; ts++) { |
| 412 | if ((slot_mask[trx] & (1 << ts))) { |
| 413 | /* schedule */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 414 | if (!bts->trx[trx].pdch[ts].add_paging(chan_needed, mi)) |
Holger Hans Peter Freyther | f098489 | 2013-10-19 18:28:59 +0200 | [diff] [blame] | 415 | return -ENOMEM; |
Max | 4382e4e | 2018-01-30 12:00:08 +0100 | [diff] [blame] | 416 | |
| 417 | LOGP(DRLCMAC, LOGL_INFO, "Paging on PACCH of TRX=%d TS=%d\n", trx, ts); |
Holger Hans Peter Freyther | 9446485 | 2013-10-19 18:33:52 +0200 | [diff] [blame] | 418 | any_tbf = 1; |
Holger Hans Peter Freyther | f098489 | 2013-10-19 18:28:59 +0200 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | if (!any_tbf) |
| 424 | LOGP(DRLCMAC, LOGL_INFO, "No paging, because no TBF\n"); |
| 425 | |
| 426 | return 0; |
| 427 | } |
| 428 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 429 | void bts_send_gsmtap_rach(struct gprs_rlcmac_bts *bts, |
| 430 | enum pcu_gsmtap_category categ, uint8_t channel, |
| 431 | const struct rach_ind_params *rip) |
Vadim Yanitskiy | 07b6487 | 2020-06-11 00:26:15 +0700 | [diff] [blame] | 432 | { |
Vadim Yanitskiy | 55022ea | 2021-01-06 22:44:06 +0100 | [diff] [blame] | 433 | struct pcu_l1_meas meas = { 0 }; |
Vadim Yanitskiy | 81b610e | 2020-06-11 01:04:44 +0700 | [diff] [blame] | 434 | uint8_t ra_buf[2]; |
| 435 | |
| 436 | /* 3GPP TS 44.004 defines 11 bit RA as follows: xxxx xxxx .... .yyy |
| 437 | * On the PCUIF, we get 16 bit machne dependent number (LE/BE) |
| 438 | * Over GSMTAP we send the following: xxxx xxxx yyy. .... |
| 439 | * This simplifies parsing in Wireshark using its CSN.1 codec. */ |
| 440 | if (rip->is_11bit) { |
| 441 | ra_buf[0] = (uint8_t) ((rip->ra >> 3) & 0xff); |
| 442 | ra_buf[1] = (uint8_t) ((rip->ra << 5) & 0xff); |
| 443 | } else { |
| 444 | ra_buf[0] = (uint8_t) (rip->ra & 0xff); |
| 445 | } |
| 446 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 447 | bts_send_gsmtap_meas(bts, categ, true, rip->trx_nr, rip->ts_nr, channel, |
| 448 | bts_rfn_to_fn(bts, rip->rfn), ra_buf, |
Vadim Yanitskiy | 07b6487 | 2020-06-11 00:26:15 +0700 | [diff] [blame] | 449 | rip->is_11bit ? 2 : 1, &meas); |
| 450 | } |
| 451 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 452 | void bts_send_gsmtap(struct gprs_rlcmac_bts *bts, |
| 453 | enum pcu_gsmtap_category categ, bool uplink, uint8_t trx_no, |
| 454 | uint8_t ts_no, uint8_t channel, uint32_t fn, |
| 455 | const uint8_t *data, unsigned int len) |
Harald Welte | 717cdf5 | 2017-07-21 21:56:23 +0200 | [diff] [blame] | 456 | { |
Vadim Yanitskiy | eb70a40 | 2021-01-13 13:58:14 +0100 | [diff] [blame] | 457 | struct pcu_l1_meas meas = { 0 }; |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 458 | bts_send_gsmtap_meas(bts, categ, uplink, trx_no, ts_no, channel, fn, data, len, &meas); |
Pau Espin Pedrol | 0b0391f | 2020-05-19 17:23:23 +0200 | [diff] [blame] | 459 | } |
| 460 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 461 | void bts_send_gsmtap_meas(struct gprs_rlcmac_bts *bts, |
| 462 | enum pcu_gsmtap_category categ, bool uplink, uint8_t trx_no, |
| 463 | uint8_t ts_no, uint8_t channel, uint32_t fn, |
| 464 | const uint8_t *data, unsigned int len, struct pcu_l1_meas *meas) |
Pau Espin Pedrol | 0b0391f | 2020-05-19 17:23:23 +0200 | [diff] [blame] | 465 | { |
Harald Welte | 717cdf5 | 2017-07-21 21:56:23 +0200 | [diff] [blame] | 466 | uint16_t arfcn; |
| 467 | |
| 468 | /* check if category is activated at all */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 469 | if (!(bts->pcu->gsmtap_categ_mask & (1 << categ))) |
Harald Welte | 717cdf5 | 2017-07-21 21:56:23 +0200 | [diff] [blame] | 470 | return; |
| 471 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 472 | arfcn = bts->trx[trx_no].arfcn; |
Harald Welte | 717cdf5 | 2017-07-21 21:56:23 +0200 | [diff] [blame] | 473 | if (uplink) |
| 474 | arfcn |= GSMTAP_ARFCN_F_UPLINK; |
| 475 | |
Pau Espin Pedrol | 0b0391f | 2020-05-19 17:23:23 +0200 | [diff] [blame] | 476 | /* GSMTAP needs the SNR here, but we only have C/I (meas->link_qual). |
| 477 | Those are not the same, but there is no known way to convert them, |
| 478 | let's pass C/I instead of nothing */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 479 | gsmtap_send(bts->pcu->gsmtap, arfcn, ts_no, channel, 0, fn, |
Pau Espin Pedrol | 0b0391f | 2020-05-19 17:23:23 +0200 | [diff] [blame] | 480 | meas->rssi, meas->link_qual, data, len); |
Harald Welte | 717cdf5 | 2017-07-21 21:56:23 +0200 | [diff] [blame] | 481 | } |
| 482 | |
Max | 341dccd | 2017-08-14 15:49:59 +0200 | [diff] [blame] | 483 | static inline bool tbf_check(gprs_rlcmac_tbf *tbf, uint32_t fn, uint8_t trx_no, uint8_t ts) |
| 484 | { |
Max | cac6b66 | 2018-01-24 11:00:17 +0100 | [diff] [blame] | 485 | if (tbf->state_is_not(GPRS_RLCMAC_RELEASING) && tbf->poll_scheduled() |
Max | 341dccd | 2017-08-14 15:49:59 +0200 | [diff] [blame] | 486 | && tbf->poll_fn == fn && tbf->trx->trx_no == trx_no && tbf->poll_ts == ts) |
| 487 | return true; |
| 488 | |
| 489 | return false; |
| 490 | } |
| 491 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 492 | struct gprs_rlcmac_dl_tbf *bts_dl_tbf_by_poll_fn(struct gprs_rlcmac_bts *bts, uint32_t fn, uint8_t trx, uint8_t ts) |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 493 | { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 494 | struct llist_item *pos; |
| 495 | struct gprs_rlcmac_tbf *tbf; |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 496 | |
| 497 | /* only one TBF can poll on specific TS/FN, because scheduler can only |
| 498 | * schedule one downlink control block (with polling) at a FN per TS */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 499 | llist_for_each_entry(pos, &bts->dl_tbfs, list) { |
| 500 | tbf = (struct gprs_rlcmac_tbf *)pos->entry; |
| 501 | if (tbf_check(tbf, fn, trx, ts)) |
| 502 | return as_dl_tbf(tbf); |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 503 | } |
Daniel Willmann | febf1a0 | 2014-07-02 17:58:16 +0200 | [diff] [blame] | 504 | return NULL; |
| 505 | } |
Max | 341dccd | 2017-08-14 15:49:59 +0200 | [diff] [blame] | 506 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 507 | struct gprs_rlcmac_ul_tbf *bts_ul_tbf_by_poll_fn(struct gprs_rlcmac_bts *bts, uint32_t fn, uint8_t trx, uint8_t ts) |
Daniel Willmann | febf1a0 | 2014-07-02 17:58:16 +0200 | [diff] [blame] | 508 | { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 509 | struct llist_item *pos; |
| 510 | struct gprs_rlcmac_tbf *tbf; |
Daniel Willmann | febf1a0 | 2014-07-02 17:58:16 +0200 | [diff] [blame] | 511 | |
| 512 | /* only one TBF can poll on specific TS/FN, because scheduler can only |
| 513 | * schedule one downlink control block (with polling) at a FN per TS */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 514 | llist_for_each_entry(pos, &bts->ul_tbfs, list) { |
| 515 | tbf = (struct gprs_rlcmac_tbf *)pos->entry; |
| 516 | if (tbf_check(tbf, fn, trx, ts)) |
| 517 | return as_ul_tbf(tbf); |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 518 | } |
| 519 | return NULL; |
| 520 | } |
| 521 | |
Daniel Willmann | 54044b0 | 2014-07-02 17:58:15 +0200 | [diff] [blame] | 522 | /* lookup downlink TBF Entity (by TFI) */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 523 | struct gprs_rlcmac_dl_tbf *bts_dl_tbf_by_tfi(struct gprs_rlcmac_bts *bts, uint8_t tfi, uint8_t trx, uint8_t ts) |
Daniel Willmann | 54044b0 | 2014-07-02 17:58:15 +0200 | [diff] [blame] | 524 | { |
Jacob Erlbeck | 3a10dbd | 2015-07-10 19:52:37 +0200 | [diff] [blame] | 525 | if (trx >= 8 || ts >= 8) |
| 526 | return NULL; |
| 527 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 528 | return bts->trx[trx].pdch[ts].dl_tbf_by_tfi(tfi); |
Daniel Willmann | 54044b0 | 2014-07-02 17:58:15 +0200 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /* lookup uplink TBF Entity (by TFI) */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 532 | struct gprs_rlcmac_ul_tbf *bts_ul_tbf_by_tfi(struct gprs_rlcmac_bts *bts, uint8_t tfi, uint8_t trx, uint8_t ts) |
Daniel Willmann | 54044b0 | 2014-07-02 17:58:15 +0200 | [diff] [blame] | 533 | { |
Jacob Erlbeck | 3a10dbd | 2015-07-10 19:52:37 +0200 | [diff] [blame] | 534 | if (trx >= 8 || ts >= 8) |
Holger Hans Peter Freyther | f63cabd | 2013-10-26 19:10:43 +0200 | [diff] [blame] | 535 | return NULL; |
| 536 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 537 | return bts->trx[trx].pdch[ts].ul_tbf_by_tfi(tfi); |
Holger Hans Peter Freyther | f63cabd | 2013-10-26 19:10:43 +0200 | [diff] [blame] | 538 | } |
| 539 | |
Pau Espin Pedrol | 983bb7e | 2020-10-26 14:52:06 +0100 | [diff] [blame] | 540 | static unsigned int trx_count_free_tfi(const struct gprs_rlcmac_trx *trx, enum gprs_rlcmac_tbf_direction dir, uint8_t *first_free_tfi) |
| 541 | { |
| 542 | const struct gprs_rlcmac_pdch *pdch; |
| 543 | uint8_t ts; |
| 544 | unsigned int i; |
| 545 | unsigned int free_tfi_cnt = 0; |
| 546 | bool has_pdch = false; |
| 547 | uint32_t mask = NO_FREE_TFI; |
| 548 | |
| 549 | for (ts = 0; ts < ARRAY_SIZE(trx->pdch); ts++) { |
| 550 | pdch = &trx->pdch[ts]; |
| 551 | if (!pdch->is_enabled()) |
| 552 | continue; |
| 553 | has_pdch = true; |
| 554 | mask &= ~pdch->assigned_tfi(dir); |
| 555 | } |
| 556 | |
| 557 | if (!has_pdch || !mask) { |
| 558 | *first_free_tfi = (uint8_t)-1; |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | /* Count free tfis and return */ |
| 563 | for (i = 0; i < sizeof(mask) * 8 ; i++) { |
| 564 | if (mask & 1) { |
| 565 | if (free_tfi_cnt == 0) |
| 566 | *first_free_tfi = i; |
| 567 | free_tfi_cnt++; |
| 568 | } |
| 569 | mask >>= 1; |
| 570 | } |
| 571 | return free_tfi_cnt; |
| 572 | } |
| 573 | |
Jacob Erlbeck | 3a10dbd | 2015-07-10 19:52:37 +0200 | [diff] [blame] | 574 | /* |
Pau Espin Pedrol | 983bb7e | 2020-10-26 14:52:06 +0100 | [diff] [blame] | 575 | * Search for free TFI and return TFI, TRX. This method returns the first TFI |
| 576 | * that is currently not used in any PDCH of a the TRX with least TFIs currently |
| 577 | * assigned. Negative values indicate errors. |
Jacob Erlbeck | 3a10dbd | 2015-07-10 19:52:37 +0200 | [diff] [blame] | 578 | */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 579 | int bts_tfi_find_free(const struct gprs_rlcmac_bts *bts, enum gprs_rlcmac_tbf_direction dir, |
| 580 | uint8_t *_trx, int8_t use_trx) |
Holger Hans Peter Freyther | 70ddde6 | 2013-10-26 19:17:58 +0200 | [diff] [blame] | 581 | { |
Pau Espin Pedrol | 983bb7e | 2020-10-26 14:52:06 +0100 | [diff] [blame] | 582 | uint8_t trx_from, trx_to, trx; |
| 583 | uint8_t best_trx_nr = 0xff; |
| 584 | unsigned int best_cnt = 0; |
| 585 | uint8_t best_first_tfi = 0; |
Holger Hans Peter Freyther | 70ddde6 | 2013-10-26 19:17:58 +0200 | [diff] [blame] | 586 | |
| 587 | if (use_trx >= 0 && use_trx < 8) |
| 588 | trx_from = trx_to = use_trx; |
| 589 | else { |
| 590 | trx_from = 0; |
| 591 | trx_to = 7; |
| 592 | } |
| 593 | |
Jacob Erlbeck | 3a10dbd | 2015-07-10 19:52:37 +0200 | [diff] [blame] | 594 | /* find a TFI that is unused on all PDCH */ |
Holger Hans Peter Freyther | 70ddde6 | 2013-10-26 19:17:58 +0200 | [diff] [blame] | 595 | for (trx = trx_from; trx <= trx_to; trx++) { |
Pau Espin Pedrol | 983bb7e | 2020-10-26 14:52:06 +0100 | [diff] [blame] | 596 | uint8_t tmp_first_tfi; |
| 597 | unsigned int tmp_cnt; |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 598 | tmp_cnt = trx_count_free_tfi(&bts->trx[trx], dir, &tmp_first_tfi); |
Pau Espin Pedrol | 983bb7e | 2020-10-26 14:52:06 +0100 | [diff] [blame] | 599 | if (tmp_cnt > best_cnt) { |
| 600 | best_cnt = tmp_cnt; |
| 601 | best_first_tfi = tmp_first_tfi; |
| 602 | best_trx_nr = trx; |
Holger Hans Peter Freyther | 70ddde6 | 2013-10-26 19:17:58 +0200 | [diff] [blame] | 603 | } |
Holger Hans Peter Freyther | 70ddde6 | 2013-10-26 19:17:58 +0200 | [diff] [blame] | 604 | } |
| 605 | |
Pau Espin Pedrol | 983bb7e | 2020-10-26 14:52:06 +0100 | [diff] [blame] | 606 | if (best_trx_nr == 0xff || best_cnt == 0) { |
Max | 69d585e | 2018-01-26 12:36:43 +0100 | [diff] [blame] | 607 | LOGP(DRLCMAC, LOGL_NOTICE, "No TFI available (suggested TRX: %d).\n", use_trx); |
Jacob Erlbeck | 3a10dbd | 2015-07-10 19:52:37 +0200 | [diff] [blame] | 608 | return -EBUSY; |
| 609 | } |
Holger Hans Peter Freyther | 70ddde6 | 2013-10-26 19:17:58 +0200 | [diff] [blame] | 610 | |
Pau Espin Pedrol | 983bb7e | 2020-10-26 14:52:06 +0100 | [diff] [blame] | 611 | OSMO_ASSERT(best_first_tfi < 32); |
Jacob Erlbeck | 3a10dbd | 2015-07-10 19:52:37 +0200 | [diff] [blame] | 612 | |
Pau Espin Pedrol | 983bb7e | 2020-10-26 14:52:06 +0100 | [diff] [blame] | 613 | LOGP(DRLCMAC, LOGL_DEBUG, "Found first unallocated TRX=%d TFI=%d\n", |
| 614 | best_trx_nr, best_first_tfi); |
| 615 | *_trx = best_trx_nr; |
| 616 | return best_first_tfi; |
Holger Hans Peter Freyther | 70ddde6 | 2013-10-26 19:17:58 +0200 | [diff] [blame] | 617 | } |
| 618 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 619 | int bts_rcv_imm_ass_cnf(struct gprs_rlcmac_bts *bts, const uint8_t *data, uint32_t fn) |
Holger Hans Peter Freyther | 40cfaa6 | 2013-10-26 19:49:16 +0200 | [diff] [blame] | 620 | { |
Jacob Erlbeck | 767193e | 2015-05-20 12:06:46 +0200 | [diff] [blame] | 621 | struct gprs_rlcmac_dl_tbf *dl_tbf = NULL; |
Holger Hans Peter Freyther | 40cfaa6 | 2013-10-26 19:49:16 +0200 | [diff] [blame] | 622 | uint8_t plen; |
| 623 | uint32_t tlli; |
Jacob Erlbeck | 767193e | 2015-05-20 12:06:46 +0200 | [diff] [blame] | 624 | GprsMs *ms; |
Holger Hans Peter Freyther | 40cfaa6 | 2013-10-26 19:49:16 +0200 | [diff] [blame] | 625 | |
| 626 | /* move to IA Rest Octets */ |
| 627 | plen = data[0] >> 2; |
| 628 | data += 1 + plen; |
| 629 | |
| 630 | if ((*data & 0xf0) != 0xd0) { |
| 631 | LOGP(DRLCMAC, LOGL_ERROR, "Got IMM.ASS confirm, but rest " |
| 632 | "octets do not start with bit sequence 'HH01' " |
| 633 | "(Packet Downlink Assignment)\n"); |
| 634 | return -EINVAL; |
| 635 | } |
| 636 | |
| 637 | /* get TLLI from downlink assignment */ |
Eric Wild | ab8b01e | 2019-07-23 17:16:06 +0200 | [diff] [blame] | 638 | tlli = (uint32_t)((*data++) & 0xf) << 28; |
Holger Hans Peter Freyther | 40cfaa6 | 2013-10-26 19:49:16 +0200 | [diff] [blame] | 639 | tlli |= (*data++) << 20; |
| 640 | tlli |= (*data++) << 12; |
| 641 | tlli |= (*data++) << 4; |
| 642 | tlli |= (*data++) >> 4; |
| 643 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 644 | ms = bts_ms_by_tlli(bts, tlli, GSM_RESERVED_TMSI); |
Jacob Erlbeck | 767193e | 2015-05-20 12:06:46 +0200 | [diff] [blame] | 645 | if (ms) |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 646 | dl_tbf = ms_dl_tbf(ms); |
Daniel Willmann | 1dac2eb | 2014-08-07 12:37:34 +0200 | [diff] [blame] | 647 | if (!dl_tbf) { |
Holger Hans Peter Freyther | 40cfaa6 | 2013-10-26 19:49:16 +0200 | [diff] [blame] | 648 | LOGP(DRLCMAC, LOGL_ERROR, "Got IMM.ASS confirm, but TLLI=%08x " |
| 649 | "does not exit\n", tlli); |
| 650 | return -EINVAL; |
| 651 | } |
| 652 | |
| 653 | LOGP(DRLCMAC, LOGL_DEBUG, "Got IMM.ASS confirm for TLLI=%08x\n", tlli); |
| 654 | |
Daniel Willmann | 7e994e3 | 2014-08-07 15:49:21 +0200 | [diff] [blame] | 655 | if (dl_tbf->m_wait_confirm) |
Pau Espin Pedrol | 28f160e | 2019-09-05 14:48:35 +0200 | [diff] [blame] | 656 | T_START(dl_tbf, T0, -2002, "assignment (AGCH)", true); |
Holger Hans Peter Freyther | 40cfaa6 | 2013-10-26 19:49:16 +0200 | [diff] [blame] | 657 | |
| 658 | return 0; |
| 659 | } |
| 660 | |
Philipp Maier | 1275a3f | 2017-02-21 19:35:23 +0100 | [diff] [blame] | 661 | /* Determine the full frame number from a relative frame number */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 662 | uint32_t bts_rfn_to_fn(const struct gprs_rlcmac_bts *bts, int32_t rfn) |
Philipp Maier | 1275a3f | 2017-02-21 19:35:23 +0100 | [diff] [blame] | 663 | { |
Max | 5dd8d1b | 2017-03-08 12:06:42 +0100 | [diff] [blame] | 664 | int32_t m_cur_rfn; |
| 665 | int32_t fn; |
| 666 | int32_t fn_rounded; |
| 667 | |
| 668 | /* double-check that relative FN is not negative and fits into int32_t */ |
| 669 | OSMO_ASSERT(rfn < GSM_MAX_FN); |
| 670 | OSMO_ASSERT(rfn >= 0); |
Philipp Maier | 1275a3f | 2017-02-21 19:35:23 +0100 | [diff] [blame] | 671 | |
| 672 | /* Note: If a BTS is sending in a rach request it will be fully aware |
| 673 | * of the frame number. If the PCU is used in a BSC-co-located setup. |
| 674 | * The BSC will forward the incoming RACH request. The RACH request |
| 675 | * only contains the relative frame number (Fn % 42432) in its request |
| 676 | * reference. This PCU implementation has to fit both scenarios, so |
| 677 | * we need to assume that Fn is a relative frame number. */ |
| 678 | |
| 679 | /* Ensure that all following calculations are performed with the |
| 680 | * relative frame number */ |
Max | 5dd8d1b | 2017-03-08 12:06:42 +0100 | [diff] [blame] | 681 | if (rfn >= RFN_MODULUS) |
| 682 | return rfn; |
Philipp Maier | 1275a3f | 2017-02-21 19:35:23 +0100 | [diff] [blame] | 683 | |
| 684 | /* Compute an internal relative frame number from the full internal |
| 685 | frame number */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 686 | m_cur_rfn = bts->cur_fn % RFN_MODULUS; |
Philipp Maier | 1275a3f | 2017-02-21 19:35:23 +0100 | [diff] [blame] | 687 | |
| 688 | /* Compute a "rounded" version of the internal frame number, which |
| 689 | * exactly fits in the RFN_MODULUS raster */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 690 | fn_rounded = bts->cur_fn - m_cur_rfn; |
Philipp Maier | 1275a3f | 2017-02-21 19:35:23 +0100 | [diff] [blame] | 691 | |
| 692 | /* If the delta between the internal and the external relative frame |
| 693 | * number exceeds a certain limit, we need to assume that the incoming |
| 694 | * rach request belongs to a the previous rfn period. To correct this, |
| 695 | * we roll back the rounded frame number by one RFN_MODULUS */ |
| 696 | if (abs(rfn - m_cur_rfn) > RFN_THRESHOLD) { |
| 697 | LOGP(DRLCMAC, LOGL_DEBUG, |
Thorsten Alteholz | 8bb7904 | 2018-10-06 10:42:58 +0200 | [diff] [blame] | 698 | "Race condition between rfn (%u) and m_cur_fn (%u) detected: rfn belongs to the previous modulus %u cycle, wrapping...\n", |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 699 | rfn, bts->cur_fn, RFN_MODULUS); |
Philipp Maier | 1275a3f | 2017-02-21 19:35:23 +0100 | [diff] [blame] | 700 | if (fn_rounded < RFN_MODULUS) { |
| 701 | LOGP(DRLCMAC, LOGL_DEBUG, |
| 702 | "Cornercase detected: wrapping crosses %u border\n", |
| 703 | GSM_MAX_FN); |
| 704 | fn_rounded = GSM_MAX_FN - (RFN_MODULUS - fn_rounded); |
| 705 | } |
| 706 | else |
| 707 | fn_rounded -= RFN_MODULUS; |
| 708 | } |
| 709 | |
| 710 | /* The real frame number is the sum of the rounded frame number and the |
| 711 | * relative framenumber computed via RACH */ |
| 712 | fn = fn_rounded + rfn; |
| 713 | |
| 714 | return fn; |
| 715 | } |
| 716 | |
Pau Espin Pedrol | 9ee90d2 | 2020-05-08 14:20:32 +0200 | [diff] [blame] | 717 | /* 3GPP TS 44.060: |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 718 | * Table 11.2.5.2: PACKET CHANNEL REQUEST |
| 719 | * Table 11.2.5a.2: EGPRS PACKET CHANNEL REQUEST |
| 720 | * Both GPRS and EGPRS use same MultislotClass coding, but since PRACH is |
Pau Espin Pedrol | 9ee90d2 | 2020-05-08 14:20:32 +0200 | [diff] [blame] | 721 | * deprecated, no PACKET CHANNEL REQUEST exists, which means for GPRS we will |
| 722 | * receive CCCH RACH which doesn't contain any mslot class. Hence in the end we |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 723 | * can only receive EGPRS mslot class through 11-bit EGPRS PACKET CHANNEL REQUEST. */ |
| 724 | static int parse_egprs_pkt_ch_req(uint16_t ra11, struct chan_req_params *chan_req) |
Max | 5881858 | 2018-01-05 15:04:50 +0100 | [diff] [blame] | 725 | { |
Vadim Yanitskiy | b90d34b | 2020-05-21 20:20:34 +0700 | [diff] [blame] | 726 | EGPRS_PacketChannelRequest_t req; |
| 727 | int rc; |
| 728 | |
| 729 | rc = decode_egprs_pkt_ch_req(ra11, &req); |
| 730 | if (rc) { |
| 731 | LOGP(DRLCMAC, LOGL_NOTICE, "Failed to decode " |
| 732 | "EGPRS Packet Channel Request: rc=%d\n", rc); |
| 733 | return rc; |
| 734 | } |
| 735 | |
| 736 | LOGP(DRLCMAC, LOGL_INFO, "Rx EGPRS Packet Channel Request: %s\n", |
| 737 | get_value_string(egprs_pkt_ch_req_type_names, req.Type)); |
| 738 | |
| 739 | switch (req.Type) { |
| 740 | case EGPRS_PKT_CHAN_REQ_ONE_PHASE: |
| 741 | chan_req->egprs_mslot_class = req.Content.MultislotClass + 1; |
| 742 | chan_req->priority = req.Content.Priority + 1; |
| 743 | break; |
| 744 | case EGPRS_PKT_CHAN_REQ_SHORT: |
| 745 | chan_req->priority = req.Content.Priority + 1; |
| 746 | if (req.Content.NumberOfBlocks == 0) |
| 747 | chan_req->single_block = true; |
| 748 | break; |
| 749 | case EGPRS_PKT_CHAN_REQ_ONE_PHASE_RED_LATENCY: |
| 750 | chan_req->priority = req.Content.Priority + 1; |
| 751 | break; |
| 752 | /* Two phase access => single block is needed */ |
| 753 | case EGPRS_PKT_CHAN_REQ_TWO_PHASE: |
| 754 | case EGPRS_PKT_CHAN_REQ_TWO_PHASE_IPA: |
| 755 | chan_req->priority = req.Content.Priority + 1; |
| 756 | chan_req->single_block = true; |
| 757 | break; |
| 758 | /* Signalling => single block is needed */ |
| 759 | case EGPRS_PKT_CHAN_REQ_SIGNALLING: |
| 760 | case EGPRS_PKT_CHAN_REQ_SIGNALLING_IPA: |
| 761 | chan_req->single_block = true; |
| 762 | break; |
| 763 | |
| 764 | /* Neither unacknowledged RLC mode, nor emergency calls are supported */ |
| 765 | case EGPRS_PKT_CHAN_REQ_ONE_PHASE_UNACK: |
| 766 | case EGPRS_PKT_CHAN_REQ_EMERGENCY_CALL: |
| 767 | case EGPRS_PKT_CHAN_REQ_DEDICATED_CHANNEL: |
| 768 | LOGP(DRLCMAC, LOGL_NOTICE, "%s is not supported, rejecting\n", |
| 769 | get_value_string(egprs_pkt_ch_req_type_names, req.Type)); |
| 770 | return -ENOTSUP; |
| 771 | |
| 772 | default: |
| 773 | LOGP(DRLCMAC, LOGL_ERROR, "Unknown EGPRS Packet Channel Request " |
| 774 | "type=0x%02x, probably a bug in CSN.1 codec\n", req.Type); |
| 775 | return -EINVAL; |
| 776 | } |
Max | 5881858 | 2018-01-05 15:04:50 +0100 | [diff] [blame] | 777 | |
| 778 | return 0; |
| 779 | } |
| 780 | |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 781 | /* NOTE: chan_req needs to be zero-initialized by the caller */ |
| 782 | static int parse_rach_ind(const struct rach_ind_params *rip, |
| 783 | struct chan_req_params *chan_req) |
Max | 5881858 | 2018-01-05 15:04:50 +0100 | [diff] [blame] | 784 | { |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 785 | int rc; |
Max | 5881858 | 2018-01-05 15:04:50 +0100 | [diff] [blame] | 786 | |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 787 | switch (rip->burst_type) { |
Max | 137fd59 | 2018-01-05 15:53:08 +0100 | [diff] [blame] | 788 | case GSM_L1_BURST_TYPE_NONE: |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 789 | LOGP(DRLCMAC, LOGL_ERROR, "RACH.ind contains no burst type, assuming TS0\n"); |
| 790 | /* fall-through */ |
| 791 | case GSM_L1_BURST_TYPE_ACCESS_0: |
| 792 | if (rip->is_11bit) { /* 11 bit Access Burst with TS0 => Packet Channel Request */ |
| 793 | LOGP(DRLCMAC, LOGL_ERROR, "11 bit Packet Channel Request " |
| 794 | "is not supported (PBCCH is deprecated)\n"); |
| 795 | return -ENOTSUP; |
| 796 | } |
| 797 | |
| 798 | /* 3GPP TS 44.018, table 9.1.8.1: 8 bit CHANNEL REQUEST. |
| 799 | * Mask 01110xxx indicates single block packet access. */ |
| 800 | chan_req->single_block = ((rip->ra & 0xf8) == 0x70); |
| 801 | break; |
| 802 | case GSM_L1_BURST_TYPE_ACCESS_1: |
| 803 | case GSM_L1_BURST_TYPE_ACCESS_2: |
| 804 | if (!rip->is_11bit) { /* TS1/TS2 => EGPRS Packet Channel Request (always 11 bit) */ |
| 805 | LOGP(DRLCMAC, LOGL_ERROR, "11 bit Packet Channel Request " |
| 806 | "is not supported (PBCCH is deprecated)\n"); |
| 807 | return -ENOTSUP; |
| 808 | } |
| 809 | |
| 810 | rc = parse_egprs_pkt_ch_req(rip->ra, chan_req); |
| 811 | if (rc) |
| 812 | return rc; |
Max | 137fd59 | 2018-01-05 15:53:08 +0100 | [diff] [blame] | 813 | break; |
| 814 | default: |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 815 | LOGP(DRLCMAC, LOGL_ERROR, "RACH.ind contains unknown burst type 0x%02x " |
| 816 | "(%u bit)\n", rip->burst_type, rip->is_11bit ? 11 : 8); |
| 817 | return -EINVAL; |
Max | 5881858 | 2018-01-05 15:04:50 +0100 | [diff] [blame] | 818 | } |
| 819 | |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 820 | return 0; |
Max | 5881858 | 2018-01-05 15:04:50 +0100 | [diff] [blame] | 821 | } |
| 822 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 823 | int bts_rcv_rach(struct gprs_rlcmac_bts *bts, const struct rach_ind_params *rip) |
Holger Hans Peter Freyther | 02beed5 | 2013-10-26 20:56:20 +0200 | [diff] [blame] | 824 | { |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 825 | struct chan_req_params chan_req = { 0 }; |
Jacob Erlbeck | 1f33294 | 2015-05-04 08:21:17 +0200 | [diff] [blame] | 826 | struct gprs_rlcmac_ul_tbf *tbf = NULL; |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 827 | uint8_t trx_no, ts_no; |
Holger Hans Peter Freyther | 02beed5 | 2013-10-26 20:56:20 +0200 | [diff] [blame] | 828 | uint32_t sb_fn = 0; |
Jacob Erlbeck | 2ca86af | 2016-01-20 18:26:13 +0100 | [diff] [blame] | 829 | uint8_t usf = 7; |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 830 | uint8_t tsc = 0; |
| 831 | int plen, rc; |
Holger Hans Peter Freyther | 02beed5 | 2013-10-26 20:56:20 +0200 | [diff] [blame] | 832 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 833 | bts_do_rate_ctr_inc(bts, CTR_RACH_REQUESTS); |
Holger Hans Peter Freyther | c1ae226 | 2013-10-27 10:50:35 +0100 | [diff] [blame] | 834 | |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 835 | if (rip->is_11bit) |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 836 | bts_do_rate_ctr_inc(bts, CTR_11BIT_RACH_REQUESTS); |
Mrinal Mishra | f86307e | 2016-11-10 18:16:30 +0530 | [diff] [blame] | 837 | |
Philipp Maier | 1275a3f | 2017-02-21 19:35:23 +0100 | [diff] [blame] | 838 | /* Determine full frame number */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 839 | uint32_t Fn = bts_rfn_to_fn(bts, rip->rfn); |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 840 | uint8_t ta = qta2ta(rip->qta); |
Philipp | d935d88 | 2016-11-07 13:07:36 +0100 | [diff] [blame] | 841 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 842 | bts_send_gsmtap_rach(bts, PCU_GSMTAP_C_UL_RACH, GSMTAP_CHANNEL_RACH, rip); |
Pau Espin Pedrol | 1ec211f | 2019-09-30 18:33:14 +0200 | [diff] [blame] | 843 | |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 844 | LOGP(DRLCMAC, LOGL_DEBUG, "MS requests Uplink resource on CCCH/RACH: " |
| 845 | "ra=0x%02x (%d bit) Fn=%u qta=%d\n", rip->ra, |
| 846 | rip->is_11bit ? 11 : 8, Fn, rip->qta); |
bhargava | 628dcfb | 2016-09-14 20:30:31 +0530 | [diff] [blame] | 847 | |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 848 | /* Parse [EGPRS Packet] Channel Request from RACH.ind */ |
| 849 | rc = parse_rach_ind(rip, &chan_req); |
| 850 | if (rc) /* Send RR Immediate Assignment Reject */ |
| 851 | goto send_imm_ass_rej; |
bhargava | 628dcfb | 2016-09-14 20:30:31 +0530 | [diff] [blame] | 852 | |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 853 | if (chan_req.single_block) |
| 854 | LOGP(DRLCMAC, LOGL_DEBUG, "MS requests single block allocation\n"); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 855 | else if (bts->pcu->vty.force_two_phase) { |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 856 | LOGP(DRLCMAC, LOGL_DEBUG, "MS requests single block allocation, " |
| 857 | "but we force two phase access\n"); |
| 858 | chan_req.single_block = true; |
| 859 | } |
| 860 | |
Vadim Yanitskiy | b90d34b | 2020-05-21 20:20:34 +0700 | [diff] [blame] | 861 | /* TODO: handle Radio Priority (see 3GPP TS 44.060, table 11.2.5a.5) */ |
| 862 | if (chan_req.priority > 0) |
| 863 | LOGP(DRLCMAC, LOGL_NOTICE, "EGPRS Packet Channel Request indicates " |
| 864 | "Radio Priority %u, however we ignore it\n", chan_req.priority); |
| 865 | |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 866 | /* Should we allocate a single block or an Uplink TBF? */ |
| 867 | if (chan_req.single_block) { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 868 | rc = bts_sba(bts)->alloc(&trx_no, &ts_no, &sb_fn, ta); |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 869 | if (rc < 0) { |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 870 | LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource for " |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 871 | "single block allocation: rc=%d\n", rc); |
| 872 | /* Send RR Immediate Assignment Reject */ |
| 873 | goto send_imm_ass_rej; |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 874 | } |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 875 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 876 | tsc = bts->trx[trx_no].pdch[ts_no].tsc; |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 877 | LOGP(DRLCMAC, LOGL_DEBUG, "Allocated a single block at " |
| 878 | "SBFn=%u TRX=%u TS=%u\n", sb_fn, trx_no, ts_no); |
Holger Hans Peter Freyther | 02beed5 | 2013-10-26 20:56:20 +0200 | [diff] [blame] | 879 | } else { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 880 | GprsMs *ms = bts_alloc_ms(bts, 0, chan_req.egprs_mslot_class); |
| 881 | tbf = tbf_alloc_ul_tbf(bts, ms, -1, true); |
Holger Hans Peter Freyther | 02beed5 | 2013-10-26 20:56:20 +0200 | [diff] [blame] | 882 | if (!tbf) { |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 883 | LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource for Uplink TBF\n"); |
| 884 | /* Send RR Immediate Assignment Reject */ |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 885 | rc = -EBUSY; |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 886 | goto send_imm_ass_rej; |
Holger Hans Peter Freyther | 02beed5 | 2013-10-26 20:56:20 +0200 | [diff] [blame] | 887 | } |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 888 | |
| 889 | /* FIXME: Copy and paste with other routines.. */ |
| 890 | tbf->set_ta(ta); |
| 891 | TBF_SET_STATE(tbf, GPRS_RLCMAC_FLOW); |
| 892 | TBF_ASS_TYPE_SET(tbf, GPRS_RLCMAC_FLAG_CCCH); |
| 893 | T_START(tbf, T3169, 3169, "RACH (new UL-TBF)", true); |
| 894 | trx_no = tbf->trx->trx_no; |
| 895 | ts_no = tbf->first_ts; |
| 896 | usf = tbf->m_usf[ts_no]; |
| 897 | tsc = tbf->tsc(); |
Holger Hans Peter Freyther | 02beed5 | 2013-10-26 20:56:20 +0200 | [diff] [blame] | 898 | } |
Jacob Erlbeck | 2ca86af | 2016-01-20 18:26:13 +0100 | [diff] [blame] | 899 | |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 900 | send_imm_ass_rej: |
| 901 | /* Allocate a bit-vector for RR Immediate Assignment [Reject] */ |
| 902 | struct bitvec *bv = bitvec_alloc(22, tall_pcu_ctx); /* without plen */ |
Vadim Yanitskiy | eb1e0fa | 2020-07-18 20:33:08 +0700 | [diff] [blame] | 903 | bitvec_unhex(bv, DUMMY_VEC); /* standard '2B'O padding */ |
Jacob Erlbeck | 2ca86af | 2016-01-20 18:26:13 +0100 | [diff] [blame] | 904 | |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 905 | if (rc != 0) { |
| 906 | LOGP(DRLCMAC, LOGL_DEBUG, "Tx Immediate Assignment Reject on AGCH\n"); |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 907 | plen = Encoding::write_immediate_assignment_reject( |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 908 | bv, rip->ra, Fn, rip->burst_type); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 909 | bts_do_rate_ctr_inc(bts, CTR_IMMEDIATE_ASSIGN_REJ); |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 910 | } else { |
| 911 | LOGP(DRLCMAC, LOGL_DEBUG, "Tx Immediate Assignment on AGCH: " |
| 912 | "TRX=%u (ARFCN %u) TS=%u TA=%u TSC=%u TFI=%d USF=%d\n", |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 913 | trx_no, bts->trx[trx_no].arfcn & ~ARFCN_FLAG_MASK, |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 914 | ts_no, ta, tsc, tbf ? tbf->tfi() : -1, usf); |
| 915 | plen = Encoding::write_immediate_assignment( |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 916 | &bts->trx[trx_no].pdch[ts_no], tbf, bv, |
Vadim Yanitskiy | 1156776 | 2020-07-18 23:34:17 +0700 | [diff] [blame] | 917 | false, rip->ra, Fn, ta, usf, false, sb_fn, |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 918 | bts->pcu->vty.alpha, bts->pcu->vty.gamma, -1, |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 919 | rip->burst_type); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 920 | bts_do_rate_ctr_inc(bts, CTR_IMMEDIATE_ASSIGN_UL_TBF); |
Mrinal Mishra | f86307e | 2016-11-10 18:16:30 +0530 | [diff] [blame] | 921 | } |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 922 | |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 923 | if (plen >= 0) |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 924 | pcu_l1if_tx_agch(bts, bv, plen); |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 925 | else |
| 926 | rc = plen; |
| 927 | |
| 928 | bitvec_free(bv); |
Holger Hans Peter Freyther | 02beed5 | 2013-10-26 20:56:20 +0200 | [diff] [blame] | 929 | |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 930 | return rc; |
Holger Hans Peter Freyther | 02beed5 | 2013-10-26 20:56:20 +0200 | [diff] [blame] | 931 | } |
| 932 | |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 933 | /* PTCCH/U sub-slot / frame-number mapping (see 3GPP TS 45.002, table 6) */ |
| 934 | static uint32_t ptcch_slot_map[PTCCH_TAI_NUM] = { |
| 935 | 12, 38, 64, 90, |
| 936 | 116, 142, 168, 194, |
| 937 | 220, 246, 272, 298, |
| 938 | 324, 350, 376, 402, |
| 939 | }; |
| 940 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 941 | int bts_rcv_ptcch_rach(struct gprs_rlcmac_bts *bts, const struct rach_ind_params *rip) |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 942 | { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 943 | uint32_t fn416 = bts_rfn_to_fn(bts, rip->rfn) % 416; |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 944 | struct gprs_rlcmac_pdch *pdch; |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 945 | uint8_t ss; |
| 946 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 947 | bts_send_gsmtap_rach(bts, PCU_GSMTAP_C_UL_PTCCH, GSMTAP_CHANNEL_PTCCH, rip); |
Vadim Yanitskiy | 07b6487 | 2020-06-11 00:26:15 +0700 | [diff] [blame] | 948 | |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 949 | /* Prevent buffer overflow */ |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 950 | if (rip->trx_nr >= ARRAY_SIZE(bts->trx) || rip->ts_nr >= 8) { |
| 951 | LOGP(DRLCMAC, LOGL_ERROR, "(TRX=%u TS=%u RFN=%u) Rx malformed " |
| 952 | "RACH.ind (PTCCH/U)\n", rip->trx_nr, rip->ts_nr, rip->rfn); |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 953 | return -EINVAL; |
| 954 | } |
| 955 | |
| 956 | /* Make sure PDCH time-slot is enabled */ |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 957 | pdch = &bts->trx[rip->trx_nr].pdch[rip->ts_nr]; |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 958 | if (!pdch->m_is_enabled) { |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 959 | LOGP(DRLCMAC, LOGL_NOTICE, "(TRX=%u TS=%u RFN=%u) Rx RACH.ind (PTCCH/U) " |
| 960 | "for inactive PDCH\n", rip->trx_nr, rip->ts_nr, rip->rfn); |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 961 | return -EAGAIN; |
| 962 | } |
| 963 | |
| 964 | /* Convert TDMA frame-number to PTCCH/U sub-slot number */ |
| 965 | for (ss = 0; ss < PTCCH_TAI_NUM; ss++) |
| 966 | if (ptcch_slot_map[ss] == fn416) |
| 967 | break; |
| 968 | if (ss == PTCCH_TAI_NUM) { |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 969 | LOGP(DRLCMAC, LOGL_ERROR, "(TRX=%u TS=%u RFN=%u) Failed to map " |
| 970 | "PTCCH/U sub-slot\n", rip->trx_nr, rip->ts_nr, rip->rfn); |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 971 | return -ENODEV; |
| 972 | } |
| 973 | |
| 974 | /* Apply the new Timing Advance value */ |
| 975 | LOGP(DRLCMAC, LOGL_INFO, "Continuous Timing Advance update " |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 976 | "for TAI %u, new TA is %u\n", ss, qta2ta(rip->qta)); |
| 977 | pdch->update_ta(ss, qta2ta(rip->qta)); |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 978 | |
| 979 | return 0; |
| 980 | } |
| 981 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 982 | void bts_snd_dl_ass(struct gprs_rlcmac_bts *bts, struct gprs_rlcmac_tbf *tbf, bool poll, uint16_t pgroup) |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 983 | { |
Vadim Yanitskiy | 1156776 | 2020-07-18 23:34:17 +0700 | [diff] [blame] | 984 | uint8_t trx_no = tbf->trx->trx_no; |
| 985 | uint8_t ts_no = tbf->first_ts; |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 986 | int plen; |
| 987 | |
Max | c21f007 | 2017-12-15 17:36:45 +0100 | [diff] [blame] | 988 | LOGPTBF(tbf, LOGL_INFO, "TX: START Immediate Assignment Downlink (PCH)\n"); |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 989 | bitvec *immediate_assignment = bitvec_alloc(22, tall_pcu_ctx); /* without plen */ |
Vadim Yanitskiy | eb1e0fa | 2020-07-18 20:33:08 +0700 | [diff] [blame] | 990 | bitvec_unhex(immediate_assignment, DUMMY_VEC); /* standard '2B'O padding */ |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 991 | /* use request reference that has maximum distance to current time, |
| 992 | * so the assignment will not conflict with possible RACH requests. */ |
Jacob Erlbeck | 2ca86af | 2016-01-20 18:26:13 +0100 | [diff] [blame] | 993 | LOGP(DRLCMAC, LOGL_DEBUG, " - TRX=%d (%d) TS=%d TA=%d pollFN=%d\n", |
Vadim Yanitskiy | 1156776 | 2020-07-18 23:34:17 +0700 | [diff] [blame] | 994 | trx_no, tbf->trx->arfcn, ts_no, tbf->ta(), poll ? tbf->poll_fn : -1); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 995 | plen = Encoding::write_immediate_assignment(&bts->trx[trx_no].pdch[ts_no], |
Vadim Yanitskiy | 1156776 | 2020-07-18 23:34:17 +0700 | [diff] [blame] | 996 | tbf, immediate_assignment, true, 125, |
| 997 | (tbf->pdch[ts_no]->last_rts_fn + 21216) % GSM_MAX_FN, |
| 998 | tbf->ta(), 7, poll, tbf->poll_fn, |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 999 | bts->pcu->vty.alpha, bts->pcu->vty.gamma, -1, |
Max | fc8afc2 | 2019-02-18 18:52:38 +0100 | [diff] [blame] | 1000 | GSM_L1_BURST_TYPE_ACCESS_0); |
Mrinal Mishra | f86307e | 2016-11-10 18:16:30 +0530 | [diff] [blame] | 1001 | if (plen >= 0) { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1002 | bts_do_rate_ctr_inc(bts, CTR_IMMEDIATE_ASSIGN_DL_TBF); |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1003 | pcu_l1if_tx_pch(bts, immediate_assignment, plen, pgroup); |
Mrinal Mishra | f86307e | 2016-11-10 18:16:30 +0530 | [diff] [blame] | 1004 | } |
| 1005 | |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 1006 | bitvec_free(immediate_assignment); |
| 1007 | } |
| 1008 | |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1009 | /* return maximum DL CS supported by BTS and allowed by VTY */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1010 | uint8_t bts_max_cs_dl(const struct gprs_rlcmac_bts* bts) |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1011 | { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1012 | return bts->max_cs_dl; |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | /* return maximum UL CS supported by BTS and allowed by VTY */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1016 | uint8_t bts_max_cs_ul(const struct gprs_rlcmac_bts* bts) |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1017 | { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1018 | return bts->max_cs_ul; |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | /* return maximum DL MCS supported by BTS and allowed by VTY */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1022 | uint8_t bts_max_mcs_dl(const struct gprs_rlcmac_bts* bts) |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1023 | { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1024 | return bts->max_mcs_dl; |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | /* return maximum UL MCS supported by BTS and allowed by VTY */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1028 | uint8_t bts_max_mcs_ul(const struct gprs_rlcmac_bts* bts) |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1029 | { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1030 | return bts->max_mcs_ul; |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | /* Set maximum DL CS supported by BTS and allowed by VTY */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1034 | void bts_set_max_cs_dl(struct gprs_rlcmac_bts* bts, uint8_t cs_dl) |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1035 | { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1036 | bts->max_cs_dl = cs_dl; |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | /* Set maximum UL CS supported by BTS and allowed by VTY */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1040 | void bts_set_max_cs_ul(struct gprs_rlcmac_bts* bts, uint8_t cs_ul) |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1041 | { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1042 | bts->max_cs_ul = cs_ul; |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | /* Set maximum DL MCS supported by BTS and allowed by VTY */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1046 | void bts_set_max_mcs_dl(struct gprs_rlcmac_bts* bts, uint8_t mcs_dl) |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1047 | { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1048 | bts->max_mcs_dl = mcs_dl; |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | /* Set maximum UL MCS supported by BTS and allowed by VTY */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1052 | void bts_set_max_mcs_ul(struct gprs_rlcmac_bts* bts, uint8_t mcs_ul) |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1053 | { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1054 | bts->max_mcs_ul = mcs_ul; |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1055 | } |
Holger Hans Peter Freyther | d11290b | 2013-10-26 17:32:04 +0200 | [diff] [blame] | 1056 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1057 | bool bts_cs_dl_is_supported(const struct gprs_rlcmac_bts* bts, CodingScheme cs) |
Pau Espin Pedrol | 022f9e5 | 2020-11-16 18:49:39 +0100 | [diff] [blame] | 1058 | { |
| 1059 | OSMO_ASSERT(mcs_is_valid(cs)); |
| 1060 | uint8_t num = mcs_chan_code(cs); |
| 1061 | if (mcs_is_gprs(cs)) { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1062 | return (bts_max_cs_dl(bts) >= num) && (bts->cs_mask & (1U << num)); |
Pau Espin Pedrol | 022f9e5 | 2020-11-16 18:49:39 +0100 | [diff] [blame] | 1063 | } else { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1064 | return (bts_max_mcs_dl(bts) >= num) && (bts->mcs_mask & (1U << num)); |
Pau Espin Pedrol | 022f9e5 | 2020-11-16 18:49:39 +0100 | [diff] [blame] | 1065 | } |
| 1066 | } |
| 1067 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1068 | GprsMs *bts_alloc_ms(struct gprs_rlcmac_bts* bts, uint8_t ms_class, uint8_t egprs_ms_class) |
Jacob Erlbeck | cb1b494 | 2015-06-19 10:59:58 +0200 | [diff] [blame] | 1069 | { |
| 1070 | GprsMs *ms; |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1071 | ms = bts_ms_store(bts)->create_ms(); |
Jacob Erlbeck | cb1b494 | 2015-06-19 10:59:58 +0200 | [diff] [blame] | 1072 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1073 | ms_set_timeout(ms, osmo_tdef_get(bts->pcu->T_defs, -2030, OSMO_TDEF_S, -1)); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 1074 | ms_set_ms_class(ms, ms_class); |
| 1075 | ms_set_egprs_ms_class(ms, egprs_ms_class); |
Jacob Erlbeck | cb1b494 | 2015-06-19 10:59:58 +0200 | [diff] [blame] | 1076 | |
| 1077 | return ms; |
| 1078 | } |
| 1079 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1080 | struct SBAController *bts_sba(struct gprs_rlcmac_bts *bts) |
| 1081 | { |
| 1082 | return bts->sba; |
| 1083 | } |
| 1084 | |
| 1085 | struct GprsMsStorage *bts_ms_store(struct gprs_rlcmac_bts *bts) |
| 1086 | { |
| 1087 | return bts->ms_store; |
| 1088 | } |
| 1089 | |
| 1090 | struct GprsMs *bts_ms_by_tlli(struct gprs_rlcmac_bts *bts, uint32_t tlli, uint32_t old_tlli) |
| 1091 | { |
| 1092 | return bts_ms_store(bts)->get_ms(tlli, old_tlli); |
| 1093 | } |
| 1094 | |
Minh-Quang Nguyen | 1bcfa9a | 2017-11-01 14:41:37 -0400 | [diff] [blame] | 1095 | /* update TA based on TA provided by PH-DATA-IND */ |
| 1096 | void update_tbf_ta(struct gprs_rlcmac_ul_tbf *tbf, int8_t ta_delta) |
| 1097 | { |
| 1098 | int16_t ta_adj; |
| 1099 | uint8_t ta_target; |
| 1100 | |
| 1101 | if (ta_delta) { |
| 1102 | /* adjust TA based on TA provided by PH-DATA-IND */ |
| 1103 | ta_adj = tbf->ta() + ta_delta; |
| 1104 | |
| 1105 | /* limit target TA in range 0..63 bits */ |
| 1106 | ta_target = ta_limit(ta_adj); |
| 1107 | |
| 1108 | LOGP(DL1IF, LOGL_INFO, "PH-DATA-IND is updating TLLI=0x%08x: TA %u -> %u on " |
| 1109 | "TRX = %d, TS = %d, FN = %d\n", |
| 1110 | tbf->tlli(), tbf->ta(), ta_target, |
| 1111 | tbf->trx->trx_no , tbf->poll_ts, tbf->poll_fn); |
| 1112 | tbf->set_ta(ta_target); |
| 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | /* set TA based on TA provided by PH-RA-IND */ |
| 1117 | void set_tbf_ta(struct gprs_rlcmac_ul_tbf *tbf, uint8_t ta) |
| 1118 | { |
| 1119 | uint8_t ta_target; |
| 1120 | |
| 1121 | if (tbf->ta() != ta) { |
| 1122 | /* limit target TA in range 0..63 bits */ |
| 1123 | ta_target = ta_limit(ta); |
| 1124 | |
| 1125 | LOGP(DL1IF, LOGL_INFO, "PH-RA-IND is updating TLLI=0x%08x: TA %u -> %u on " |
| 1126 | "TRX = %d, TS = %d, FN = %d\n", |
| 1127 | tbf->tlli(), tbf->ta(), ta_target, |
| 1128 | tbf->trx->trx_no , tbf->poll_ts, tbf->poll_fn); |
| 1129 | tbf->set_ta(ta_target); |
| 1130 | } |
| 1131 | } |
| 1132 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1133 | void bts_update_tbf_ta(struct gprs_rlcmac_bts *bts, const char *p, uint32_t fn, |
| 1134 | uint8_t trx_no, uint8_t ts, int8_t ta, bool is_rach) |
Max | d71e8b3 | 2016-09-19 16:17:06 +0200 | [diff] [blame] | 1135 | { |
| 1136 | struct gprs_rlcmac_ul_tbf *tbf = |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1137 | bts_ul_tbf_by_poll_fn(bts, fn, trx_no, ts); |
Max | d71e8b3 | 2016-09-19 16:17:06 +0200 | [diff] [blame] | 1138 | if (!tbf) |
| 1139 | LOGP(DL1IF, LOGL_DEBUG, "[%s] update TA = %u ignored due to " |
| 1140 | "unknown UL TBF on TRX = %d, TS = %d, FN = %d\n", |
| 1141 | p, ta, trx_no, ts, fn); |
Minh-Quang Nguyen | 1bcfa9a | 2017-11-01 14:41:37 -0400 | [diff] [blame] | 1142 | else { |
| 1143 | /* we need to distinguish TA information provided by L1 |
| 1144 | * from PH-DATA-IND and PHY-RA-IND so that we can properly |
| 1145 | * update TA for given TBF |
| 1146 | */ |
| 1147 | if (is_rach) |
| 1148 | set_tbf_ta(tbf, (uint8_t)ta); |
| 1149 | else |
| 1150 | update_tbf_ta(tbf, ta); |
| 1151 | |
Max | d71e8b3 | 2016-09-19 16:17:06 +0200 | [diff] [blame] | 1152 | } |
| 1153 | } |
| 1154 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 1155 | void bts_trx_reserve_slots(struct gprs_rlcmac_trx *trx, enum gprs_rlcmac_tbf_direction dir, |
Jacob Erlbeck | 23f93a1 | 2015-06-30 08:52:54 +0200 | [diff] [blame] | 1156 | uint8_t slots) |
| 1157 | { |
| 1158 | unsigned i; |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 1159 | for (i = 0; i < ARRAY_SIZE(trx->pdch); i += 1) |
Jacob Erlbeck | 23f93a1 | 2015-06-30 08:52:54 +0200 | [diff] [blame] | 1160 | if (slots & (1 << i)) |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 1161 | trx->pdch[i].reserve(dir); |
Jacob Erlbeck | 23f93a1 | 2015-06-30 08:52:54 +0200 | [diff] [blame] | 1162 | } |
| 1163 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 1164 | void bts_trx_unreserve_slots(struct gprs_rlcmac_trx *trx, enum gprs_rlcmac_tbf_direction dir, |
Jacob Erlbeck | 23f93a1 | 2015-06-30 08:52:54 +0200 | [diff] [blame] | 1165 | uint8_t slots) |
| 1166 | { |
| 1167 | unsigned i; |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 1168 | for (i = 0; i < ARRAY_SIZE(trx->pdch); i += 1) |
Jacob Erlbeck | 23f93a1 | 2015-06-30 08:52:54 +0200 | [diff] [blame] | 1169 | if (slots & (1 << i)) |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 1170 | trx->pdch[i].unreserve(dir); |
Jacob Erlbeck | 23f93a1 | 2015-06-30 08:52:54 +0200 | [diff] [blame] | 1171 | } |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1172 | |
Pau Espin Pedrol | 793583e | 2021-01-14 16:20:57 +0100 | [diff] [blame] | 1173 | void bts_recalc_initial_cs(struct gprs_rlcmac_bts *bts) |
| 1174 | { |
| 1175 | uint8_t max_cs_dl, max_cs_ul; |
| 1176 | |
| 1177 | if (the_pcu->vty.force_initial_cs) { |
| 1178 | bts->initial_cs_dl = the_pcu->vty.initial_cs_dl; |
| 1179 | bts->initial_cs_ul = the_pcu->vty.initial_cs_ul; |
| 1180 | return; |
| 1181 | } |
| 1182 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1183 | max_cs_dl = bts_max_cs_dl(bts); |
Pau Espin Pedrol | 793583e | 2021-01-14 16:20:57 +0100 | [diff] [blame] | 1184 | if (bts->pcuif_info_ind.initial_cs > max_cs_dl) { |
| 1185 | LOGP(DL1IF, LOGL_DEBUG, " downgrading initial_cs_dl to %d\n", max_cs_dl); |
| 1186 | bts->initial_cs_dl = max_cs_dl; |
| 1187 | } else { |
| 1188 | bts->initial_cs_dl = bts->pcuif_info_ind.initial_cs; |
| 1189 | } |
| 1190 | if (bts->initial_cs_dl == 0) |
| 1191 | bts->initial_cs_dl = 1; /* CS1 Must always be supported */ |
| 1192 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1193 | max_cs_ul = bts_max_cs_ul(bts); |
Pau Espin Pedrol | 793583e | 2021-01-14 16:20:57 +0100 | [diff] [blame] | 1194 | if (bts->pcuif_info_ind.initial_cs > max_cs_ul) { |
| 1195 | LOGP(DL1IF, LOGL_DEBUG, " downgrading initial_cs_ul to %d\n", max_cs_ul); |
| 1196 | bts->initial_cs_ul = max_cs_ul; |
| 1197 | } else { |
| 1198 | bts->initial_cs_ul = bts->pcuif_info_ind.initial_cs; |
| 1199 | } |
| 1200 | if (bts->initial_cs_ul == 0) |
| 1201 | bts->initial_cs_ul = 1; /* CS1 Must always be supported */ |
| 1202 | } |
| 1203 | void bts_recalc_initial_mcs(struct gprs_rlcmac_bts *bts) |
| 1204 | { |
| 1205 | uint8_t max_mcs_dl, max_mcs_ul; |
| 1206 | |
| 1207 | if (the_pcu->vty.force_initial_mcs) { |
| 1208 | bts->initial_mcs_dl = the_pcu->vty.initial_mcs_dl; |
| 1209 | bts->initial_mcs_ul = the_pcu->vty.initial_mcs_ul; |
| 1210 | return; |
| 1211 | } |
| 1212 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1213 | max_mcs_dl = bts_max_mcs_dl(bts); |
Pau Espin Pedrol | 793583e | 2021-01-14 16:20:57 +0100 | [diff] [blame] | 1214 | if (bts->pcuif_info_ind.initial_mcs > max_mcs_dl) { |
| 1215 | LOGP(DL1IF, LOGL_DEBUG, " downgrading initial_mcs_dl to %d\n", max_mcs_dl); |
| 1216 | bts->initial_mcs_dl = max_mcs_dl; |
| 1217 | } else { |
| 1218 | bts->initial_mcs_dl = bts->pcuif_info_ind.initial_mcs; |
| 1219 | } |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1220 | max_mcs_ul = bts_max_mcs_ul(bts); |
Pau Espin Pedrol | 793583e | 2021-01-14 16:20:57 +0100 | [diff] [blame] | 1221 | if (bts->pcuif_info_ind.initial_mcs > max_mcs_ul) { |
| 1222 | LOGP(DL1IF, LOGL_DEBUG, " downgrading initial_mcs_ul to %d\n", max_mcs_ul); |
| 1223 | bts->initial_mcs_ul = max_mcs_ul; |
| 1224 | } else { |
| 1225 | bts->initial_mcs_ul = bts->pcuif_info_ind.initial_mcs; |
| 1226 | } |
| 1227 | } |
| 1228 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1229 | void bts_recalc_max_cs(struct gprs_rlcmac_bts *bts) |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1230 | { |
| 1231 | int i; |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1232 | uint8_t cs_dl, cs_ul; |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1233 | struct gprs_pcu *pcu = bts->pcu; |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1234 | |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1235 | cs_dl = 0; |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1236 | for (i = pcu->vty.max_cs_dl - 1; i >= 0; i--) { |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1237 | if (bts->cs_mask & (1 << i)) { |
| 1238 | cs_dl = i + 1; |
| 1239 | break; |
| 1240 | } |
| 1241 | } |
| 1242 | |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1243 | cs_ul = 0; |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1244 | for (i = pcu->vty.max_cs_ul - 1; i >= 0; i--) { |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1245 | if (bts->cs_mask & (1 << i)) { |
| 1246 | cs_ul = i + 1; |
| 1247 | break; |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | LOGP(DRLCMAC, LOGL_DEBUG, "New max CS: DL=%u UL=%u\n", cs_dl, cs_ul); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1252 | bts_set_max_cs_dl(bts, cs_dl); |
| 1253 | bts_set_max_cs_ul(bts, cs_ul); |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1254 | } |
| 1255 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1256 | void bts_recalc_max_mcs(struct gprs_rlcmac_bts *bts) |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1257 | { |
| 1258 | int i; |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1259 | uint8_t mcs_dl, mcs_ul; |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1260 | struct gprs_pcu *pcu = bts->pcu; |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1261 | |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1262 | mcs_dl = 0; |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1263 | for (i = pcu->vty.max_mcs_dl - 1; i >= 0; i--) { |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1264 | if (bts->mcs_mask & (1 << i)) { |
| 1265 | mcs_dl = i + 1; |
| 1266 | break; |
| 1267 | } |
| 1268 | } |
| 1269 | |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1270 | mcs_ul = 0; |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1271 | for (i = pcu->vty.max_mcs_ul - 1; i >= 0; i--) { |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1272 | if (bts->mcs_mask & (1 << i)) { |
| 1273 | mcs_ul = i + 1; |
| 1274 | break; |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | LOGP(DRLCMAC, LOGL_DEBUG, "New max MCS: DL=%u UL=%u\n", mcs_dl, mcs_ul); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1279 | bts_set_max_mcs_dl(bts, mcs_dl); |
| 1280 | bts_set_max_mcs_ul(bts, mcs_ul); |
Pau Espin Pedrol | 343ec9b | 2020-10-30 18:35:54 +0100 | [diff] [blame] | 1281 | } |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 1282 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1283 | struct GprsMs *bts_ms_by_imsi(struct gprs_rlcmac_bts *bts, const char *imsi) |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 1284 | { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1285 | return bts_ms_store(bts)->get_ms(0, 0, imsi); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 1286 | } |