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