blob: 9a139ba16cc86f0f548e924e6e9c9f16dcfe5a67 [file] [log] [blame]
Daniel Willmannca102af2014-08-08 12:14:12 +02001/* Copied from tbf.cpp
2 *
3 * Copyright (C) 2012 Ivan Klyuchnikov
4 * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu>
5 * Copyright (C) 2013 by Holger Hans Peter Freyther
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Daniel Willmannca102af2014-08-08 12:14:12 +020016 */
17
18#include <bts.h>
Oliver Smithd3c75912021-07-09 16:37:16 +020019#include <bts_pch_timer.h>
Daniel Willmannca102af2014-08-08 12:14:12 +020020#include <tbf.h>
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020021#include <tbf_ul.h>
Daniel Willmannca102af2014-08-08 12:14:12 +020022#include <rlc.h>
23#include <encoding.h>
24#include <gprs_rlcmac.h>
25#include <gprs_debug.h>
26#include <gprs_bssgp_pcu.h>
27#include <decoding.h>
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +020028#include <pcu_l1_if.h>
Max1187a772018-01-26 13:31:42 +010029#include <gprs_ms.h>
30#include <llc.h>
sivasankari8adfcd02017-01-16 15:41:21 +053031#include "pcu_utils.h"
Pau Espin Pedrold6c555e2023-04-20 20:10:53 +020032#include "alloc_algo.h"
sivasankari8adfcd02017-01-16 15:41:21 +053033
Daniel Willmannca102af2014-08-08 12:14:12 +020034extern "C" {
35#include <osmocom/core/msgb.h>
36#include <osmocom/core/talloc.h>
Max1187a772018-01-26 13:31:42 +010037 #include <osmocom/core/bitvec.h>
38 #include <osmocom/core/logging.h>
39 #include <osmocom/core/rate_ctr.h>
Pau Espin Pedrol442198c2020-10-23 22:30:04 +020040 #include <osmocom/core/stats.h>
Max1187a772018-01-26 13:31:42 +010041 #include <osmocom/core/utils.h>
42 #include <osmocom/gprs/gprs_bssgp_bss.h>
43 #include <osmocom/gprs/protocol/gsm_08_18.h>
44 #include <osmocom/gsm/tlv.h>
Max136ebcc2019-03-05 14:59:03 +010045 #include "coding_scheme.h"
Daniel Willmannca102af2014-08-08 12:14:12 +020046}
47
48#include <errno.h>
49#include <string.h>
50
51/* After receiving these frames, we send ack/nack. */
52#define SEND_ACK_AFTER_FRAMES 20
53
54extern void *tall_pcu_ctx;
55
Pau Espin Pedrol442198c2020-10-23 22:30:04 +020056static const struct rate_ctr_desc tbf_ul_gprs_ctr_description[] = {
57 { "gprs:uplink:cs1", "CS1 " },
58 { "gprs:uplink:cs2", "CS2 " },
59 { "gprs:uplink:cs3", "CS3 " },
60 { "gprs:uplink:cs4", "CS4 " },
61};
62
63static const struct rate_ctr_desc tbf_ul_egprs_ctr_description[] = {
64 { "egprs:uplink:mcs1", "MCS1 " },
65 { "egprs:uplink:mcs2", "MCS2 " },
66 { "egprs:uplink:mcs3", "MCS3 " },
67 { "egprs:uplink:mcs4", "MCS4 " },
68 { "egprs:uplink:mcs5", "MCS5 " },
69 { "egprs:uplink:mcs6", "MCS6 " },
70 { "egprs:uplink:mcs7", "MCS7 " },
71 { "egprs:uplink:mcs8", "MCS8 " },
72 { "egprs:uplink:mcs9", "MCS9 " },
73};
74
75static const struct rate_ctr_group_desc tbf_ul_gprs_ctrg_desc = {
76 "tbf:gprs",
77 "Data Blocks",
78 OSMO_STATS_CLASS_SUBSCRIBER,
79 ARRAY_SIZE(tbf_ul_gprs_ctr_description),
80 tbf_ul_gprs_ctr_description,
81};
82
83static const struct rate_ctr_group_desc tbf_ul_egprs_ctrg_desc = {
84 "tbf:egprs",
85 "Data Blocks",
86 OSMO_STATS_CLASS_SUBSCRIBER,
87 ARRAY_SIZE(tbf_ul_egprs_ctr_description),
88 tbf_ul_egprs_ctr_description,
89};
90
Pau Espin Pedrol131deb02021-07-26 18:24:14 +020091gprs_rlcmac_ul_tbf::~gprs_rlcmac_ul_tbf()
92{
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +020093 osmo_fsm_inst_free(ul_ack_fsm.fi);
94 ul_ack_fsm.fi = NULL;
95
Pau Espin Pedrol131deb02021-07-26 18:24:14 +020096 rate_ctr_group_free(m_ul_egprs_ctrs);
97 rate_ctr_group_free(m_ul_gprs_ctrs);
98 /* ~gprs_rlcmac_tbf() is called automatically upon return */
99}
100
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200101static int ul_tbf_dtor(struct gprs_rlcmac_ul_tbf *tbf)
102{
103 tbf->~gprs_rlcmac_ul_tbf();
104 return 0;
105}
106
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200107/* Generic function to alloc a UL TBF, later configured to be assigned either over CCCH or PACCH */
Pau Espin Pedrol4d363912023-04-21 19:32:16 +0200108struct gprs_rlcmac_ul_tbf *ul_tbf_alloc(struct gprs_rlcmac_bts *bts, struct GprsMs *ms)
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200109{
110 struct gprs_rlcmac_ul_tbf *tbf;
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200111
112 OSMO_ASSERT(ms != NULL);
113
Pau Espin Pedrol36177c62021-02-25 17:57:37 +0100114 LOGPMS(ms, DTBF, LOGL_DEBUG, "********** UL-TBF starts here **********\n");
115 LOGPMS(ms, DTBF, LOGL_INFO, "Allocating UL TBF\n");
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200116
117 tbf = talloc(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
118 if (!tbf)
119 return NULL;
120 talloc_set_destructor(tbf, ul_tbf_dtor);
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100121 new (tbf) gprs_rlcmac_ul_tbf(bts, ms);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200122
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100123 bts_do_rate_ctr_inc(tbf->bts, CTR_TBF_UL_ALLOCATED);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200124
125 return tbf;
126}
127
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100128gprs_rlcmac_ul_tbf::gprs_rlcmac_ul_tbf(struct gprs_rlcmac_bts *bts_, GprsMs *ms) :
Pau Espin Pedrole9f77d32020-10-23 18:41:40 +0200129 gprs_rlcmac_tbf(bts_, ms, GPRS_RLCMAC_UL_TBF),
Pau Espin Pedrolbddf1ad2019-09-26 14:41:18 +0200130 m_rx_counter(0),
Pau Espin Pedrol94386132022-10-28 19:50:09 +0200131 m_contention_resolution_done(true),
Pau Espin Pedrolbddf1ad2019-09-26 14:41:18 +0200132 m_ul_gprs_ctrs(NULL),
133 m_ul_egprs_ctrs(NULL)
134{
Pau Espin Pedrol7bd92a32021-03-24 13:14:09 +0100135 memset(&m_usf, USF_INVALID, sizeof(m_usf));
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +0200136
Pau Espin Pedrol343c0ee2022-11-17 19:55:08 +0100137 memset(&state_fsm, 0, sizeof(state_fsm));
Pau Espin Pedrolcdc762a2022-12-12 19:58:37 +0100138 state_fsm.ul_tbf = this;
Pau Espin Pedrol343c0ee2022-11-17 19:55:08 +0100139 state_fi = osmo_fsm_inst_alloc(&tbf_ul_fsm, this, &state_fsm, LOGL_INFO, NULL);
140 OSMO_ASSERT(state_fi);
141
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +0200142 memset(&ul_ack_fsm, 0, sizeof(ul_ack_fsm));
143 ul_ack_fsm.tbf = this;
144 ul_ack_fsm.fi = osmo_fsm_inst_alloc(&tbf_ul_ack_fsm, this, &ul_ack_fsm, LOGL_INFO, NULL);
Pau Espin Pedrole0e42512023-04-19 18:30:01 +0200145
146 m_ul_egprs_ctrs = rate_ctr_group_alloc(this, &tbf_ul_egprs_ctrg_desc, m_ctrs->idx);
147 OSMO_ASSERT(m_ul_egprs_ctrs);
148 m_ul_gprs_ctrs = rate_ctr_group_alloc(this, &tbf_ul_gprs_ctrg_desc, m_ctrs->idx);
149 OSMO_ASSERT(m_ul_gprs_ctrs);
Pau Espin Pedrol759724c2023-04-19 18:36:40 +0200150
151 /* This has to be called in child constructor because enable_egprs()
152 * uses the window() virtual function which is dependent on subclass. */
153 if (ms_mode(m_ms) != GPRS)
154 enable_egprs();
Pau Espin Pedrolbddf1ad2019-09-26 14:41:18 +0200155}
156
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100157/*
158 * Store received block data in LLC message(s) and forward to SGSN
159 * if complete.
160 */
161int gprs_rlcmac_ul_tbf::assemble_forward_llc(const gprs_rlc_data *_data)
162{
163 const uint8_t *data = _data->block;
164 uint8_t len = _data->len;
Jacob Erlbeckf2ba4cb2016-01-07 18:59:28 +0100165 const struct gprs_rlc_data_block_info *rdbi = &_data->block_info;
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +0200166 enum CodingScheme cs = _data->cs_last;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100167
168 Decoding::RlcData frames[16], *frame;
169 int i, num_frames = 0;
170 uint32_t dummy_tlli;
171
Max0524e382018-01-19 18:22:25 +0100172 LOGPTBFUL(this, LOGL_DEBUG, "Assembling frames: (len=%d)\n", len);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100173
174 num_frames = Decoding::rlc_data_from_ul_data(
Alexander Couzensce936f32016-05-24 14:45:41 +0200175 rdbi, cs, data, &(frames[0]), ARRAY_SIZE(frames),
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100176 &dummy_tlli);
177
178 /* create LLC frames */
179 for (i = 0; i < num_frames; i++) {
180 frame = frames + i;
181
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530182 if (frame->length) {
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100183 bts_do_rate_ctr_add(bts, CTR_RLC_UL_PAYLOAD_BYTES, frame->length);
Alexander Couzens7fdbf892016-05-21 19:45:23 +0200184
Max0524e382018-01-19 18:22:25 +0100185 LOGPTBFUL(this, LOGL_DEBUG, "Frame %d "
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530186 "starts at offset %d, "
187 "length=%d, is_complete=%d\n",
188 i + 1, frame->offset, frame->length,
189 frame->is_complete);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100190
Pau Espin Pedrol4f8384b2022-03-31 19:36:12 +0200191 llc_append_frame(&m_llc, data + frame->offset, frame->length);
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100192 llc_consume(&m_llc, frame->length);
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530193 }
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100194
195 if (frame->is_complete) {
196 /* send frame to SGSN */
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100197 LOGPTBFUL(this, LOGL_DEBUG, "complete UL frame len=%d\n", llc_frame_length(&m_llc));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100198 snd_ul_ud();
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100199 bts_do_rate_ctr_add(bts, CTR_LLC_UL_BYTES, llc_frame_length(&m_llc));
Pau Espin Pedrol4f8384b2022-03-31 19:36:12 +0200200 llc_reset(&m_llc);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100201 }
202 }
203
204 return 0;
205}
206
Pau Espin Pedrolf38a47e2022-10-28 19:06:45 +0200207/* 3GPP TS 44.060 sec 7a.2.1 Contention Resolution */
Pau Espin Pedrol4b6f0bf2021-05-10 18:54:52 +0200208void gprs_rlcmac_ul_tbf::contention_resolution_start()
209{
210 /* 3GPP TS 44.018 sec 11.1.2 Timers on the network side: "This timer is
211 * started when a temporary block flow is allocated with an IMMEDIATE
212 * ASSIGNMENT or an IMMEDIATE PACKET ASSIGNMENT or an EC IMMEDIATE
213 * ASSIGNMENT TYPE 1 message during a packet access procedure. It is
214 * stopped when the mobile station has correctly seized the temporary
215 * block flow."
216 * In our code base, it means we want to do contention resolution
217 * timeout only for one-phase packet access, since two-phase is handled
218 * through SBA structs, which are freed by the PDCH UL Controller if the
219 * single allocated block is lost. */
Pau Espin Pedrol94386132022-10-28 19:50:09 +0200220 m_contention_resolution_done = false;
Pau Espin Pedrol4b6f0bf2021-05-10 18:54:52 +0200221 T_START(this, T3141, 3141, "Contention resolution (UL-TBF, CCCH)", true);
222}
223void gprs_rlcmac_ul_tbf::contention_resolution_success()
224{
Pau Espin Pedrolf38a47e2022-10-28 19:06:45 +0200225 /* now we must set this flag, so we are allowed to assign downlink
226 * TBF on PACCH. it is only allowed when TLLI is acknowledged
227 * (3GPP TS 44.060 sec 7.1.3.1). */
228 m_contention_resolution_done = true;
Pau Espin Pedrol4b6f0bf2021-05-10 18:54:52 +0200229
Pau Espin Pedrol4b6f0bf2021-05-10 18:54:52 +0200230 /* 3GPP TS 44.018 3.5.2.1.4 Packet access completion: The one phase
231 packet access procedure is completed at a successful contention
232 resolution. The mobile station has entered the packet transfer mode.
233 Timer T3141 is stopped on the network side */
234 t_stop(T3141, "Contention resolution success (UL-TBF, CCCH)");
235
Pau Espin Pedrolba568312021-11-02 18:47:44 +0100236 bts_do_rate_ctr_inc(bts, CTR_IMMEDIATE_ASSIGN_UL_TBF_CONTENTION_RESOLUTION_SUCCESS);
Pau Espin Pedrol01dfe042022-10-31 15:56:55 +0100237
238 /* Check if we can create a DL TBF to start sending the enqueued
239 * data. Otherwise it will be triggered later when it is reachable
240 * again. */
241 if (ms_need_dl_tbf(ms()) && !tbf_ul_ack_waiting_cnf_final_ack(this))
242 ms_new_dl_tbf_assigned_on_pacch(ms(), this);
Pau Espin Pedrol4b6f0bf2021-05-10 18:54:52 +0200243}
244
Alexander Couzens2fcfc292016-05-24 14:40:03 +0200245/*! \brief receive data from PDCH/L1 */
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100246int gprs_rlcmac_ul_tbf::rcv_data_block_acknowledged(
Jacob Erlbeckf2ba4cb2016-01-07 18:59:28 +0100247 const struct gprs_rlc_data_info *rlc,
Jacob Erlbeckfc1b3e62016-01-11 09:58:11 +0100248 uint8_t *data, struct pcu_l1_meas *meas)
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100249{
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200250 const struct gprs_rlc_data_block_info *rdbi;
251 struct gprs_rlc_data *block;
252
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100253 int8_t rssi = meas->have_rssi ? meas->rssi : 0;
254
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100255 const uint16_t ws = m_window.ws();
256
Max0524e382018-01-19 18:22:25 +0100257 LOGPTBFUL(this, LOGL_DEBUG, "UL DATA TFI=%d received (V(Q)=%d .. "
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100258 "V(R)=%d)\n", rlc->tfi, this->m_window.v_q(),
259 this->m_window.v_r());
260
261 /* process RSSI */
262 gprs_rlcmac_rssi(this, rssi);
263
264 /* store measurement values */
Pau Espin Pedrolf53815f2021-05-11 14:23:51 +0200265 ms_update_l1_meas(ms(), meas);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100266
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700267 uint32_t new_tlli = GSM_RESERVED_TMSI;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100268 unsigned int block_idx;
269
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100270 /* Increment RX-counter */
271 this->m_rx_counter++;
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530272 update_coding_scheme_counter_ul(rlc->cs);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100273 /* Loop over num_blocks */
274 for (block_idx = 0; block_idx < rlc->num_data_blocks; block_idx++) {
275 int num_chunks;
276 uint8_t *rlc_data;
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200277 rdbi = &rlc->block_info[block_idx];
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100278
Max0524e382018-01-19 18:22:25 +0100279 LOGPTBFUL(this, LOGL_DEBUG,
280 "Got %s RLC data block: CV=%d, BSN=%d, SPB=%d, PI=%d, E=%d, TI=%d, bitoffs=%d\n",
Max136ebcc2019-03-05 14:59:03 +0100281 mcs_name(rlc->cs),
Max0524e382018-01-19 18:22:25 +0100282 rdbi->cv, rdbi->bsn, rdbi->spb,
283 rdbi->pi, rdbi->e, rdbi->ti,
284 rlc->data_offs_bits[block_idx]);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100285
286 /* Check whether the block needs to be decoded */
287
288 if (!m_window.is_in_window(rdbi->bsn)) {
Max0524e382018-01-19 18:22:25 +0100289 LOGPTBFUL(this, LOGL_DEBUG, "BSN %d out of window %d..%d (it's normal)\n",
290 rdbi->bsn,
291 m_window.v_q(), m_window.mod_sns(m_window.v_q() + ws - 1));
Pau Espin Pedrol58916312021-05-11 14:40:41 +0200292 continue;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100293 } else if (m_window.is_received(rdbi->bsn)) {
Max0524e382018-01-19 18:22:25 +0100294 LOGPTBFUL(this, LOGL_DEBUG,
295 "BSN %d already received\n", rdbi->bsn);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100296 continue;
Pau Espin Pedrol58916312021-05-11 14:40:41 +0200297 }
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100298
299 /* Store block and meta info to BSN buffer */
300
Max0524e382018-01-19 18:22:25 +0100301 LOGPTBFUL(this, LOGL_DEBUG, "BSN %d storing in window (%d..%d)\n",
302 rdbi->bsn, m_window.v_q(),
303 m_window.mod_sns(m_window.v_q() + ws - 1));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100304 block = m_rlc.block(rdbi->bsn);
Aravind Sirsikar550a5412016-06-14 18:59:18 +0530305 OSMO_ASSERT(rdbi->data_len <= sizeof(block->block));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100306 rlc_data = &(block->block[0]);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100307
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530308 if (rdbi->spb) {
309 egprs_rlc_ul_reseg_bsn_state assemble_status;
310
311 assemble_status = handle_egprs_ul_spb(rlc,
312 block, data, block_idx);
313
314 if (assemble_status != EGPRS_RESEG_DEFAULT)
315 return 0;
316 } else {
317 block->block_info = *rdbi;
318 block->cs_last = rlc->cs;
319 block->len =
320 Decoding::rlc_copy_to_aligned_buffer(rlc,
321 block_idx, data, rlc_data);
322 }
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100323
Max0524e382018-01-19 18:22:25 +0100324 LOGPTBFUL(this, LOGL_DEBUG,
325 "data_length=%d, data=%s\n",
326 block->len, osmo_hexdump(rlc_data, block->len));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100327 /* Get/Handle TLLI */
328 if (rdbi->ti) {
329 num_chunks = Decoding::rlc_data_from_ul_data(
330 rdbi, rlc->cs, rlc_data, NULL, 0, &new_tlli);
331
332 if (num_chunks < 0) {
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100333 bts_do_rate_ctr_inc(bts, CTR_DECODE_ERRORS);
Max0524e382018-01-19 18:22:25 +0100334 LOGPTBFUL(this, LOGL_NOTICE,
335 "Failed to decode TLLI of %s UL DATA TFI=%d.\n",
Max136ebcc2019-03-05 14:59:03 +0100336 mcs_name(rlc->cs), rlc->tfi);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100337 m_window.invalidate_bsn(rdbi->bsn);
338 continue;
339 }
340 if (!this->is_tlli_valid()) {
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700341 if (new_tlli == GSM_RESERVED_TMSI) {
Max0524e382018-01-19 18:22:25 +0100342 LOGPTBFUL(this, LOGL_NOTICE,
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700343 "TLLI is 0x%08x within UL DATA?!?\n",
344 new_tlli);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100345 m_window.invalidate_bsn(rdbi->bsn);
346 continue;
347 }
Max0524e382018-01-19 18:22:25 +0100348 LOGPTBFUL(this, LOGL_INFO,
349 "Decoded premier TLLI=0x%08x of UL DATA TFI=%d.\n",
Vadim Yanitskiy3f27fb52020-04-20 11:26:12 +0700350 new_tlli, rlc->tfi);
Pau Espin Pedrol8abe13c2022-10-21 18:49:48 +0200351 ms_update_announced_tlli(ms(), new_tlli);
Pau Espin Pedrolf197f152022-11-17 20:18:46 +0100352 osmo_fsm_inst_dispatch(this->state_fi, TBF_EV_FIRST_UL_DATA_RECVD, NULL);
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700353 } else if (new_tlli != GSM_RESERVED_TMSI && new_tlli != tlli()) {
Max0524e382018-01-19 18:22:25 +0100354 LOGPTBFUL(this, LOGL_NOTICE,
Pau Espin Pedrol305763d2020-11-06 20:03:24 +0100355 "Decoded TLLI=%08x mismatch on UL DATA TFI=%d. (Ignoring due to contention resolution)\n",
356 new_tlli, rlc->tfi);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100357 m_window.invalidate_bsn(rdbi->bsn);
358 continue;
359 }
Pau Espin Pedrol58916312021-05-11 14:40:41 +0200360 } else if (!is_tlli_valid()) {
361 LOGPTBFUL(this, LOGL_NOTICE, "Missing TLLI within UL DATA.\n");
362 m_window.invalidate_bsn(rdbi->bsn);
363 continue;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100364 }
365
366 m_window.receive_bsn(rdbi->bsn);
367 }
368
369 /* Raise V(Q) if possible, and retrieve LLC frames from blocks.
370 * This is looped until there is a gap (non received block) or
371 * the window is empty.*/
372 const uint16_t v_q_beg = m_window.v_q();
373 const uint16_t count = m_window.raise_v_q();
374
375 /* Retrieve LLC frames from blocks that are ready */
376 for (uint16_t i = 0; i < count; ++i) {
Jacob Erlbeck93c55d02015-12-23 16:29:07 +0100377 uint16_t index = m_window.mod_sns(v_q_beg + i);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100378 assemble_forward_llc(m_rlc.block(index));
379 }
380
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200381 /* Last frame in buffer: */
382 block = m_rlc.block(m_window.mod_sns(m_window.v_r() - 1));
383 rdbi = &block->block_info;
384
385 /* Check if we already received all data TBF had to send: */
Pau Espin Pedroldc2aaac2021-05-14 12:50:46 +0200386 if (this->state_is(TBF_ST_FLOW) /* still in flow state */
Pau Espin Pedrol9b63cd02021-05-11 14:54:40 +0200387 && this->m_window.v_q() == this->m_window.v_r() /* if complete */
388 && block->len) { /* if there was ever a last block received */
Max0524e382018-01-19 18:22:25 +0100389 LOGPTBFUL(this, LOGL_DEBUG,
390 "No gaps in received block, last block: BSN=%d CV=%d\n",
391 rdbi->bsn, rdbi->cv);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100392 if (rdbi->cv == 0) {
Max0524e382018-01-19 18:22:25 +0100393 LOGPTBFUL(this, LOGL_DEBUG, "Finished with UL TBF\n");
Pau Espin Pedrolf197f152022-11-17 20:18:46 +0100394 osmo_fsm_inst_dispatch(this->state_fi, TBF_EV_LAST_UL_DATA_RECVD, NULL);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100395 /* Reset N3103 counter. */
Max847ed9f2018-02-20 18:16:11 +0100396 this->n_reset(N3103);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100397 }
398 }
399
400 /* If TLLI is included or if we received half of the window, we send
401 * an ack/nack */
Pau Espin Pedrol9b63cd02021-05-11 14:54:40 +0200402 maybe_schedule_uplink_acknack(rlc, block->len && rdbi->cv == 0);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100403
404 return 0;
405}
406
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100407void gprs_rlcmac_ul_tbf::maybe_schedule_uplink_acknack(
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200408 const gprs_rlc_data_info *rlc, bool countdown_finished)
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100409{
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200410 bool require_ack = false;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100411 bool have_ti = rlc->block_info[0].ti ||
412 (rlc->num_data_blocks > 1 && rlc->block_info[1].ti);
413
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200414 if (rlc->si) {
415 require_ack = true;
416 LOGPTBFUL(this, LOGL_NOTICE,
417 "Scheduling Ack/Nack, because MS is stalled.\n");
418 }
419 if (have_ti) {
420 require_ack = true;
421 LOGPTBFUL(this, LOGL_DEBUG,
422 "Scheduling Ack/Nack, because TLLI is included.\n");
423 }
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200424 if (countdown_finished) {
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200425 require_ack = true;
Pau Espin Pedroldc2aaac2021-05-14 12:50:46 +0200426 if (state_is(TBF_ST_FLOW))
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200427 LOGPTBFUL(this, LOGL_DEBUG,
428 "Scheduling Ack/Nack, because some data is missing and last block has CV==0.\n");
Pau Espin Pedroldc2aaac2021-05-14 12:50:46 +0200429 else if (state_is(TBF_ST_FINISHED))
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200430 LOGPTBFUL(this, LOGL_DEBUG,
431 "Scheduling final Ack/Nack, because all data was received and last block has CV==0.\n");
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200432 }
433 if ((m_rx_counter % SEND_ACK_AFTER_FRAMES) == 0) {
434 require_ack = true;
435 LOGPTBFUL(this, LOGL_DEBUG,
436 "Scheduling Ack/Nack, because %d frames received.\n",
437 SEND_ACK_AFTER_FRAMES);
438 }
439
440 if (!require_ack)
441 return;
442
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +0200443 osmo_fsm_inst_dispatch(this->ul_ack_fsm.fi, TBF_UL_ACK_EV_SCHED_ACK, NULL);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100444}
445
Daniel Willmannca102af2014-08-08 12:14:12 +0200446/* Send Uplink unit-data to SGSN. */
447int gprs_rlcmac_ul_tbf::snd_ul_ud()
448{
449 uint8_t qos_profile[3];
450 struct msgb *llc_pdu;
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100451 unsigned msg_len = NS_HDR_LEN + BSSGP_HDR_LEN + llc_frame_length(&m_llc);
Pau Espin Pedroldb5e3392021-01-21 18:02:40 +0100452 struct bssgp_bvc_ctx *bctx = bts->pcu->bssgp.bctx;
Daniel Willmannca102af2014-08-08 12:14:12 +0200453
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100454 LOGP(DBSSGP, LOGL_INFO, "LLC [PCU -> SGSN] %s len=%d\n", tbf_name(this), llc_frame_length(&m_llc));
Daniel Willmannca102af2014-08-08 12:14:12 +0200455 if (!bctx) {
456 LOGP(DBSSGP, LOGL_ERROR, "No bctx\n");
Pau Espin Pedrol4f8384b2022-03-31 19:36:12 +0200457 llc_reset_frame_space(&m_llc);
Daniel Willmannca102af2014-08-08 12:14:12 +0200458 return -EIO;
459 }
Pau Espin Pedrol488aa292019-09-25 17:48:35 +0200460
Daniel Willmannca102af2014-08-08 12:14:12 +0200461 llc_pdu = msgb_alloc_headroom(msg_len, msg_len,"llc_pdu");
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100462 uint8_t *buf = msgb_push(llc_pdu, TL16V_GROSS_LEN(sizeof(uint8_t)*llc_frame_length(&m_llc)));
463 tl16v_put(buf, BSSGP_IE_LLC_PDU, sizeof(uint8_t)*llc_frame_length(&m_llc), m_llc.frame);
Daniel Willmannca102af2014-08-08 12:14:12 +0200464 qos_profile[0] = QOS_PROFILE >> 16;
465 qos_profile[1] = QOS_PROFILE >> 8;
466 qos_profile[2] = QOS_PROFILE;
467 bssgp_tx_ul_ud(bctx, tlli(), qos_profile, llc_pdu);
468
Pau Espin Pedrol4f8384b2022-03-31 19:36:12 +0200469 llc_reset_frame_space(&m_llc);
Daniel Willmannca102af2014-08-08 12:14:12 +0200470 return 0;
471}
472
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530473egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_second_seg(
474 const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block,
475 uint8_t *data, const uint8_t block_idx)
476{
477 const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx];
478 union split_block_status *spb_status = &block->spb_status;
479 uint8_t *rlc_data = &block->block[0];
480
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100481 bts_do_rate_ctr_inc(bts, CTR_SPB_UL_SECOND_SEGMENT);
sivasankarida7250a2016-12-16 12:57:18 +0530482
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530483 if (spb_status->block_status_ul &
484 EGPRS_RESEG_FIRST_SEG_RXD) {
Max0524e382018-01-19 18:22:25 +0100485 LOGPTBFUL(this, LOGL_DEBUG,
486 "Second seg is received first seg is already present set the status to complete\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530487 spb_status->block_status_ul = EGPRS_RESEG_DEFAULT;
488
489 block->len += Decoding::rlc_copy_to_aligned_buffer(rlc,
490 block_idx, data, rlc_data + block->len);
491 block->block_info.data_len += rdbi->data_len;
492 } else if (spb_status->block_status_ul == EGPRS_RESEG_DEFAULT) {
Max0524e382018-01-19 18:22:25 +0100493 LOGPTBFUL(this, LOGL_DEBUG,
494 "Second seg is received first seg is not received set the status to second seg received\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530495
496 block->len = Decoding::rlc_copy_to_aligned_buffer(rlc,
497 block_idx, data,
498 rlc_data + rlc->block_info[block_idx].data_len);
499
500 spb_status->block_status_ul = EGPRS_RESEG_SECOND_SEG_RXD;
501 block->block_info = *rdbi;
502 }
503 return spb_status->block_status_ul;
504}
505
506egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_first_seg(
507 const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block,
508 uint8_t *data, const uint8_t block_idx)
509{
510 const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx];
511 uint8_t *rlc_data = &block->block[0];
512 union split_block_status *spb_status = &block->spb_status;
513
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100514 bts_do_rate_ctr_inc(bts, CTR_SPB_UL_FIRST_SEGMENT);
sivasankarida7250a2016-12-16 12:57:18 +0530515
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530516 if (spb_status->block_status_ul & EGPRS_RESEG_SECOND_SEG_RXD) {
Max0524e382018-01-19 18:22:25 +0100517 LOGPTBFUL(this, LOGL_DEBUG,
518 "First seg is received second seg is already present set the status to complete\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530519
520 block->len += Decoding::rlc_copy_to_aligned_buffer(rlc,
521 block_idx, data, rlc_data);
522
523 block->block_info.data_len = block->len;
524 spb_status->block_status_ul = EGPRS_RESEG_DEFAULT;
525 } else if (spb_status->block_status_ul == EGPRS_RESEG_DEFAULT) {
Max0524e382018-01-19 18:22:25 +0100526 LOGPTBFUL(this, LOGL_DEBUG,
527 "First seg is received second seg is not received set the status to first seg received\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530528
529 spb_status->block_status_ul = EGPRS_RESEG_FIRST_SEG_RXD;
530 block->len = Decoding::rlc_copy_to_aligned_buffer(rlc,
531 block_idx, data, rlc_data);
532 block->block_info = *rdbi;
533 }
534 return spb_status->block_status_ul;
535}
536
537egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_spb(
538 const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block,
539 uint8_t *data, const uint8_t block_idx)
540{
541 const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx];
542
Max0524e382018-01-19 18:22:25 +0100543 LOGPTBFUL(this, LOGL_DEBUG,
544 "Got SPB(%d) cs(%s) data block with BSN (%d), TFI(%d).\n",
Max136ebcc2019-03-05 14:59:03 +0100545 rdbi->spb, mcs_name(rlc->cs), rdbi->bsn, rlc->tfi);
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530546
547 egprs_rlc_ul_reseg_bsn_state assemble_status = EGPRS_RESEG_INVALID;
548
549 /* Section 10.4.8b of 44.060*/
550 if (rdbi->spb == 2)
551 assemble_status = handle_egprs_ul_first_seg(rlc,
552 block, data, block_idx);
553 else if (rdbi->spb == 3)
554 assemble_status = handle_egprs_ul_second_seg(rlc,
555 block, data, block_idx);
556 else {
Max0524e382018-01-19 18:22:25 +0100557 LOGPTBFUL(this, LOGL_ERROR,
558 "spb(%d) Not supported SPB for this EGPRS configuration\n",
559 rdbi->spb);
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530560 }
561
562 /*
563 * When the block is successfully constructed out of segmented blocks
564 * upgrade the MCS to the type 2
565 */
566 if (assemble_status == EGPRS_RESEG_DEFAULT) {
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +0200567 switch (rlc->cs) {
Maxbea2edb2019-03-06 17:04:59 +0100568 case MCS3 :
569 block->cs_last = MCS6;
Max0524e382018-01-19 18:22:25 +0100570 LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS6\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530571 break;
Maxbea2edb2019-03-06 17:04:59 +0100572 case MCS2 :
573 block->cs_last = MCS5;
Max0524e382018-01-19 18:22:25 +0100574 LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS5\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530575 break;
Maxbea2edb2019-03-06 17:04:59 +0100576 case MCS1 :
Max0524e382018-01-19 18:22:25 +0100577 LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS4\n");
Maxbea2edb2019-03-06 17:04:59 +0100578 block->cs_last = MCS4;
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530579 break;
580 default:
Max0524e382018-01-19 18:22:25 +0100581 LOGPTBFUL(this, LOGL_ERROR,
582 "cs(%s) Error in Upgrading to higher MCS\n",
Max136ebcc2019-03-05 14:59:03 +0100583 mcs_name(rlc->cs));
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530584 break;
585 }
586 }
587 return assemble_status;
588}
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530589
Maxfb59a932019-03-13 18:40:19 +0100590void gprs_rlcmac_ul_tbf::update_coding_scheme_counter_ul(enum CodingScheme cs)
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530591{
Maxfb59a932019-03-13 18:40:19 +0100592 switch (cs) {
593 case CS1:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100594 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS1);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200595 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_gprs_ctrs, TBF_CTR_GPRS_UL_CS1));
Maxfb59a932019-03-13 18:40:19 +0100596 break;
597 case CS2:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100598 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS2);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200599 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_gprs_ctrs, TBF_CTR_GPRS_UL_CS2));
Maxfb59a932019-03-13 18:40:19 +0100600 break;
601 case CS3:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100602 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS3);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200603 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_gprs_ctrs, TBF_CTR_GPRS_UL_CS3));
Maxfb59a932019-03-13 18:40:19 +0100604 break;
605 case CS4:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100606 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS4);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200607 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_gprs_ctrs, TBF_CTR_GPRS_UL_CS4));
Maxfb59a932019-03-13 18:40:19 +0100608 break;
609 case MCS1:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100610 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS1);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200611 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS1));
Maxfb59a932019-03-13 18:40:19 +0100612 break;
613 case MCS2:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100614 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS2);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200615 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS2));
Maxfb59a932019-03-13 18:40:19 +0100616 break;
617 case MCS3:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100618 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS3);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200619 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS3));
Maxfb59a932019-03-13 18:40:19 +0100620 break;
621 case MCS4:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100622 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS4);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200623 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS4));
Maxfb59a932019-03-13 18:40:19 +0100624 break;
625 case MCS5:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100626 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS5);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200627 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS5));
Maxfb59a932019-03-13 18:40:19 +0100628 break;
629 case MCS6:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100630 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS6);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200631 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS6));
Maxfb59a932019-03-13 18:40:19 +0100632 break;
633 case MCS7:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100634 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS7);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200635 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS7));
Maxfb59a932019-03-13 18:40:19 +0100636 break;
637 case MCS8:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100638 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS8);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200639 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS8));
Maxfb59a932019-03-13 18:40:19 +0100640 break;
641 case MCS9:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100642 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS9);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200643 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS9));
Maxfb59a932019-03-13 18:40:19 +0100644 break;
645 default:
646 LOGPTBFUL(this, LOGL_ERROR, "attempting to update rate counters for unsupported (M)CS %s\n",
647 mcs_name(cs));
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530648 }
649}
sivasankari8adfcd02017-01-16 15:41:21 +0530650
Max9d7357e2017-12-14 15:02:33 +0100651void gprs_rlcmac_ul_tbf::set_window_size()
sivasankari8adfcd02017-01-16 15:41:21 +0530652{
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100653 const struct gprs_rlcmac_bts *b = bts;
Max34513fe2018-12-11 16:47:30 +0100654 uint16_t ws = egprs_window_size(b, ul_slots());
Max0524e382018-01-19 18:22:25 +0100655 LOGPTBFUL(this, LOGL_INFO, "setting EGPRS UL window size to %u, base(%u) slots(%u) ws_pdch(%u)\n",
Pau Espin Pedrol519d0712021-01-14 14:30:03 +0100656 ws, bts->pcu->vty.ws_base, pcu_bitcount(ul_slots()), bts->pcu->vty.ws_pdch);
sivasankari8adfcd02017-01-16 15:41:21 +0530657 m_window.set_ws(ws);
658}
Pau Espin Pedrol9767e442020-10-23 21:11:41 +0200659
Pau Espin Pedrolb3f23972020-10-23 21:00:23 +0200660gprs_rlc_window *gprs_rlcmac_ul_tbf::window()
Pau Espin Pedrol9767e442020-10-23 21:11:41 +0200661{
662 return &m_window;
663}
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100664
Pau Espin Pedrold6c555e2023-04-20 20:10:53 +0200665void gprs_rlcmac_ul_tbf::apply_allocated_resources(const struct alloc_resources_res *res)
666{
667 uint8_t ts;
668
Pau Espin Pedrol4d363912023-04-21 19:32:16 +0200669 if (this->trx)
670 llist_del(&this->m_trx_list.list);
671
672 llist_add(&this->m_trx_list.list, &res->trx->ul_tbfs);
673
Pau Espin Pedrold6c555e2023-04-20 20:10:53 +0200674 this->trx = res->trx;
675 this->upgrade_to_multislot = res->upgrade_to_multislot;
676
677 for (ts = 0; ts < ARRAY_SIZE(trx->pdch); ts++) {
678 struct gprs_rlcmac_pdch *pdch = &trx->pdch[ts];
679 OSMO_ASSERT(!this->pdch[pdch->ts_no]);
680 if (!(res->ass_slots_mask & (1 << ts)))
681 continue;
682 LOGPTBFUL(this, LOGL_DEBUG, "Assigning TS=%u TFI=%d USF=%u\n",
683 ts, res->tfi, res->usf[ts]);
684 OSMO_ASSERT(res->usf[ts] >= 0);
685
686 this->m_tfi = res->tfi;
687 this->m_usf[pdch->ts_no] = res->usf[ts];
688
689 this->pdch[pdch->ts_no] = pdch;
690 pdch->attach_tbf(this);
691 }
Pau Espin Pedrol4d363912023-04-21 19:32:16 +0200692
693 /* assign initial control ts */
694 tbf_assign_control_ts(this);
695
696 /* res.ass_slots_mask == 0 -> special case for Rejected UL TBFs,
697 * see ms_new_ul_tbf_rejected_pacch() */
698 if (res->ass_slots_mask != 0) {
699 LOGPTBF(this, LOGL_INFO,
700 "Allocated: trx = %d, ul_slots = %02x, dl_slots = %02x\n",
701 this->trx->trx_no, ul_slots(), dl_slots());
702
703 if (tbf_is_egprs_enabled(this))
704 this->set_window_size();
705 }
706
707 tbf_update_state_fsm_name(this);
708}
709
710void ul_tbf_apply_allocated_resources(struct gprs_rlcmac_ul_tbf *ul_tbf, const struct alloc_resources_res *res)
711{
712 ul_tbf->apply_allocated_resources(res);
Pau Espin Pedrold6c555e2023-04-20 20:10:53 +0200713}
714
Pau Espin Pedrol0b998b12021-03-24 14:45:43 +0100715void gprs_rlcmac_ul_tbf::usf_timeout()
716{
Pau Espin Pedrolcfb61d92021-07-26 17:17:02 +0200717 if (n_inc(N3101))
Pau Espin Pedrolf197f152022-11-17 20:18:46 +0100718 osmo_fsm_inst_dispatch(this->state_fi, TBF_EV_MAX_N3101, NULL);
Pau Espin Pedrol0b998b12021-03-24 14:45:43 +0100719}
720
Pau Espin Pedrolcc30b052022-10-27 15:25:55 +0200721struct gprs_rlcmac_ul_tbf *tbf_as_ul_tbf(struct gprs_rlcmac_tbf *tbf)
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100722{
723 if (tbf && tbf->direction == GPRS_RLCMAC_UL_TBF)
724 return static_cast<gprs_rlcmac_ul_tbf *>(tbf);
725 else
726 return NULL;
727}
Pau Espin Pedrol0b998b12021-03-24 14:45:43 +0100728
Pau Espin Pedrol1e1275f2022-11-17 20:57:34 +0100729const struct gprs_rlcmac_ul_tbf *tbf_as_ul_tbf_const(const struct gprs_rlcmac_tbf *tbf)
730{
731 if (tbf && tbf->direction == GPRS_RLCMAC_UL_TBF)
732 return static_cast<const gprs_rlcmac_ul_tbf *>(tbf);
733 else
734 return NULL;
735}
736
Pau Espin Pedrol0b998b12021-03-24 14:45:43 +0100737void tbf_usf_timeout(struct gprs_rlcmac_ul_tbf *tbf)
738{
739 tbf->usf_timeout();
740}
Pau Espin Pedrol49a2f402021-07-27 17:33:07 +0200741
742
743bool ul_tbf_contention_resolution_done(const struct gprs_rlcmac_ul_tbf *tbf)
744{
745 return tbf->m_contention_resolution_done;
746}
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +0200747
748struct osmo_fsm_inst *tbf_ul_ack_fi(const struct gprs_rlcmac_ul_tbf *tbf)
749{
750 return tbf->ul_ack_fsm.fi;
751}
752
Pau Espin Pedrol94386132022-10-28 19:50:09 +0200753void ul_tbf_contention_resolution_start(struct gprs_rlcmac_ul_tbf *tbf)
754{
755 tbf->contention_resolution_start();
756}
757
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +0200758void ul_tbf_contention_resolution_success(struct gprs_rlcmac_ul_tbf *tbf)
759{
760 return tbf->contention_resolution_success();
761}