blob: 1d06e531fe8db960735785be59ebcb7498093dcd [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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#include <bts.h>
Oliver Smithd3c75912021-07-09 16:37:16 +020023#include <bts_pch_timer.h>
Daniel Willmannca102af2014-08-08 12:14:12 +020024#include <tbf.h>
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020025#include <tbf_ul.h>
Daniel Willmannca102af2014-08-08 12:14:12 +020026#include <rlc.h>
27#include <encoding.h>
28#include <gprs_rlcmac.h>
29#include <gprs_debug.h>
30#include <gprs_bssgp_pcu.h>
31#include <decoding.h>
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +020032#include <pcu_l1_if.h>
Max1187a772018-01-26 13:31:42 +010033#include <gprs_ms.h>
34#include <llc.h>
sivasankari8adfcd02017-01-16 15:41:21 +053035#include "pcu_utils.h"
36
Daniel Willmannca102af2014-08-08 12:14:12 +020037extern "C" {
38#include <osmocom/core/msgb.h>
39#include <osmocom/core/talloc.h>
Max1187a772018-01-26 13:31:42 +010040 #include <osmocom/core/bitvec.h>
41 #include <osmocom/core/logging.h>
42 #include <osmocom/core/rate_ctr.h>
Pau Espin Pedrol442198c2020-10-23 22:30:04 +020043 #include <osmocom/core/stats.h>
Max1187a772018-01-26 13:31:42 +010044 #include <osmocom/core/utils.h>
45 #include <osmocom/gprs/gprs_bssgp_bss.h>
46 #include <osmocom/gprs/protocol/gsm_08_18.h>
47 #include <osmocom/gsm/tlv.h>
Max136ebcc2019-03-05 14:59:03 +010048 #include "coding_scheme.h"
Daniel Willmannca102af2014-08-08 12:14:12 +020049}
50
51#include <errno.h>
52#include <string.h>
53
54/* After receiving these frames, we send ack/nack. */
55#define SEND_ACK_AFTER_FRAMES 20
56
57extern void *tall_pcu_ctx;
58
Pau Espin Pedrol442198c2020-10-23 22:30:04 +020059static const struct rate_ctr_desc tbf_ul_gprs_ctr_description[] = {
60 { "gprs:uplink:cs1", "CS1 " },
61 { "gprs:uplink:cs2", "CS2 " },
62 { "gprs:uplink:cs3", "CS3 " },
63 { "gprs:uplink:cs4", "CS4 " },
64};
65
66static const struct rate_ctr_desc tbf_ul_egprs_ctr_description[] = {
67 { "egprs:uplink:mcs1", "MCS1 " },
68 { "egprs:uplink:mcs2", "MCS2 " },
69 { "egprs:uplink:mcs3", "MCS3 " },
70 { "egprs:uplink:mcs4", "MCS4 " },
71 { "egprs:uplink:mcs5", "MCS5 " },
72 { "egprs:uplink:mcs6", "MCS6 " },
73 { "egprs:uplink:mcs7", "MCS7 " },
74 { "egprs:uplink:mcs8", "MCS8 " },
75 { "egprs:uplink:mcs9", "MCS9 " },
76};
77
78static const struct rate_ctr_group_desc tbf_ul_gprs_ctrg_desc = {
79 "tbf:gprs",
80 "Data Blocks",
81 OSMO_STATS_CLASS_SUBSCRIBER,
82 ARRAY_SIZE(tbf_ul_gprs_ctr_description),
83 tbf_ul_gprs_ctr_description,
84};
85
86static const struct rate_ctr_group_desc tbf_ul_egprs_ctrg_desc = {
87 "tbf:egprs",
88 "Data Blocks",
89 OSMO_STATS_CLASS_SUBSCRIBER,
90 ARRAY_SIZE(tbf_ul_egprs_ctr_description),
91 tbf_ul_egprs_ctr_description,
92};
93
Pau Espin Pedrol131deb02021-07-26 18:24:14 +020094gprs_rlcmac_ul_tbf::~gprs_rlcmac_ul_tbf()
95{
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +020096 osmo_fsm_inst_free(ul_ack_fsm.fi);
97 ul_ack_fsm.fi = NULL;
98
Pau Espin Pedrol131deb02021-07-26 18:24:14 +020099 rate_ctr_group_free(m_ul_egprs_ctrs);
100 rate_ctr_group_free(m_ul_gprs_ctrs);
101 /* ~gprs_rlcmac_tbf() is called automatically upon return */
102}
103
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200104static int ul_tbf_dtor(struct gprs_rlcmac_ul_tbf *tbf)
105{
106 tbf->~gprs_rlcmac_ul_tbf();
107 return 0;
108}
109
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200110/* Generic function to alloc a UL TBF, later configured to be assigned either over CCCH or PACCH */
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200111struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_tbf(struct gprs_rlcmac_bts *bts, GprsMs *ms, int8_t use_trx, bool single_slot)
112{
113 struct gprs_rlcmac_ul_tbf *tbf;
114 int rc;
115
116 OSMO_ASSERT(ms != NULL);
117
Pau Espin Pedrol36177c62021-02-25 17:57:37 +0100118 LOGPMS(ms, DTBF, LOGL_DEBUG, "********** UL-TBF starts here **********\n");
119 LOGPMS(ms, DTBF, LOGL_INFO, "Allocating UL TBF\n");
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200120
121 tbf = talloc(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
122 if (!tbf)
123 return NULL;
124 talloc_set_destructor(tbf, ul_tbf_dtor);
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100125 new (tbf) gprs_rlcmac_ul_tbf(bts, ms);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200126
127 rc = tbf->setup(use_trx, single_slot);
128
129 /* if no resource */
130 if (rc < 0) {
131 talloc_free(tbf);
132 return NULL;
133 }
134
135 if (tbf->is_egprs_enabled())
136 tbf->set_window_size();
137
138 tbf->m_ul_egprs_ctrs = rate_ctr_group_alloc(tbf,
139 &tbf_ul_egprs_ctrg_desc, tbf->m_ctrs->idx);
140 tbf->m_ul_gprs_ctrs = rate_ctr_group_alloc(tbf,
141 &tbf_ul_gprs_ctrg_desc, tbf->m_ctrs->idx);
142 if (!tbf->m_ul_egprs_ctrs || !tbf->m_ul_gprs_ctrs) {
143 LOGPTBF(tbf, LOGL_ERROR, "Couldn't allocate TBF UL counters\n");
144 talloc_free(tbf);
145 return NULL;
146 }
147
Pau Espin Pedrol1a1557a2021-05-13 18:39:36 +0200148 llist_add_tail(tbf_trx_list(tbf), &tbf->trx->ul_tbfs);
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100149 bts_do_rate_ctr_inc(tbf->bts, CTR_TBF_UL_ALLOCATED);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200150
151 return tbf;
152}
153
Pau Espin Pedrolcc77eed2021-11-02 18:46:40 +0100154/* Alloc a UL TBF to be assigned over PACCH. Called when an MS requests to
155 * create a new UL TBF during the end of life of a previous UL TBF (or an SBA).
156 * In summary, this TBF is allocated as a consequence of receiving a "Pkt
157 * Resource Req" or "Pkt Ctrl Ack" from the MS.
158 * See TS 44.060 9.3.2.4.2 "Non-extended uplink TBF mode".
159 */
Pau Espin Pedrol59223962021-10-18 12:24:38 +0200160gprs_rlcmac_ul_tbf *tbf_alloc_ul_pacch(struct gprs_rlcmac_bts *bts, GprsMs *ms, int8_t use_trx)
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200161{
162 struct gprs_rlcmac_ul_tbf *tbf;
163
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200164 tbf = tbf_alloc_ul_tbf(bts, ms, use_trx, false);
165 if (!tbf) {
Pau Espin Pedrol36177c62021-02-25 17:57:37 +0100166 LOGPMS(ms, DTBF, LOGL_NOTICE, "No PDCH resource\n");
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200167 /* Caller will most probably send a Imm Ass Reject after return */
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200168 return NULL;
169 }
Pau Espin Pedrolcc77eed2021-11-02 18:46:40 +0100170 /* Contention resolution is considered to be done since TLLI is known in MS: */
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200171 tbf->m_contention_resolution_done = 1;
Pau Espin Pedrol33e80072021-07-22 19:20:50 +0200172 osmo_fsm_inst_dispatch(tbf->state_fsm.fi, TBF_EV_ASSIGN_ADD_PACCH, NULL);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200173
174 return tbf;
175}
176
Pau Espin Pedrol858f0382021-11-02 14:13:47 +0100177/* Alloc a UL TBF to be assigned over CCCH. Used by request of a "One phase
178 * packet access", where MS requested only 1 PDCH TS (TS 44.018 Table 9.1.8.1). */
Pau Espin Pedrol20271c42021-05-10 17:21:03 +0200179struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_ccch(struct gprs_rlcmac_bts *bts, struct GprsMs *ms)
180{
181 struct gprs_rlcmac_ul_tbf *tbf;
182
183 tbf = tbf_alloc_ul_tbf(bts, ms, -1, true);
184 if (!tbf) {
185 LOGP(DTBF, LOGL_NOTICE, "No PDCH resource for Uplink TBF\n");
186 /* Caller will most probably send a Imm Ass Reject after return */
187 return NULL;
188 }
Pau Espin Pedrol33e80072021-07-22 19:20:50 +0200189 osmo_fsm_inst_dispatch(tbf->state_fsm.fi, TBF_EV_ASSIGN_ADD_CCCH, NULL);
Pau Espin Pedrol4b6f0bf2021-05-10 18:54:52 +0200190 tbf->contention_resolution_start();
Pau Espin Pedrol20271c42021-05-10 17:21:03 +0200191 OSMO_ASSERT(tbf->ms());
192
193 return tbf;
194}
195
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200196/* Create a temporary dummy TBF to Tx a ImmAssReject if allocating a new one during
197 * packet resource Request failed. This is similar as tbf_alloc_ul() but without
198 * calling tbf->setup() (in charge of TFI/USF allocation), and reusing resources
199 * from Packet Resource Request we received. See TS 44.060 sec 7.1.3.2.1 */
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200200struct gprs_rlcmac_ul_tbf *handle_tbf_reject(struct gprs_rlcmac_bts *bts,
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200201 GprsMs *ms, uint8_t trx_no, uint8_t ts)
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200202{
203 struct gprs_rlcmac_ul_tbf *ul_tbf = NULL;
204 struct gprs_rlcmac_trx *trx = &bts->trx[trx_no];
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200205 OSMO_ASSERT(ms);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200206
207 ul_tbf = talloc(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
208 if (!ul_tbf)
209 return ul_tbf;
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200210 talloc_set_destructor(ul_tbf, ul_tbf_dtor);
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100211 new (ul_tbf) gprs_rlcmac_ul_tbf(bts, ms);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200212
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200213 ul_tbf->trx = trx;
Pau Espin Pedrol06329682021-11-08 12:42:06 +0100214 /* The only one TS is the common, control TS */
215 ul_tbf->first_ts = ts;
216 ul_tbf->first_common_ts = ts;
217 tbf_assign_control_ts(ul_tbf);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200218 ul_tbf->m_ctrs = rate_ctr_group_alloc(ul_tbf, &tbf_ctrg_desc, next_tbf_ctr_group_id++);
219 ul_tbf->m_ul_egprs_ctrs = rate_ctr_group_alloc(ul_tbf,
220 &tbf_ul_egprs_ctrg_desc,
221 ul_tbf->m_ctrs->idx);
222 ul_tbf->m_ul_gprs_ctrs = rate_ctr_group_alloc(ul_tbf,
223 &tbf_ul_gprs_ctrg_desc,
224 ul_tbf->m_ctrs->idx);
225 if (!ul_tbf->m_ctrs || !ul_tbf->m_ul_egprs_ctrs || !ul_tbf->m_ul_gprs_ctrs) {
226 LOGPTBF(ul_tbf, LOGL_ERROR, "Cound not allocate TBF UL rate counters\n");
227 talloc_free(ul_tbf);
228 return NULL;
229 }
Pau Espin Pedroldbd3b782021-11-08 13:21:39 +0100230 tbf_update_state_fsm_name(ul_tbf);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200231
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200232 ms_attach_tbf(ms, ul_tbf);
Pau Espin Pedrol1a1557a2021-05-13 18:39:36 +0200233 llist_add(tbf_trx_list((struct gprs_rlcmac_tbf *)ul_tbf), &trx->ul_tbfs);
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200234 bts_do_rate_ctr_inc(ul_tbf->bts, CTR_TBF_UL_ALLOCATED);
Pau Espin Pedrol33e80072021-07-22 19:20:50 +0200235 osmo_fsm_inst_dispatch(ul_tbf->state_fsm.fi, TBF_EV_ASSIGN_ADD_PACCH, NULL);
Pau Espin Pedrol6ad11a62021-07-27 12:27:08 +0200236 osmo_fsm_inst_dispatch(ul_tbf->ul_ass_fsm.fi, TBF_UL_ASS_EV_SCHED_ASS_REJ, NULL);
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200237
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200238 return ul_tbf;
239}
240
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100241gprs_rlcmac_ul_tbf::gprs_rlcmac_ul_tbf(struct gprs_rlcmac_bts *bts_, GprsMs *ms) :
Pau Espin Pedrole9f77d32020-10-23 18:41:40 +0200242 gprs_rlcmac_tbf(bts_, ms, GPRS_RLCMAC_UL_TBF),
Pau Espin Pedrolbddf1ad2019-09-26 14:41:18 +0200243 m_rx_counter(0),
244 m_contention_resolution_done(0),
Pau Espin Pedrolbddf1ad2019-09-26 14:41:18 +0200245 m_ul_gprs_ctrs(NULL),
246 m_ul_egprs_ctrs(NULL)
247{
Pau Espin Pedrol7bd92a32021-03-24 13:14:09 +0100248 memset(&m_usf, USF_INVALID, sizeof(m_usf));
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +0200249
250 memset(&ul_ack_fsm, 0, sizeof(ul_ack_fsm));
251 ul_ack_fsm.tbf = this;
252 ul_ack_fsm.fi = osmo_fsm_inst_alloc(&tbf_ul_ack_fsm, this, &ul_ack_fsm, LOGL_INFO, NULL);
253
Pau Espin Pedrolbddf1ad2019-09-26 14:41:18 +0200254}
255
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100256/*
257 * Store received block data in LLC message(s) and forward to SGSN
258 * if complete.
259 */
260int gprs_rlcmac_ul_tbf::assemble_forward_llc(const gprs_rlc_data *_data)
261{
262 const uint8_t *data = _data->block;
263 uint8_t len = _data->len;
Jacob Erlbeckf2ba4cb2016-01-07 18:59:28 +0100264 const struct gprs_rlc_data_block_info *rdbi = &_data->block_info;
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +0200265 enum CodingScheme cs = _data->cs_last;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100266
267 Decoding::RlcData frames[16], *frame;
268 int i, num_frames = 0;
269 uint32_t dummy_tlli;
270
Max0524e382018-01-19 18:22:25 +0100271 LOGPTBFUL(this, LOGL_DEBUG, "Assembling frames: (len=%d)\n", len);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100272
273 num_frames = Decoding::rlc_data_from_ul_data(
Alexander Couzensce936f32016-05-24 14:45:41 +0200274 rdbi, cs, data, &(frames[0]), ARRAY_SIZE(frames),
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100275 &dummy_tlli);
276
277 /* create LLC frames */
278 for (i = 0; i < num_frames; i++) {
279 frame = frames + i;
280
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530281 if (frame->length) {
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100282 bts_do_rate_ctr_add(bts, CTR_RLC_UL_PAYLOAD_BYTES, frame->length);
Alexander Couzens7fdbf892016-05-21 19:45:23 +0200283
Max0524e382018-01-19 18:22:25 +0100284 LOGPTBFUL(this, LOGL_DEBUG, "Frame %d "
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530285 "starts at offset %d, "
286 "length=%d, is_complete=%d\n",
287 i + 1, frame->offset, frame->length,
288 frame->is_complete);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100289
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530290 m_llc.append_frame(data + frame->offset, frame->length);
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100291 llc_consume(&m_llc, frame->length);
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530292 }
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100293
294 if (frame->is_complete) {
295 /* send frame to SGSN */
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100296 LOGPTBFUL(this, LOGL_DEBUG, "complete UL frame len=%d\n", llc_frame_length(&m_llc));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100297 snd_ul_ud();
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100298 bts_do_rate_ctr_add(bts, CTR_LLC_UL_BYTES, llc_frame_length(&m_llc));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100299 m_llc.reset();
300 }
301 }
302
303 return 0;
304}
305
Pau Espin Pedrol4b6f0bf2021-05-10 18:54:52 +0200306void gprs_rlcmac_ul_tbf::contention_resolution_start()
307{
308 /* 3GPP TS 44.018 sec 11.1.2 Timers on the network side: "This timer is
309 * started when a temporary block flow is allocated with an IMMEDIATE
310 * ASSIGNMENT or an IMMEDIATE PACKET ASSIGNMENT or an EC IMMEDIATE
311 * ASSIGNMENT TYPE 1 message during a packet access procedure. It is
312 * stopped when the mobile station has correctly seized the temporary
313 * block flow."
314 * In our code base, it means we want to do contention resolution
315 * timeout only for one-phase packet access, since two-phase is handled
316 * through SBA structs, which are freed by the PDCH UL Controller if the
317 * single allocated block is lost. */
318 T_START(this, T3141, 3141, "Contention resolution (UL-TBF, CCCH)", true);
319}
320void gprs_rlcmac_ul_tbf::contention_resolution_success()
321{
322 if (m_contention_resolution_done)
323 return;
324
325 /* 3GPP TS 44.060 sec 7a.2.1 Contention Resolution */
326 /* 3GPP TS 44.018 3.5.2.1.4 Packet access completion: The one phase
327 packet access procedure is completed at a successful contention
328 resolution. The mobile station has entered the packet transfer mode.
329 Timer T3141 is stopped on the network side */
330 t_stop(T3141, "Contention resolution success (UL-TBF, CCCH)");
331
332 /* now we must set this flag, so we are allowed to assign downlink
333 * TBF on PACCH. it is only allowed when TLLI is acknowledged. */
334 m_contention_resolution_done = 1;
Pau Espin Pedrolba568312021-11-02 18:47:44 +0100335
336 bts_do_rate_ctr_inc(bts, CTR_IMMEDIATE_ASSIGN_UL_TBF_CONTENTION_RESOLUTION_SUCCESS);
Pau Espin Pedrol4b6f0bf2021-05-10 18:54:52 +0200337}
338
Alexander Couzens2fcfc292016-05-24 14:40:03 +0200339/*! \brief receive data from PDCH/L1 */
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100340int gprs_rlcmac_ul_tbf::rcv_data_block_acknowledged(
Jacob Erlbeckf2ba4cb2016-01-07 18:59:28 +0100341 const struct gprs_rlc_data_info *rlc,
Jacob Erlbeckfc1b3e62016-01-11 09:58:11 +0100342 uint8_t *data, struct pcu_l1_meas *meas)
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100343{
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200344 const struct gprs_rlc_data_block_info *rdbi;
345 struct gprs_rlc_data *block;
346
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100347 int8_t rssi = meas->have_rssi ? meas->rssi : 0;
348
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100349 const uint16_t ws = m_window.ws();
350
Max0524e382018-01-19 18:22:25 +0100351 LOGPTBFUL(this, LOGL_DEBUG, "UL DATA TFI=%d received (V(Q)=%d .. "
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100352 "V(R)=%d)\n", rlc->tfi, this->m_window.v_q(),
353 this->m_window.v_r());
354
355 /* process RSSI */
356 gprs_rlcmac_rssi(this, rssi);
357
358 /* store measurement values */
Pau Espin Pedrolf53815f2021-05-11 14:23:51 +0200359 ms_update_l1_meas(ms(), meas);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100360
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700361 uint32_t new_tlli = GSM_RESERVED_TMSI;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100362 unsigned int block_idx;
363
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100364 /* Increment RX-counter */
365 this->m_rx_counter++;
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530366 update_coding_scheme_counter_ul(rlc->cs);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100367 /* Loop over num_blocks */
368 for (block_idx = 0; block_idx < rlc->num_data_blocks; block_idx++) {
369 int num_chunks;
370 uint8_t *rlc_data;
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200371 rdbi = &rlc->block_info[block_idx];
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100372
Max0524e382018-01-19 18:22:25 +0100373 LOGPTBFUL(this, LOGL_DEBUG,
374 "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 +0100375 mcs_name(rlc->cs),
Max0524e382018-01-19 18:22:25 +0100376 rdbi->cv, rdbi->bsn, rdbi->spb,
377 rdbi->pi, rdbi->e, rdbi->ti,
378 rlc->data_offs_bits[block_idx]);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100379
380 /* Check whether the block needs to be decoded */
381
382 if (!m_window.is_in_window(rdbi->bsn)) {
Max0524e382018-01-19 18:22:25 +0100383 LOGPTBFUL(this, LOGL_DEBUG, "BSN %d out of window %d..%d (it's normal)\n",
384 rdbi->bsn,
385 m_window.v_q(), m_window.mod_sns(m_window.v_q() + ws - 1));
Pau Espin Pedrol58916312021-05-11 14:40:41 +0200386 continue;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100387 } else if (m_window.is_received(rdbi->bsn)) {
Max0524e382018-01-19 18:22:25 +0100388 LOGPTBFUL(this, LOGL_DEBUG,
389 "BSN %d already received\n", rdbi->bsn);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100390 continue;
Pau Espin Pedrol58916312021-05-11 14:40:41 +0200391 }
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100392
393 /* Store block and meta info to BSN buffer */
394
Max0524e382018-01-19 18:22:25 +0100395 LOGPTBFUL(this, LOGL_DEBUG, "BSN %d storing in window (%d..%d)\n",
396 rdbi->bsn, m_window.v_q(),
397 m_window.mod_sns(m_window.v_q() + ws - 1));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100398 block = m_rlc.block(rdbi->bsn);
Aravind Sirsikar550a5412016-06-14 18:59:18 +0530399 OSMO_ASSERT(rdbi->data_len <= sizeof(block->block));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100400 rlc_data = &(block->block[0]);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100401
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530402 if (rdbi->spb) {
403 egprs_rlc_ul_reseg_bsn_state assemble_status;
404
405 assemble_status = handle_egprs_ul_spb(rlc,
406 block, data, block_idx);
407
408 if (assemble_status != EGPRS_RESEG_DEFAULT)
409 return 0;
410 } else {
411 block->block_info = *rdbi;
412 block->cs_last = rlc->cs;
413 block->len =
414 Decoding::rlc_copy_to_aligned_buffer(rlc,
415 block_idx, data, rlc_data);
416 }
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100417
Max0524e382018-01-19 18:22:25 +0100418 LOGPTBFUL(this, LOGL_DEBUG,
419 "data_length=%d, data=%s\n",
420 block->len, osmo_hexdump(rlc_data, block->len));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100421 /* Get/Handle TLLI */
422 if (rdbi->ti) {
423 num_chunks = Decoding::rlc_data_from_ul_data(
424 rdbi, rlc->cs, rlc_data, NULL, 0, &new_tlli);
425
426 if (num_chunks < 0) {
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100427 bts_do_rate_ctr_inc(bts, CTR_DECODE_ERRORS);
Max0524e382018-01-19 18:22:25 +0100428 LOGPTBFUL(this, LOGL_NOTICE,
429 "Failed to decode TLLI of %s UL DATA TFI=%d.\n",
Max136ebcc2019-03-05 14:59:03 +0100430 mcs_name(rlc->cs), rlc->tfi);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100431 m_window.invalidate_bsn(rdbi->bsn);
432 continue;
433 }
434 if (!this->is_tlli_valid()) {
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700435 if (new_tlli == GSM_RESERVED_TMSI) {
Max0524e382018-01-19 18:22:25 +0100436 LOGPTBFUL(this, LOGL_NOTICE,
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700437 "TLLI is 0x%08x within UL DATA?!?\n",
438 new_tlli);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100439 m_window.invalidate_bsn(rdbi->bsn);
440 continue;
441 }
Max0524e382018-01-19 18:22:25 +0100442 LOGPTBFUL(this, LOGL_INFO,
443 "Decoded premier TLLI=0x%08x of UL DATA TFI=%d.\n",
Vadim Yanitskiy3f27fb52020-04-20 11:26:12 +0700444 new_tlli, rlc->tfi);
Pau Espin Pedrold21e9612020-06-26 14:20:37 +0200445 update_ms(new_tlli, GPRS_RLCMAC_UL_TBF);
Oliver Smithd3c75912021-07-09 16:37:16 +0200446 bts_pch_timer_stop(bts, ms_imsi(ms()));
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700447 } else if (new_tlli != GSM_RESERVED_TMSI && new_tlli != tlli()) {
Max0524e382018-01-19 18:22:25 +0100448 LOGPTBFUL(this, LOGL_NOTICE,
Pau Espin Pedrol305763d2020-11-06 20:03:24 +0100449 "Decoded TLLI=%08x mismatch on UL DATA TFI=%d. (Ignoring due to contention resolution)\n",
450 new_tlli, rlc->tfi);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100451 m_window.invalidate_bsn(rdbi->bsn);
452 continue;
453 }
Pau Espin Pedrol58916312021-05-11 14:40:41 +0200454 } else if (!is_tlli_valid()) {
455 LOGPTBFUL(this, LOGL_NOTICE, "Missing TLLI within UL DATA.\n");
456 m_window.invalidate_bsn(rdbi->bsn);
457 continue;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100458 }
459
460 m_window.receive_bsn(rdbi->bsn);
461 }
462
463 /* Raise V(Q) if possible, and retrieve LLC frames from blocks.
464 * This is looped until there is a gap (non received block) or
465 * the window is empty.*/
466 const uint16_t v_q_beg = m_window.v_q();
467 const uint16_t count = m_window.raise_v_q();
468
469 /* Retrieve LLC frames from blocks that are ready */
470 for (uint16_t i = 0; i < count; ++i) {
Jacob Erlbeck93c55d02015-12-23 16:29:07 +0100471 uint16_t index = m_window.mod_sns(v_q_beg + i);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100472 assemble_forward_llc(m_rlc.block(index));
473 }
474
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200475 /* Last frame in buffer: */
476 block = m_rlc.block(m_window.mod_sns(m_window.v_r() - 1));
477 rdbi = &block->block_info;
478
479 /* Check if we already received all data TBF had to send: */
Pau Espin Pedroldc2aaac2021-05-14 12:50:46 +0200480 if (this->state_is(TBF_ST_FLOW) /* still in flow state */
Pau Espin Pedrol9b63cd02021-05-11 14:54:40 +0200481 && this->m_window.v_q() == this->m_window.v_r() /* if complete */
482 && block->len) { /* if there was ever a last block received */
Max0524e382018-01-19 18:22:25 +0100483 LOGPTBFUL(this, LOGL_DEBUG,
484 "No gaps in received block, last block: BSN=%d CV=%d\n",
485 rdbi->bsn, rdbi->cv);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100486 if (rdbi->cv == 0) {
Max0524e382018-01-19 18:22:25 +0100487 LOGPTBFUL(this, LOGL_DEBUG, "Finished with UL TBF\n");
Pau Espin Pedrolc32c4a32021-07-23 18:27:57 +0200488 osmo_fsm_inst_dispatch(this->state_fsm.fi, TBF_EV_LAST_UL_DATA_RECVD, NULL);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100489 /* Reset N3103 counter. */
Max847ed9f2018-02-20 18:16:11 +0100490 this->n_reset(N3103);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100491 }
492 }
493
494 /* If TLLI is included or if we received half of the window, we send
495 * an ack/nack */
Pau Espin Pedrol9b63cd02021-05-11 14:54:40 +0200496 maybe_schedule_uplink_acknack(rlc, block->len && rdbi->cv == 0);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100497
498 return 0;
499}
500
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100501void gprs_rlcmac_ul_tbf::maybe_schedule_uplink_acknack(
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200502 const gprs_rlc_data_info *rlc, bool countdown_finished)
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100503{
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200504 bool require_ack = false;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100505 bool have_ti = rlc->block_info[0].ti ||
506 (rlc->num_data_blocks > 1 && rlc->block_info[1].ti);
507
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200508 if (rlc->si) {
509 require_ack = true;
510 LOGPTBFUL(this, LOGL_NOTICE,
511 "Scheduling Ack/Nack, because MS is stalled.\n");
512 }
513 if (have_ti) {
514 require_ack = true;
515 LOGPTBFUL(this, LOGL_DEBUG,
516 "Scheduling Ack/Nack, because TLLI is included.\n");
517 }
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200518 if (countdown_finished) {
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200519 require_ack = true;
Pau Espin Pedroldc2aaac2021-05-14 12:50:46 +0200520 if (state_is(TBF_ST_FLOW))
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200521 LOGPTBFUL(this, LOGL_DEBUG,
522 "Scheduling Ack/Nack, because some data is missing and last block has CV==0.\n");
Pau Espin Pedroldc2aaac2021-05-14 12:50:46 +0200523 else if (state_is(TBF_ST_FINISHED))
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200524 LOGPTBFUL(this, LOGL_DEBUG,
525 "Scheduling final Ack/Nack, because all data was received and last block has CV==0.\n");
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200526 }
527 if ((m_rx_counter % SEND_ACK_AFTER_FRAMES) == 0) {
528 require_ack = true;
529 LOGPTBFUL(this, LOGL_DEBUG,
530 "Scheduling Ack/Nack, because %d frames received.\n",
531 SEND_ACK_AFTER_FRAMES);
532 }
533
534 if (!require_ack)
535 return;
536
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +0200537 osmo_fsm_inst_dispatch(this->ul_ack_fsm.fi, TBF_UL_ACK_EV_SCHED_ACK, NULL);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100538}
539
Daniel Willmannca102af2014-08-08 12:14:12 +0200540/* Send Uplink unit-data to SGSN. */
541int gprs_rlcmac_ul_tbf::snd_ul_ud()
542{
543 uint8_t qos_profile[3];
544 struct msgb *llc_pdu;
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100545 unsigned msg_len = NS_HDR_LEN + BSSGP_HDR_LEN + llc_frame_length(&m_llc);
Pau Espin Pedroldb5e3392021-01-21 18:02:40 +0100546 struct bssgp_bvc_ctx *bctx = bts->pcu->bssgp.bctx;
Daniel Willmannca102af2014-08-08 12:14:12 +0200547
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100548 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 +0200549 if (!bctx) {
550 LOGP(DBSSGP, LOGL_ERROR, "No bctx\n");
551 m_llc.reset_frame_space();
552 return -EIO;
553 }
Pau Espin Pedrol488aa292019-09-25 17:48:35 +0200554
Daniel Willmannca102af2014-08-08 12:14:12 +0200555 llc_pdu = msgb_alloc_headroom(msg_len, msg_len,"llc_pdu");
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100556 uint8_t *buf = msgb_push(llc_pdu, TL16V_GROSS_LEN(sizeof(uint8_t)*llc_frame_length(&m_llc)));
557 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 +0200558 qos_profile[0] = QOS_PROFILE >> 16;
559 qos_profile[1] = QOS_PROFILE >> 8;
560 qos_profile[2] = QOS_PROFILE;
561 bssgp_tx_ul_ud(bctx, tlli(), qos_profile, llc_pdu);
562
563 m_llc.reset_frame_space();
564 return 0;
565}
566
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530567egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_second_seg(
568 const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block,
569 uint8_t *data, const uint8_t block_idx)
570{
571 const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx];
572 union split_block_status *spb_status = &block->spb_status;
573 uint8_t *rlc_data = &block->block[0];
574
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100575 bts_do_rate_ctr_inc(bts, CTR_SPB_UL_SECOND_SEGMENT);
sivasankarida7250a2016-12-16 12:57:18 +0530576
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530577 if (spb_status->block_status_ul &
578 EGPRS_RESEG_FIRST_SEG_RXD) {
Max0524e382018-01-19 18:22:25 +0100579 LOGPTBFUL(this, LOGL_DEBUG,
580 "Second seg is received first seg is already present set the status to complete\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530581 spb_status->block_status_ul = EGPRS_RESEG_DEFAULT;
582
583 block->len += Decoding::rlc_copy_to_aligned_buffer(rlc,
584 block_idx, data, rlc_data + block->len);
585 block->block_info.data_len += rdbi->data_len;
586 } else if (spb_status->block_status_ul == EGPRS_RESEG_DEFAULT) {
Max0524e382018-01-19 18:22:25 +0100587 LOGPTBFUL(this, LOGL_DEBUG,
588 "Second seg is received first seg is not received set the status to second seg received\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530589
590 block->len = Decoding::rlc_copy_to_aligned_buffer(rlc,
591 block_idx, data,
592 rlc_data + rlc->block_info[block_idx].data_len);
593
594 spb_status->block_status_ul = EGPRS_RESEG_SECOND_SEG_RXD;
595 block->block_info = *rdbi;
596 }
597 return spb_status->block_status_ul;
598}
599
600egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_first_seg(
601 const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block,
602 uint8_t *data, const uint8_t block_idx)
603{
604 const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx];
605 uint8_t *rlc_data = &block->block[0];
606 union split_block_status *spb_status = &block->spb_status;
607
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100608 bts_do_rate_ctr_inc(bts, CTR_SPB_UL_FIRST_SEGMENT);
sivasankarida7250a2016-12-16 12:57:18 +0530609
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530610 if (spb_status->block_status_ul & EGPRS_RESEG_SECOND_SEG_RXD) {
Max0524e382018-01-19 18:22:25 +0100611 LOGPTBFUL(this, LOGL_DEBUG,
612 "First seg is received second seg is already present set the status to complete\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530613
614 block->len += Decoding::rlc_copy_to_aligned_buffer(rlc,
615 block_idx, data, rlc_data);
616
617 block->block_info.data_len = block->len;
618 spb_status->block_status_ul = EGPRS_RESEG_DEFAULT;
619 } else if (spb_status->block_status_ul == EGPRS_RESEG_DEFAULT) {
Max0524e382018-01-19 18:22:25 +0100620 LOGPTBFUL(this, LOGL_DEBUG,
621 "First seg is received second seg is not received set the status to first seg received\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530622
623 spb_status->block_status_ul = EGPRS_RESEG_FIRST_SEG_RXD;
624 block->len = Decoding::rlc_copy_to_aligned_buffer(rlc,
625 block_idx, data, rlc_data);
626 block->block_info = *rdbi;
627 }
628 return spb_status->block_status_ul;
629}
630
631egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_spb(
632 const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block,
633 uint8_t *data, const uint8_t block_idx)
634{
635 const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx];
636
Max0524e382018-01-19 18:22:25 +0100637 LOGPTBFUL(this, LOGL_DEBUG,
638 "Got SPB(%d) cs(%s) data block with BSN (%d), TFI(%d).\n",
Max136ebcc2019-03-05 14:59:03 +0100639 rdbi->spb, mcs_name(rlc->cs), rdbi->bsn, rlc->tfi);
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530640
641 egprs_rlc_ul_reseg_bsn_state assemble_status = EGPRS_RESEG_INVALID;
642
643 /* Section 10.4.8b of 44.060*/
644 if (rdbi->spb == 2)
645 assemble_status = handle_egprs_ul_first_seg(rlc,
646 block, data, block_idx);
647 else if (rdbi->spb == 3)
648 assemble_status = handle_egprs_ul_second_seg(rlc,
649 block, data, block_idx);
650 else {
Max0524e382018-01-19 18:22:25 +0100651 LOGPTBFUL(this, LOGL_ERROR,
652 "spb(%d) Not supported SPB for this EGPRS configuration\n",
653 rdbi->spb);
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530654 }
655
656 /*
657 * When the block is successfully constructed out of segmented blocks
658 * upgrade the MCS to the type 2
659 */
660 if (assemble_status == EGPRS_RESEG_DEFAULT) {
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +0200661 switch (rlc->cs) {
Maxbea2edb2019-03-06 17:04:59 +0100662 case MCS3 :
663 block->cs_last = MCS6;
Max0524e382018-01-19 18:22:25 +0100664 LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS6\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530665 break;
Maxbea2edb2019-03-06 17:04:59 +0100666 case MCS2 :
667 block->cs_last = MCS5;
Max0524e382018-01-19 18:22:25 +0100668 LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS5\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530669 break;
Maxbea2edb2019-03-06 17:04:59 +0100670 case MCS1 :
Max0524e382018-01-19 18:22:25 +0100671 LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS4\n");
Maxbea2edb2019-03-06 17:04:59 +0100672 block->cs_last = MCS4;
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530673 break;
674 default:
Max0524e382018-01-19 18:22:25 +0100675 LOGPTBFUL(this, LOGL_ERROR,
676 "cs(%s) Error in Upgrading to higher MCS\n",
Max136ebcc2019-03-05 14:59:03 +0100677 mcs_name(rlc->cs));
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530678 break;
679 }
680 }
681 return assemble_status;
682}
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530683
Maxfb59a932019-03-13 18:40:19 +0100684void gprs_rlcmac_ul_tbf::update_coding_scheme_counter_ul(enum CodingScheme cs)
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530685{
Maxfb59a932019-03-13 18:40:19 +0100686 switch (cs) {
687 case CS1:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100688 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS1);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200689 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_gprs_ctrs, TBF_CTR_GPRS_UL_CS1));
Maxfb59a932019-03-13 18:40:19 +0100690 break;
691 case CS2:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100692 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS2);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200693 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_gprs_ctrs, TBF_CTR_GPRS_UL_CS2));
Maxfb59a932019-03-13 18:40:19 +0100694 break;
695 case CS3:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100696 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS3);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200697 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_gprs_ctrs, TBF_CTR_GPRS_UL_CS3));
Maxfb59a932019-03-13 18:40:19 +0100698 break;
699 case CS4:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100700 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS4);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200701 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_gprs_ctrs, TBF_CTR_GPRS_UL_CS4));
Maxfb59a932019-03-13 18:40:19 +0100702 break;
703 case MCS1:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100704 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS1);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200705 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS1));
Maxfb59a932019-03-13 18:40:19 +0100706 break;
707 case MCS2:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100708 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS2);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200709 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS2));
Maxfb59a932019-03-13 18:40:19 +0100710 break;
711 case MCS3:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100712 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS3);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200713 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS3));
Maxfb59a932019-03-13 18:40:19 +0100714 break;
715 case MCS4:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100716 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS4);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200717 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS4));
Maxfb59a932019-03-13 18:40:19 +0100718 break;
719 case MCS5:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100720 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS5);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200721 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS5));
Maxfb59a932019-03-13 18:40:19 +0100722 break;
723 case MCS6:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100724 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS6);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200725 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS6));
Maxfb59a932019-03-13 18:40:19 +0100726 break;
727 case MCS7:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100728 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS7);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200729 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS7));
Maxfb59a932019-03-13 18:40:19 +0100730 break;
731 case MCS8:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100732 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS8);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200733 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS8));
Maxfb59a932019-03-13 18:40:19 +0100734 break;
735 case MCS9:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100736 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS9);
Pau Espin Pedrol9c1db172021-06-04 17:05:51 +0200737 rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS9));
Maxfb59a932019-03-13 18:40:19 +0100738 break;
739 default:
740 LOGPTBFUL(this, LOGL_ERROR, "attempting to update rate counters for unsupported (M)CS %s\n",
741 mcs_name(cs));
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530742 }
743}
sivasankari8adfcd02017-01-16 15:41:21 +0530744
Max9d7357e2017-12-14 15:02:33 +0100745void gprs_rlcmac_ul_tbf::set_window_size()
sivasankari8adfcd02017-01-16 15:41:21 +0530746{
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100747 const struct gprs_rlcmac_bts *b = bts;
Max34513fe2018-12-11 16:47:30 +0100748 uint16_t ws = egprs_window_size(b, ul_slots());
Max0524e382018-01-19 18:22:25 +0100749 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 +0100750 ws, bts->pcu->vty.ws_base, pcu_bitcount(ul_slots()), bts->pcu->vty.ws_pdch);
sivasankari8adfcd02017-01-16 15:41:21 +0530751 m_window.set_ws(ws);
752}
Pau Espin Pedrol9767e442020-10-23 21:11:41 +0200753
Pau Espin Pedrolb3f23972020-10-23 21:00:23 +0200754gprs_rlc_window *gprs_rlcmac_ul_tbf::window()
Pau Espin Pedrol9767e442020-10-23 21:11:41 +0200755{
756 return &m_window;
757}
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100758
Pau Espin Pedrol0b998b12021-03-24 14:45:43 +0100759void gprs_rlcmac_ul_tbf::usf_timeout()
760{
Pau Espin Pedrolcfb61d92021-07-26 17:17:02 +0200761 if (n_inc(N3101))
Pau Espin Pedrol55f600b2021-07-26 15:54:39 +0200762 osmo_fsm_inst_dispatch(this->state_fsm.fi, TBF_EV_MAX_N3101, NULL);
Pau Espin Pedrol0b998b12021-03-24 14:45:43 +0100763}
764
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100765struct gprs_rlcmac_ul_tbf *as_ul_tbf(struct gprs_rlcmac_tbf *tbf)
766{
767 if (tbf && tbf->direction == GPRS_RLCMAC_UL_TBF)
768 return static_cast<gprs_rlcmac_ul_tbf *>(tbf);
769 else
770 return NULL;
771}
Pau Espin Pedrol0b998b12021-03-24 14:45:43 +0100772
773void tbf_usf_timeout(struct gprs_rlcmac_ul_tbf *tbf)
774{
775 tbf->usf_timeout();
776}
Pau Espin Pedrol49a2f402021-07-27 17:33:07 +0200777
778
779bool ul_tbf_contention_resolution_done(const struct gprs_rlcmac_ul_tbf *tbf)
780{
781 return tbf->m_contention_resolution_done;
782}
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +0200783
784struct osmo_fsm_inst *tbf_ul_ack_fi(const struct gprs_rlcmac_ul_tbf *tbf)
785{
786 return tbf->ul_ack_fsm.fi;
787}
788
789void ul_tbf_contention_resolution_success(struct gprs_rlcmac_ul_tbf *tbf)
790{
791 return tbf->contention_resolution_success();
792}