blob: a6c4ee37c771660f57b3c44c2539fa6df4b74a46 [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"
32
Daniel Willmannca102af2014-08-08 12:14:12 +020033extern "C" {
34#include <osmocom/core/msgb.h>
35#include <osmocom/core/talloc.h>
Max1187a772018-01-26 13:31:42 +010036 #include <osmocom/core/bitvec.h>
37 #include <osmocom/core/logging.h>
38 #include <osmocom/core/rate_ctr.h>
Pau Espin Pedrol442198c2020-10-23 22:30:04 +020039 #include <osmocom/core/stats.h>
Max1187a772018-01-26 13:31:42 +010040 #include <osmocom/core/utils.h>
41 #include <osmocom/gprs/gprs_bssgp_bss.h>
42 #include <osmocom/gprs/protocol/gsm_08_18.h>
43 #include <osmocom/gsm/tlv.h>
Max136ebcc2019-03-05 14:59:03 +010044 #include "coding_scheme.h"
Daniel Willmannca102af2014-08-08 12:14:12 +020045}
46
47#include <errno.h>
48#include <string.h>
49
50/* After receiving these frames, we send ack/nack. */
51#define SEND_ACK_AFTER_FRAMES 20
52
53extern void *tall_pcu_ctx;
54
Pau Espin Pedrol442198c2020-10-23 22:30:04 +020055static const struct rate_ctr_desc tbf_ul_gprs_ctr_description[] = {
56 { "gprs:uplink:cs1", "CS1 " },
57 { "gprs:uplink:cs2", "CS2 " },
58 { "gprs:uplink:cs3", "CS3 " },
59 { "gprs:uplink:cs4", "CS4 " },
60};
61
62static const struct rate_ctr_desc tbf_ul_egprs_ctr_description[] = {
63 { "egprs:uplink:mcs1", "MCS1 " },
64 { "egprs:uplink:mcs2", "MCS2 " },
65 { "egprs:uplink:mcs3", "MCS3 " },
66 { "egprs:uplink:mcs4", "MCS4 " },
67 { "egprs:uplink:mcs5", "MCS5 " },
68 { "egprs:uplink:mcs6", "MCS6 " },
69 { "egprs:uplink:mcs7", "MCS7 " },
70 { "egprs:uplink:mcs8", "MCS8 " },
71 { "egprs:uplink:mcs9", "MCS9 " },
72};
73
74static const struct rate_ctr_group_desc tbf_ul_gprs_ctrg_desc = {
75 "tbf:gprs",
76 "Data Blocks",
77 OSMO_STATS_CLASS_SUBSCRIBER,
78 ARRAY_SIZE(tbf_ul_gprs_ctr_description),
79 tbf_ul_gprs_ctr_description,
80};
81
82static const struct rate_ctr_group_desc tbf_ul_egprs_ctrg_desc = {
83 "tbf:egprs",
84 "Data Blocks",
85 OSMO_STATS_CLASS_SUBSCRIBER,
86 ARRAY_SIZE(tbf_ul_egprs_ctr_description),
87 tbf_ul_egprs_ctr_description,
88};
89
Pau Espin Pedrol131deb02021-07-26 18:24:14 +020090gprs_rlcmac_ul_tbf::~gprs_rlcmac_ul_tbf()
91{
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +020092 osmo_fsm_inst_free(ul_ack_fsm.fi);
93 ul_ack_fsm.fi = NULL;
94
Pau Espin Pedrol131deb02021-07-26 18:24:14 +020095 rate_ctr_group_free(m_ul_egprs_ctrs);
96 rate_ctr_group_free(m_ul_gprs_ctrs);
97 /* ~gprs_rlcmac_tbf() is called automatically upon return */
98}
99
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200100static int ul_tbf_dtor(struct gprs_rlcmac_ul_tbf *tbf)
101{
102 tbf->~gprs_rlcmac_ul_tbf();
103 return 0;
104}
105
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200106/* Generic function to alloc a UL TBF, later configured to be assigned either over CCCH or PACCH */
Pau Espin Pedrolbda7bb72022-10-31 14:33:09 +0100107struct gprs_rlcmac_ul_tbf *ul_tbf_alloc(struct gprs_rlcmac_bts *bts, struct GprsMs *ms, int8_t use_trx, bool single_slot)
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200108{
109 struct gprs_rlcmac_ul_tbf *tbf;
110 int rc;
111
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
123 rc = tbf->setup(use_trx, single_slot);
124
125 /* if no resource */
126 if (rc < 0) {
127 talloc_free(tbf);
128 return NULL;
129 }
130
131 if (tbf->is_egprs_enabled())
132 tbf->set_window_size();
133
Pau Espin Pedrol1a1557a2021-05-13 18:39:36 +0200134 llist_add_tail(tbf_trx_list(tbf), &tbf->trx->ul_tbfs);
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100135 bts_do_rate_ctr_inc(tbf->bts, CTR_TBF_UL_ALLOCATED);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200136
137 return tbf;
138}
139
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200140/* Create a temporary dummy TBF to Tx a ImmAssReject if allocating a new one during
141 * packet resource Request failed. This is similar as tbf_alloc_ul() but without
142 * calling tbf->setup() (in charge of TFI/USF allocation), and reusing resources
143 * from Packet Resource Request we received. See TS 44.060 sec 7.1.3.2.1 */
Pau Espin Pedrola621d592022-12-13 17:35:04 +0100144struct gprs_rlcmac_ul_tbf *ul_tbf_alloc_rejected(struct gprs_rlcmac_bts *bts, struct GprsMs *ms,
145 struct gprs_rlcmac_pdch *pdch)
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200146{
147 struct gprs_rlcmac_ul_tbf *ul_tbf = NULL;
Pau Espin Pedrola621d592022-12-13 17:35:04 +0100148 struct gprs_rlcmac_trx *trx = pdch->trx;
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200149 OSMO_ASSERT(ms);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200150
151 ul_tbf = talloc(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
152 if (!ul_tbf)
153 return ul_tbf;
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200154 talloc_set_destructor(ul_tbf, ul_tbf_dtor);
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100155 new (ul_tbf) gprs_rlcmac_ul_tbf(bts, ms);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200156
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200157 ul_tbf->trx = trx;
Pau Espin Pedrol06329682021-11-08 12:42:06 +0100158 /* The only one TS is the common, control TS */
Pau Espin Pedrol9935d0d2022-12-13 18:29:25 +0100159 ms_set_first_common_ts(ms, pdch);
Pau Espin Pedrol06329682021-11-08 12:42:06 +0100160 tbf_assign_control_ts(ul_tbf);
Pau Espin Pedroldbd3b782021-11-08 13:21:39 +0100161 tbf_update_state_fsm_name(ul_tbf);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200162
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200163 ms_attach_tbf(ms, ul_tbf);
Pau Espin Pedrola621d592022-12-13 17:35:04 +0100164 llist_add(tbf_trx_list(ul_tbf), &trx->ul_tbfs);
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200165 bts_do_rate_ctr_inc(ul_tbf->bts, CTR_TBF_UL_ALLOCATED);
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200166
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200167 return ul_tbf;
168}
169
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100170gprs_rlcmac_ul_tbf::gprs_rlcmac_ul_tbf(struct gprs_rlcmac_bts *bts_, GprsMs *ms) :
Pau Espin Pedrole9f77d32020-10-23 18:41:40 +0200171 gprs_rlcmac_tbf(bts_, ms, GPRS_RLCMAC_UL_TBF),
Pau Espin Pedrolbddf1ad2019-09-26 14:41:18 +0200172 m_rx_counter(0),
Pau Espin Pedrol94386132022-10-28 19:50:09 +0200173 m_contention_resolution_done(true),
Pau Espin Pedrolbddf1ad2019-09-26 14:41:18 +0200174 m_ul_gprs_ctrs(NULL),
175 m_ul_egprs_ctrs(NULL)
176{
Pau Espin Pedrol7bd92a32021-03-24 13:14:09 +0100177 memset(&m_usf, USF_INVALID, sizeof(m_usf));
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +0200178
Pau Espin Pedrol343c0ee2022-11-17 19:55:08 +0100179 memset(&state_fsm, 0, sizeof(state_fsm));
Pau Espin Pedrolcdc762a2022-12-12 19:58:37 +0100180 state_fsm.ul_tbf = this;
Pau Espin Pedrol343c0ee2022-11-17 19:55:08 +0100181 state_fi = osmo_fsm_inst_alloc(&tbf_ul_fsm, this, &state_fsm, LOGL_INFO, NULL);
182 OSMO_ASSERT(state_fi);
183
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +0200184 memset(&ul_ack_fsm, 0, sizeof(ul_ack_fsm));
185 ul_ack_fsm.tbf = this;
186 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 +0200187
188 m_ul_egprs_ctrs = rate_ctr_group_alloc(this, &tbf_ul_egprs_ctrg_desc, m_ctrs->idx);
189 OSMO_ASSERT(m_ul_egprs_ctrs);
190 m_ul_gprs_ctrs = rate_ctr_group_alloc(this, &tbf_ul_gprs_ctrg_desc, m_ctrs->idx);
191 OSMO_ASSERT(m_ul_gprs_ctrs);
Pau Espin Pedrolbddf1ad2019-09-26 14:41:18 +0200192}
193
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100194/*
195 * Store received block data in LLC message(s) and forward to SGSN
196 * if complete.
197 */
198int gprs_rlcmac_ul_tbf::assemble_forward_llc(const gprs_rlc_data *_data)
199{
200 const uint8_t *data = _data->block;
201 uint8_t len = _data->len;
Jacob Erlbeckf2ba4cb2016-01-07 18:59:28 +0100202 const struct gprs_rlc_data_block_info *rdbi = &_data->block_info;
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +0200203 enum CodingScheme cs = _data->cs_last;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100204
205 Decoding::RlcData frames[16], *frame;
206 int i, num_frames = 0;
207 uint32_t dummy_tlli;
208
Max0524e382018-01-19 18:22:25 +0100209 LOGPTBFUL(this, LOGL_DEBUG, "Assembling frames: (len=%d)\n", len);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100210
211 num_frames = Decoding::rlc_data_from_ul_data(
Alexander Couzensce936f32016-05-24 14:45:41 +0200212 rdbi, cs, data, &(frames[0]), ARRAY_SIZE(frames),
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100213 &dummy_tlli);
214
215 /* create LLC frames */
216 for (i = 0; i < num_frames; i++) {
217 frame = frames + i;
218
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530219 if (frame->length) {
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100220 bts_do_rate_ctr_add(bts, CTR_RLC_UL_PAYLOAD_BYTES, frame->length);
Alexander Couzens7fdbf892016-05-21 19:45:23 +0200221
Max0524e382018-01-19 18:22:25 +0100222 LOGPTBFUL(this, LOGL_DEBUG, "Frame %d "
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530223 "starts at offset %d, "
224 "length=%d, is_complete=%d\n",
225 i + 1, frame->offset, frame->length,
226 frame->is_complete);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100227
Pau Espin Pedrol4f8384b2022-03-31 19:36:12 +0200228 llc_append_frame(&m_llc, data + frame->offset, frame->length);
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100229 llc_consume(&m_llc, frame->length);
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530230 }
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100231
232 if (frame->is_complete) {
233 /* send frame to SGSN */
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100234 LOGPTBFUL(this, LOGL_DEBUG, "complete UL frame len=%d\n", llc_frame_length(&m_llc));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100235 snd_ul_ud();
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100236 bts_do_rate_ctr_add(bts, CTR_LLC_UL_BYTES, llc_frame_length(&m_llc));
Pau Espin Pedrol4f8384b2022-03-31 19:36:12 +0200237 llc_reset(&m_llc);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100238 }
239 }
240
241 return 0;
242}
243
Pau Espin Pedrolf38a47e2022-10-28 19:06:45 +0200244/* 3GPP TS 44.060 sec 7a.2.1 Contention Resolution */
Pau Espin Pedrol4b6f0bf2021-05-10 18:54:52 +0200245void gprs_rlcmac_ul_tbf::contention_resolution_start()
246{
247 /* 3GPP TS 44.018 sec 11.1.2 Timers on the network side: "This timer is
248 * started when a temporary block flow is allocated with an IMMEDIATE
249 * ASSIGNMENT or an IMMEDIATE PACKET ASSIGNMENT or an EC IMMEDIATE
250 * ASSIGNMENT TYPE 1 message during a packet access procedure. It is
251 * stopped when the mobile station has correctly seized the temporary
252 * block flow."
253 * In our code base, it means we want to do contention resolution
254 * timeout only for one-phase packet access, since two-phase is handled
255 * through SBA structs, which are freed by the PDCH UL Controller if the
256 * single allocated block is lost. */
Pau Espin Pedrol94386132022-10-28 19:50:09 +0200257 m_contention_resolution_done = false;
Pau Espin Pedrol4b6f0bf2021-05-10 18:54:52 +0200258 T_START(this, T3141, 3141, "Contention resolution (UL-TBF, CCCH)", true);
259}
260void gprs_rlcmac_ul_tbf::contention_resolution_success()
261{
Pau Espin Pedrolf38a47e2022-10-28 19:06:45 +0200262 /* now we must set this flag, so we are allowed to assign downlink
263 * TBF on PACCH. it is only allowed when TLLI is acknowledged
264 * (3GPP TS 44.060 sec 7.1.3.1). */
265 m_contention_resolution_done = true;
Pau Espin Pedrol4b6f0bf2021-05-10 18:54:52 +0200266
Pau Espin Pedrol4b6f0bf2021-05-10 18:54:52 +0200267 /* 3GPP TS 44.018 3.5.2.1.4 Packet access completion: The one phase
268 packet access procedure is completed at a successful contention
269 resolution. The mobile station has entered the packet transfer mode.
270 Timer T3141 is stopped on the network side */
271 t_stop(T3141, "Contention resolution success (UL-TBF, CCCH)");
272
Pau Espin Pedrolba568312021-11-02 18:47:44 +0100273 bts_do_rate_ctr_inc(bts, CTR_IMMEDIATE_ASSIGN_UL_TBF_CONTENTION_RESOLUTION_SUCCESS);
Pau Espin Pedrol01dfe042022-10-31 15:56:55 +0100274
275 /* Check if we can create a DL TBF to start sending the enqueued
276 * data. Otherwise it will be triggered later when it is reachable
277 * again. */
278 if (ms_need_dl_tbf(ms()) && !tbf_ul_ack_waiting_cnf_final_ack(this))
279 ms_new_dl_tbf_assigned_on_pacch(ms(), this);
Pau Espin Pedrol4b6f0bf2021-05-10 18:54:52 +0200280}
281
Alexander Couzens2fcfc292016-05-24 14:40:03 +0200282/*! \brief receive data from PDCH/L1 */
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100283int gprs_rlcmac_ul_tbf::rcv_data_block_acknowledged(
Jacob Erlbeckf2ba4cb2016-01-07 18:59:28 +0100284 const struct gprs_rlc_data_info *rlc,
Jacob Erlbeckfc1b3e62016-01-11 09:58:11 +0100285 uint8_t *data, struct pcu_l1_meas *meas)
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100286{
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200287 const struct gprs_rlc_data_block_info *rdbi;
288 struct gprs_rlc_data *block;
289
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100290 int8_t rssi = meas->have_rssi ? meas->rssi : 0;
291
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100292 const uint16_t ws = m_window.ws();
293
Max0524e382018-01-19 18:22:25 +0100294 LOGPTBFUL(this, LOGL_DEBUG, "UL DATA TFI=%d received (V(Q)=%d .. "
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100295 "V(R)=%d)\n", rlc->tfi, this->m_window.v_q(),
296 this->m_window.v_r());
297
298 /* process RSSI */
299 gprs_rlcmac_rssi(this, rssi);
300
301 /* store measurement values */
Pau Espin Pedrolf53815f2021-05-11 14:23:51 +0200302 ms_update_l1_meas(ms(), meas);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100303
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700304 uint32_t new_tlli = GSM_RESERVED_TMSI;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100305 unsigned int block_idx;
306
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100307 /* Increment RX-counter */
308 this->m_rx_counter++;
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530309 update_coding_scheme_counter_ul(rlc->cs);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100310 /* Loop over num_blocks */
311 for (block_idx = 0; block_idx < rlc->num_data_blocks; block_idx++) {
312 int num_chunks;
313 uint8_t *rlc_data;
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200314 rdbi = &rlc->block_info[block_idx];
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100315
Max0524e382018-01-19 18:22:25 +0100316 LOGPTBFUL(this, LOGL_DEBUG,
317 "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 +0100318 mcs_name(rlc->cs),
Max0524e382018-01-19 18:22:25 +0100319 rdbi->cv, rdbi->bsn, rdbi->spb,
320 rdbi->pi, rdbi->e, rdbi->ti,
321 rlc->data_offs_bits[block_idx]);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100322
323 /* Check whether the block needs to be decoded */
324
325 if (!m_window.is_in_window(rdbi->bsn)) {
Max0524e382018-01-19 18:22:25 +0100326 LOGPTBFUL(this, LOGL_DEBUG, "BSN %d out of window %d..%d (it's normal)\n",
327 rdbi->bsn,
328 m_window.v_q(), m_window.mod_sns(m_window.v_q() + ws - 1));
Pau Espin Pedrol58916312021-05-11 14:40:41 +0200329 continue;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100330 } else if (m_window.is_received(rdbi->bsn)) {
Max0524e382018-01-19 18:22:25 +0100331 LOGPTBFUL(this, LOGL_DEBUG,
332 "BSN %d already received\n", rdbi->bsn);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100333 continue;
Pau Espin Pedrol58916312021-05-11 14:40:41 +0200334 }
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100335
336 /* Store block and meta info to BSN buffer */
337
Max0524e382018-01-19 18:22:25 +0100338 LOGPTBFUL(this, LOGL_DEBUG, "BSN %d storing in window (%d..%d)\n",
339 rdbi->bsn, m_window.v_q(),
340 m_window.mod_sns(m_window.v_q() + ws - 1));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100341 block = m_rlc.block(rdbi->bsn);
Aravind Sirsikar550a5412016-06-14 18:59:18 +0530342 OSMO_ASSERT(rdbi->data_len <= sizeof(block->block));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100343 rlc_data = &(block->block[0]);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100344
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530345 if (rdbi->spb) {
346 egprs_rlc_ul_reseg_bsn_state assemble_status;
347
348 assemble_status = handle_egprs_ul_spb(rlc,
349 block, data, block_idx);
350
351 if (assemble_status != EGPRS_RESEG_DEFAULT)
352 return 0;
353 } else {
354 block->block_info = *rdbi;
355 block->cs_last = rlc->cs;
356 block->len =
357 Decoding::rlc_copy_to_aligned_buffer(rlc,
358 block_idx, data, rlc_data);
359 }
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100360
Max0524e382018-01-19 18:22:25 +0100361 LOGPTBFUL(this, LOGL_DEBUG,
362 "data_length=%d, data=%s\n",
363 block->len, osmo_hexdump(rlc_data, block->len));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100364 /* Get/Handle TLLI */
365 if (rdbi->ti) {
366 num_chunks = Decoding::rlc_data_from_ul_data(
367 rdbi, rlc->cs, rlc_data, NULL, 0, &new_tlli);
368
369 if (num_chunks < 0) {
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100370 bts_do_rate_ctr_inc(bts, CTR_DECODE_ERRORS);
Max0524e382018-01-19 18:22:25 +0100371 LOGPTBFUL(this, LOGL_NOTICE,
372 "Failed to decode TLLI of %s UL DATA TFI=%d.\n",
Max136ebcc2019-03-05 14:59:03 +0100373 mcs_name(rlc->cs), rlc->tfi);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100374 m_window.invalidate_bsn(rdbi->bsn);
375 continue;
376 }
377 if (!this->is_tlli_valid()) {
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700378 if (new_tlli == GSM_RESERVED_TMSI) {
Max0524e382018-01-19 18:22:25 +0100379 LOGPTBFUL(this, LOGL_NOTICE,
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700380 "TLLI is 0x%08x within UL DATA?!?\n",
381 new_tlli);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100382 m_window.invalidate_bsn(rdbi->bsn);
383 continue;
384 }
Max0524e382018-01-19 18:22:25 +0100385 LOGPTBFUL(this, LOGL_INFO,
386 "Decoded premier TLLI=0x%08x of UL DATA TFI=%d.\n",
Vadim Yanitskiy3f27fb52020-04-20 11:26:12 +0700387 new_tlli, rlc->tfi);
Pau Espin Pedrol8abe13c2022-10-21 18:49:48 +0200388 ms_update_announced_tlli(ms(), new_tlli);
Pau Espin Pedrolf197f152022-11-17 20:18:46 +0100389 osmo_fsm_inst_dispatch(this->state_fi, TBF_EV_FIRST_UL_DATA_RECVD, NULL);
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700390 } else if (new_tlli != GSM_RESERVED_TMSI && new_tlli != tlli()) {
Max0524e382018-01-19 18:22:25 +0100391 LOGPTBFUL(this, LOGL_NOTICE,
Pau Espin Pedrol305763d2020-11-06 20:03:24 +0100392 "Decoded TLLI=%08x mismatch on UL DATA TFI=%d. (Ignoring due to contention resolution)\n",
393 new_tlli, rlc->tfi);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100394 m_window.invalidate_bsn(rdbi->bsn);
395 continue;
396 }
Pau Espin Pedrol58916312021-05-11 14:40:41 +0200397 } else if (!is_tlli_valid()) {
398 LOGPTBFUL(this, LOGL_NOTICE, "Missing TLLI within UL DATA.\n");
399 m_window.invalidate_bsn(rdbi->bsn);
400 continue;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100401 }
402
403 m_window.receive_bsn(rdbi->bsn);
404 }
405
406 /* Raise V(Q) if possible, and retrieve LLC frames from blocks.
407 * This is looped until there is a gap (non received block) or
408 * the window is empty.*/
409 const uint16_t v_q_beg = m_window.v_q();
410 const uint16_t count = m_window.raise_v_q();
411
412 /* Retrieve LLC frames from blocks that are ready */
413 for (uint16_t i = 0; i < count; ++i) {
Jacob Erlbeck93c55d02015-12-23 16:29:07 +0100414 uint16_t index = m_window.mod_sns(v_q_beg + i);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100415 assemble_forward_llc(m_rlc.block(index));
416 }
417
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200418 /* Last frame in buffer: */
419 block = m_rlc.block(m_window.mod_sns(m_window.v_r() - 1));
420 rdbi = &block->block_info;
421
422 /* Check if we already received all data TBF had to send: */
Pau Espin Pedroldc2aaac2021-05-14 12:50:46 +0200423 if (this->state_is(TBF_ST_FLOW) /* still in flow state */
Pau Espin Pedrol9b63cd02021-05-11 14:54:40 +0200424 && this->m_window.v_q() == this->m_window.v_r() /* if complete */
425 && block->len) { /* if there was ever a last block received */
Max0524e382018-01-19 18:22:25 +0100426 LOGPTBFUL(this, LOGL_DEBUG,
427 "No gaps in received block, last block: BSN=%d CV=%d\n",
428 rdbi->bsn, rdbi->cv);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100429 if (rdbi->cv == 0) {
Max0524e382018-01-19 18:22:25 +0100430 LOGPTBFUL(this, LOGL_DEBUG, "Finished with UL TBF\n");
Pau Espin Pedrolf197f152022-11-17 20:18:46 +0100431 osmo_fsm_inst_dispatch(this->state_fi, TBF_EV_LAST_UL_DATA_RECVD, NULL);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100432 /* Reset N3103 counter. */
Max847ed9f2018-02-20 18:16:11 +0100433 this->n_reset(N3103);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100434 }
435 }
436
437 /* If TLLI is included or if we received half of the window, we send
438 * an ack/nack */
Pau Espin Pedrol9b63cd02021-05-11 14:54:40 +0200439 maybe_schedule_uplink_acknack(rlc, block->len && rdbi->cv == 0);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100440
441 return 0;
442}
443
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100444void gprs_rlcmac_ul_tbf::maybe_schedule_uplink_acknack(
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200445 const gprs_rlc_data_info *rlc, bool countdown_finished)
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100446{
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200447 bool require_ack = false;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100448 bool have_ti = rlc->block_info[0].ti ||
449 (rlc->num_data_blocks > 1 && rlc->block_info[1].ti);
450
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200451 if (rlc->si) {
452 require_ack = true;
453 LOGPTBFUL(this, LOGL_NOTICE,
454 "Scheduling Ack/Nack, because MS is stalled.\n");
455 }
456 if (have_ti) {
457 require_ack = true;
458 LOGPTBFUL(this, LOGL_DEBUG,
459 "Scheduling Ack/Nack, because TLLI is included.\n");
460 }
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200461 if (countdown_finished) {
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200462 require_ack = true;
Pau Espin Pedroldc2aaac2021-05-14 12:50:46 +0200463 if (state_is(TBF_ST_FLOW))
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200464 LOGPTBFUL(this, LOGL_DEBUG,
465 "Scheduling Ack/Nack, because some data is missing and last block has CV==0.\n");
Pau Espin Pedroldc2aaac2021-05-14 12:50:46 +0200466 else if (state_is(TBF_ST_FINISHED))
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200467 LOGPTBFUL(this, LOGL_DEBUG,
468 "Scheduling final Ack/Nack, because all data was received and last block has CV==0.\n");
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200469 }
470 if ((m_rx_counter % SEND_ACK_AFTER_FRAMES) == 0) {
471 require_ack = true;
472 LOGPTBFUL(this, LOGL_DEBUG,
473 "Scheduling Ack/Nack, because %d frames received.\n",
474 SEND_ACK_AFTER_FRAMES);
475 }
476
477 if (!require_ack)
478 return;
479
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +0200480 osmo_fsm_inst_dispatch(this->ul_ack_fsm.fi, TBF_UL_ACK_EV_SCHED_ACK, NULL);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100481}
482
Daniel Willmannca102af2014-08-08 12:14:12 +0200483/* Send Uplink unit-data to SGSN. */
484int gprs_rlcmac_ul_tbf::snd_ul_ud()
485{
486 uint8_t qos_profile[3];
487 struct msgb *llc_pdu;
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100488 unsigned msg_len = NS_HDR_LEN + BSSGP_HDR_LEN + llc_frame_length(&m_llc);
Pau Espin Pedroldb5e3392021-01-21 18:02:40 +0100489 struct bssgp_bvc_ctx *bctx = bts->pcu->bssgp.bctx;
Daniel Willmannca102af2014-08-08 12:14:12 +0200490
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100491 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 +0200492 if (!bctx) {
493 LOGP(DBSSGP, LOGL_ERROR, "No bctx\n");
Pau Espin Pedrol4f8384b2022-03-31 19:36:12 +0200494 llc_reset_frame_space(&m_llc);
Daniel Willmannca102af2014-08-08 12:14:12 +0200495 return -EIO;
496 }
Pau Espin Pedrol488aa292019-09-25 17:48:35 +0200497
Daniel Willmannca102af2014-08-08 12:14:12 +0200498 llc_pdu = msgb_alloc_headroom(msg_len, msg_len,"llc_pdu");
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100499 uint8_t *buf = msgb_push(llc_pdu, TL16V_GROSS_LEN(sizeof(uint8_t)*llc_frame_length(&m_llc)));
500 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 +0200501 qos_profile[0] = QOS_PROFILE >> 16;
502 qos_profile[1] = QOS_PROFILE >> 8;
503 qos_profile[2] = QOS_PROFILE;
504 bssgp_tx_ul_ud(bctx, tlli(), qos_profile, llc_pdu);
505
Pau Espin Pedrol4f8384b2022-03-31 19:36:12 +0200506 llc_reset_frame_space(&m_llc);
Daniel Willmannca102af2014-08-08 12:14:12 +0200507 return 0;
508}
509
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530510egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_second_seg(
511 const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block,
512 uint8_t *data, const uint8_t block_idx)
513{
514 const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx];
515 union split_block_status *spb_status = &block->spb_status;
516 uint8_t *rlc_data = &block->block[0];
517
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100518 bts_do_rate_ctr_inc(bts, CTR_SPB_UL_SECOND_SEGMENT);
sivasankarida7250a2016-12-16 12:57:18 +0530519
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530520 if (spb_status->block_status_ul &
521 EGPRS_RESEG_FIRST_SEG_RXD) {
Max0524e382018-01-19 18:22:25 +0100522 LOGPTBFUL(this, LOGL_DEBUG,
523 "Second seg is received first seg is already present set the status to complete\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530524 spb_status->block_status_ul = EGPRS_RESEG_DEFAULT;
525
526 block->len += Decoding::rlc_copy_to_aligned_buffer(rlc,
527 block_idx, data, rlc_data + block->len);
528 block->block_info.data_len += rdbi->data_len;
529 } else if (spb_status->block_status_ul == EGPRS_RESEG_DEFAULT) {
Max0524e382018-01-19 18:22:25 +0100530 LOGPTBFUL(this, LOGL_DEBUG,
531 "Second seg is received first seg is not received set the status to second seg received\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530532
533 block->len = Decoding::rlc_copy_to_aligned_buffer(rlc,
534 block_idx, data,
535 rlc_data + rlc->block_info[block_idx].data_len);
536
537 spb_status->block_status_ul = EGPRS_RESEG_SECOND_SEG_RXD;
538 block->block_info = *rdbi;
539 }
540 return spb_status->block_status_ul;
541}
542
543egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_first_seg(
544 const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block,
545 uint8_t *data, const uint8_t block_idx)
546{
547 const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx];
548 uint8_t *rlc_data = &block->block[0];
549 union split_block_status *spb_status = &block->spb_status;
550
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100551 bts_do_rate_ctr_inc(bts, CTR_SPB_UL_FIRST_SEGMENT);
sivasankarida7250a2016-12-16 12:57:18 +0530552
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530553 if (spb_status->block_status_ul & EGPRS_RESEG_SECOND_SEG_RXD) {
Max0524e382018-01-19 18:22:25 +0100554 LOGPTBFUL(this, LOGL_DEBUG,
555 "First seg is received second seg is already present set the status to complete\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530556
557 block->len += Decoding::rlc_copy_to_aligned_buffer(rlc,
558 block_idx, data, rlc_data);
559
560 block->block_info.data_len = block->len;
561 spb_status->block_status_ul = EGPRS_RESEG_DEFAULT;
562 } else if (spb_status->block_status_ul == EGPRS_RESEG_DEFAULT) {
Max0524e382018-01-19 18:22:25 +0100563 LOGPTBFUL(this, LOGL_DEBUG,
564 "First seg is received second seg is not received set the status to first seg received\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530565
566 spb_status->block_status_ul = EGPRS_RESEG_FIRST_SEG_RXD;
567 block->len = Decoding::rlc_copy_to_aligned_buffer(rlc,
568 block_idx, data, rlc_data);
569 block->block_info = *rdbi;
570 }
571 return spb_status->block_status_ul;
572}
573
574egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_spb(
575 const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block,
576 uint8_t *data, const uint8_t block_idx)
577{
578 const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx];
579
Max0524e382018-01-19 18:22:25 +0100580 LOGPTBFUL(this, LOGL_DEBUG,
581 "Got SPB(%d) cs(%s) data block with BSN (%d), TFI(%d).\n",
Max136ebcc2019-03-05 14:59:03 +0100582 rdbi->spb, mcs_name(rlc->cs), rdbi->bsn, rlc->tfi);
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530583
584 egprs_rlc_ul_reseg_bsn_state assemble_status = EGPRS_RESEG_INVALID;
585
586 /* Section 10.4.8b of 44.060*/
587 if (rdbi->spb == 2)
588 assemble_status = handle_egprs_ul_first_seg(rlc,
589 block, data, block_idx);
590 else if (rdbi->spb == 3)
591 assemble_status = handle_egprs_ul_second_seg(rlc,
592 block, data, block_idx);
593 else {
Max0524e382018-01-19 18:22:25 +0100594 LOGPTBFUL(this, LOGL_ERROR,
595 "spb(%d) Not supported SPB for this EGPRS configuration\n",
596 rdbi->spb);
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530597 }
598
599 /*
600 * When the block is successfully constructed out of segmented blocks
601 * upgrade the MCS to the type 2
602 */
603 if (assemble_status == EGPRS_RESEG_DEFAULT) {
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +0200604 switch (rlc->cs) {
Maxbea2edb2019-03-06 17:04:59 +0100605 case MCS3 :
606 block->cs_last = MCS6;
Max0524e382018-01-19 18:22:25 +0100607 LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS6\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530608 break;
Maxbea2edb2019-03-06 17:04:59 +0100609 case MCS2 :
610 block->cs_last = MCS5;
Max0524e382018-01-19 18:22:25 +0100611 LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS5\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530612 break;
Maxbea2edb2019-03-06 17:04:59 +0100613 case MCS1 :
Max0524e382018-01-19 18:22:25 +0100614 LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS4\n");
Maxbea2edb2019-03-06 17:04:59 +0100615 block->cs_last = MCS4;
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530616 break;
617 default:
Max0524e382018-01-19 18:22:25 +0100618 LOGPTBFUL(this, LOGL_ERROR,
619 "cs(%s) Error in Upgrading to higher MCS\n",
Max136ebcc2019-03-05 14:59:03 +0100620 mcs_name(rlc->cs));
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530621 break;
622 }
623 }
624 return assemble_status;
625}
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530626
Maxfb59a932019-03-13 18:40:19 +0100627void gprs_rlcmac_ul_tbf::update_coding_scheme_counter_ul(enum CodingScheme cs)
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530628{
Maxfb59a932019-03-13 18:40:19 +0100629 switch (cs) {
630 case CS1:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100631 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS1);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200632 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_gprs_ctrs, TBF_CTR_GPRS_UL_CS1));
Maxfb59a932019-03-13 18:40:19 +0100633 break;
634 case CS2:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100635 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS2);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200636 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_gprs_ctrs, TBF_CTR_GPRS_UL_CS2));
Maxfb59a932019-03-13 18:40:19 +0100637 break;
638 case CS3:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100639 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS3);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200640 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_gprs_ctrs, TBF_CTR_GPRS_UL_CS3));
Maxfb59a932019-03-13 18:40:19 +0100641 break;
642 case CS4:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100643 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS4);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200644 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_gprs_ctrs, TBF_CTR_GPRS_UL_CS4));
Maxfb59a932019-03-13 18:40:19 +0100645 break;
646 case MCS1:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100647 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS1);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200648 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS1));
Maxfb59a932019-03-13 18:40:19 +0100649 break;
650 case MCS2:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100651 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS2);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200652 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS2));
Maxfb59a932019-03-13 18:40:19 +0100653 break;
654 case MCS3:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100655 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS3);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200656 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS3));
Maxfb59a932019-03-13 18:40:19 +0100657 break;
658 case MCS4:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100659 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS4);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200660 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS4));
Maxfb59a932019-03-13 18:40:19 +0100661 break;
662 case MCS5:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100663 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS5);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200664 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS5));
Maxfb59a932019-03-13 18:40:19 +0100665 break;
666 case MCS6:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100667 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS6);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200668 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS6));
Maxfb59a932019-03-13 18:40:19 +0100669 break;
670 case MCS7:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100671 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS7);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200672 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS7));
Maxfb59a932019-03-13 18:40:19 +0100673 break;
674 case MCS8:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100675 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS8);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200676 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS8));
Maxfb59a932019-03-13 18:40:19 +0100677 break;
678 case MCS9:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100679 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS9);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200680 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS9));
Maxfb59a932019-03-13 18:40:19 +0100681 break;
682 default:
683 LOGPTBFUL(this, LOGL_ERROR, "attempting to update rate counters for unsupported (M)CS %s\n",
684 mcs_name(cs));
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530685 }
686}
sivasankari8adfcd02017-01-16 15:41:21 +0530687
Max9d7357e2017-12-14 15:02:33 +0100688void gprs_rlcmac_ul_tbf::set_window_size()
sivasankari8adfcd02017-01-16 15:41:21 +0530689{
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100690 const struct gprs_rlcmac_bts *b = bts;
Max34513fe2018-12-11 16:47:30 +0100691 uint16_t ws = egprs_window_size(b, ul_slots());
Max0524e382018-01-19 18:22:25 +0100692 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 +0100693 ws, bts->pcu->vty.ws_base, pcu_bitcount(ul_slots()), bts->pcu->vty.ws_pdch);
sivasankari8adfcd02017-01-16 15:41:21 +0530694 m_window.set_ws(ws);
695}
Pau Espin Pedrol9767e442020-10-23 21:11:41 +0200696
Pau Espin Pedrolb3f23972020-10-23 21:00:23 +0200697gprs_rlc_window *gprs_rlcmac_ul_tbf::window()
Pau Espin Pedrol9767e442020-10-23 21:11:41 +0200698{
699 return &m_window;
700}
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100701
Pau Espin Pedrol0b998b12021-03-24 14:45:43 +0100702void gprs_rlcmac_ul_tbf::usf_timeout()
703{
Pau Espin Pedrolcfb61d92021-07-26 17:17:02 +0200704 if (n_inc(N3101))
Pau Espin Pedrolf197f152022-11-17 20:18:46 +0100705 osmo_fsm_inst_dispatch(this->state_fi, TBF_EV_MAX_N3101, NULL);
Pau Espin Pedrol0b998b12021-03-24 14:45:43 +0100706}
707
Pau Espin Pedrolcc30b052022-10-27 15:25:55 +0200708struct gprs_rlcmac_ul_tbf *tbf_as_ul_tbf(struct gprs_rlcmac_tbf *tbf)
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100709{
710 if (tbf && tbf->direction == GPRS_RLCMAC_UL_TBF)
711 return static_cast<gprs_rlcmac_ul_tbf *>(tbf);
712 else
713 return NULL;
714}
Pau Espin Pedrol0b998b12021-03-24 14:45:43 +0100715
Pau Espin Pedrol1e1275f2022-11-17 20:57:34 +0100716const struct gprs_rlcmac_ul_tbf *tbf_as_ul_tbf_const(const struct gprs_rlcmac_tbf *tbf)
717{
718 if (tbf && tbf->direction == GPRS_RLCMAC_UL_TBF)
719 return static_cast<const gprs_rlcmac_ul_tbf *>(tbf);
720 else
721 return NULL;
722}
723
Pau Espin Pedrol0b998b12021-03-24 14:45:43 +0100724void tbf_usf_timeout(struct gprs_rlcmac_ul_tbf *tbf)
725{
726 tbf->usf_timeout();
727}
Pau Espin Pedrol49a2f402021-07-27 17:33:07 +0200728
729
730bool ul_tbf_contention_resolution_done(const struct gprs_rlcmac_ul_tbf *tbf)
731{
732 return tbf->m_contention_resolution_done;
733}
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +0200734
735struct osmo_fsm_inst *tbf_ul_ack_fi(const struct gprs_rlcmac_ul_tbf *tbf)
736{
737 return tbf->ul_ack_fsm.fi;
738}
739
Pau Espin Pedrol94386132022-10-28 19:50:09 +0200740void ul_tbf_contention_resolution_start(struct gprs_rlcmac_ul_tbf *tbf)
741{
742 tbf->contention_resolution_start();
743}
744
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +0200745void ul_tbf_contention_resolution_success(struct gprs_rlcmac_ul_tbf *tbf)
746{
747 return tbf->contention_resolution_success();
748}