blob: ff291ef7342b4e8710d992badff0b00d297beb57 [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>
23#include <tbf.h>
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020024#include <tbf_ul.h>
Daniel Willmannca102af2014-08-08 12:14:12 +020025#include <rlc.h>
26#include <encoding.h>
27#include <gprs_rlcmac.h>
28#include <gprs_debug.h>
29#include <gprs_bssgp_pcu.h>
30#include <decoding.h>
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +020031#include <pcu_l1_if.h>
Max1187a772018-01-26 13:31:42 +010032#include <gprs_ms.h>
33#include <llc.h>
sivasankari8adfcd02017-01-16 15:41:21 +053034#include "pcu_utils.h"
35
Daniel Willmannca102af2014-08-08 12:14:12 +020036extern "C" {
37#include <osmocom/core/msgb.h>
38#include <osmocom/core/talloc.h>
Max1187a772018-01-26 13:31:42 +010039 #include <osmocom/core/bitvec.h>
40 #include <osmocom/core/logging.h>
41 #include <osmocom/core/rate_ctr.h>
Pau Espin Pedrol442198c2020-10-23 22:30:04 +020042 #include <osmocom/core/stats.h>
Max1187a772018-01-26 13:31:42 +010043 #include <osmocom/core/utils.h>
44 #include <osmocom/gprs/gprs_bssgp_bss.h>
45 #include <osmocom/gprs/protocol/gsm_08_18.h>
46 #include <osmocom/gsm/tlv.h>
Max136ebcc2019-03-05 14:59:03 +010047 #include "coding_scheme.h"
Daniel Willmannca102af2014-08-08 12:14:12 +020048}
49
50#include <errno.h>
51#include <string.h>
52
53/* After receiving these frames, we send ack/nack. */
54#define SEND_ACK_AFTER_FRAMES 20
55
56extern void *tall_pcu_ctx;
57
Pau Espin Pedrol442198c2020-10-23 22:30:04 +020058static const struct rate_ctr_desc tbf_ul_gprs_ctr_description[] = {
59 { "gprs:uplink:cs1", "CS1 " },
60 { "gprs:uplink:cs2", "CS2 " },
61 { "gprs:uplink:cs3", "CS3 " },
62 { "gprs:uplink:cs4", "CS4 " },
63};
64
65static const struct rate_ctr_desc tbf_ul_egprs_ctr_description[] = {
66 { "egprs:uplink:mcs1", "MCS1 " },
67 { "egprs:uplink:mcs2", "MCS2 " },
68 { "egprs:uplink:mcs3", "MCS3 " },
69 { "egprs:uplink:mcs4", "MCS4 " },
70 { "egprs:uplink:mcs5", "MCS5 " },
71 { "egprs:uplink:mcs6", "MCS6 " },
72 { "egprs:uplink:mcs7", "MCS7 " },
73 { "egprs:uplink:mcs8", "MCS8 " },
74 { "egprs:uplink:mcs9", "MCS9 " },
75};
76
77static const struct rate_ctr_group_desc tbf_ul_gprs_ctrg_desc = {
78 "tbf:gprs",
79 "Data Blocks",
80 OSMO_STATS_CLASS_SUBSCRIBER,
81 ARRAY_SIZE(tbf_ul_gprs_ctr_description),
82 tbf_ul_gprs_ctr_description,
83};
84
85static const struct rate_ctr_group_desc tbf_ul_egprs_ctrg_desc = {
86 "tbf:egprs",
87 "Data Blocks",
88 OSMO_STATS_CLASS_SUBSCRIBER,
89 ARRAY_SIZE(tbf_ul_egprs_ctr_description),
90 tbf_ul_egprs_ctr_description,
91};
92
93static int ul_tbf_dtor(struct gprs_rlcmac_ul_tbf *tbf)
94{
95 tbf->~gprs_rlcmac_ul_tbf();
96 return 0;
97}
98
99struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_tbf(struct gprs_rlcmac_bts *bts, GprsMs *ms, int8_t use_trx, bool single_slot)
100{
101 struct gprs_rlcmac_ul_tbf *tbf;
102 int rc;
103
104 OSMO_ASSERT(ms != NULL);
105
Pau Espin Pedrol36177c62021-02-25 17:57:37 +0100106 LOGPMS(ms, DTBF, LOGL_DEBUG, "********** UL-TBF starts here **********\n");
107 LOGPMS(ms, DTBF, LOGL_INFO, "Allocating UL TBF\n");
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200108
109 tbf = talloc(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
110 if (!tbf)
111 return NULL;
112 talloc_set_destructor(tbf, ul_tbf_dtor);
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100113 new (tbf) gprs_rlcmac_ul_tbf(bts, ms);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200114
115 rc = tbf->setup(use_trx, single_slot);
116
117 /* if no resource */
118 if (rc < 0) {
119 talloc_free(tbf);
120 return NULL;
121 }
122
123 if (tbf->is_egprs_enabled())
124 tbf->set_window_size();
125
126 tbf->m_ul_egprs_ctrs = rate_ctr_group_alloc(tbf,
127 &tbf_ul_egprs_ctrg_desc, tbf->m_ctrs->idx);
128 tbf->m_ul_gprs_ctrs = rate_ctr_group_alloc(tbf,
129 &tbf_ul_gprs_ctrg_desc, tbf->m_ctrs->idx);
130 if (!tbf->m_ul_egprs_ctrs || !tbf->m_ul_gprs_ctrs) {
131 LOGPTBF(tbf, LOGL_ERROR, "Couldn't allocate TBF UL counters\n");
132 talloc_free(tbf);
133 return NULL;
134 }
135
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100136 llist_add_tail(tbf_bts_list(tbf), &bts->ul_tbfs);
137 bts_do_rate_ctr_inc(tbf->bts, CTR_TBF_UL_ALLOCATED);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200138
139 return tbf;
140}
141
142
143gprs_rlcmac_ul_tbf *tbf_alloc_ul(struct gprs_rlcmac_bts *bts, GprsMs *ms, int8_t use_trx,
144 uint32_t tlli)
145{
146 struct gprs_rlcmac_ul_tbf *tbf;
147
148/* FIXME: Copy and paste with tbf_new_dl_assignment */
149 /* create new TBF, use same TRX as DL TBF */
150 /* use multislot class of downlink TBF */
151 tbf = tbf_alloc_ul_tbf(bts, ms, use_trx, false);
152 if (!tbf) {
Pau Espin Pedrol36177c62021-02-25 17:57:37 +0100153 LOGPMS(ms, DTBF, LOGL_NOTICE, "No PDCH resource\n");
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200154 /* FIXME: send reject */
155 return NULL;
156 }
157 tbf->m_contention_resolution_done = 1;
158 TBF_SET_ASS_ON(tbf, GPRS_RLCMAC_FLAG_PACCH, false);
159 T_START(tbf, T3169, 3169, "allocation (UL-TBF)", true);
160 tbf->update_ms(tlli, GPRS_RLCMAC_UL_TBF);
161 OSMO_ASSERT(tbf->ms());
162
163 return tbf;
164}
165
166struct gprs_rlcmac_ul_tbf *handle_tbf_reject(struct gprs_rlcmac_bts *bts,
167 GprsMs *ms, uint32_t tlli, uint8_t trx_no, uint8_t ts)
168{
169 struct gprs_rlcmac_ul_tbf *ul_tbf = NULL;
170 struct gprs_rlcmac_trx *trx = &bts->trx[trx_no];
171
172 if (!ms)
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100173 ms = bts_alloc_ms(bts, 0, 0);
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100174 ms_set_tlli(ms, tlli);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200175
176 ul_tbf = talloc(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
177 if (!ul_tbf)
178 return ul_tbf;
179
180 talloc_set_destructor(ul_tbf, ul_tbf_dtor);
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100181 new (ul_tbf) gprs_rlcmac_ul_tbf(bts, ms);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200182
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100183 llist_add(tbf_bts_list((struct gprs_rlcmac_tbf *)ul_tbf), &bts->ul_tbfs);
184 bts_do_rate_ctr_inc(ul_tbf->bts, CTR_TBF_UL_ALLOCATED);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200185 TBF_SET_ASS_ON(ul_tbf, GPRS_RLCMAC_FLAG_PACCH, false);
186
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100187 ms_attach_tbf(ms, ul_tbf);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200188 ul_tbf->update_ms(tlli, GPRS_RLCMAC_UL_TBF);
189 TBF_SET_ASS_STATE_UL(ul_tbf, GPRS_RLCMAC_UL_ASS_SEND_ASS_REJ);
190 ul_tbf->control_ts = ts;
191 ul_tbf->trx = trx;
192 ul_tbf->m_ctrs = rate_ctr_group_alloc(ul_tbf, &tbf_ctrg_desc, next_tbf_ctr_group_id++);
193 ul_tbf->m_ul_egprs_ctrs = rate_ctr_group_alloc(ul_tbf,
194 &tbf_ul_egprs_ctrg_desc,
195 ul_tbf->m_ctrs->idx);
196 ul_tbf->m_ul_gprs_ctrs = rate_ctr_group_alloc(ul_tbf,
197 &tbf_ul_gprs_ctrg_desc,
198 ul_tbf->m_ctrs->idx);
199 if (!ul_tbf->m_ctrs || !ul_tbf->m_ul_egprs_ctrs || !ul_tbf->m_ul_gprs_ctrs) {
200 LOGPTBF(ul_tbf, LOGL_ERROR, "Cound not allocate TBF UL rate counters\n");
201 talloc_free(ul_tbf);
202 return NULL;
203 }
204
205 return ul_tbf;
206}
207
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100208gprs_rlcmac_ul_tbf::gprs_rlcmac_ul_tbf(struct gprs_rlcmac_bts *bts_, GprsMs *ms) :
Pau Espin Pedrole9f77d32020-10-23 18:41:40 +0200209 gprs_rlcmac_tbf(bts_, ms, GPRS_RLCMAC_UL_TBF),
Pau Espin Pedrolbddf1ad2019-09-26 14:41:18 +0200210 m_rx_counter(0),
211 m_contention_resolution_done(0),
212 m_final_ack_sent(0),
213 m_ul_gprs_ctrs(NULL),
214 m_ul_egprs_ctrs(NULL)
215{
Pau Espin Pedrol7bd92a32021-03-24 13:14:09 +0100216 memset(&m_usf, USF_INVALID, sizeof(m_usf));
Pau Espin Pedrolbddf1ad2019-09-26 14:41:18 +0200217}
218
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100219/*
220 * Store received block data in LLC message(s) and forward to SGSN
221 * if complete.
222 */
223int gprs_rlcmac_ul_tbf::assemble_forward_llc(const gprs_rlc_data *_data)
224{
225 const uint8_t *data = _data->block;
226 uint8_t len = _data->len;
Jacob Erlbeckf2ba4cb2016-01-07 18:59:28 +0100227 const struct gprs_rlc_data_block_info *rdbi = &_data->block_info;
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +0200228 enum CodingScheme cs = _data->cs_last;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100229
230 Decoding::RlcData frames[16], *frame;
231 int i, num_frames = 0;
232 uint32_t dummy_tlli;
233
Max0524e382018-01-19 18:22:25 +0100234 LOGPTBFUL(this, LOGL_DEBUG, "Assembling frames: (len=%d)\n", len);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100235
236 num_frames = Decoding::rlc_data_from_ul_data(
Alexander Couzensce936f32016-05-24 14:45:41 +0200237 rdbi, cs, data, &(frames[0]), ARRAY_SIZE(frames),
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100238 &dummy_tlli);
239
240 /* create LLC frames */
241 for (i = 0; i < num_frames; i++) {
242 frame = frames + i;
243
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530244 if (frame->length) {
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100245 bts_do_rate_ctr_add(bts, CTR_RLC_UL_PAYLOAD_BYTES, frame->length);
Alexander Couzens7fdbf892016-05-21 19:45:23 +0200246
Max0524e382018-01-19 18:22:25 +0100247 LOGPTBFUL(this, LOGL_DEBUG, "Frame %d "
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530248 "starts at offset %d, "
249 "length=%d, is_complete=%d\n",
250 i + 1, frame->offset, frame->length,
251 frame->is_complete);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100252
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530253 m_llc.append_frame(data + frame->offset, frame->length);
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100254 llc_consume(&m_llc, frame->length);
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530255 }
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100256
257 if (frame->is_complete) {
258 /* send frame to SGSN */
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100259 LOGPTBFUL(this, LOGL_DEBUG, "complete UL frame len=%d\n", llc_frame_length(&m_llc));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100260 snd_ul_ud();
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100261 bts_do_rate_ctr_add(bts, CTR_LLC_UL_BYTES, llc_frame_length(&m_llc));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100262 m_llc.reset();
263 }
264 }
265
266 return 0;
267}
268
Maxfd13f6c2017-07-07 14:29:36 +0200269bool gprs_rlcmac_ul_tbf::ctrl_ack_to_toggle()
270{
Max8dce1de2018-01-02 14:17:04 +0100271 if (check_n_clear(GPRS_RLCMAC_FLAG_TO_UL_ACK))
Maxfd13f6c2017-07-07 14:29:36 +0200272 return true; /* GPRS_RLCMAC_FLAG_TO_UL_ACK was set, now cleared */
Maxfd13f6c2017-07-07 14:29:36 +0200273
274 state_flags |= (1 << GPRS_RLCMAC_FLAG_TO_UL_ACK);
275 return false; /* GPRS_RLCMAC_FLAG_TO_UL_ACK was unset, now set */
276}
277
Pau Espin Pedrol86580e12021-03-29 18:15:30 +0200278bool gprs_rlcmac_ul_tbf::handle_ctrl_ack(enum pdch_ulc_tbf_poll_reason reason)
Maxfd13f6c2017-07-07 14:29:36 +0200279{
280 /* check if this control ack belongs to packet uplink ack */
Pau Espin Pedrol86580e12021-03-29 18:15:30 +0200281 if (reason == PDCH_ULC_POLL_UL_ACK && ul_ack_state_is(GPRS_RLCMAC_UL_ACK_WAIT_ACK)) {
Max088c7df2018-01-23 20:16:23 +0100282 TBF_SET_ACK_STATE(this, GPRS_RLCMAC_UL_ACK_NONE);
Maxfd13f6c2017-07-07 14:29:36 +0200283 return true;
284 }
285
286 return false;
287}
Daniel Willmannca102af2014-08-08 12:14:12 +0200288
Jacob Erlbeck5a3c84d2016-01-22 17:25:38 +0100289struct msgb *gprs_rlcmac_ul_tbf::create_ul_ack(uint32_t fn, uint8_t ts)
Daniel Willmannca102af2014-08-08 12:14:12 +0200290{
291 int final = (state_is(GPRS_RLCMAC_FINISHED));
292 struct msgb *msg;
Jacob Erlbeckf2694b72016-01-26 21:46:26 +0100293 int rc;
294 unsigned int rrbp = 0;
295 uint32_t new_poll_fn = 0;
Daniel Willmannca102af2014-08-08 12:14:12 +0200296
297 if (final) {
Pau Espin Pedroled066b52021-03-29 16:16:27 +0200298 if (ul_ack_state_is(GPRS_RLCMAC_UL_ACK_WAIT_ACK)) {
Maxc21f0072017-12-15 17:36:45 +0100299 LOGPTBFUL(this, LOGL_DEBUG,
300 "Polling is already scheduled, so we must wait for the final uplink ack...\n");
Daniel Willmannca102af2014-08-08 12:14:12 +0200301 return NULL;
302 }
Jacob Erlbeckf2694b72016-01-26 21:46:26 +0100303
304 rc = check_polling(fn, ts, &new_poll_fn, &rrbp);
305 if (rc < 0)
Daniel Willmannca102af2014-08-08 12:14:12 +0200306 return NULL;
Daniel Willmannca102af2014-08-08 12:14:12 +0200307 }
308
309 msg = msgb_alloc(23, "rlcmac_ul_ack");
310 if (!msg)
311 return NULL;
Alexander Couzensccde5c92017-02-04 03:10:08 +0100312 bitvec *ack_vec = bitvec_alloc(23, tall_pcu_ctx);
Daniel Willmannca102af2014-08-08 12:14:12 +0200313 if (!ack_vec) {
314 msgb_free(msg);
315 return NULL;
316 }
Max7426c5f2019-02-18 20:42:42 +0100317 bitvec_unhex(ack_vec, DUMMY_VEC);
Alexander Couzens3a499f32019-06-16 15:25:30 +0200318 Encoding::write_packet_uplink_ack(ack_vec, this, final, rrbp);
Daniel Willmannca102af2014-08-08 12:14:12 +0200319 bitvec_pack(ack_vec, msgb_put(msg, 23));
320 bitvec_free(ack_vec);
Daniel Willmannca102af2014-08-08 12:14:12 +0200321
322 /* now we must set this flag, so we are allowed to assign downlink
323 * TBF on PACCH. it is only allowed when TLLI is acknowledged. */
324 m_contention_resolution_done = 1;
325
326 if (final) {
Pau Espin Pedrol86580e12021-03-29 18:15:30 +0200327 set_polling(new_poll_fn, ts, PDCH_ULC_POLL_UL_ACK);
Daniel Willmannca102af2014-08-08 12:14:12 +0200328 /* waiting for final acknowledge */
Daniel Willmannca102af2014-08-08 12:14:12 +0200329 m_final_ack_sent = 1;
330 } else
Max088c7df2018-01-23 20:16:23 +0100331 TBF_SET_ACK_STATE(this, GPRS_RLCMAC_UL_ACK_NONE);
Daniel Willmannca102af2014-08-08 12:14:12 +0200332
333 return msg;
334}
335
Alexander Couzens2fcfc292016-05-24 14:40:03 +0200336/*! \brief receive data from PDCH/L1 */
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100337int gprs_rlcmac_ul_tbf::rcv_data_block_acknowledged(
Jacob Erlbeckf2ba4cb2016-01-07 18:59:28 +0100338 const struct gprs_rlc_data_info *rlc,
Jacob Erlbeckfc1b3e62016-01-11 09:58:11 +0100339 uint8_t *data, struct pcu_l1_meas *meas)
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100340{
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200341 const struct gprs_rlc_data_block_info *rdbi;
342 struct gprs_rlc_data *block;
343
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100344 int8_t rssi = meas->have_rssi ? meas->rssi : 0;
345
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100346 const uint16_t ws = m_window.ws();
347
348 this->state_flags |= (1 << GPRS_RLCMAC_FLAG_UL_DATA);
349
Max0524e382018-01-19 18:22:25 +0100350 LOGPTBFUL(this, LOGL_DEBUG, "UL DATA TFI=%d received (V(Q)=%d .. "
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100351 "V(R)=%d)\n", rlc->tfi, this->m_window.v_q(),
352 this->m_window.v_r());
353
354 /* process RSSI */
355 gprs_rlcmac_rssi(this, rssi);
356
357 /* store measurement values */
358 if (ms())
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100359 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
364 /* restart T3169 */
Pau Espin Pedrol28f160e2019-09-05 14:48:35 +0200365 T_START(this, T3169, 3169, "acked (data)", true);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100366
367 /* Increment RX-counter */
368 this->m_rx_counter++;
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530369 update_coding_scheme_counter_ul(rlc->cs);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100370 /* Loop over num_blocks */
371 for (block_idx = 0; block_idx < rlc->num_data_blocks; block_idx++) {
372 int num_chunks;
373 uint8_t *rlc_data;
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200374 rdbi = &rlc->block_info[block_idx];
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100375 bool need_rlc_data = false;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100376
Max0524e382018-01-19 18:22:25 +0100377 LOGPTBFUL(this, LOGL_DEBUG,
378 "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 +0100379 mcs_name(rlc->cs),
Max0524e382018-01-19 18:22:25 +0100380 rdbi->cv, rdbi->bsn, rdbi->spb,
381 rdbi->pi, rdbi->e, rdbi->ti,
382 rlc->data_offs_bits[block_idx]);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100383
384 /* Check whether the block needs to be decoded */
385
386 if (!m_window.is_in_window(rdbi->bsn)) {
Max0524e382018-01-19 18:22:25 +0100387 LOGPTBFUL(this, LOGL_DEBUG, "BSN %d out of window %d..%d (it's normal)\n",
388 rdbi->bsn,
389 m_window.v_q(), m_window.mod_sns(m_window.v_q() + ws - 1));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100390 } else if (m_window.is_received(rdbi->bsn)) {
Max0524e382018-01-19 18:22:25 +0100391 LOGPTBFUL(this, LOGL_DEBUG,
392 "BSN %d already received\n", rdbi->bsn);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100393 } else {
394 need_rlc_data = true;
395 }
396
397 if (!is_tlli_valid()) {
398 if (!rdbi->ti) {
Max0524e382018-01-19 18:22:25 +0100399 LOGPTBFUL(this, LOGL_NOTICE, "Missing TLLI within UL DATA.\n");
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100400 continue;
401 }
402 need_rlc_data = true;
403 }
404
405 if (!need_rlc_data)
406 continue;
407
408 /* Store block and meta info to BSN buffer */
409
Max0524e382018-01-19 18:22:25 +0100410 LOGPTBFUL(this, LOGL_DEBUG, "BSN %d storing in window (%d..%d)\n",
411 rdbi->bsn, m_window.v_q(),
412 m_window.mod_sns(m_window.v_q() + ws - 1));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100413 block = m_rlc.block(rdbi->bsn);
Aravind Sirsikar550a5412016-06-14 18:59:18 +0530414 OSMO_ASSERT(rdbi->data_len <= sizeof(block->block));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100415 rlc_data = &(block->block[0]);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100416
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530417 if (rdbi->spb) {
418 egprs_rlc_ul_reseg_bsn_state assemble_status;
419
420 assemble_status = handle_egprs_ul_spb(rlc,
421 block, data, block_idx);
422
423 if (assemble_status != EGPRS_RESEG_DEFAULT)
424 return 0;
425 } else {
426 block->block_info = *rdbi;
427 block->cs_last = rlc->cs;
428 block->len =
429 Decoding::rlc_copy_to_aligned_buffer(rlc,
430 block_idx, data, rlc_data);
431 }
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100432
Max0524e382018-01-19 18:22:25 +0100433 LOGPTBFUL(this, LOGL_DEBUG,
434 "data_length=%d, data=%s\n",
435 block->len, osmo_hexdump(rlc_data, block->len));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100436 /* Get/Handle TLLI */
437 if (rdbi->ti) {
438 num_chunks = Decoding::rlc_data_from_ul_data(
439 rdbi, rlc->cs, rlc_data, NULL, 0, &new_tlli);
440
441 if (num_chunks < 0) {
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100442 bts_do_rate_ctr_inc(bts, CTR_DECODE_ERRORS);
Max0524e382018-01-19 18:22:25 +0100443 LOGPTBFUL(this, LOGL_NOTICE,
444 "Failed to decode TLLI of %s UL DATA TFI=%d.\n",
Max136ebcc2019-03-05 14:59:03 +0100445 mcs_name(rlc->cs), rlc->tfi);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100446 m_window.invalidate_bsn(rdbi->bsn);
447 continue;
448 }
449 if (!this->is_tlli_valid()) {
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700450 if (new_tlli == GSM_RESERVED_TMSI) {
Max0524e382018-01-19 18:22:25 +0100451 LOGPTBFUL(this, LOGL_NOTICE,
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700452 "TLLI is 0x%08x within UL DATA?!?\n",
453 new_tlli);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100454 m_window.invalidate_bsn(rdbi->bsn);
455 continue;
456 }
Max0524e382018-01-19 18:22:25 +0100457 LOGPTBFUL(this, LOGL_INFO,
458 "Decoded premier TLLI=0x%08x of UL DATA TFI=%d.\n",
Vadim Yanitskiy3f27fb52020-04-20 11:26:12 +0700459 new_tlli, rlc->tfi);
Pau Espin Pedrold21e9612020-06-26 14:20:37 +0200460 update_ms(new_tlli, GPRS_RLCMAC_UL_TBF);
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700461 } else if (new_tlli != GSM_RESERVED_TMSI && new_tlli != tlli()) {
Max0524e382018-01-19 18:22:25 +0100462 LOGPTBFUL(this, LOGL_NOTICE,
Pau Espin Pedrol305763d2020-11-06 20:03:24 +0100463 "Decoded TLLI=%08x mismatch on UL DATA TFI=%d. (Ignoring due to contention resolution)\n",
464 new_tlli, rlc->tfi);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100465 m_window.invalidate_bsn(rdbi->bsn);
466 continue;
467 }
468 }
469
470 m_window.receive_bsn(rdbi->bsn);
471 }
472
473 /* Raise V(Q) if possible, and retrieve LLC frames from blocks.
474 * This is looped until there is a gap (non received block) or
475 * the window is empty.*/
476 const uint16_t v_q_beg = m_window.v_q();
477 const uint16_t count = m_window.raise_v_q();
478
479 /* Retrieve LLC frames from blocks that are ready */
480 for (uint16_t i = 0; i < count; ++i) {
Jacob Erlbeck93c55d02015-12-23 16:29:07 +0100481 uint16_t index = m_window.mod_sns(v_q_beg + i);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100482 assemble_forward_llc(m_rlc.block(index));
483 }
484
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200485 /* Last frame in buffer: */
486 block = m_rlc.block(m_window.mod_sns(m_window.v_r() - 1));
487 rdbi = &block->block_info;
488
489 /* Check if we already received all data TBF had to send: */
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100490 if (this->state_is(GPRS_RLCMAC_FLOW) /* still in flow state */
491 && this->m_window.v_q() == this->m_window.v_r()) { /* if complete */
Max0524e382018-01-19 18:22:25 +0100492 LOGPTBFUL(this, LOGL_DEBUG,
493 "No gaps in received block, last block: BSN=%d CV=%d\n",
494 rdbi->bsn, rdbi->cv);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100495 if (rdbi->cv == 0) {
Max0524e382018-01-19 18:22:25 +0100496 LOGPTBFUL(this, LOGL_DEBUG, "Finished with UL TBF\n");
Max2399b1d2018-01-12 15:48:12 +0100497 TBF_SET_STATE(this, GPRS_RLCMAC_FINISHED);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100498 /* Reset N3103 counter. */
Max847ed9f2018-02-20 18:16:11 +0100499 this->n_reset(N3103);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100500 }
501 }
502
503 /* If TLLI is included or if we received half of the window, we send
504 * an ack/nack */
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200505 maybe_schedule_uplink_acknack(rlc, rdbi->cv == 0);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100506
507 return 0;
508}
509
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100510void gprs_rlcmac_ul_tbf::maybe_schedule_uplink_acknack(
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200511 const gprs_rlc_data_info *rlc, bool countdown_finished)
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100512{
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200513 bool require_ack = false;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100514 bool have_ti = rlc->block_info[0].ti ||
515 (rlc->num_data_blocks > 1 && rlc->block_info[1].ti);
516
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200517 if (rlc->si) {
518 require_ack = true;
519 LOGPTBFUL(this, LOGL_NOTICE,
520 "Scheduling Ack/Nack, because MS is stalled.\n");
521 }
522 if (have_ti) {
523 require_ack = true;
524 LOGPTBFUL(this, LOGL_DEBUG,
525 "Scheduling Ack/Nack, because TLLI is included.\n");
526 }
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200527 if (countdown_finished) {
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200528 require_ack = true;
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200529 if (state_is(GPRS_RLCMAC_FLOW))
530 LOGPTBFUL(this, LOGL_DEBUG,
531 "Scheduling Ack/Nack, because some data is missing and last block has CV==0.\n");
532 else if (state_is(GPRS_RLCMAC_FINISHED))
533 LOGPTBFUL(this, LOGL_DEBUG,
534 "Scheduling final Ack/Nack, because all data was received and last block has CV==0.\n");
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200535 }
536 if ((m_rx_counter % SEND_ACK_AFTER_FRAMES) == 0) {
537 require_ack = true;
538 LOGPTBFUL(this, LOGL_DEBUG,
539 "Scheduling Ack/Nack, because %d frames received.\n",
540 SEND_ACK_AFTER_FRAMES);
541 }
542
543 if (!require_ack)
544 return;
545
546 if (ul_ack_state_is(GPRS_RLCMAC_UL_ACK_NONE)) {
547 /* trigger sending at next RTS */
548 TBF_SET_ACK_STATE(this, GPRS_RLCMAC_UL_ACK_SEND_ACK);
549 } else {
550 /* already triggered */
551 LOGPTBFUL(this, LOGL_DEBUG,
552 "Sending Ack/Nack already scheduled, no need to re-schedule\n");
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100553 }
554}
555
Daniel Willmannca102af2014-08-08 12:14:12 +0200556/* Send Uplink unit-data to SGSN. */
557int gprs_rlcmac_ul_tbf::snd_ul_ud()
558{
559 uint8_t qos_profile[3];
560 struct msgb *llc_pdu;
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100561 unsigned msg_len = NS_HDR_LEN + BSSGP_HDR_LEN + llc_frame_length(&m_llc);
Pau Espin Pedroldb5e3392021-01-21 18:02:40 +0100562 struct bssgp_bvc_ctx *bctx = bts->pcu->bssgp.bctx;
Daniel Willmannca102af2014-08-08 12:14:12 +0200563
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100564 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 +0200565 if (!bctx) {
566 LOGP(DBSSGP, LOGL_ERROR, "No bctx\n");
567 m_llc.reset_frame_space();
568 return -EIO;
569 }
Pau Espin Pedrol488aa292019-09-25 17:48:35 +0200570
Daniel Willmannca102af2014-08-08 12:14:12 +0200571 llc_pdu = msgb_alloc_headroom(msg_len, msg_len,"llc_pdu");
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100572 uint8_t *buf = msgb_push(llc_pdu, TL16V_GROSS_LEN(sizeof(uint8_t)*llc_frame_length(&m_llc)));
573 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 +0200574 qos_profile[0] = QOS_PROFILE >> 16;
575 qos_profile[1] = QOS_PROFILE >> 8;
576 qos_profile[2] = QOS_PROFILE;
577 bssgp_tx_ul_ud(bctx, tlli(), qos_profile, llc_pdu);
578
579 m_llc.reset_frame_space();
580 return 0;
581}
582
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530583egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_second_seg(
584 const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block,
585 uint8_t *data, const uint8_t block_idx)
586{
587 const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx];
588 union split_block_status *spb_status = &block->spb_status;
589 uint8_t *rlc_data = &block->block[0];
590
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100591 bts_do_rate_ctr_inc(bts, CTR_SPB_UL_SECOND_SEGMENT);
sivasankarida7250a2016-12-16 12:57:18 +0530592
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530593 if (spb_status->block_status_ul &
594 EGPRS_RESEG_FIRST_SEG_RXD) {
Max0524e382018-01-19 18:22:25 +0100595 LOGPTBFUL(this, LOGL_DEBUG,
596 "Second seg is received first seg is already present set the status to complete\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530597 spb_status->block_status_ul = EGPRS_RESEG_DEFAULT;
598
599 block->len += Decoding::rlc_copy_to_aligned_buffer(rlc,
600 block_idx, data, rlc_data + block->len);
601 block->block_info.data_len += rdbi->data_len;
602 } else if (spb_status->block_status_ul == EGPRS_RESEG_DEFAULT) {
Max0524e382018-01-19 18:22:25 +0100603 LOGPTBFUL(this, LOGL_DEBUG,
604 "Second seg is received first seg is not received set the status to second seg received\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530605
606 block->len = Decoding::rlc_copy_to_aligned_buffer(rlc,
607 block_idx, data,
608 rlc_data + rlc->block_info[block_idx].data_len);
609
610 spb_status->block_status_ul = EGPRS_RESEG_SECOND_SEG_RXD;
611 block->block_info = *rdbi;
612 }
613 return spb_status->block_status_ul;
614}
615
616egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_first_seg(
617 const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block,
618 uint8_t *data, const uint8_t block_idx)
619{
620 const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx];
621 uint8_t *rlc_data = &block->block[0];
622 union split_block_status *spb_status = &block->spb_status;
623
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100624 bts_do_rate_ctr_inc(bts, CTR_SPB_UL_FIRST_SEGMENT);
sivasankarida7250a2016-12-16 12:57:18 +0530625
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530626 if (spb_status->block_status_ul & EGPRS_RESEG_SECOND_SEG_RXD) {
Max0524e382018-01-19 18:22:25 +0100627 LOGPTBFUL(this, LOGL_DEBUG,
628 "First seg is received second seg is already present set the status to complete\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530629
630 block->len += Decoding::rlc_copy_to_aligned_buffer(rlc,
631 block_idx, data, rlc_data);
632
633 block->block_info.data_len = block->len;
634 spb_status->block_status_ul = EGPRS_RESEG_DEFAULT;
635 } else if (spb_status->block_status_ul == EGPRS_RESEG_DEFAULT) {
Max0524e382018-01-19 18:22:25 +0100636 LOGPTBFUL(this, LOGL_DEBUG,
637 "First seg is received second seg is not received set the status to first seg received\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530638
639 spb_status->block_status_ul = EGPRS_RESEG_FIRST_SEG_RXD;
640 block->len = Decoding::rlc_copy_to_aligned_buffer(rlc,
641 block_idx, data, rlc_data);
642 block->block_info = *rdbi;
643 }
644 return spb_status->block_status_ul;
645}
646
647egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_spb(
648 const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block,
649 uint8_t *data, const uint8_t block_idx)
650{
651 const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx];
652
Max0524e382018-01-19 18:22:25 +0100653 LOGPTBFUL(this, LOGL_DEBUG,
654 "Got SPB(%d) cs(%s) data block with BSN (%d), TFI(%d).\n",
Max136ebcc2019-03-05 14:59:03 +0100655 rdbi->spb, mcs_name(rlc->cs), rdbi->bsn, rlc->tfi);
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530656
657 egprs_rlc_ul_reseg_bsn_state assemble_status = EGPRS_RESEG_INVALID;
658
659 /* Section 10.4.8b of 44.060*/
660 if (rdbi->spb == 2)
661 assemble_status = handle_egprs_ul_first_seg(rlc,
662 block, data, block_idx);
663 else if (rdbi->spb == 3)
664 assemble_status = handle_egprs_ul_second_seg(rlc,
665 block, data, block_idx);
666 else {
Max0524e382018-01-19 18:22:25 +0100667 LOGPTBFUL(this, LOGL_ERROR,
668 "spb(%d) Not supported SPB for this EGPRS configuration\n",
669 rdbi->spb);
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530670 }
671
672 /*
673 * When the block is successfully constructed out of segmented blocks
674 * upgrade the MCS to the type 2
675 */
676 if (assemble_status == EGPRS_RESEG_DEFAULT) {
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +0200677 switch (rlc->cs) {
Maxbea2edb2019-03-06 17:04:59 +0100678 case MCS3 :
679 block->cs_last = MCS6;
Max0524e382018-01-19 18:22:25 +0100680 LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS6\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530681 break;
Maxbea2edb2019-03-06 17:04:59 +0100682 case MCS2 :
683 block->cs_last = MCS5;
Max0524e382018-01-19 18:22:25 +0100684 LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS5\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530685 break;
Maxbea2edb2019-03-06 17:04:59 +0100686 case MCS1 :
Max0524e382018-01-19 18:22:25 +0100687 LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS4\n");
Maxbea2edb2019-03-06 17:04:59 +0100688 block->cs_last = MCS4;
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530689 break;
690 default:
Max0524e382018-01-19 18:22:25 +0100691 LOGPTBFUL(this, LOGL_ERROR,
692 "cs(%s) Error in Upgrading to higher MCS\n",
Max136ebcc2019-03-05 14:59:03 +0100693 mcs_name(rlc->cs));
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530694 break;
695 }
696 }
697 return assemble_status;
698}
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530699
Maxfb59a932019-03-13 18:40:19 +0100700void gprs_rlcmac_ul_tbf::update_coding_scheme_counter_ul(enum CodingScheme cs)
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530701{
Maxfb59a932019-03-13 18:40:19 +0100702 switch (cs) {
703 case CS1:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100704 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS1);
Maxfb59a932019-03-13 18:40:19 +0100705 rate_ctr_inc(&m_ul_gprs_ctrs->ctr[TBF_CTR_GPRS_UL_CS1]);
706 break;
707 case CS2:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100708 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS2);
Maxfb59a932019-03-13 18:40:19 +0100709 rate_ctr_inc(&m_ul_gprs_ctrs->ctr[TBF_CTR_GPRS_UL_CS2]);
710 break;
711 case CS3:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100712 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS3);
Maxfb59a932019-03-13 18:40:19 +0100713 rate_ctr_inc(&m_ul_gprs_ctrs->ctr[TBF_CTR_GPRS_UL_CS3]);
714 break;
715 case CS4:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100716 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS4);
Maxfb59a932019-03-13 18:40:19 +0100717 rate_ctr_inc(&m_ul_gprs_ctrs->ctr[TBF_CTR_GPRS_UL_CS4]);
718 break;
719 case MCS1:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100720 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS1);
Maxfb59a932019-03-13 18:40:19 +0100721 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS1]);
722 break;
723 case MCS2:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100724 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS2);
Maxfb59a932019-03-13 18:40:19 +0100725 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS2]);
726 break;
727 case MCS3:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100728 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS3);
Maxfb59a932019-03-13 18:40:19 +0100729 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS3]);
730 break;
731 case MCS4:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100732 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS4);
Maxfb59a932019-03-13 18:40:19 +0100733 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS4]);
734 break;
735 case MCS5:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100736 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS5);
Maxfb59a932019-03-13 18:40:19 +0100737 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS5]);
738 break;
739 case MCS6:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100740 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS6);
Maxfb59a932019-03-13 18:40:19 +0100741 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS6]);
742 break;
743 case MCS7:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100744 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS7);
Maxfb59a932019-03-13 18:40:19 +0100745 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS7]);
746 break;
747 case MCS8:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100748 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS8);
Maxfb59a932019-03-13 18:40:19 +0100749 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS8]);
750 break;
751 case MCS9:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100752 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS9);
Maxfb59a932019-03-13 18:40:19 +0100753 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS9]);
754 break;
755 default:
756 LOGPTBFUL(this, LOGL_ERROR, "attempting to update rate counters for unsupported (M)CS %s\n",
757 mcs_name(cs));
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530758 }
759}
sivasankari8adfcd02017-01-16 15:41:21 +0530760
Max9d7357e2017-12-14 15:02:33 +0100761void gprs_rlcmac_ul_tbf::set_window_size()
sivasankari8adfcd02017-01-16 15:41:21 +0530762{
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100763 const struct gprs_rlcmac_bts *b = bts;
Max34513fe2018-12-11 16:47:30 +0100764 uint16_t ws = egprs_window_size(b, ul_slots());
Max0524e382018-01-19 18:22:25 +0100765 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 +0100766 ws, bts->pcu->vty.ws_base, pcu_bitcount(ul_slots()), bts->pcu->vty.ws_pdch);
sivasankari8adfcd02017-01-16 15:41:21 +0530767 m_window.set_ws(ws);
768}
Pau Espin Pedrol9767e442020-10-23 21:11:41 +0200769
Pau Espin Pedrolb3f23972020-10-23 21:00:23 +0200770gprs_rlc_window *gprs_rlcmac_ul_tbf::window()
Pau Espin Pedrol9767e442020-10-23 21:11:41 +0200771{
772 return &m_window;
773}
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100774
Pau Espin Pedrol0b998b12021-03-24 14:45:43 +0100775void gprs_rlcmac_ul_tbf::usf_timeout()
776{
777 if (n_inc(N3101)) {
778 TBF_SET_STATE(this, GPRS_RLCMAC_RELEASING);
779 T_START(this, T3169, 3169, "MAX N3101 reached", false);
780 return;
781 }
782}
783
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100784struct gprs_rlcmac_ul_tbf *as_ul_tbf(struct gprs_rlcmac_tbf *tbf)
785{
786 if (tbf && tbf->direction == GPRS_RLCMAC_UL_TBF)
787 return static_cast<gprs_rlcmac_ul_tbf *>(tbf);
788 else
789 return NULL;
790}
Pau Espin Pedrol0b998b12021-03-24 14:45:43 +0100791
792void tbf_usf_timeout(struct gprs_rlcmac_ul_tbf *tbf)
793{
794 tbf->usf_timeout();
795}