blob: 5cd2b1d9957918719b7e1c20ef81a4ec9da073be [file] [log] [blame]
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +02001/*
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 Freytherb78adcd2013-10-17 20:12:37 +020022#include <poll_controller.h>
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +020023#include <tbf.h>
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020024#include <tbf_ul.h>
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020025#include <encoding.h>
Holger Hans Peter Freytherd11290b2013-10-26 17:32:04 +020026#include <decoding.h>
27#include <rlc.h>
Holger Hans Peter Freytherd9262b32013-10-26 20:12:59 +020028#include <pcu_l1_if.h>
Max1187a772018-01-26 13:31:42 +010029#include <gprs_ms.h>
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +020030#include <gprs_rlcmac.h>
Holger Hans Peter Freyther24e98d02013-10-19 18:15:44 +020031#include <gprs_debug.h>
Max1187a772018-01-26 13:31:42 +010032#include <cxx_linuxlist.h>
Max6dc90b82018-02-19 17:17:28 +010033#include <pdch.h>
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +020034
35extern "C" {
36 #include <osmocom/core/talloc.h>
Holger Hans Peter Freyther24e98d02013-10-19 18:15:44 +020037 #include <osmocom/core/msgb.h>
Holger Hans Peter Freyther8df447d2015-11-07 21:04:40 +010038 #include <osmocom/core/stats.h>
Max9bbe1602016-07-18 12:50:18 +020039 #include <osmocom/gsm/protocol/gsm_04_08.h>
Philipp Maier1275a3f2017-02-21 19:35:23 +010040 #include <osmocom/gsm/gsm_utils.h>
Pau Espin Pedrolfbfab292019-12-23 13:19:25 +010041 #include <osmocom/gsm/gsm48.h>
Harald Welte717cdf52017-07-21 21:56:23 +020042 #include <osmocom/core/gsmtap_util.h>
Harald Welte3e51d3e2017-10-29 10:57:27 +010043 #include <osmocom/core/application.h>
Max1187a772018-01-26 13:31:42 +010044 #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 Freyther17b0d832013-10-19 17:37:48 +020048}
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +020049
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +020050#include <errno.h>
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +020051#include <string.h>
52
Philipp Maier1275a3f2017-02-21 19:35:23 +010053#define RFN_MODULUS 42432
54#define RFN_THRESHOLD RFN_MODULUS / 2
55
Holger Hans Peter Freyther24e98d02013-10-19 18:15:44 +020056extern void *tall_pcu_ctx;
57
Harald Welte3e51d3e2017-10-29 10:57:27 +010058extern "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. */
62 __attribute__((constructor)) static void early_init(void)
63 {
Neels Hofmeyr42f2d612018-04-01 16:54:40 +020064 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 Welte3e51d3e2017-10-29 10:57:27 +010068 }
69}
70
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +020071static BTS s_bts;
72
Pau Espin Pedrol28f160e2019-09-05 14:48:35 +020073static 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 Pedrol5360ef52019-09-13 12:41:54 +020079 { .T=0, .default_val=0, .unit=OSMO_TDEF_S, .desc=NULL, .val=0 } /* empty item at the end */
Pau Espin Pedrol28f160e2019-09-05 14:48:35 +020080};
81static struct osmo_tdef T_defs_pcu[] = {
Pau Espin Pedrol5211d9d2019-09-05 16:20:22 +020082 { .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 Pedrol38cfa732019-09-09 12:55:01 +020084 { .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 Pedrol28f160e2019-09-05 14:48:35 +020085 { .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 Pedrol63700ea2019-09-09 13:19:06 +020088 { .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 Pedrol2b5c6292019-09-09 13:41:00 +020089 { .T=-2031, .default_val=2000, .unit=OSMO_TDEF_MS, .desc="Time to keep an idle DL TBF alive (ms)", .val=0 },
Pau Espin Pedrol5360ef52019-09-13 12:41:54 +020090 { .T=0, .default_val=0, .unit=OSMO_TDEF_S, .desc=NULL, .val=0 } /* empty item at the end */
Pau Espin Pedrol28f160e2019-09-05 14:48:35 +020091};
92
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +010093/**
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 */
98static const struct rate_ctr_desc bts_ctr_description[] = {
Maxa5eb67d2017-11-21 20:24:54 +010099 { "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 "},
108 { "tbf:failed:egprs-only", "TBF Failed EGPRS-only"},
109 { "rlc:sent", "RLC Sent "},
110 { "rlc:resent", "RLC Resent "},
111 { "rlc:restarted", "RLC Restarted "},
112 { "rlc:stalled", "RLC Stalled "},
113 { "rlc:nacked", "RLC Nacked "},
114 { "rlc:final_block_resent", "RLC Final Blk resent "},
115 { "rlc:ass:timedout", "RLC Assign Timeout "},
116 { "rlc:ass:failed", "RLC Assign Failed "},
117 { "rlc:ack:timedout", "RLC Ack Timeout "},
118 { "rlc:ack:failed", "RLC Ack Failed "},
119 { "rlc:rel:timedout", "RLC Release Timeout "},
120 { "rlc:late-block", "RLC Late Block "},
121 { "rlc:sent-dummy", "RLC Sent Dummy "},
122 { "rlc:sent-control", "RLC Sent Control "},
123 { "rlc:dl_bytes", "RLC DL Bytes "},
124 { "rlc:dl_payload_bytes", "RLC DL Payload Bytes "},
125 { "rlc:ul_bytes", "RLC UL Bytes "},
126 { "rlc:ul_payload_bytes", "RLC UL Payload Bytes "},
127 { "decode:errors", "Decode Errors "},
128 { "sba:allocated", "SBA Allocated "},
129 { "sba:freed", "SBA Freed "},
130 { "sba:timedout", "SBA Timeout "},
131 { "llc:timeout", "Timedout Frames "},
132 { "llc:dropped", "Dropped Frames "},
133 { "llc:scheduled", "Scheduled Frames "},
134 { "llc:dl_bytes", "RLC encapsulated PDUs"},
135 { "llc:ul_bytes", "full PDUs received "},
136 { "rach:requests", "RACH requests "},
137 { "11bit_rach:requests", "11BIT_RACH requests "},
138 { "spb:uplink_first_segment", "First seg of UL SPB "},
139 { "spb:uplink_second_segment", "Second seg of UL SPB "},
140 { "spb:downlink_first_segment", "First seg of DL SPB "},
141 { "spb:downlink_second_segment","Second seg of DL SPB "},
142 { "immediate:assignment_UL", "Immediate Assign UL "},
143 { "immediate:assignment_rej", "Immediate Assign Rej "},
144 { "immediate:assignment_DL", "Immediate Assign DL "},
145 { "channel:request_description","Channel Request Desc "},
146 { "pkt:ul_assignment", "Packet UL Assignment "},
147 { "pkt:access_reject", "Packet Access Reject "},
148 { "pkt:dl_assignment", "Packet DL Assignment "},
149 { "ul:control", "UL control Block "},
150 { "ul:assignment_poll_timeout", "UL Assign Timeout "},
151 { "ul:assignment_failed", "UL Assign Failed "},
152 { "dl:assignment_timeout", "DL Assign Timeout "},
153 { "dl:assignment_failed", "DL Assign Failed "},
154 { "pkt:ul_ack_nack_timeout", "PUAN Poll Timeout "},
155 { "pkt:ul_ack_nack_failed", "PUAN poll Failed "},
156 { "pkt:dl_ack_nack_timeout", "PDAN poll Timeout "},
157 { "pkt:dl_ack_nack_failed", "PDAN poll Failed "},
158 { "gprs:downlink_cs1", "CS1 downlink "},
159 { "gprs:downlink_cs2", "CS2 downlink "},
160 { "gprs:downlink_cs3", "CS3 downlink "},
161 { "gprs:downlink_cs4", "CS4 downlink "},
162 { "egprs:downlink_mcs1", "MCS1 downlink "},
163 { "egprs:downlink_mcs2", "MCS2 downlink "},
164 { "egprs:downlink_mcs3", "MCS3 downlink "},
165 { "egprs:downlink_mcs4", "MCS4 downlink "},
166 { "egprs:downlink_mcs5", "MCS5 downlink "},
167 { "egprs:downlink_mcs6", "MCS6 downlink "},
168 { "egprs:downlink_mcs7", "MCS7 downlink "},
169 { "egprs:downlink_mcs8", "MCS8 downlink "},
170 { "egprs:downlink_mcs9", "MCS9 downlink "},
171 { "gprs:uplink_cs1", "CS1 Uplink "},
172 { "gprs:uplink_cs2", "CS2 Uplink "},
173 { "gprs:uplink_cs3", "CS3 Uplink "},
174 { "gprs:uplink_cs4", "CS4 Uplink "},
175 { "egprs:uplink_mcs1", "MCS1 Uplink "},
176 { "egprs:uplink_mcs2", "MCS2 Uplink "},
177 { "egprs:uplink_mcs3", "MCS3 Uplink "},
178 { "egprs:uplink_mcs4", "MCS4 Uplink "},
179 { "egprs:uplink_mcs5", "MCS5 Uplink "},
180 { "egprs:uplink_mcs6", "MCS6 Uplink "},
181 { "egprs:uplink_mcs7", "MCS7 Uplink "},
182 { "egprs:uplink_mcs8", "MCS8 Uplink "},
183 { "egprs:uplink_mcs9", "MCS9 Uplink "},
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100184};
185
186static const struct rate_ctr_group_desc bts_ctrg_desc = {
187 "bts",
188 "BTS Statistics",
Holger Hans Peter Freytherb8a54262015-11-07 21:00:00 +0100189 OSMO_STATS_CLASS_GLOBAL,
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100190 ARRAY_SIZE(bts_ctr_description),
191 bts_ctr_description,
192};
193
Jacob Erlbeckf5898a02015-11-27 19:05:13 +0100194static const struct osmo_stat_item_desc bts_stat_item_description[] = {
195 { "ms.present", "MS Present ",
196 OSMO_STAT_ITEM_NO_UNIT, 4, 0},
197};
198
199static const struct osmo_stat_item_group_desc bts_statg_desc = {
200 "bts",
201 "BTS Statistics",
202 OSMO_STATS_CLASS_GLOBAL,
203 ARRAY_SIZE(bts_stat_item_description),
204 bts_stat_item_description,
205};
206
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200207BTS* BTS::main_bts()
208{
209 return &s_bts;
210}
211
212struct gprs_rlcmac_bts *BTS::bts_data()
213{
214 return &m_bts;
215}
216
217struct gprs_rlcmac_bts *bts_main_data()
218{
219 return BTS::main_bts()->bts_data();
220}
221
Maxd5ffeb52019-03-18 15:48:38 +0100222void bts_cleanup()
223{
224 return BTS::main_bts()->cleanup();
225}
226
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100227struct rate_ctr_group *bts_main_data_stats()
228{
229 return BTS::main_bts()->rate_counters();
230}
231
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200232BTS::BTS()
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200233 : m_cur_fn(0)
Jacob Erlbeck60f77032015-08-24 14:35:14 +0200234 , m_cur_blk_fn(-1)
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200235 , m_pollController(*this)
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200236 , m_sba(*this)
Jacob Erlbeck17214bb2015-06-02 14:06:12 +0200237 , m_ms_store(this)
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200238{
239 memset(&m_bts, 0, sizeof(m_bts));
240 m_bts.bts = this;
Oliver Smithcfb63212019-09-05 17:13:33 +0200241 m_bts.app_info = NULL;
Oliver Smith45fdc442019-09-05 15:12:20 +0200242 m_bts.dl_tbf_preemptive_retransmission = true;
Pau Espin Pedrol28f160e2019-09-05 14:48:35 +0200243 m_bts.T_defs_bts = T_defs_bts;
244 m_bts.T_defs_pcu = T_defs_pcu;
245 osmo_tdefs_reset(m_bts.T_defs_bts);
246 osmo_tdefs_reset(m_bts.T_defs_pcu);
Holger Hans Peter Freyther4ed1dae2013-10-20 10:14:03 +0200247
248 /* initialize back pointers */
249 for (size_t trx_no = 0; trx_no < ARRAY_SIZE(m_bts.trx); ++trx_no) {
250 struct gprs_rlcmac_trx *trx = &m_bts.trx[trx_no];
251 trx->trx_no = trx_no;
252 trx->bts = this;
253
254 for (size_t ts_no = 0; ts_no < ARRAY_SIZE(trx->pdch); ++ts_no) {
255 struct gprs_rlcmac_pdch *pdch = &trx->pdch[ts_no];
Vadim Yanitskiybd0dac32019-10-05 21:57:14 +0700256 pdch->init_ptcch_msg();
Holger Hans Peter Freyther4ed1dae2013-10-20 10:14:03 +0200257 pdch->ts_no = ts_no;
258 pdch->trx = trx;
259 }
260 }
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100261
Maxea9968f2017-12-18 22:52:52 +0100262 /* The static allocator might have already registered the counter group.
Max1714aea2017-12-21 11:19:39 +0100263 If this happens and we still called explicitly (in tests/ for example)
Maxea9968f2017-12-18 22:52:52 +0100264 than just allocate the group with different index.
265 This shall be removed once weget rid of BTS singleton */
266 if (rate_ctr_get_group_by_name_idx(bts_ctrg_desc.group_name_prefix, 0))
267 m_ratectrs = rate_ctr_group_alloc(tall_pcu_ctx, &bts_ctrg_desc, 1);
268 else
269 m_ratectrs = rate_ctr_group_alloc(tall_pcu_ctx, &bts_ctrg_desc, 0);
Harald Welte9530a402017-07-12 00:46:36 +0200270 OSMO_ASSERT(m_ratectrs);
Maxea9968f2017-12-18 22:52:52 +0100271
Jacob Erlbeckf5898a02015-11-27 19:05:13 +0100272 m_statg = osmo_stat_item_group_alloc(tall_pcu_ctx, &bts_statg_desc, 0);
Harald Welte9530a402017-07-12 00:46:36 +0200273 OSMO_ASSERT(m_statg);
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200274}
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200275
Maxd5ffeb52019-03-18 15:48:38 +0100276void BTS::cleanup()
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100277{
Jacob Erlbeckc362df22016-01-20 22:02:19 +0100278 /* this can cause counter updates and must not be left to the
279 * m_ms_store's destructor */
280 m_ms_store.cleanup();
281
Maxd5ffeb52019-03-18 15:48:38 +0100282 if (m_ratectrs) {
283 rate_ctr_group_free(m_ratectrs);
284 m_ratectrs = NULL;
285 }
286
287 if (m_statg) {
288 osmo_stat_item_group_free(m_statg);
289 m_statg = NULL;
290 }
Oliver Smithcfb63212019-09-05 17:13:33 +0200291
292 if (m_bts.app_info) {
293 msgb_free(m_bts.app_info);
294 m_bts.app_info = NULL;
295 }
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100296}
297
Maxd5ffeb52019-03-18 15:48:38 +0100298BTS::~BTS()
299{
300 cleanup();
301}
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100302
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200303void BTS::set_current_frame_number(int fn)
304{
Jacob Erlbeckac49d092015-08-27 13:18:24 +0200305 /* The UL frame numbers lag 3 behind the DL frames and the data
306 * indication is only sent after all 4 frames of the block have been
307 * received. Sometimes there is an idle frame between the end of one
308 * and start of another frame (every 3 blocks). So the timeout should
309 * definitely be there if we're more than 8 frames past poll_fn. Let's
Jacob Erlbecke77d49f2015-08-27 13:28:05 +0200310 * stay on the safe side and say 13 or more. An additional delay can
311 * happen due to the block processing time in the DSP, so the delay of
312 * decoded blocks relative to the timing clock can be much larger.
313 * Values up to 50 frames have been observed under load. */
314 const static int max_delay = 60;
Jacob Erlbeckac49d092015-08-27 13:18:24 +0200315
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200316 m_cur_fn = fn;
Jacob Erlbeckac49d092015-08-27 13:18:24 +0200317 m_pollController.expireTimedout(m_cur_fn, max_delay);
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200318}
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200319
Max9dabfa22017-05-16 16:10:45 +0200320static inline int delta_fn(int fn, int to)
321{
322 return (fn + GSM_MAX_FN * 3 / 2 - to) % GSM_MAX_FN - GSM_MAX_FN/2;
323}
324
Jacob Erlbeckaf75ce82015-08-26 13:22:28 +0200325void BTS::set_current_block_frame_number(int fn, unsigned max_delay)
Jacob Erlbeck60f77032015-08-24 14:35:14 +0200326{
327 int delay = 0;
328 const int late_block_delay_thresh = 13;
329 const int fn_update_ok_min_delay = -500;
330 const int fn_update_ok_max_delay = 0;
331
332 /* frame numbers in the received blocks are assumed to be strongly
333 * monotonic. */
334 if (m_cur_blk_fn >= 0) {
Max9dabfa22017-05-16 16:10:45 +0200335 int delta = delta_fn(fn, m_cur_blk_fn);
Jacob Erlbeck60f77032015-08-24 14:35:14 +0200336 if (delta <= 0)
337 return;
338 }
339
340 /* Check block delay vs. the current frame number */
341 if (current_frame_number() != 0)
Max9dabfa22017-05-16 16:10:45 +0200342 delay = delta_fn(fn, current_frame_number());
Jacob Erlbeckbe4a08b2015-08-25 15:19:31 +0200343 if (delay <= -late_block_delay_thresh) {
Jacob Erlbeck60f77032015-08-24 14:35:14 +0200344 LOGP(DRLCMAC, LOGL_NOTICE,
345 "Late RLC block, FN delta: %d FN: %d curFN: %d\n",
346 delay, fn, current_frame_number());
Pau Espin Pedrol2338e532020-05-12 20:54:35 +0200347 do_rate_ctr_inc(CTR_RLC_LATE_BLOCK);
Jacob Erlbeckbe4a08b2015-08-25 15:19:31 +0200348 }
Jacob Erlbeck60f77032015-08-24 14:35:14 +0200349
350 m_cur_blk_fn = fn;
351 if (delay < fn_update_ok_min_delay || delay > fn_update_ok_max_delay ||
352 current_frame_number() == 0)
353 m_cur_fn = fn;
354
Jacob Erlbeckaf75ce82015-08-26 13:22:28 +0200355 m_pollController.expireTimedout(fn, max_delay);
Jacob Erlbeck60f77032015-08-24 14:35:14 +0200356}
357
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +0200358int BTS::add_paging(uint8_t chan_needed, const struct osmo_mobile_identity *mi)
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200359{
360 uint8_t l, trx, ts, any_tbf = 0;
361 struct gprs_rlcmac_tbf *tbf;
Jacob Erlbecked2dbf62015-12-28 19:15:40 +0100362 LListHead<gprs_rlcmac_tbf> *pos;
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200363 uint8_t slot_mask[8];
364 int8_t first_ts; /* must be signed */
365
Jacob Erlbecked2dbf62015-12-28 19:15:40 +0100366 LListHead<gprs_rlcmac_tbf> *tbfs_lists[] = {
367 &m_ul_tbfs,
368 &m_dl_tbfs,
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200369 NULL
370 };
371
Neels Hofmeyr00520512020-08-21 15:44:58 +0200372 if (log_check_level(DRLCMAC, LOGL_INFO)) {
Neels Hofmeyr00520512020-08-21 15:44:58 +0200373 char str[64];
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +0200374 osmo_mobile_identity_to_str_buf(str, sizeof(str), mi);
Neels Hofmeyr00520512020-08-21 15:44:58 +0200375 LOGP(DRLCMAC, LOGL_INFO, "Add RR paging: chan-needed=%d MI=%s\n", chan_needed, str);
376 }
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200377
378 /* collect slots to page
379 * Mark slots for every TBF, but only mark one of it.
380 * Mark only the first slot found.
381 * Don't mark, if TBF uses a different slot that is already marked. */
382 memset(slot_mask, 0, sizeof(slot_mask));
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200383 for (l = 0; tbfs_lists[l]; l++) {
Jacob Erlbecked2dbf62015-12-28 19:15:40 +0100384 llist_for_each(pos, tbfs_lists[l]) {
385 tbf = pos->entry();
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200386 first_ts = -1;
387 for (ts = 0; ts < 8; ts++) {
388 if (tbf->pdch[ts]) {
389 /* remember the first slot found */
390 if (first_ts < 0)
391 first_ts = ts;
392 /* break, if we already marked a slot */
Holger Hans Peter Freytherec80f822013-10-27 13:44:37 +0100393 if ((slot_mask[tbf->trx->trx_no] & (1 << ts)))
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200394 break;
395 }
396 }
397 /* mark first slot found, if none is marked already */
398 if (ts == 8 && first_ts >= 0) {
Maxc21f0072017-12-15 17:36:45 +0100399 LOGPTBF(tbf, LOGL_DEBUG, "uses "
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200400 "TRX=%d TS=%d, so we mark\n",
Holger Hans Peter Freytherbd449f52013-10-27 16:39:36 +0100401 tbf->trx->trx_no, first_ts);
Holger Hans Peter Freytherec80f822013-10-27 13:44:37 +0100402 slot_mask[tbf->trx->trx_no] |= (1 << first_ts);
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200403 } else
Maxc21f0072017-12-15 17:36:45 +0100404 LOGPTBF(tbf, LOGL_DEBUG, "uses "
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200405 "already marked TRX=%d TS=%d\n",
Holger Hans Peter Freytherbd449f52013-10-27 16:39:36 +0100406 tbf->trx->trx_no, ts);
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200407 }
408 }
409
410 /* Now we have a list of marked slots. Every TBF uses at least one
411 * of these slots. */
412
413 /* schedule paging to all marked slots */
414 for (trx = 0; trx < 8; trx++) {
415 if (slot_mask[trx] == 0)
416 continue;
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200417 for (ts = 0; ts < 8; ts++) {
418 if ((slot_mask[trx] & (1 << ts))) {
419 /* schedule */
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +0200420 if (!m_bts.trx[trx].pdch[ts].add_paging(chan_needed, mi))
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200421 return -ENOMEM;
Max4382e4e2018-01-30 12:00:08 +0100422
423 LOGP(DRLCMAC, LOGL_INFO, "Paging on PACCH of TRX=%d TS=%d\n", trx, ts);
Holger Hans Peter Freyther94464852013-10-19 18:33:52 +0200424 any_tbf = 1;
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200425 }
426 }
427 }
428
429 if (!any_tbf)
430 LOGP(DRLCMAC, LOGL_INFO, "No paging, because no TBF\n");
431
432 return 0;
433}
434
Vadim Yanitskiy07b64872020-06-11 00:26:15 +0700435void BTS::send_gsmtap_rach(enum pcu_gsmtap_category categ, uint8_t channel,
436 const struct rach_ind_params *rip)
437{
438 struct pcu_l1_meas meas;
Vadim Yanitskiy81b610e2020-06-11 01:04:44 +0700439 uint8_t ra_buf[2];
440
441 /* 3GPP TS 44.004 defines 11 bit RA as follows: xxxx xxxx .... .yyy
442 * On the PCUIF, we get 16 bit machne dependent number (LE/BE)
443 * Over GSMTAP we send the following: xxxx xxxx yyy. ....
444 * This simplifies parsing in Wireshark using its CSN.1 codec. */
445 if (rip->is_11bit) {
446 ra_buf[0] = (uint8_t) ((rip->ra >> 3) & 0xff);
447 ra_buf[1] = (uint8_t) ((rip->ra << 5) & 0xff);
448 } else {
449 ra_buf[0] = (uint8_t) (rip->ra & 0xff);
450 }
451
Vadim Yanitskiy07b64872020-06-11 00:26:15 +0700452 send_gsmtap_meas(categ, true, rip->trx_nr, rip->ts_nr, channel,
Vadim Yanitskiy81b610e2020-06-11 01:04:44 +0700453 rfn_to_fn(rip->rfn), ra_buf,
Vadim Yanitskiy07b64872020-06-11 00:26:15 +0700454 rip->is_11bit ? 2 : 1, &meas);
455}
456
Harald Welte717cdf52017-07-21 21:56:23 +0200457void BTS::send_gsmtap(enum pcu_gsmtap_category categ, bool uplink, uint8_t trx_no,
458 uint8_t ts_no, uint8_t channel, uint32_t fn,
459 const uint8_t *data, unsigned int len)
460{
Pau Espin Pedrol0b0391f2020-05-19 17:23:23 +0200461 struct pcu_l1_meas meas;
462 send_gsmtap_meas(categ, uplink, trx_no, ts_no, channel, fn, data, len, &meas);
463}
464
465void BTS::send_gsmtap_meas(enum pcu_gsmtap_category categ, bool uplink, uint8_t trx_no,
466 uint8_t ts_no, uint8_t channel, uint32_t fn,
467 const uint8_t *data, unsigned int len, struct pcu_l1_meas *meas)
468{
Harald Welte717cdf52017-07-21 21:56:23 +0200469 uint16_t arfcn;
470
471 /* check if category is activated at all */
472 if (!(m_bts.gsmtap_categ_mask & (1 << categ)))
473 return;
474
475 arfcn = m_bts.trx[trx_no].arfcn;
476 if (uplink)
477 arfcn |= GSMTAP_ARFCN_F_UPLINK;
478
Pau Espin Pedrol0b0391f2020-05-19 17:23:23 +0200479 /* GSMTAP needs the SNR here, but we only have C/I (meas->link_qual).
480 Those are not the same, but there is no known way to convert them,
481 let's pass C/I instead of nothing */
482 gsmtap_send(m_bts.gsmtap, arfcn, ts_no, channel, 0, fn,
483 meas->rssi, meas->link_qual, data, len);
Harald Welte717cdf52017-07-21 21:56:23 +0200484}
485
Max341dccd2017-08-14 15:49:59 +0200486static inline bool tbf_check(gprs_rlcmac_tbf *tbf, uint32_t fn, uint8_t trx_no, uint8_t ts)
487{
Maxcac6b662018-01-24 11:00:17 +0100488 if (tbf->state_is_not(GPRS_RLCMAC_RELEASING) && tbf->poll_scheduled()
Max341dccd2017-08-14 15:49:59 +0200489 && tbf->poll_fn == fn && tbf->trx->trx_no == trx_no && tbf->poll_ts == ts)
490 return true;
491
492 return false;
493}
494
Daniel Willmannfe6e2e42014-07-10 17:44:06 +0200495gprs_rlcmac_dl_tbf *BTS::dl_tbf_by_poll_fn(uint32_t fn, uint8_t trx, uint8_t ts)
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200496{
Jacob Erlbecked2dbf62015-12-28 19:15:40 +0100497 LListHead<gprs_rlcmac_tbf> *pos;
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200498
499 /* only one TBF can poll on specific TS/FN, because scheduler can only
500 * schedule one downlink control block (with polling) at a FN per TS */
Jacob Erlbecked2dbf62015-12-28 19:15:40 +0100501 llist_for_each(pos, &m_dl_tbfs) {
Max341dccd2017-08-14 15:49:59 +0200502 if (tbf_check(pos->entry(), fn, trx, ts))
503 return as_dl_tbf(pos->entry());
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200504 }
Daniel Willmannfebf1a02014-07-02 17:58:16 +0200505 return NULL;
506}
Max341dccd2017-08-14 15:49:59 +0200507
Daniel Willmannfe6e2e42014-07-10 17:44:06 +0200508gprs_rlcmac_ul_tbf *BTS::ul_tbf_by_poll_fn(uint32_t fn, uint8_t trx, uint8_t ts)
Daniel Willmannfebf1a02014-07-02 17:58:16 +0200509{
Jacob Erlbecked2dbf62015-12-28 19:15:40 +0100510 LListHead<gprs_rlcmac_tbf> *pos;
Daniel Willmannfebf1a02014-07-02 17:58:16 +0200511
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 */
Jacob Erlbecked2dbf62015-12-28 19:15:40 +0100514 llist_for_each(pos, &m_ul_tbfs) {
Max341dccd2017-08-14 15:49:59 +0200515 if (tbf_check(pos->entry(), fn, trx, ts))
516 return as_ul_tbf(pos->entry());
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200517 }
518 return NULL;
519}
520
Daniel Willmann54044b02014-07-02 17:58:15 +0200521/* lookup downlink TBF Entity (by TFI) */
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200522gprs_rlcmac_dl_tbf *BTS::dl_tbf_by_tfi(uint8_t tfi, uint8_t trx, uint8_t ts)
Daniel Willmann54044b02014-07-02 17:58:15 +0200523{
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200524 if (trx >= 8 || ts >= 8)
525 return NULL;
526
527 return m_bts.trx[trx].pdch[ts].dl_tbf_by_tfi(tfi);
Daniel Willmann54044b02014-07-02 17:58:15 +0200528}
529
530/* lookup uplink TBF Entity (by TFI) */
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200531gprs_rlcmac_ul_tbf *BTS::ul_tbf_by_tfi(uint8_t tfi, uint8_t trx, uint8_t ts)
Daniel Willmann54044b02014-07-02 17:58:15 +0200532{
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200533 if (trx >= 8 || ts >= 8)
Holger Hans Peter Freytherf63cabd2013-10-26 19:10:43 +0200534 return NULL;
535
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200536 return m_bts.trx[trx].pdch[ts].ul_tbf_by_tfi(tfi);
Holger Hans Peter Freytherf63cabd2013-10-26 19:10:43 +0200537}
538
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200539/*
540 * Search for free TFI and return TFI, TRX.
541 * This method returns the first TFI that is currently not used in any PDCH of
542 * a TRX. The first TRX that contains such an TFI is returned. Negative values
543 * indicate errors.
544 */
Maxa76a7d02018-01-26 11:09:16 +0100545int BTS::tfi_find_free(enum gprs_rlcmac_tbf_direction dir, uint8_t *_trx, int8_t use_trx) const
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +0200546{
Maxa76a7d02018-01-26 11:09:16 +0100547 const struct gprs_rlcmac_pdch *pdch;
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200548 uint32_t free_tfis;
549 bool has_pdch = false;
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +0200550 uint8_t trx_from, trx_to, trx, ts, tfi;
551
552 if (use_trx >= 0 && use_trx < 8)
553 trx_from = trx_to = use_trx;
554 else {
555 trx_from = 0;
556 trx_to = 7;
557 }
558
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200559 /* find a TFI that is unused on all PDCH */
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +0200560 for (trx = trx_from; trx <= trx_to; trx++) {
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200561 bool trx_has_pdch = false;
562
Maxd000d802017-09-20 17:55:28 +0200563 free_tfis = NO_FREE_TFI;
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200564
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +0200565 for (ts = 0; ts < 8; ts++) {
566 pdch = &m_bts.trx[trx].pdch[ts];
567 if (!pdch->is_enabled())
568 continue;
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200569 free_tfis &= ~pdch->assigned_tfi(dir);
570 trx_has_pdch = true;
571 has_pdch = true;
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +0200572 }
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200573 if (trx_has_pdch && free_tfis)
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +0200574 break;
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200575
576 free_tfis = 0;
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +0200577 }
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200578 if (!has_pdch) {
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +0200579 LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH available.\n");
580 return -EINVAL;
581 }
582
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200583 if (!free_tfis) {
Max69d585e2018-01-26 12:36:43 +0100584 LOGP(DRLCMAC, LOGL_NOTICE, "No TFI available (suggested TRX: %d).\n", use_trx);
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200585 return -EBUSY;
586 }
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +0200587
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200588
589 LOGP(DRLCMAC, LOGL_DEBUG,
590 "Searching for first unallocated TFI: TRX=%d\n", trx);
591
592 /* find the first */
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +0200593 for (tfi = 0; tfi < 32; tfi++) {
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200594 if (free_tfis & 1 << tfi)
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +0200595 break;
596 }
597
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200598 OSMO_ASSERT(tfi < 32);
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +0200599
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200600 LOGP(DRLCMAC, LOGL_DEBUG, " Found TFI=%d.\n", tfi);
601 *_trx = trx;
602 return tfi;
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +0200603}
604
Holger Hans Peter Freyther40cfaa62013-10-26 19:49:16 +0200605int BTS::rcv_imm_ass_cnf(const uint8_t *data, uint32_t fn)
606{
Jacob Erlbeck767193e2015-05-20 12:06:46 +0200607 struct gprs_rlcmac_dl_tbf *dl_tbf = NULL;
Holger Hans Peter Freyther40cfaa62013-10-26 19:49:16 +0200608 uint8_t plen;
609 uint32_t tlli;
Jacob Erlbeck767193e2015-05-20 12:06:46 +0200610 GprsMs *ms;
Holger Hans Peter Freyther40cfaa62013-10-26 19:49:16 +0200611
612 /* move to IA Rest Octets */
613 plen = data[0] >> 2;
614 data += 1 + plen;
615
616 if ((*data & 0xf0) != 0xd0) {
617 LOGP(DRLCMAC, LOGL_ERROR, "Got IMM.ASS confirm, but rest "
618 "octets do not start with bit sequence 'HH01' "
619 "(Packet Downlink Assignment)\n");
620 return -EINVAL;
621 }
622
623 /* get TLLI from downlink assignment */
Eric Wildab8b01e2019-07-23 17:16:06 +0200624 tlli = (uint32_t)((*data++) & 0xf) << 28;
Holger Hans Peter Freyther40cfaa62013-10-26 19:49:16 +0200625 tlli |= (*data++) << 20;
626 tlli |= (*data++) << 12;
627 tlli |= (*data++) << 4;
628 tlli |= (*data++) >> 4;
629
Jacob Erlbeck767193e2015-05-20 12:06:46 +0200630 ms = ms_by_tlli(tlli);
631 if (ms)
632 dl_tbf = ms->dl_tbf();
Daniel Willmann1dac2eb2014-08-07 12:37:34 +0200633 if (!dl_tbf) {
Holger Hans Peter Freyther40cfaa62013-10-26 19:49:16 +0200634 LOGP(DRLCMAC, LOGL_ERROR, "Got IMM.ASS confirm, but TLLI=%08x "
635 "does not exit\n", tlli);
636 return -EINVAL;
637 }
638
639 LOGP(DRLCMAC, LOGL_DEBUG, "Got IMM.ASS confirm for TLLI=%08x\n", tlli);
640
Daniel Willmann7e994e32014-08-07 15:49:21 +0200641 if (dl_tbf->m_wait_confirm)
Pau Espin Pedrol28f160e2019-09-05 14:48:35 +0200642 T_START(dl_tbf, T0, -2002, "assignment (AGCH)", true);
Holger Hans Peter Freyther40cfaa62013-10-26 19:49:16 +0200643
644 return 0;
645}
646
Philipp Maier1275a3f2017-02-21 19:35:23 +0100647/* Determine the full frame number from a relative frame number */
Max5dd8d1b2017-03-08 12:06:42 +0100648uint32_t BTS::rfn_to_fn(int32_t rfn)
Philipp Maier1275a3f2017-02-21 19:35:23 +0100649{
Max5dd8d1b2017-03-08 12:06:42 +0100650 int32_t m_cur_rfn;
651 int32_t fn;
652 int32_t fn_rounded;
653
654 /* double-check that relative FN is not negative and fits into int32_t */
655 OSMO_ASSERT(rfn < GSM_MAX_FN);
656 OSMO_ASSERT(rfn >= 0);
Philipp Maier1275a3f2017-02-21 19:35:23 +0100657
658 /* Note: If a BTS is sending in a rach request it will be fully aware
659 * of the frame number. If the PCU is used in a BSC-co-located setup.
660 * The BSC will forward the incoming RACH request. The RACH request
661 * only contains the relative frame number (Fn % 42432) in its request
662 * reference. This PCU implementation has to fit both scenarios, so
663 * we need to assume that Fn is a relative frame number. */
664
665 /* Ensure that all following calculations are performed with the
666 * relative frame number */
Max5dd8d1b2017-03-08 12:06:42 +0100667 if (rfn >= RFN_MODULUS)
668 return rfn;
Philipp Maier1275a3f2017-02-21 19:35:23 +0100669
670 /* Compute an internal relative frame number from the full internal
671 frame number */
672 m_cur_rfn = m_cur_fn % RFN_MODULUS;
673
674 /* Compute a "rounded" version of the internal frame number, which
675 * exactly fits in the RFN_MODULUS raster */
676 fn_rounded = m_cur_fn - m_cur_rfn;
677
678 /* If the delta between the internal and the external relative frame
679 * number exceeds a certain limit, we need to assume that the incoming
680 * rach request belongs to a the previous rfn period. To correct this,
681 * we roll back the rounded frame number by one RFN_MODULUS */
682 if (abs(rfn - m_cur_rfn) > RFN_THRESHOLD) {
683 LOGP(DRLCMAC, LOGL_DEBUG,
Thorsten Alteholz8bb79042018-10-06 10:42:58 +0200684 "Race condition between rfn (%u) and m_cur_fn (%u) detected: rfn belongs to the previous modulus %u cycle, wrapping...\n",
Philipp Maier1275a3f2017-02-21 19:35:23 +0100685 rfn, m_cur_fn, RFN_MODULUS);
686 if (fn_rounded < RFN_MODULUS) {
687 LOGP(DRLCMAC, LOGL_DEBUG,
688 "Cornercase detected: wrapping crosses %u border\n",
689 GSM_MAX_FN);
690 fn_rounded = GSM_MAX_FN - (RFN_MODULUS - fn_rounded);
691 }
692 else
693 fn_rounded -= RFN_MODULUS;
694 }
695
696 /* The real frame number is the sum of the rounded frame number and the
697 * relative framenumber computed via RACH */
698 fn = fn_rounded + rfn;
699
700 return fn;
701}
702
Pau Espin Pedrol9ee90d22020-05-08 14:20:32 +0200703/* 3GPP TS 44.060:
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700704 * Table 11.2.5.2: PACKET CHANNEL REQUEST
705 * Table 11.2.5a.2: EGPRS PACKET CHANNEL REQUEST
706 * Both GPRS and EGPRS use same MultislotClass coding, but since PRACH is
Pau Espin Pedrol9ee90d22020-05-08 14:20:32 +0200707 * deprecated, no PACKET CHANNEL REQUEST exists, which means for GPRS we will
708 * receive CCCH RACH which doesn't contain any mslot class. Hence in the end we
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700709 * can only receive EGPRS mslot class through 11-bit EGPRS PACKET CHANNEL REQUEST. */
710static int parse_egprs_pkt_ch_req(uint16_t ra11, struct chan_req_params *chan_req)
Max58818582018-01-05 15:04:50 +0100711{
Vadim Yanitskiyb90d34b2020-05-21 20:20:34 +0700712 EGPRS_PacketChannelRequest_t req;
713 int rc;
714
715 rc = decode_egprs_pkt_ch_req(ra11, &req);
716 if (rc) {
717 LOGP(DRLCMAC, LOGL_NOTICE, "Failed to decode "
718 "EGPRS Packet Channel Request: rc=%d\n", rc);
719 return rc;
720 }
721
722 LOGP(DRLCMAC, LOGL_INFO, "Rx EGPRS Packet Channel Request: %s\n",
723 get_value_string(egprs_pkt_ch_req_type_names, req.Type));
724
725 switch (req.Type) {
726 case EGPRS_PKT_CHAN_REQ_ONE_PHASE:
727 chan_req->egprs_mslot_class = req.Content.MultislotClass + 1;
728 chan_req->priority = req.Content.Priority + 1;
729 break;
730 case EGPRS_PKT_CHAN_REQ_SHORT:
731 chan_req->priority = req.Content.Priority + 1;
732 if (req.Content.NumberOfBlocks == 0)
733 chan_req->single_block = true;
734 break;
735 case EGPRS_PKT_CHAN_REQ_ONE_PHASE_RED_LATENCY:
736 chan_req->priority = req.Content.Priority + 1;
737 break;
738 /* Two phase access => single block is needed */
739 case EGPRS_PKT_CHAN_REQ_TWO_PHASE:
740 case EGPRS_PKT_CHAN_REQ_TWO_PHASE_IPA:
741 chan_req->priority = req.Content.Priority + 1;
742 chan_req->single_block = true;
743 break;
744 /* Signalling => single block is needed */
745 case EGPRS_PKT_CHAN_REQ_SIGNALLING:
746 case EGPRS_PKT_CHAN_REQ_SIGNALLING_IPA:
747 chan_req->single_block = true;
748 break;
749
750 /* Neither unacknowledged RLC mode, nor emergency calls are supported */
751 case EGPRS_PKT_CHAN_REQ_ONE_PHASE_UNACK:
752 case EGPRS_PKT_CHAN_REQ_EMERGENCY_CALL:
753 case EGPRS_PKT_CHAN_REQ_DEDICATED_CHANNEL:
754 LOGP(DRLCMAC, LOGL_NOTICE, "%s is not supported, rejecting\n",
755 get_value_string(egprs_pkt_ch_req_type_names, req.Type));
756 return -ENOTSUP;
757
758 default:
759 LOGP(DRLCMAC, LOGL_ERROR, "Unknown EGPRS Packet Channel Request "
760 "type=0x%02x, probably a bug in CSN.1 codec\n", req.Type);
761 return -EINVAL;
762 }
Max58818582018-01-05 15:04:50 +0100763
764 return 0;
765}
766
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700767/* NOTE: chan_req needs to be zero-initialized by the caller */
768static int parse_rach_ind(const struct rach_ind_params *rip,
769 struct chan_req_params *chan_req)
Max58818582018-01-05 15:04:50 +0100770{
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700771 int rc;
Max58818582018-01-05 15:04:50 +0100772
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700773 switch (rip->burst_type) {
Max137fd592018-01-05 15:53:08 +0100774 case GSM_L1_BURST_TYPE_NONE:
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700775 LOGP(DRLCMAC, LOGL_ERROR, "RACH.ind contains no burst type, assuming TS0\n");
776 /* fall-through */
777 case GSM_L1_BURST_TYPE_ACCESS_0:
778 if (rip->is_11bit) { /* 11 bit Access Burst with TS0 => Packet Channel Request */
779 LOGP(DRLCMAC, LOGL_ERROR, "11 bit Packet Channel Request "
780 "is not supported (PBCCH is deprecated)\n");
781 return -ENOTSUP;
782 }
783
784 /* 3GPP TS 44.018, table 9.1.8.1: 8 bit CHANNEL REQUEST.
785 * Mask 01110xxx indicates single block packet access. */
786 chan_req->single_block = ((rip->ra & 0xf8) == 0x70);
787 break;
788 case GSM_L1_BURST_TYPE_ACCESS_1:
789 case GSM_L1_BURST_TYPE_ACCESS_2:
790 if (!rip->is_11bit) { /* TS1/TS2 => EGPRS Packet Channel Request (always 11 bit) */
791 LOGP(DRLCMAC, LOGL_ERROR, "11 bit Packet Channel Request "
792 "is not supported (PBCCH is deprecated)\n");
793 return -ENOTSUP;
794 }
795
796 rc = parse_egprs_pkt_ch_req(rip->ra, chan_req);
797 if (rc)
798 return rc;
Max137fd592018-01-05 15:53:08 +0100799 break;
800 default:
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700801 LOGP(DRLCMAC, LOGL_ERROR, "RACH.ind contains unknown burst type 0x%02x "
802 "(%u bit)\n", rip->burst_type, rip->is_11bit ? 11 : 8);
803 return -EINVAL;
Max58818582018-01-05 15:04:50 +0100804 }
805
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700806 return 0;
Max58818582018-01-05 15:04:50 +0100807}
808
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700809int BTS::rcv_rach(const struct rach_ind_params *rip)
Holger Hans Peter Freyther02beed52013-10-26 20:56:20 +0200810{
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700811 struct chan_req_params chan_req = { 0 };
Jacob Erlbeck1f332942015-05-04 08:21:17 +0200812 struct gprs_rlcmac_ul_tbf *tbf = NULL;
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700813 uint8_t trx_no, ts_no;
Holger Hans Peter Freyther02beed52013-10-26 20:56:20 +0200814 uint32_t sb_fn = 0;
Jacob Erlbeck2ca86af2016-01-20 18:26:13 +0100815 uint8_t usf = 7;
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700816 uint8_t tsc = 0;
817 int plen, rc;
Holger Hans Peter Freyther02beed52013-10-26 20:56:20 +0200818
Pau Espin Pedrol2338e532020-05-12 20:54:35 +0200819 do_rate_ctr_inc(CTR_RACH_REQUESTS);
Holger Hans Peter Freytherc1ae2262013-10-27 10:50:35 +0100820
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700821 if (rip->is_11bit)
Pau Espin Pedrol2338e532020-05-12 20:54:35 +0200822 do_rate_ctr_inc(CTR_11BIT_RACH_REQUESTS);
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530823
Philipp Maier1275a3f2017-02-21 19:35:23 +0100824 /* Determine full frame number */
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700825 uint32_t Fn = rfn_to_fn(rip->rfn);
826 uint8_t ta = qta2ta(rip->qta);
Philippd935d882016-11-07 13:07:36 +0100827
Vadim Yanitskiy07b64872020-06-11 00:26:15 +0700828 send_gsmtap_rach(PCU_GSMTAP_C_UL_RACH, GSMTAP_CHANNEL_RACH, rip);
Pau Espin Pedrol1ec211f2019-09-30 18:33:14 +0200829
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700830 LOGP(DRLCMAC, LOGL_DEBUG, "MS requests Uplink resource on CCCH/RACH: "
831 "ra=0x%02x (%d bit) Fn=%u qta=%d\n", rip->ra,
832 rip->is_11bit ? 11 : 8, Fn, rip->qta);
bhargava628dcfb2016-09-14 20:30:31 +0530833
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700834 /* Parse [EGPRS Packet] Channel Request from RACH.ind */
835 rc = parse_rach_ind(rip, &chan_req);
836 if (rc) /* Send RR Immediate Assignment Reject */
837 goto send_imm_ass_rej;
bhargava628dcfb2016-09-14 20:30:31 +0530838
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700839 if (chan_req.single_block)
840 LOGP(DRLCMAC, LOGL_DEBUG, "MS requests single block allocation\n");
841 else if (m_bts.force_two_phase) {
842 LOGP(DRLCMAC, LOGL_DEBUG, "MS requests single block allocation, "
843 "but we force two phase access\n");
844 chan_req.single_block = true;
845 }
846
Vadim Yanitskiyb90d34b2020-05-21 20:20:34 +0700847 /* TODO: handle Radio Priority (see 3GPP TS 44.060, table 11.2.5a.5) */
848 if (chan_req.priority > 0)
849 LOGP(DRLCMAC, LOGL_NOTICE, "EGPRS Packet Channel Request indicates "
850 "Radio Priority %u, however we ignore it\n", chan_req.priority);
851
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700852 /* Should we allocate a single block or an Uplink TBF? */
853 if (chan_req.single_block) {
Jacob Erlbeck2ca86af2016-01-20 18:26:13 +0100854 rc = sba()->alloc(&trx_no, &ts_no, &sb_fn, ta);
aravind sirsikarc0c3afd2016-11-09 16:27:00 +0530855 if (rc < 0) {
aravind sirsikarc0c3afd2016-11-09 16:27:00 +0530856 LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource for "
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700857 "single block allocation: rc=%d\n", rc);
858 /* Send RR Immediate Assignment Reject */
859 goto send_imm_ass_rej;
aravind sirsikarc0c3afd2016-11-09 16:27:00 +0530860 }
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700861
862 tsc = m_bts.trx[trx_no].pdch[ts_no].tsc;
863 LOGP(DRLCMAC, LOGL_DEBUG, "Allocated a single block at "
864 "SBFn=%u TRX=%u TS=%u\n", sb_fn, trx_no, ts_no);
Holger Hans Peter Freyther02beed52013-10-26 20:56:20 +0200865 } else {
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700866 GprsMs *ms = ms_alloc(0, chan_req.egprs_mslot_class);
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200867 tbf = tbf_alloc_ul_tbf(&m_bts, ms, -1, true);
Holger Hans Peter Freyther02beed52013-10-26 20:56:20 +0200868 if (!tbf) {
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700869 LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource for Uplink TBF\n");
870 /* Send RR Immediate Assignment Reject */
aravind sirsikarc0c3afd2016-11-09 16:27:00 +0530871 rc = -EBUSY;
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700872 goto send_imm_ass_rej;
Holger Hans Peter Freyther02beed52013-10-26 20:56:20 +0200873 }
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700874
875 /* FIXME: Copy and paste with other routines.. */
876 tbf->set_ta(ta);
877 TBF_SET_STATE(tbf, GPRS_RLCMAC_FLOW);
878 TBF_ASS_TYPE_SET(tbf, GPRS_RLCMAC_FLAG_CCCH);
879 T_START(tbf, T3169, 3169, "RACH (new UL-TBF)", true);
880 trx_no = tbf->trx->trx_no;
881 ts_no = tbf->first_ts;
882 usf = tbf->m_usf[ts_no];
883 tsc = tbf->tsc();
Holger Hans Peter Freyther02beed52013-10-26 20:56:20 +0200884 }
Jacob Erlbeck2ca86af2016-01-20 18:26:13 +0100885
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700886send_imm_ass_rej:
887 /* Allocate a bit-vector for RR Immediate Assignment [Reject] */
888 struct bitvec *bv = bitvec_alloc(22, tall_pcu_ctx); /* without plen */
Vadim Yanitskiyeb1e0fa2020-07-18 20:33:08 +0700889 bitvec_unhex(bv, DUMMY_VEC); /* standard '2B'O padding */
Jacob Erlbeck2ca86af2016-01-20 18:26:13 +0100890
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700891 if (rc != 0) {
892 LOGP(DRLCMAC, LOGL_DEBUG, "Tx Immediate Assignment Reject on AGCH\n");
aravind sirsikarc0c3afd2016-11-09 16:27:00 +0530893 plen = Encoding::write_immediate_assignment_reject(
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700894 bv, rip->ra, Fn, rip->burst_type);
Pau Espin Pedrol2338e532020-05-12 20:54:35 +0200895 do_rate_ctr_inc(CTR_IMMEDIATE_ASSIGN_REJ);
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700896 } else {
897 LOGP(DRLCMAC, LOGL_DEBUG, "Tx Immediate Assignment on AGCH: "
898 "TRX=%u (ARFCN %u) TS=%u TA=%u TSC=%u TFI=%d USF=%d\n",
899 trx_no, m_bts.trx[trx_no].arfcn & ~ARFCN_FLAG_MASK,
900 ts_no, ta, tsc, tbf ? tbf->tfi() : -1, usf);
901 plen = Encoding::write_immediate_assignment(
Vadim Yanitskiy11567762020-07-18 23:34:17 +0700902 &m_bts.trx[trx_no].pdch[ts_no], tbf, bv,
903 false, rip->ra, Fn, ta, usf, false, sb_fn,
904 m_bts.alpha, m_bts.gamma, -1,
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700905 rip->burst_type);
Pau Espin Pedrol2338e532020-05-12 20:54:35 +0200906 do_rate_ctr_inc(CTR_IMMEDIATE_ASSIGN_UL_TBF);
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530907 }
Jacob Erlbeck2647a332016-02-01 16:13:38 +0100908
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700909 if (plen >= 0)
910 pcu_l1if_tx_agch(bv, plen);
911 else
912 rc = plen;
913
914 bitvec_free(bv);
Holger Hans Peter Freyther02beed52013-10-26 20:56:20 +0200915
aravind sirsikarc0c3afd2016-11-09 16:27:00 +0530916 return rc;
Holger Hans Peter Freyther02beed52013-10-26 20:56:20 +0200917}
918
Vadim Yanitskiyffebd242019-10-05 23:45:31 +0700919/* PTCCH/U sub-slot / frame-number mapping (see 3GPP TS 45.002, table 6) */
920static uint32_t ptcch_slot_map[PTCCH_TAI_NUM] = {
921 12, 38, 64, 90,
922 116, 142, 168, 194,
923 220, 246, 272, 298,
924 324, 350, 376, 402,
925};
926
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700927int BTS::rcv_ptcch_rach(const struct rach_ind_params *rip)
Vadim Yanitskiyffebd242019-10-05 23:45:31 +0700928{
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700929 uint32_t fn416 = rfn_to_fn(rip->rfn) % 416;
Vadim Yanitskiyffebd242019-10-05 23:45:31 +0700930 struct gprs_rlcmac_bts *bts = bts_data();
931 struct gprs_rlcmac_pdch *pdch;
Vadim Yanitskiyffebd242019-10-05 23:45:31 +0700932 uint8_t ss;
933
Vadim Yanitskiy07b64872020-06-11 00:26:15 +0700934 send_gsmtap_rach(PCU_GSMTAP_C_UL_PTCCH, GSMTAP_CHANNEL_PTCCH, rip);
935
Vadim Yanitskiyffebd242019-10-05 23:45:31 +0700936 /* Prevent buffer overflow */
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700937 if (rip->trx_nr >= ARRAY_SIZE(bts->trx) || rip->ts_nr >= 8) {
938 LOGP(DRLCMAC, LOGL_ERROR, "(TRX=%u TS=%u RFN=%u) Rx malformed "
939 "RACH.ind (PTCCH/U)\n", rip->trx_nr, rip->ts_nr, rip->rfn);
Vadim Yanitskiyffebd242019-10-05 23:45:31 +0700940 return -EINVAL;
941 }
942
943 /* Make sure PDCH time-slot is enabled */
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700944 pdch = &bts->trx[rip->trx_nr].pdch[rip->ts_nr];
Vadim Yanitskiyffebd242019-10-05 23:45:31 +0700945 if (!pdch->m_is_enabled) {
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700946 LOGP(DRLCMAC, LOGL_NOTICE, "(TRX=%u TS=%u RFN=%u) Rx RACH.ind (PTCCH/U) "
947 "for inactive PDCH\n", rip->trx_nr, rip->ts_nr, rip->rfn);
Vadim Yanitskiyffebd242019-10-05 23:45:31 +0700948 return -EAGAIN;
949 }
950
951 /* Convert TDMA frame-number to PTCCH/U sub-slot number */
952 for (ss = 0; ss < PTCCH_TAI_NUM; ss++)
953 if (ptcch_slot_map[ss] == fn416)
954 break;
955 if (ss == PTCCH_TAI_NUM) {
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700956 LOGP(DRLCMAC, LOGL_ERROR, "(TRX=%u TS=%u RFN=%u) Failed to map "
957 "PTCCH/U sub-slot\n", rip->trx_nr, rip->ts_nr, rip->rfn);
Vadim Yanitskiyffebd242019-10-05 23:45:31 +0700958 return -ENODEV;
959 }
960
961 /* Apply the new Timing Advance value */
962 LOGP(DRLCMAC, LOGL_INFO, "Continuous Timing Advance update "
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700963 "for TAI %u, new TA is %u\n", ss, qta2ta(rip->qta));
964 pdch->update_ta(ss, qta2ta(rip->qta));
Vadim Yanitskiyffebd242019-10-05 23:45:31 +0700965
966 return 0;
967}
968
Pau Espin Pedrold7c32652019-12-23 12:41:34 +0100969void BTS::snd_dl_ass(gprs_rlcmac_tbf *tbf, bool poll, uint16_t pgroup)
Holger Hans Peter Freytherd9262b32013-10-26 20:12:59 +0200970{
Vadim Yanitskiy11567762020-07-18 23:34:17 +0700971 uint8_t trx_no = tbf->trx->trx_no;
972 uint8_t ts_no = tbf->first_ts;
Holger Hans Peter Freytherd9262b32013-10-26 20:12:59 +0200973 int plen;
974
Maxc21f0072017-12-15 17:36:45 +0100975 LOGPTBF(tbf, LOGL_INFO, "TX: START Immediate Assignment Downlink (PCH)\n");
Alexander Couzensccde5c92017-02-04 03:10:08 +0100976 bitvec *immediate_assignment = bitvec_alloc(22, tall_pcu_ctx); /* without plen */
Vadim Yanitskiyeb1e0fa2020-07-18 20:33:08 +0700977 bitvec_unhex(immediate_assignment, DUMMY_VEC); /* standard '2B'O padding */
Holger Hans Peter Freytherd9262b32013-10-26 20:12:59 +0200978 /* use request reference that has maximum distance to current time,
979 * so the assignment will not conflict with possible RACH requests. */
Jacob Erlbeck2ca86af2016-01-20 18:26:13 +0100980 LOGP(DRLCMAC, LOGL_DEBUG, " - TRX=%d (%d) TS=%d TA=%d pollFN=%d\n",
Vadim Yanitskiy11567762020-07-18 23:34:17 +0700981 trx_no, tbf->trx->arfcn, ts_no, tbf->ta(), poll ? tbf->poll_fn : -1);
982 plen = Encoding::write_immediate_assignment(&m_bts.trx[trx_no].pdch[ts_no],
983 tbf, immediate_assignment, true, 125,
984 (tbf->pdch[ts_no]->last_rts_fn + 21216) % GSM_MAX_FN,
985 tbf->ta(), 7, poll, tbf->poll_fn,
986 m_bts.alpha, m_bts.gamma, -1,
Maxfc8afc22019-02-18 18:52:38 +0100987 GSM_L1_BURST_TYPE_ACCESS_0);
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530988 if (plen >= 0) {
Pau Espin Pedrol2338e532020-05-12 20:54:35 +0200989 do_rate_ctr_inc(CTR_IMMEDIATE_ASSIGN_DL_TBF);
Pau Espin Pedrold7c32652019-12-23 12:41:34 +0100990 pcu_l1if_tx_pch(immediate_assignment, plen, pgroup);
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530991 }
992
Holger Hans Peter Freytherd9262b32013-10-26 20:12:59 +0200993 bitvec_free(immediate_assignment);
994}
995
Holger Hans Peter Freytherd11290b2013-10-26 17:32:04 +0200996
Jacob Erlbeck86b6f052015-11-27 15:17:34 +0100997GprsMs *BTS::ms_alloc(uint8_t ms_class, uint8_t egprs_ms_class)
Jacob Erlbeckcb1b4942015-06-19 10:59:58 +0200998{
999 GprsMs *ms;
1000 ms = ms_store().create_ms();
1001
Pau Espin Pedrol63700ea2019-09-09 13:19:06 +02001002 ms->set_timeout(osmo_tdef_get(m_bts.T_defs_pcu, -2030, OSMO_TDEF_S, -1));
Jacob Erlbeckcb1b4942015-06-19 10:59:58 +02001003 ms->set_ms_class(ms_class);
Jacob Erlbeck86b6f052015-11-27 15:17:34 +01001004 ms->set_egprs_ms_class(egprs_ms_class);
Jacob Erlbeckcb1b4942015-06-19 10:59:58 +02001005
1006 return ms;
1007}
1008
Minh-Quang Nguyen1bcfa9a2017-11-01 14:41:37 -04001009/* update TA based on TA provided by PH-DATA-IND */
1010void update_tbf_ta(struct gprs_rlcmac_ul_tbf *tbf, int8_t ta_delta)
1011{
1012 int16_t ta_adj;
1013 uint8_t ta_target;
1014
1015 if (ta_delta) {
1016 /* adjust TA based on TA provided by PH-DATA-IND */
1017 ta_adj = tbf->ta() + ta_delta;
1018
1019 /* limit target TA in range 0..63 bits */
1020 ta_target = ta_limit(ta_adj);
1021
1022 LOGP(DL1IF, LOGL_INFO, "PH-DATA-IND is updating TLLI=0x%08x: TA %u -> %u on "
1023 "TRX = %d, TS = %d, FN = %d\n",
1024 tbf->tlli(), tbf->ta(), ta_target,
1025 tbf->trx->trx_no , tbf->poll_ts, tbf->poll_fn);
1026 tbf->set_ta(ta_target);
1027 }
1028}
1029
1030/* set TA based on TA provided by PH-RA-IND */
1031void set_tbf_ta(struct gprs_rlcmac_ul_tbf *tbf, uint8_t ta)
1032{
1033 uint8_t ta_target;
1034
1035 if (tbf->ta() != ta) {
1036 /* limit target TA in range 0..63 bits */
1037 ta_target = ta_limit(ta);
1038
1039 LOGP(DL1IF, LOGL_INFO, "PH-RA-IND is updating TLLI=0x%08x: TA %u -> %u on "
1040 "TRX = %d, TS = %d, FN = %d\n",
1041 tbf->tlli(), tbf->ta(), ta_target,
1042 tbf->trx->trx_no , tbf->poll_ts, tbf->poll_fn);
1043 tbf->set_ta(ta_target);
1044 }
1045}
1046
1047void bts_update_tbf_ta(const char *p, uint32_t fn, uint8_t trx_no, uint8_t ts, int8_t ta, bool is_rach)
Maxd71e8b32016-09-19 16:17:06 +02001048{
1049 struct gprs_rlcmac_ul_tbf *tbf =
1050 bts_main_data()->bts->ul_tbf_by_poll_fn(fn, trx_no, ts);
1051 if (!tbf)
1052 LOGP(DL1IF, LOGL_DEBUG, "[%s] update TA = %u ignored due to "
1053 "unknown UL TBF on TRX = %d, TS = %d, FN = %d\n",
1054 p, ta, trx_no, ts, fn);
Minh-Quang Nguyen1bcfa9a2017-11-01 14:41:37 -04001055 else {
1056 /* we need to distinguish TA information provided by L1
1057 * from PH-DATA-IND and PHY-RA-IND so that we can properly
1058 * update TA for given TBF
1059 */
1060 if (is_rach)
1061 set_tbf_ta(tbf, (uint8_t)ta);
1062 else
1063 update_tbf_ta(tbf, ta);
1064
Maxd71e8b32016-09-19 16:17:06 +02001065 }
1066}
1067
Jacob Erlbeck23f93a12015-06-30 08:52:54 +02001068void gprs_rlcmac_trx::reserve_slots(enum gprs_rlcmac_tbf_direction dir,
1069 uint8_t slots)
1070{
1071 unsigned i;
1072 for (i = 0; i < ARRAY_SIZE(pdch); i += 1)
1073 if (slots & (1 << i))
1074 pdch[i].reserve(dir);
1075}
1076
1077void gprs_rlcmac_trx::unreserve_slots(enum gprs_rlcmac_tbf_direction dir,
1078 uint8_t slots)
1079{
1080 unsigned i;
1081 for (i = 0; i < ARRAY_SIZE(pdch); i += 1)
1082 if (slots & (1 << i))
1083 pdch[i].unreserve(dir);
1084}