blob: cf8c75c54202a6dcf691ecd208ca2cfdae3e3d64 [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
Pau Espin Pedrol54742f22021-04-26 16:48:34 +020099/* 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 +0200100struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_tbf(struct gprs_rlcmac_bts *bts, GprsMs *ms, int8_t use_trx, bool single_slot)
101{
102 struct gprs_rlcmac_ul_tbf *tbf;
103 int rc;
104
105 OSMO_ASSERT(ms != NULL);
106
Pau Espin Pedrol36177c62021-02-25 17:57:37 +0100107 LOGPMS(ms, DTBF, LOGL_DEBUG, "********** UL-TBF starts here **********\n");
108 LOGPMS(ms, DTBF, LOGL_INFO, "Allocating UL TBF\n");
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200109
110 tbf = talloc(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
111 if (!tbf)
112 return NULL;
113 talloc_set_destructor(tbf, ul_tbf_dtor);
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100114 new (tbf) gprs_rlcmac_ul_tbf(bts, ms);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200115
116 rc = tbf->setup(use_trx, single_slot);
117
118 /* if no resource */
119 if (rc < 0) {
120 talloc_free(tbf);
121 return NULL;
122 }
123
124 if (tbf->is_egprs_enabled())
125 tbf->set_window_size();
126
127 tbf->m_ul_egprs_ctrs = rate_ctr_group_alloc(tbf,
128 &tbf_ul_egprs_ctrg_desc, tbf->m_ctrs->idx);
129 tbf->m_ul_gprs_ctrs = rate_ctr_group_alloc(tbf,
130 &tbf_ul_gprs_ctrg_desc, tbf->m_ctrs->idx);
131 if (!tbf->m_ul_egprs_ctrs || !tbf->m_ul_gprs_ctrs) {
132 LOGPTBF(tbf, LOGL_ERROR, "Couldn't allocate TBF UL counters\n");
133 talloc_free(tbf);
134 return NULL;
135 }
136
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100137 llist_add_tail(tbf_bts_list(tbf), &bts->ul_tbfs);
138 bts_do_rate_ctr_inc(tbf->bts, CTR_TBF_UL_ALLOCATED);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200139
140 return tbf;
141}
142
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200143/* Alloc a UL TBF to be assigned over PACCH */
Pau Espin Pedrolc6571b52021-05-10 17:10:37 +0200144gprs_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 +0200145 uint32_t tlli)
146{
147 struct gprs_rlcmac_ul_tbf *tbf;
148
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200149 tbf = tbf_alloc_ul_tbf(bts, ms, use_trx, false);
150 if (!tbf) {
Pau Espin Pedrol36177c62021-02-25 17:57:37 +0100151 LOGPMS(ms, DTBF, LOGL_NOTICE, "No PDCH resource\n");
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200152 /* Caller will most probably send a Imm Ass Reject after return */
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200153 return NULL;
154 }
155 tbf->m_contention_resolution_done = 1;
156 TBF_SET_ASS_ON(tbf, GPRS_RLCMAC_FLAG_PACCH, false);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200157 tbf->update_ms(tlli, GPRS_RLCMAC_UL_TBF);
158 OSMO_ASSERT(tbf->ms());
159
160 return tbf;
161}
162
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200163/* Create a temporary dummy TBF to Tx a ImmAssReject if allocating a new one during
164 * packet resource Request failed. This is similar as tbf_alloc_ul() but without
165 * calling tbf->setup() (in charge of TFI/USF allocation), and reusing resources
166 * from Packet Resource Request we received. See TS 44.060 sec 7.1.3.2.1 */
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200167struct gprs_rlcmac_ul_tbf *handle_tbf_reject(struct gprs_rlcmac_bts *bts,
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200168 GprsMs *ms, uint8_t trx_no, uint8_t ts)
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200169{
170 struct gprs_rlcmac_ul_tbf *ul_tbf = NULL;
171 struct gprs_rlcmac_trx *trx = &bts->trx[trx_no];
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200172 OSMO_ASSERT(ms);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200173
174 ul_tbf = talloc(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
175 if (!ul_tbf)
176 return ul_tbf;
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200177 talloc_set_destructor(ul_tbf, ul_tbf_dtor);
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100178 new (ul_tbf) gprs_rlcmac_ul_tbf(bts, ms);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200179
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200180 ul_tbf->control_ts = ts;
181 ul_tbf->trx = trx;
182 ul_tbf->m_ctrs = rate_ctr_group_alloc(ul_tbf, &tbf_ctrg_desc, next_tbf_ctr_group_id++);
183 ul_tbf->m_ul_egprs_ctrs = rate_ctr_group_alloc(ul_tbf,
184 &tbf_ul_egprs_ctrg_desc,
185 ul_tbf->m_ctrs->idx);
186 ul_tbf->m_ul_gprs_ctrs = rate_ctr_group_alloc(ul_tbf,
187 &tbf_ul_gprs_ctrg_desc,
188 ul_tbf->m_ctrs->idx);
189 if (!ul_tbf->m_ctrs || !ul_tbf->m_ul_egprs_ctrs || !ul_tbf->m_ul_gprs_ctrs) {
190 LOGPTBF(ul_tbf, LOGL_ERROR, "Cound not allocate TBF UL rate counters\n");
191 talloc_free(ul_tbf);
192 return NULL;
193 }
194
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200195 ms_attach_tbf(ms, ul_tbf);
196 llist_add(tbf_bts_list((struct gprs_rlcmac_tbf *)ul_tbf), &bts->ul_tbfs);
197 bts_do_rate_ctr_inc(ul_tbf->bts, CTR_TBF_UL_ALLOCATED);
198 TBF_SET_ASS_ON(ul_tbf, GPRS_RLCMAC_FLAG_PACCH, false);
199 TBF_SET_ASS_STATE_UL(ul_tbf, GPRS_RLCMAC_UL_ASS_SEND_ASS_REJ);
200
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200201 return ul_tbf;
202}
203
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100204gprs_rlcmac_ul_tbf::gprs_rlcmac_ul_tbf(struct gprs_rlcmac_bts *bts_, GprsMs *ms) :
Pau Espin Pedrole9f77d32020-10-23 18:41:40 +0200205 gprs_rlcmac_tbf(bts_, ms, GPRS_RLCMAC_UL_TBF),
Pau Espin Pedrolbddf1ad2019-09-26 14:41:18 +0200206 m_rx_counter(0),
207 m_contention_resolution_done(0),
208 m_final_ack_sent(0),
209 m_ul_gprs_ctrs(NULL),
210 m_ul_egprs_ctrs(NULL)
211{
Pau Espin Pedrol7bd92a32021-03-24 13:14:09 +0100212 memset(&m_usf, USF_INVALID, sizeof(m_usf));
Pau Espin Pedrolbddf1ad2019-09-26 14:41:18 +0200213}
214
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100215/*
216 * Store received block data in LLC message(s) and forward to SGSN
217 * if complete.
218 */
219int gprs_rlcmac_ul_tbf::assemble_forward_llc(const gprs_rlc_data *_data)
220{
221 const uint8_t *data = _data->block;
222 uint8_t len = _data->len;
Jacob Erlbeckf2ba4cb2016-01-07 18:59:28 +0100223 const struct gprs_rlc_data_block_info *rdbi = &_data->block_info;
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +0200224 enum CodingScheme cs = _data->cs_last;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100225
226 Decoding::RlcData frames[16], *frame;
227 int i, num_frames = 0;
228 uint32_t dummy_tlli;
229
Max0524e382018-01-19 18:22:25 +0100230 LOGPTBFUL(this, LOGL_DEBUG, "Assembling frames: (len=%d)\n", len);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100231
232 num_frames = Decoding::rlc_data_from_ul_data(
Alexander Couzensce936f32016-05-24 14:45:41 +0200233 rdbi, cs, data, &(frames[0]), ARRAY_SIZE(frames),
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100234 &dummy_tlli);
235
236 /* create LLC frames */
237 for (i = 0; i < num_frames; i++) {
238 frame = frames + i;
239
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530240 if (frame->length) {
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100241 bts_do_rate_ctr_add(bts, CTR_RLC_UL_PAYLOAD_BYTES, frame->length);
Alexander Couzens7fdbf892016-05-21 19:45:23 +0200242
Max0524e382018-01-19 18:22:25 +0100243 LOGPTBFUL(this, LOGL_DEBUG, "Frame %d "
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530244 "starts at offset %d, "
245 "length=%d, is_complete=%d\n",
246 i + 1, frame->offset, frame->length,
247 frame->is_complete);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100248
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530249 m_llc.append_frame(data + frame->offset, frame->length);
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100250 llc_consume(&m_llc, frame->length);
Aravind Sirsikar22a90192016-09-15 17:24:49 +0530251 }
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100252
253 if (frame->is_complete) {
254 /* send frame to SGSN */
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100255 LOGPTBFUL(this, LOGL_DEBUG, "complete UL frame len=%d\n", llc_frame_length(&m_llc));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100256 snd_ul_ud();
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100257 bts_do_rate_ctr_add(bts, CTR_LLC_UL_BYTES, llc_frame_length(&m_llc));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100258 m_llc.reset();
259 }
260 }
261
262 return 0;
263}
264
Maxfd13f6c2017-07-07 14:29:36 +0200265bool gprs_rlcmac_ul_tbf::ctrl_ack_to_toggle()
266{
Max8dce1de2018-01-02 14:17:04 +0100267 if (check_n_clear(GPRS_RLCMAC_FLAG_TO_UL_ACK))
Maxfd13f6c2017-07-07 14:29:36 +0200268 return true; /* GPRS_RLCMAC_FLAG_TO_UL_ACK was set, now cleared */
Maxfd13f6c2017-07-07 14:29:36 +0200269
270 state_flags |= (1 << GPRS_RLCMAC_FLAG_TO_UL_ACK);
271 return false; /* GPRS_RLCMAC_FLAG_TO_UL_ACK was unset, now set */
272}
273
Pau Espin Pedrol86580e12021-03-29 18:15:30 +0200274bool gprs_rlcmac_ul_tbf::handle_ctrl_ack(enum pdch_ulc_tbf_poll_reason reason)
Maxfd13f6c2017-07-07 14:29:36 +0200275{
276 /* check if this control ack belongs to packet uplink ack */
Pau Espin Pedrol86580e12021-03-29 18:15:30 +0200277 if (reason == PDCH_ULC_POLL_UL_ACK && ul_ack_state_is(GPRS_RLCMAC_UL_ACK_WAIT_ACK)) {
Max088c7df2018-01-23 20:16:23 +0100278 TBF_SET_ACK_STATE(this, GPRS_RLCMAC_UL_ACK_NONE);
Maxfd13f6c2017-07-07 14:29:36 +0200279 return true;
280 }
281
282 return false;
283}
Daniel Willmannca102af2014-08-08 12:14:12 +0200284
Jacob Erlbeck5a3c84d2016-01-22 17:25:38 +0100285struct msgb *gprs_rlcmac_ul_tbf::create_ul_ack(uint32_t fn, uint8_t ts)
Daniel Willmannca102af2014-08-08 12:14:12 +0200286{
287 int final = (state_is(GPRS_RLCMAC_FINISHED));
288 struct msgb *msg;
Jacob Erlbeckf2694b72016-01-26 21:46:26 +0100289 int rc;
290 unsigned int rrbp = 0;
291 uint32_t new_poll_fn = 0;
Daniel Willmannca102af2014-08-08 12:14:12 +0200292
293 if (final) {
Pau Espin Pedroled066b52021-03-29 16:16:27 +0200294 if (ul_ack_state_is(GPRS_RLCMAC_UL_ACK_WAIT_ACK)) {
Maxc21f0072017-12-15 17:36:45 +0100295 LOGPTBFUL(this, LOGL_DEBUG,
296 "Polling is already scheduled, so we must wait for the final uplink ack...\n");
Daniel Willmannca102af2014-08-08 12:14:12 +0200297 return NULL;
298 }
Jacob Erlbeckf2694b72016-01-26 21:46:26 +0100299
300 rc = check_polling(fn, ts, &new_poll_fn, &rrbp);
301 if (rc < 0)
Daniel Willmannca102af2014-08-08 12:14:12 +0200302 return NULL;
Daniel Willmannca102af2014-08-08 12:14:12 +0200303 }
304
305 msg = msgb_alloc(23, "rlcmac_ul_ack");
306 if (!msg)
307 return NULL;
Alexander Couzensccde5c92017-02-04 03:10:08 +0100308 bitvec *ack_vec = bitvec_alloc(23, tall_pcu_ctx);
Daniel Willmannca102af2014-08-08 12:14:12 +0200309 if (!ack_vec) {
310 msgb_free(msg);
311 return NULL;
312 }
Max7426c5f2019-02-18 20:42:42 +0100313 bitvec_unhex(ack_vec, DUMMY_VEC);
Alexander Couzens3a499f32019-06-16 15:25:30 +0200314 Encoding::write_packet_uplink_ack(ack_vec, this, final, rrbp);
Daniel Willmannca102af2014-08-08 12:14:12 +0200315 bitvec_pack(ack_vec, msgb_put(msg, 23));
316 bitvec_free(ack_vec);
Daniel Willmannca102af2014-08-08 12:14:12 +0200317
318 /* now we must set this flag, so we are allowed to assign downlink
319 * TBF on PACCH. it is only allowed when TLLI is acknowledged. */
320 m_contention_resolution_done = 1;
321
322 if (final) {
Pau Espin Pedrol86580e12021-03-29 18:15:30 +0200323 set_polling(new_poll_fn, ts, PDCH_ULC_POLL_UL_ACK);
Daniel Willmannca102af2014-08-08 12:14:12 +0200324 /* waiting for final acknowledge */
Daniel Willmannca102af2014-08-08 12:14:12 +0200325 m_final_ack_sent = 1;
326 } else
Max088c7df2018-01-23 20:16:23 +0100327 TBF_SET_ACK_STATE(this, GPRS_RLCMAC_UL_ACK_NONE);
Daniel Willmannca102af2014-08-08 12:14:12 +0200328
329 return msg;
330}
331
Alexander Couzens2fcfc292016-05-24 14:40:03 +0200332/*! \brief receive data from PDCH/L1 */
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100333int gprs_rlcmac_ul_tbf::rcv_data_block_acknowledged(
Jacob Erlbeckf2ba4cb2016-01-07 18:59:28 +0100334 const struct gprs_rlc_data_info *rlc,
Jacob Erlbeckfc1b3e62016-01-11 09:58:11 +0100335 uint8_t *data, struct pcu_l1_meas *meas)
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100336{
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200337 const struct gprs_rlc_data_block_info *rdbi;
338 struct gprs_rlc_data *block;
339
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100340 int8_t rssi = meas->have_rssi ? meas->rssi : 0;
341
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100342 const uint16_t ws = m_window.ws();
343
344 this->state_flags |= (1 << GPRS_RLCMAC_FLAG_UL_DATA);
345
Max0524e382018-01-19 18:22:25 +0100346 LOGPTBFUL(this, LOGL_DEBUG, "UL DATA TFI=%d received (V(Q)=%d .. "
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100347 "V(R)=%d)\n", rlc->tfi, this->m_window.v_q(),
348 this->m_window.v_r());
349
350 /* process RSSI */
351 gprs_rlcmac_rssi(this, rssi);
352
353 /* store measurement values */
354 if (ms())
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100355 ms_update_l1_meas(ms(), meas);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100356
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700357 uint32_t new_tlli = GSM_RESERVED_TMSI;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100358 unsigned int block_idx;
359
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100360 /* Increment RX-counter */
361 this->m_rx_counter++;
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530362 update_coding_scheme_counter_ul(rlc->cs);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100363 /* Loop over num_blocks */
364 for (block_idx = 0; block_idx < rlc->num_data_blocks; block_idx++) {
365 int num_chunks;
366 uint8_t *rlc_data;
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200367 rdbi = &rlc->block_info[block_idx];
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100368 bool need_rlc_data = false;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100369
Max0524e382018-01-19 18:22:25 +0100370 LOGPTBFUL(this, LOGL_DEBUG,
371 "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 +0100372 mcs_name(rlc->cs),
Max0524e382018-01-19 18:22:25 +0100373 rdbi->cv, rdbi->bsn, rdbi->spb,
374 rdbi->pi, rdbi->e, rdbi->ti,
375 rlc->data_offs_bits[block_idx]);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100376
377 /* Check whether the block needs to be decoded */
378
379 if (!m_window.is_in_window(rdbi->bsn)) {
Max0524e382018-01-19 18:22:25 +0100380 LOGPTBFUL(this, LOGL_DEBUG, "BSN %d out of window %d..%d (it's normal)\n",
381 rdbi->bsn,
382 m_window.v_q(), m_window.mod_sns(m_window.v_q() + ws - 1));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100383 } else if (m_window.is_received(rdbi->bsn)) {
Max0524e382018-01-19 18:22:25 +0100384 LOGPTBFUL(this, LOGL_DEBUG,
385 "BSN %d already received\n", rdbi->bsn);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100386 } else {
387 need_rlc_data = true;
388 }
389
390 if (!is_tlli_valid()) {
391 if (!rdbi->ti) {
Max0524e382018-01-19 18:22:25 +0100392 LOGPTBFUL(this, LOGL_NOTICE, "Missing TLLI within UL DATA.\n");
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100393 continue;
394 }
395 need_rlc_data = true;
396 }
397
398 if (!need_rlc_data)
399 continue;
400
401 /* Store block and meta info to BSN buffer */
402
Max0524e382018-01-19 18:22:25 +0100403 LOGPTBFUL(this, LOGL_DEBUG, "BSN %d storing in window (%d..%d)\n",
404 rdbi->bsn, m_window.v_q(),
405 m_window.mod_sns(m_window.v_q() + ws - 1));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100406 block = m_rlc.block(rdbi->bsn);
Aravind Sirsikar550a5412016-06-14 18:59:18 +0530407 OSMO_ASSERT(rdbi->data_len <= sizeof(block->block));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100408 rlc_data = &(block->block[0]);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100409
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530410 if (rdbi->spb) {
411 egprs_rlc_ul_reseg_bsn_state assemble_status;
412
413 assemble_status = handle_egprs_ul_spb(rlc,
414 block, data, block_idx);
415
416 if (assemble_status != EGPRS_RESEG_DEFAULT)
417 return 0;
418 } else {
419 block->block_info = *rdbi;
420 block->cs_last = rlc->cs;
421 block->len =
422 Decoding::rlc_copy_to_aligned_buffer(rlc,
423 block_idx, data, rlc_data);
424 }
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100425
Max0524e382018-01-19 18:22:25 +0100426 LOGPTBFUL(this, LOGL_DEBUG,
427 "data_length=%d, data=%s\n",
428 block->len, osmo_hexdump(rlc_data, block->len));
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100429 /* Get/Handle TLLI */
430 if (rdbi->ti) {
431 num_chunks = Decoding::rlc_data_from_ul_data(
432 rdbi, rlc->cs, rlc_data, NULL, 0, &new_tlli);
433
434 if (num_chunks < 0) {
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100435 bts_do_rate_ctr_inc(bts, CTR_DECODE_ERRORS);
Max0524e382018-01-19 18:22:25 +0100436 LOGPTBFUL(this, LOGL_NOTICE,
437 "Failed to decode TLLI of %s UL DATA TFI=%d.\n",
Max136ebcc2019-03-05 14:59:03 +0100438 mcs_name(rlc->cs), rlc->tfi);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100439 m_window.invalidate_bsn(rdbi->bsn);
440 continue;
441 }
442 if (!this->is_tlli_valid()) {
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700443 if (new_tlli == GSM_RESERVED_TMSI) {
Max0524e382018-01-19 18:22:25 +0100444 LOGPTBFUL(this, LOGL_NOTICE,
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700445 "TLLI is 0x%08x within UL DATA?!?\n",
446 new_tlli);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100447 m_window.invalidate_bsn(rdbi->bsn);
448 continue;
449 }
Max0524e382018-01-19 18:22:25 +0100450 LOGPTBFUL(this, LOGL_INFO,
451 "Decoded premier TLLI=0x%08x of UL DATA TFI=%d.\n",
Vadim Yanitskiy3f27fb52020-04-20 11:26:12 +0700452 new_tlli, rlc->tfi);
Pau Espin Pedrold21e9612020-06-26 14:20:37 +0200453 update_ms(new_tlli, GPRS_RLCMAC_UL_TBF);
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700454 } else if (new_tlli != GSM_RESERVED_TMSI && new_tlli != tlli()) {
Max0524e382018-01-19 18:22:25 +0100455 LOGPTBFUL(this, LOGL_NOTICE,
Pau Espin Pedrol305763d2020-11-06 20:03:24 +0100456 "Decoded TLLI=%08x mismatch on UL DATA TFI=%d. (Ignoring due to contention resolution)\n",
457 new_tlli, rlc->tfi);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100458 m_window.invalidate_bsn(rdbi->bsn);
459 continue;
460 }
461 }
462
463 m_window.receive_bsn(rdbi->bsn);
464 }
465
466 /* Raise V(Q) if possible, and retrieve LLC frames from blocks.
467 * This is looped until there is a gap (non received block) or
468 * the window is empty.*/
469 const uint16_t v_q_beg = m_window.v_q();
470 const uint16_t count = m_window.raise_v_q();
471
472 /* Retrieve LLC frames from blocks that are ready */
473 for (uint16_t i = 0; i < count; ++i) {
Jacob Erlbeck93c55d02015-12-23 16:29:07 +0100474 uint16_t index = m_window.mod_sns(v_q_beg + i);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100475 assemble_forward_llc(m_rlc.block(index));
476 }
477
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200478 /* Last frame in buffer: */
479 block = m_rlc.block(m_window.mod_sns(m_window.v_r() - 1));
480 rdbi = &block->block_info;
481
482 /* Check if we already received all data TBF had to send: */
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100483 if (this->state_is(GPRS_RLCMAC_FLOW) /* still in flow state */
484 && this->m_window.v_q() == this->m_window.v_r()) { /* if complete */
Max0524e382018-01-19 18:22:25 +0100485 LOGPTBFUL(this, LOGL_DEBUG,
486 "No gaps in received block, last block: BSN=%d CV=%d\n",
487 rdbi->bsn, rdbi->cv);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100488 if (rdbi->cv == 0) {
Max0524e382018-01-19 18:22:25 +0100489 LOGPTBFUL(this, LOGL_DEBUG, "Finished with UL TBF\n");
Max2399b1d2018-01-12 15:48:12 +0100490 TBF_SET_STATE(this, GPRS_RLCMAC_FINISHED);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100491 /* Reset N3103 counter. */
Max847ed9f2018-02-20 18:16:11 +0100492 this->n_reset(N3103);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100493 }
494 }
495
496 /* If TLLI is included or if we received half of the window, we send
497 * an ack/nack */
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200498 maybe_schedule_uplink_acknack(rlc, rdbi->cv == 0);
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100499
500 return 0;
501}
502
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100503void gprs_rlcmac_ul_tbf::maybe_schedule_uplink_acknack(
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200504 const gprs_rlc_data_info *rlc, bool countdown_finished)
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100505{
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200506 bool require_ack = false;
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100507 bool have_ti = rlc->block_info[0].ti ||
508 (rlc->num_data_blocks > 1 && rlc->block_info[1].ti);
509
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200510 if (rlc->si) {
511 require_ack = true;
512 LOGPTBFUL(this, LOGL_NOTICE,
513 "Scheduling Ack/Nack, because MS is stalled.\n");
514 }
515 if (have_ti) {
516 require_ack = true;
517 LOGPTBFUL(this, LOGL_DEBUG,
518 "Scheduling Ack/Nack, because TLLI is included.\n");
519 }
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200520 if (countdown_finished) {
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200521 require_ack = true;
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200522 if (state_is(GPRS_RLCMAC_FLOW))
523 LOGPTBFUL(this, LOGL_DEBUG,
524 "Scheduling Ack/Nack, because some data is missing and last block has CV==0.\n");
525 else if (state_is(GPRS_RLCMAC_FINISHED))
526 LOGPTBFUL(this, LOGL_DEBUG,
527 "Scheduling final Ack/Nack, because all data was received and last block has CV==0.\n");
Pau Espin Pedrol09afd6f2020-05-15 16:40:18 +0200528 }
529 if ((m_rx_counter % SEND_ACK_AFTER_FRAMES) == 0) {
530 require_ack = true;
531 LOGPTBFUL(this, LOGL_DEBUG,
532 "Scheduling Ack/Nack, because %d frames received.\n",
533 SEND_ACK_AFTER_FRAMES);
534 }
535
536 if (!require_ack)
537 return;
538
539 if (ul_ack_state_is(GPRS_RLCMAC_UL_ACK_NONE)) {
540 /* trigger sending at next RTS */
541 TBF_SET_ACK_STATE(this, GPRS_RLCMAC_UL_ACK_SEND_ACK);
542 } else {
543 /* already triggered */
544 LOGPTBFUL(this, LOGL_DEBUG,
545 "Sending Ack/Nack already scheduled, no need to re-schedule\n");
Jacob Erlbeckb3100e12015-12-14 13:36:13 +0100546 }
547}
548
Daniel Willmannca102af2014-08-08 12:14:12 +0200549/* Send Uplink unit-data to SGSN. */
550int gprs_rlcmac_ul_tbf::snd_ul_ud()
551{
552 uint8_t qos_profile[3];
553 struct msgb *llc_pdu;
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100554 unsigned msg_len = NS_HDR_LEN + BSSGP_HDR_LEN + llc_frame_length(&m_llc);
Pau Espin Pedroldb5e3392021-01-21 18:02:40 +0100555 struct bssgp_bvc_ctx *bctx = bts->pcu->bssgp.bctx;
Daniel Willmannca102af2014-08-08 12:14:12 +0200556
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100557 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 +0200558 if (!bctx) {
559 LOGP(DBSSGP, LOGL_ERROR, "No bctx\n");
560 m_llc.reset_frame_space();
561 return -EIO;
562 }
Pau Espin Pedrol488aa292019-09-25 17:48:35 +0200563
Daniel Willmannca102af2014-08-08 12:14:12 +0200564 llc_pdu = msgb_alloc_headroom(msg_len, msg_len,"llc_pdu");
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100565 uint8_t *buf = msgb_push(llc_pdu, TL16V_GROSS_LEN(sizeof(uint8_t)*llc_frame_length(&m_llc)));
566 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 +0200567 qos_profile[0] = QOS_PROFILE >> 16;
568 qos_profile[1] = QOS_PROFILE >> 8;
569 qos_profile[2] = QOS_PROFILE;
570 bssgp_tx_ul_ud(bctx, tlli(), qos_profile, llc_pdu);
571
572 m_llc.reset_frame_space();
573 return 0;
574}
575
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530576egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_second_seg(
577 const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block,
578 uint8_t *data, const uint8_t block_idx)
579{
580 const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx];
581 union split_block_status *spb_status = &block->spb_status;
582 uint8_t *rlc_data = &block->block[0];
583
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100584 bts_do_rate_ctr_inc(bts, CTR_SPB_UL_SECOND_SEGMENT);
sivasankarida7250a2016-12-16 12:57:18 +0530585
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530586 if (spb_status->block_status_ul &
587 EGPRS_RESEG_FIRST_SEG_RXD) {
Max0524e382018-01-19 18:22:25 +0100588 LOGPTBFUL(this, LOGL_DEBUG,
589 "Second seg is received first seg is already present set the status to complete\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530590 spb_status->block_status_ul = EGPRS_RESEG_DEFAULT;
591
592 block->len += Decoding::rlc_copy_to_aligned_buffer(rlc,
593 block_idx, data, rlc_data + block->len);
594 block->block_info.data_len += rdbi->data_len;
595 } else if (spb_status->block_status_ul == EGPRS_RESEG_DEFAULT) {
Max0524e382018-01-19 18:22:25 +0100596 LOGPTBFUL(this, LOGL_DEBUG,
597 "Second seg is received first seg is not received set the status to second seg received\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530598
599 block->len = Decoding::rlc_copy_to_aligned_buffer(rlc,
600 block_idx, data,
601 rlc_data + rlc->block_info[block_idx].data_len);
602
603 spb_status->block_status_ul = EGPRS_RESEG_SECOND_SEG_RXD;
604 block->block_info = *rdbi;
605 }
606 return spb_status->block_status_ul;
607}
608
609egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_first_seg(
610 const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block,
611 uint8_t *data, const uint8_t block_idx)
612{
613 const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx];
614 uint8_t *rlc_data = &block->block[0];
615 union split_block_status *spb_status = &block->spb_status;
616
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100617 bts_do_rate_ctr_inc(bts, CTR_SPB_UL_FIRST_SEGMENT);
sivasankarida7250a2016-12-16 12:57:18 +0530618
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530619 if (spb_status->block_status_ul & EGPRS_RESEG_SECOND_SEG_RXD) {
Max0524e382018-01-19 18:22:25 +0100620 LOGPTBFUL(this, LOGL_DEBUG,
621 "First seg is received second seg is already present set the status to complete\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530622
623 block->len += Decoding::rlc_copy_to_aligned_buffer(rlc,
624 block_idx, data, rlc_data);
625
626 block->block_info.data_len = block->len;
627 spb_status->block_status_ul = EGPRS_RESEG_DEFAULT;
628 } else if (spb_status->block_status_ul == EGPRS_RESEG_DEFAULT) {
Max0524e382018-01-19 18:22:25 +0100629 LOGPTBFUL(this, LOGL_DEBUG,
630 "First seg is received second seg is not received set the status to first seg received\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530631
632 spb_status->block_status_ul = EGPRS_RESEG_FIRST_SEG_RXD;
633 block->len = Decoding::rlc_copy_to_aligned_buffer(rlc,
634 block_idx, data, rlc_data);
635 block->block_info = *rdbi;
636 }
637 return spb_status->block_status_ul;
638}
639
640egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_spb(
641 const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block,
642 uint8_t *data, const uint8_t block_idx)
643{
644 const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx];
645
Max0524e382018-01-19 18:22:25 +0100646 LOGPTBFUL(this, LOGL_DEBUG,
647 "Got SPB(%d) cs(%s) data block with BSN (%d), TFI(%d).\n",
Max136ebcc2019-03-05 14:59:03 +0100648 rdbi->spb, mcs_name(rlc->cs), rdbi->bsn, rlc->tfi);
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530649
650 egprs_rlc_ul_reseg_bsn_state assemble_status = EGPRS_RESEG_INVALID;
651
652 /* Section 10.4.8b of 44.060*/
653 if (rdbi->spb == 2)
654 assemble_status = handle_egprs_ul_first_seg(rlc,
655 block, data, block_idx);
656 else if (rdbi->spb == 3)
657 assemble_status = handle_egprs_ul_second_seg(rlc,
658 block, data, block_idx);
659 else {
Max0524e382018-01-19 18:22:25 +0100660 LOGPTBFUL(this, LOGL_ERROR,
661 "spb(%d) Not supported SPB for this EGPRS configuration\n",
662 rdbi->spb);
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530663 }
664
665 /*
666 * When the block is successfully constructed out of segmented blocks
667 * upgrade the MCS to the type 2
668 */
669 if (assemble_status == EGPRS_RESEG_DEFAULT) {
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +0200670 switch (rlc->cs) {
Maxbea2edb2019-03-06 17:04:59 +0100671 case MCS3 :
672 block->cs_last = MCS6;
Max0524e382018-01-19 18:22:25 +0100673 LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS6\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530674 break;
Maxbea2edb2019-03-06 17:04:59 +0100675 case MCS2 :
676 block->cs_last = MCS5;
Max0524e382018-01-19 18:22:25 +0100677 LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS5\n");
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530678 break;
Maxbea2edb2019-03-06 17:04:59 +0100679 case MCS1 :
Max0524e382018-01-19 18:22:25 +0100680 LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS4\n");
Maxbea2edb2019-03-06 17:04:59 +0100681 block->cs_last = MCS4;
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530682 break;
683 default:
Max0524e382018-01-19 18:22:25 +0100684 LOGPTBFUL(this, LOGL_ERROR,
685 "cs(%s) Error in Upgrading to higher MCS\n",
Max136ebcc2019-03-05 14:59:03 +0100686 mcs_name(rlc->cs));
Aravind Sirsikar505a86d2016-07-26 18:26:21 +0530687 break;
688 }
689 }
690 return assemble_status;
691}
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530692
Maxfb59a932019-03-13 18:40:19 +0100693void gprs_rlcmac_ul_tbf::update_coding_scheme_counter_ul(enum CodingScheme cs)
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530694{
Maxfb59a932019-03-13 18:40:19 +0100695 switch (cs) {
696 case CS1:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100697 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS1);
Maxfb59a932019-03-13 18:40:19 +0100698 rate_ctr_inc(&m_ul_gprs_ctrs->ctr[TBF_CTR_GPRS_UL_CS1]);
699 break;
700 case CS2:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100701 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS2);
Maxfb59a932019-03-13 18:40:19 +0100702 rate_ctr_inc(&m_ul_gprs_ctrs->ctr[TBF_CTR_GPRS_UL_CS2]);
703 break;
704 case CS3:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100705 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS3);
Maxfb59a932019-03-13 18:40:19 +0100706 rate_ctr_inc(&m_ul_gprs_ctrs->ctr[TBF_CTR_GPRS_UL_CS3]);
707 break;
708 case CS4:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100709 bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS4);
Maxfb59a932019-03-13 18:40:19 +0100710 rate_ctr_inc(&m_ul_gprs_ctrs->ctr[TBF_CTR_GPRS_UL_CS4]);
711 break;
712 case MCS1:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100713 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS1);
Maxfb59a932019-03-13 18:40:19 +0100714 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS1]);
715 break;
716 case MCS2:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100717 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS2);
Maxfb59a932019-03-13 18:40:19 +0100718 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS2]);
719 break;
720 case MCS3:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100721 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS3);
Maxfb59a932019-03-13 18:40:19 +0100722 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS3]);
723 break;
724 case MCS4:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100725 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS4);
Maxfb59a932019-03-13 18:40:19 +0100726 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS4]);
727 break;
728 case MCS5:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100729 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS5);
Maxfb59a932019-03-13 18:40:19 +0100730 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS5]);
731 break;
732 case MCS6:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100733 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS6);
Maxfb59a932019-03-13 18:40:19 +0100734 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS6]);
735 break;
736 case MCS7:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100737 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS7);
Maxfb59a932019-03-13 18:40:19 +0100738 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS7]);
739 break;
740 case MCS8:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100741 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS8);
Maxfb59a932019-03-13 18:40:19 +0100742 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS8]);
743 break;
744 case MCS9:
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100745 bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS9);
Maxfb59a932019-03-13 18:40:19 +0100746 rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS9]);
747 break;
748 default:
749 LOGPTBFUL(this, LOGL_ERROR, "attempting to update rate counters for unsupported (M)CS %s\n",
750 mcs_name(cs));
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530751 }
752}
sivasankari8adfcd02017-01-16 15:41:21 +0530753
Max9d7357e2017-12-14 15:02:33 +0100754void gprs_rlcmac_ul_tbf::set_window_size()
sivasankari8adfcd02017-01-16 15:41:21 +0530755{
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100756 const struct gprs_rlcmac_bts *b = bts;
Max34513fe2018-12-11 16:47:30 +0100757 uint16_t ws = egprs_window_size(b, ul_slots());
Max0524e382018-01-19 18:22:25 +0100758 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 +0100759 ws, bts->pcu->vty.ws_base, pcu_bitcount(ul_slots()), bts->pcu->vty.ws_pdch);
sivasankari8adfcd02017-01-16 15:41:21 +0530760 m_window.set_ws(ws);
761}
Pau Espin Pedrol9767e442020-10-23 21:11:41 +0200762
Pau Espin Pedrolb3f23972020-10-23 21:00:23 +0200763gprs_rlc_window *gprs_rlcmac_ul_tbf::window()
Pau Espin Pedrol9767e442020-10-23 21:11:41 +0200764{
765 return &m_window;
766}
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100767
Pau Espin Pedrol0b998b12021-03-24 14:45:43 +0100768void gprs_rlcmac_ul_tbf::usf_timeout()
769{
770 if (n_inc(N3101)) {
771 TBF_SET_STATE(this, GPRS_RLCMAC_RELEASING);
772 T_START(this, T3169, 3169, "MAX N3101 reached", false);
773 return;
774 }
775}
776
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100777struct gprs_rlcmac_ul_tbf *as_ul_tbf(struct gprs_rlcmac_tbf *tbf)
778{
779 if (tbf && tbf->direction == GPRS_RLCMAC_UL_TBF)
780 return static_cast<gprs_rlcmac_ul_tbf *>(tbf);
781 else
782 return NULL;
783}
Pau Espin Pedrol0b998b12021-03-24 14:45:43 +0100784
785void tbf_usf_timeout(struct gprs_rlcmac_ul_tbf *tbf)
786{
787 tbf->usf_timeout();
788}