Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 1 | /* 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 Smith | d3c7591 | 2021-07-09 16:37:16 +0200 | [diff] [blame] | 23 | #include <bts_pch_timer.h> |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 24 | #include <tbf.h> |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 25 | #include <tbf_ul.h> |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 26 | #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 Erlbeck | 20f6fd1 | 2015-06-08 11:05:45 +0200 | [diff] [blame] | 32 | #include <pcu_l1_if.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 33 | #include <gprs_ms.h> |
| 34 | #include <llc.h> |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 35 | #include "pcu_utils.h" |
| 36 | |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 37 | extern "C" { |
| 38 | #include <osmocom/core/msgb.h> |
| 39 | #include <osmocom/core/talloc.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 40 | #include <osmocom/core/bitvec.h> |
| 41 | #include <osmocom/core/logging.h> |
| 42 | #include <osmocom/core/rate_ctr.h> |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 43 | #include <osmocom/core/stats.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 44 | #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> |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 48 | #include "coding_scheme.h" |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 49 | } |
| 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 | |
| 57 | extern void *tall_pcu_ctx; |
| 58 | |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 59 | static 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 | |
| 66 | static 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 | |
| 78 | static 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 | |
| 86 | static 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 | |
| 94 | static int ul_tbf_dtor(struct gprs_rlcmac_ul_tbf *tbf) |
| 95 | { |
| 96 | tbf->~gprs_rlcmac_ul_tbf(); |
| 97 | return 0; |
| 98 | } |
| 99 | |
Pau Espin Pedrol | 54742f2 | 2021-04-26 16:48:34 +0200 | [diff] [blame] | 100 | /* Generic function to alloc a UL TBF, later configured to be assigned either over CCCH or PACCH */ |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 101 | struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_tbf(struct gprs_rlcmac_bts *bts, GprsMs *ms, int8_t use_trx, bool single_slot) |
| 102 | { |
| 103 | struct gprs_rlcmac_ul_tbf *tbf; |
| 104 | int rc; |
| 105 | |
| 106 | OSMO_ASSERT(ms != NULL); |
| 107 | |
Pau Espin Pedrol | 36177c6 | 2021-02-25 17:57:37 +0100 | [diff] [blame] | 108 | LOGPMS(ms, DTBF, LOGL_DEBUG, "********** UL-TBF starts here **********\n"); |
| 109 | LOGPMS(ms, DTBF, LOGL_INFO, "Allocating UL TBF\n"); |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 110 | |
| 111 | tbf = talloc(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf); |
| 112 | if (!tbf) |
| 113 | return NULL; |
| 114 | talloc_set_destructor(tbf, ul_tbf_dtor); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 115 | new (tbf) gprs_rlcmac_ul_tbf(bts, ms); |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 116 | |
| 117 | rc = tbf->setup(use_trx, single_slot); |
| 118 | |
| 119 | /* if no resource */ |
| 120 | if (rc < 0) { |
| 121 | talloc_free(tbf); |
| 122 | return NULL; |
| 123 | } |
| 124 | |
| 125 | if (tbf->is_egprs_enabled()) |
| 126 | tbf->set_window_size(); |
| 127 | |
| 128 | tbf->m_ul_egprs_ctrs = rate_ctr_group_alloc(tbf, |
| 129 | &tbf_ul_egprs_ctrg_desc, tbf->m_ctrs->idx); |
| 130 | tbf->m_ul_gprs_ctrs = rate_ctr_group_alloc(tbf, |
| 131 | &tbf_ul_gprs_ctrg_desc, tbf->m_ctrs->idx); |
| 132 | if (!tbf->m_ul_egprs_ctrs || !tbf->m_ul_gprs_ctrs) { |
| 133 | LOGPTBF(tbf, LOGL_ERROR, "Couldn't allocate TBF UL counters\n"); |
| 134 | talloc_free(tbf); |
| 135 | return NULL; |
| 136 | } |
| 137 | |
Pau Espin Pedrol | 1a1557a | 2021-05-13 18:39:36 +0200 | [diff] [blame] | 138 | llist_add_tail(tbf_trx_list(tbf), &tbf->trx->ul_tbfs); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 139 | bts_do_rate_ctr_inc(tbf->bts, CTR_TBF_UL_ALLOCATED); |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 140 | |
| 141 | return tbf; |
| 142 | } |
| 143 | |
Pau Espin Pedrol | 54742f2 | 2021-04-26 16:48:34 +0200 | [diff] [blame] | 144 | /* Alloc a UL TBF to be assigned over PACCH */ |
Pau Espin Pedrol | c6571b5 | 2021-05-10 17:10:37 +0200 | [diff] [blame] | 145 | gprs_rlcmac_ul_tbf *tbf_alloc_ul_pacch(struct gprs_rlcmac_bts *bts, GprsMs *ms, int8_t use_trx, |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 146 | uint32_t tlli) |
| 147 | { |
| 148 | struct gprs_rlcmac_ul_tbf *tbf; |
| 149 | |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 150 | tbf = tbf_alloc_ul_tbf(bts, ms, use_trx, false); |
| 151 | if (!tbf) { |
Pau Espin Pedrol | 36177c6 | 2021-02-25 17:57:37 +0100 | [diff] [blame] | 152 | LOGPMS(ms, DTBF, LOGL_NOTICE, "No PDCH resource\n"); |
Pau Espin Pedrol | 54742f2 | 2021-04-26 16:48:34 +0200 | [diff] [blame] | 153 | /* Caller will most probably send a Imm Ass Reject after return */ |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 154 | return NULL; |
| 155 | } |
| 156 | tbf->m_contention_resolution_done = 1; |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 157 | osmo_fsm_inst_dispatch(tbf->state_fsm.fi, TBF_EV_ASSIGN_ADD_PACCH, NULL); |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 158 | tbf->update_ms(tlli, GPRS_RLCMAC_UL_TBF); |
| 159 | OSMO_ASSERT(tbf->ms()); |
| 160 | |
| 161 | return tbf; |
| 162 | } |
| 163 | |
Pau Espin Pedrol | 20271c4 | 2021-05-10 17:21:03 +0200 | [diff] [blame] | 164 | /* Alloc a UL TBF to be assigned over CCCH */ |
| 165 | struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_ccch(struct gprs_rlcmac_bts *bts, struct GprsMs *ms) |
| 166 | { |
| 167 | struct gprs_rlcmac_ul_tbf *tbf; |
| 168 | |
| 169 | tbf = tbf_alloc_ul_tbf(bts, ms, -1, true); |
| 170 | if (!tbf) { |
| 171 | LOGP(DTBF, LOGL_NOTICE, "No PDCH resource for Uplink TBF\n"); |
| 172 | /* Caller will most probably send a Imm Ass Reject after return */ |
| 173 | return NULL; |
| 174 | } |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 175 | osmo_fsm_inst_dispatch(tbf->state_fsm.fi, TBF_EV_ASSIGN_ADD_CCCH, NULL); |
Pau Espin Pedrol | 4b6f0bf | 2021-05-10 18:54:52 +0200 | [diff] [blame] | 176 | tbf->contention_resolution_start(); |
Pau Espin Pedrol | 20271c4 | 2021-05-10 17:21:03 +0200 | [diff] [blame] | 177 | OSMO_ASSERT(tbf->ms()); |
| 178 | |
| 179 | return tbf; |
| 180 | } |
| 181 | |
Pau Espin Pedrol | 54742f2 | 2021-04-26 16:48:34 +0200 | [diff] [blame] | 182 | /* Create a temporary dummy TBF to Tx a ImmAssReject if allocating a new one during |
| 183 | * packet resource Request failed. This is similar as tbf_alloc_ul() but without |
| 184 | * calling tbf->setup() (in charge of TFI/USF allocation), and reusing resources |
| 185 | * from Packet Resource Request we received. See TS 44.060 sec 7.1.3.2.1 */ |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 186 | struct gprs_rlcmac_ul_tbf *handle_tbf_reject(struct gprs_rlcmac_bts *bts, |
Pau Espin Pedrol | 54742f2 | 2021-04-26 16:48:34 +0200 | [diff] [blame] | 187 | GprsMs *ms, uint8_t trx_no, uint8_t ts) |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 188 | { |
| 189 | struct gprs_rlcmac_ul_tbf *ul_tbf = NULL; |
| 190 | struct gprs_rlcmac_trx *trx = &bts->trx[trx_no]; |
Pau Espin Pedrol | 54742f2 | 2021-04-26 16:48:34 +0200 | [diff] [blame] | 191 | OSMO_ASSERT(ms); |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 192 | |
| 193 | ul_tbf = talloc(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf); |
| 194 | if (!ul_tbf) |
| 195 | return ul_tbf; |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 196 | talloc_set_destructor(ul_tbf, ul_tbf_dtor); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 197 | new (ul_tbf) gprs_rlcmac_ul_tbf(bts, ms); |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 198 | |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 199 | ul_tbf->control_ts = ts; |
| 200 | ul_tbf->trx = trx; |
| 201 | ul_tbf->m_ctrs = rate_ctr_group_alloc(ul_tbf, &tbf_ctrg_desc, next_tbf_ctr_group_id++); |
| 202 | ul_tbf->m_ul_egprs_ctrs = rate_ctr_group_alloc(ul_tbf, |
| 203 | &tbf_ul_egprs_ctrg_desc, |
| 204 | ul_tbf->m_ctrs->idx); |
| 205 | ul_tbf->m_ul_gprs_ctrs = rate_ctr_group_alloc(ul_tbf, |
| 206 | &tbf_ul_gprs_ctrg_desc, |
| 207 | ul_tbf->m_ctrs->idx); |
| 208 | if (!ul_tbf->m_ctrs || !ul_tbf->m_ul_egprs_ctrs || !ul_tbf->m_ul_gprs_ctrs) { |
| 209 | LOGPTBF(ul_tbf, LOGL_ERROR, "Cound not allocate TBF UL rate counters\n"); |
| 210 | talloc_free(ul_tbf); |
| 211 | return NULL; |
| 212 | } |
| 213 | |
Pau Espin Pedrol | 54742f2 | 2021-04-26 16:48:34 +0200 | [diff] [blame] | 214 | ms_attach_tbf(ms, ul_tbf); |
Pau Espin Pedrol | 1a1557a | 2021-05-13 18:39:36 +0200 | [diff] [blame] | 215 | llist_add(tbf_trx_list((struct gprs_rlcmac_tbf *)ul_tbf), &trx->ul_tbfs); |
Pau Espin Pedrol | 54742f2 | 2021-04-26 16:48:34 +0200 | [diff] [blame] | 216 | bts_do_rate_ctr_inc(ul_tbf->bts, CTR_TBF_UL_ALLOCATED); |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 217 | osmo_fsm_inst_dispatch(ul_tbf->state_fsm.fi, TBF_EV_ASSIGN_ADD_PACCH, NULL); |
Pau Espin Pedrol | 54742f2 | 2021-04-26 16:48:34 +0200 | [diff] [blame] | 218 | TBF_SET_ASS_STATE_UL(ul_tbf, GPRS_RLCMAC_UL_ASS_SEND_ASS_REJ); |
| 219 | |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 220 | return ul_tbf; |
| 221 | } |
| 222 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 223 | gprs_rlcmac_ul_tbf::gprs_rlcmac_ul_tbf(struct gprs_rlcmac_bts *bts_, GprsMs *ms) : |
Pau Espin Pedrol | e9f77d3 | 2020-10-23 18:41:40 +0200 | [diff] [blame] | 224 | gprs_rlcmac_tbf(bts_, ms, GPRS_RLCMAC_UL_TBF), |
Pau Espin Pedrol | bddf1ad | 2019-09-26 14:41:18 +0200 | [diff] [blame] | 225 | m_rx_counter(0), |
| 226 | m_contention_resolution_done(0), |
| 227 | m_final_ack_sent(0), |
| 228 | m_ul_gprs_ctrs(NULL), |
| 229 | m_ul_egprs_ctrs(NULL) |
| 230 | { |
Pau Espin Pedrol | 7bd92a3 | 2021-03-24 13:14:09 +0100 | [diff] [blame] | 231 | memset(&m_usf, USF_INVALID, sizeof(m_usf)); |
Pau Espin Pedrol | bddf1ad | 2019-09-26 14:41:18 +0200 | [diff] [blame] | 232 | } |
| 233 | |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 234 | /* |
| 235 | * Store received block data in LLC message(s) and forward to SGSN |
| 236 | * if complete. |
| 237 | */ |
| 238 | int gprs_rlcmac_ul_tbf::assemble_forward_llc(const gprs_rlc_data *_data) |
| 239 | { |
| 240 | const uint8_t *data = _data->block; |
| 241 | uint8_t len = _data->len; |
Jacob Erlbeck | f2ba4cb | 2016-01-07 18:59:28 +0100 | [diff] [blame] | 242 | const struct gprs_rlc_data_block_info *rdbi = &_data->block_info; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 243 | enum CodingScheme cs = _data->cs_last; |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 244 | |
| 245 | Decoding::RlcData frames[16], *frame; |
| 246 | int i, num_frames = 0; |
| 247 | uint32_t dummy_tlli; |
| 248 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 249 | LOGPTBFUL(this, LOGL_DEBUG, "Assembling frames: (len=%d)\n", len); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 250 | |
| 251 | num_frames = Decoding::rlc_data_from_ul_data( |
Alexander Couzens | ce936f3 | 2016-05-24 14:45:41 +0200 | [diff] [blame] | 252 | rdbi, cs, data, &(frames[0]), ARRAY_SIZE(frames), |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 253 | &dummy_tlli); |
| 254 | |
| 255 | /* create LLC frames */ |
| 256 | for (i = 0; i < num_frames; i++) { |
| 257 | frame = frames + i; |
| 258 | |
Aravind Sirsikar | 22a9019 | 2016-09-15 17:24:49 +0530 | [diff] [blame] | 259 | if (frame->length) { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 260 | bts_do_rate_ctr_add(bts, CTR_RLC_UL_PAYLOAD_BYTES, frame->length); |
Alexander Couzens | 7fdbf89 | 2016-05-21 19:45:23 +0200 | [diff] [blame] | 261 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 262 | LOGPTBFUL(this, LOGL_DEBUG, "Frame %d " |
Aravind Sirsikar | 22a9019 | 2016-09-15 17:24:49 +0530 | [diff] [blame] | 263 | "starts at offset %d, " |
| 264 | "length=%d, is_complete=%d\n", |
| 265 | i + 1, frame->offset, frame->length, |
| 266 | frame->is_complete); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 267 | |
Aravind Sirsikar | 22a9019 | 2016-09-15 17:24:49 +0530 | [diff] [blame] | 268 | m_llc.append_frame(data + frame->offset, frame->length); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 269 | llc_consume(&m_llc, frame->length); |
Aravind Sirsikar | 22a9019 | 2016-09-15 17:24:49 +0530 | [diff] [blame] | 270 | } |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 271 | |
| 272 | if (frame->is_complete) { |
| 273 | /* send frame to SGSN */ |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 274 | LOGPTBFUL(this, LOGL_DEBUG, "complete UL frame len=%d\n", llc_frame_length(&m_llc)); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 275 | snd_ul_ud(); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 276 | bts_do_rate_ctr_add(bts, CTR_LLC_UL_BYTES, llc_frame_length(&m_llc)); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 277 | m_llc.reset(); |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | return 0; |
| 282 | } |
| 283 | |
Max | fd13f6c | 2017-07-07 14:29:36 +0200 | [diff] [blame] | 284 | bool gprs_rlcmac_ul_tbf::ctrl_ack_to_toggle() |
| 285 | { |
Max | 8dce1de | 2018-01-02 14:17:04 +0100 | [diff] [blame] | 286 | if (check_n_clear(GPRS_RLCMAC_FLAG_TO_UL_ACK)) |
Max | fd13f6c | 2017-07-07 14:29:36 +0200 | [diff] [blame] | 287 | return true; /* GPRS_RLCMAC_FLAG_TO_UL_ACK was set, now cleared */ |
Max | fd13f6c | 2017-07-07 14:29:36 +0200 | [diff] [blame] | 288 | |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 289 | state_fsm.state_flags |= (1 << GPRS_RLCMAC_FLAG_TO_UL_ACK); |
Max | fd13f6c | 2017-07-07 14:29:36 +0200 | [diff] [blame] | 290 | return false; /* GPRS_RLCMAC_FLAG_TO_UL_ACK was unset, now set */ |
| 291 | } |
| 292 | |
Pau Espin Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 293 | bool gprs_rlcmac_ul_tbf::handle_ctrl_ack(enum pdch_ulc_tbf_poll_reason reason) |
Max | fd13f6c | 2017-07-07 14:29:36 +0200 | [diff] [blame] | 294 | { |
| 295 | /* check if this control ack belongs to packet uplink ack */ |
Pau Espin Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 296 | if (reason == PDCH_ULC_POLL_UL_ACK && ul_ack_state_is(GPRS_RLCMAC_UL_ACK_WAIT_ACK)) { |
Max | 088c7df | 2018-01-23 20:16:23 +0100 | [diff] [blame] | 297 | TBF_SET_ACK_STATE(this, GPRS_RLCMAC_UL_ACK_NONE); |
Max | fd13f6c | 2017-07-07 14:29:36 +0200 | [diff] [blame] | 298 | return true; |
| 299 | } |
| 300 | |
| 301 | return false; |
| 302 | } |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 303 | |
Pau Espin Pedrol | 4b6f0bf | 2021-05-10 18:54:52 +0200 | [diff] [blame] | 304 | void gprs_rlcmac_ul_tbf::contention_resolution_start() |
| 305 | { |
| 306 | /* 3GPP TS 44.018 sec 11.1.2 Timers on the network side: "This timer is |
| 307 | * started when a temporary block flow is allocated with an IMMEDIATE |
| 308 | * ASSIGNMENT or an IMMEDIATE PACKET ASSIGNMENT or an EC IMMEDIATE |
| 309 | * ASSIGNMENT TYPE 1 message during a packet access procedure. It is |
| 310 | * stopped when the mobile station has correctly seized the temporary |
| 311 | * block flow." |
| 312 | * In our code base, it means we want to do contention resolution |
| 313 | * timeout only for one-phase packet access, since two-phase is handled |
| 314 | * through SBA structs, which are freed by the PDCH UL Controller if the |
| 315 | * single allocated block is lost. */ |
| 316 | T_START(this, T3141, 3141, "Contention resolution (UL-TBF, CCCH)", true); |
| 317 | } |
| 318 | void gprs_rlcmac_ul_tbf::contention_resolution_success() |
| 319 | { |
| 320 | if (m_contention_resolution_done) |
| 321 | return; |
| 322 | |
| 323 | /* 3GPP TS 44.060 sec 7a.2.1 Contention Resolution */ |
| 324 | /* 3GPP TS 44.018 3.5.2.1.4 Packet access completion: The one phase |
| 325 | packet access procedure is completed at a successful contention |
| 326 | resolution. The mobile station has entered the packet transfer mode. |
| 327 | Timer T3141 is stopped on the network side */ |
| 328 | t_stop(T3141, "Contention resolution success (UL-TBF, CCCH)"); |
| 329 | |
| 330 | /* now we must set this flag, so we are allowed to assign downlink |
| 331 | * TBF on PACCH. it is only allowed when TLLI is acknowledged. */ |
| 332 | m_contention_resolution_done = 1; |
| 333 | } |
| 334 | |
Jacob Erlbeck | 5a3c84d | 2016-01-22 17:25:38 +0100 | [diff] [blame] | 335 | struct msgb *gprs_rlcmac_ul_tbf::create_ul_ack(uint32_t fn, uint8_t ts) |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 336 | { |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 337 | int final = (state_is(TBF_ST_FINISHED)); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 338 | struct msgb *msg; |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 339 | int rc; |
| 340 | unsigned int rrbp = 0; |
| 341 | uint32_t new_poll_fn = 0; |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 342 | |
| 343 | if (final) { |
Pau Espin Pedrol | ed066b5 | 2021-03-29 16:16:27 +0200 | [diff] [blame] | 344 | if (ul_ack_state_is(GPRS_RLCMAC_UL_ACK_WAIT_ACK)) { |
Max | c21f007 | 2017-12-15 17:36:45 +0100 | [diff] [blame] | 345 | LOGPTBFUL(this, LOGL_DEBUG, |
| 346 | "Polling is already scheduled, so we must wait for the final uplink ack...\n"); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 347 | return NULL; |
| 348 | } |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 349 | |
| 350 | rc = check_polling(fn, ts, &new_poll_fn, &rrbp); |
| 351 | if (rc < 0) |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 352 | return NULL; |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | msg = msgb_alloc(23, "rlcmac_ul_ack"); |
| 356 | if (!msg) |
| 357 | return NULL; |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 358 | bitvec *ack_vec = bitvec_alloc(23, tall_pcu_ctx); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 359 | if (!ack_vec) { |
| 360 | msgb_free(msg); |
| 361 | return NULL; |
| 362 | } |
Max | 7426c5f | 2019-02-18 20:42:42 +0100 | [diff] [blame] | 363 | bitvec_unhex(ack_vec, DUMMY_VEC); |
Alexander Couzens | 3a499f3 | 2019-06-16 15:25:30 +0200 | [diff] [blame] | 364 | Encoding::write_packet_uplink_ack(ack_vec, this, final, rrbp); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 365 | bitvec_pack(ack_vec, msgb_put(msg, 23)); |
| 366 | bitvec_free(ack_vec); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 367 | |
Pau Espin Pedrol | 4b6f0bf | 2021-05-10 18:54:52 +0200 | [diff] [blame] | 368 | /* TS 44.060 7a.2.1.1: "The contention resolution is completed on |
| 369 | * the network side when the network receives an RLC data block that |
| 370 | * comprises the TLLI value that identifies the mobile station and the |
| 371 | * TFI value associated with the TBF." |
| 372 | * However, it's handier for us to mark contention resolution success |
| 373 | * here since according to spec upon rx UL ACK is the time at which MS |
| 374 | * realizes contention resolution succeeds. */ |
Pau Espin Pedrol | faf0ccb | 2021-05-11 12:55:31 +0200 | [diff] [blame] | 375 | if (is_tlli_valid()) |
Pau Espin Pedrol | 4b6f0bf | 2021-05-10 18:54:52 +0200 | [diff] [blame] | 376 | contention_resolution_success(); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 377 | |
| 378 | if (final) { |
Pau Espin Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 379 | set_polling(new_poll_fn, ts, PDCH_ULC_POLL_UL_ACK); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 380 | /* waiting for final acknowledge */ |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 381 | m_final_ack_sent = 1; |
| 382 | } else |
Max | 088c7df | 2018-01-23 20:16:23 +0100 | [diff] [blame] | 383 | TBF_SET_ACK_STATE(this, GPRS_RLCMAC_UL_ACK_NONE); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 384 | |
| 385 | return msg; |
| 386 | } |
| 387 | |
Alexander Couzens | 2fcfc29 | 2016-05-24 14:40:03 +0200 | [diff] [blame] | 388 | /*! \brief receive data from PDCH/L1 */ |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 389 | int gprs_rlcmac_ul_tbf::rcv_data_block_acknowledged( |
Jacob Erlbeck | f2ba4cb | 2016-01-07 18:59:28 +0100 | [diff] [blame] | 390 | const struct gprs_rlc_data_info *rlc, |
Jacob Erlbeck | fc1b3e6 | 2016-01-11 09:58:11 +0100 | [diff] [blame] | 391 | uint8_t *data, struct pcu_l1_meas *meas) |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 392 | { |
Pau Espin Pedrol | c33a024 | 2020-05-15 16:57:48 +0200 | [diff] [blame] | 393 | const struct gprs_rlc_data_block_info *rdbi; |
| 394 | struct gprs_rlc_data *block; |
| 395 | |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 396 | int8_t rssi = meas->have_rssi ? meas->rssi : 0; |
| 397 | |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 398 | const uint16_t ws = m_window.ws(); |
| 399 | |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 400 | this->state_fsm.state_flags |= (1 << GPRS_RLCMAC_FLAG_UL_DATA); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 401 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 402 | LOGPTBFUL(this, LOGL_DEBUG, "UL DATA TFI=%d received (V(Q)=%d .. " |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 403 | "V(R)=%d)\n", rlc->tfi, this->m_window.v_q(), |
| 404 | this->m_window.v_r()); |
| 405 | |
| 406 | /* process RSSI */ |
| 407 | gprs_rlcmac_rssi(this, rssi); |
| 408 | |
| 409 | /* store measurement values */ |
Pau Espin Pedrol | f53815f | 2021-05-11 14:23:51 +0200 | [diff] [blame] | 410 | ms_update_l1_meas(ms(), meas); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 411 | |
Vadim Yanitskiy | cb98894 | 2020-11-08 13:27:35 +0700 | [diff] [blame] | 412 | uint32_t new_tlli = GSM_RESERVED_TMSI; |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 413 | unsigned int block_idx; |
| 414 | |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 415 | /* Increment RX-counter */ |
| 416 | this->m_rx_counter++; |
Mrinal Mishra | f86307e | 2016-11-10 18:16:30 +0530 | [diff] [blame] | 417 | update_coding_scheme_counter_ul(rlc->cs); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 418 | /* Loop over num_blocks */ |
| 419 | for (block_idx = 0; block_idx < rlc->num_data_blocks; block_idx++) { |
| 420 | int num_chunks; |
| 421 | uint8_t *rlc_data; |
Pau Espin Pedrol | c33a024 | 2020-05-15 16:57:48 +0200 | [diff] [blame] | 422 | rdbi = &rlc->block_info[block_idx]; |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 423 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 424 | LOGPTBFUL(this, LOGL_DEBUG, |
| 425 | "Got %s RLC data block: CV=%d, BSN=%d, SPB=%d, PI=%d, E=%d, TI=%d, bitoffs=%d\n", |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 426 | mcs_name(rlc->cs), |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 427 | rdbi->cv, rdbi->bsn, rdbi->spb, |
| 428 | rdbi->pi, rdbi->e, rdbi->ti, |
| 429 | rlc->data_offs_bits[block_idx]); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 430 | |
| 431 | /* Check whether the block needs to be decoded */ |
| 432 | |
| 433 | if (!m_window.is_in_window(rdbi->bsn)) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 434 | LOGPTBFUL(this, LOGL_DEBUG, "BSN %d out of window %d..%d (it's normal)\n", |
| 435 | rdbi->bsn, |
| 436 | m_window.v_q(), m_window.mod_sns(m_window.v_q() + ws - 1)); |
Pau Espin Pedrol | 5891631 | 2021-05-11 14:40:41 +0200 | [diff] [blame] | 437 | continue; |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 438 | } else if (m_window.is_received(rdbi->bsn)) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 439 | LOGPTBFUL(this, LOGL_DEBUG, |
| 440 | "BSN %d already received\n", rdbi->bsn); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 441 | continue; |
Pau Espin Pedrol | 5891631 | 2021-05-11 14:40:41 +0200 | [diff] [blame] | 442 | } |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 443 | |
| 444 | /* Store block and meta info to BSN buffer */ |
| 445 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 446 | LOGPTBFUL(this, LOGL_DEBUG, "BSN %d storing in window (%d..%d)\n", |
| 447 | rdbi->bsn, m_window.v_q(), |
| 448 | m_window.mod_sns(m_window.v_q() + ws - 1)); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 449 | block = m_rlc.block(rdbi->bsn); |
Aravind Sirsikar | 550a541 | 2016-06-14 18:59:18 +0530 | [diff] [blame] | 450 | OSMO_ASSERT(rdbi->data_len <= sizeof(block->block)); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 451 | rlc_data = &(block->block[0]); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 452 | |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 453 | if (rdbi->spb) { |
| 454 | egprs_rlc_ul_reseg_bsn_state assemble_status; |
| 455 | |
| 456 | assemble_status = handle_egprs_ul_spb(rlc, |
| 457 | block, data, block_idx); |
| 458 | |
| 459 | if (assemble_status != EGPRS_RESEG_DEFAULT) |
| 460 | return 0; |
| 461 | } else { |
| 462 | block->block_info = *rdbi; |
| 463 | block->cs_last = rlc->cs; |
| 464 | block->len = |
| 465 | Decoding::rlc_copy_to_aligned_buffer(rlc, |
| 466 | block_idx, data, rlc_data); |
| 467 | } |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 468 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 469 | LOGPTBFUL(this, LOGL_DEBUG, |
| 470 | "data_length=%d, data=%s\n", |
| 471 | block->len, osmo_hexdump(rlc_data, block->len)); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 472 | /* Get/Handle TLLI */ |
| 473 | if (rdbi->ti) { |
| 474 | num_chunks = Decoding::rlc_data_from_ul_data( |
| 475 | rdbi, rlc->cs, rlc_data, NULL, 0, &new_tlli); |
| 476 | |
| 477 | if (num_chunks < 0) { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 478 | bts_do_rate_ctr_inc(bts, CTR_DECODE_ERRORS); |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 479 | LOGPTBFUL(this, LOGL_NOTICE, |
| 480 | "Failed to decode TLLI of %s UL DATA TFI=%d.\n", |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 481 | mcs_name(rlc->cs), rlc->tfi); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 482 | m_window.invalidate_bsn(rdbi->bsn); |
| 483 | continue; |
| 484 | } |
| 485 | if (!this->is_tlli_valid()) { |
Vadim Yanitskiy | cb98894 | 2020-11-08 13:27:35 +0700 | [diff] [blame] | 486 | if (new_tlli == GSM_RESERVED_TMSI) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 487 | LOGPTBFUL(this, LOGL_NOTICE, |
Vadim Yanitskiy | cb98894 | 2020-11-08 13:27:35 +0700 | [diff] [blame] | 488 | "TLLI is 0x%08x within UL DATA?!?\n", |
| 489 | new_tlli); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 490 | m_window.invalidate_bsn(rdbi->bsn); |
| 491 | continue; |
| 492 | } |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 493 | LOGPTBFUL(this, LOGL_INFO, |
| 494 | "Decoded premier TLLI=0x%08x of UL DATA TFI=%d.\n", |
Vadim Yanitskiy | 3f27fb5 | 2020-04-20 11:26:12 +0700 | [diff] [blame] | 495 | new_tlli, rlc->tfi); |
Pau Espin Pedrol | d21e961 | 2020-06-26 14:20:37 +0200 | [diff] [blame] | 496 | update_ms(new_tlli, GPRS_RLCMAC_UL_TBF); |
Oliver Smith | d3c7591 | 2021-07-09 16:37:16 +0200 | [diff] [blame] | 497 | bts_pch_timer_stop(bts, ms_imsi(ms())); |
Vadim Yanitskiy | cb98894 | 2020-11-08 13:27:35 +0700 | [diff] [blame] | 498 | } else if (new_tlli != GSM_RESERVED_TMSI && new_tlli != tlli()) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 499 | LOGPTBFUL(this, LOGL_NOTICE, |
Pau Espin Pedrol | 305763d | 2020-11-06 20:03:24 +0100 | [diff] [blame] | 500 | "Decoded TLLI=%08x mismatch on UL DATA TFI=%d. (Ignoring due to contention resolution)\n", |
| 501 | new_tlli, rlc->tfi); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 502 | m_window.invalidate_bsn(rdbi->bsn); |
| 503 | continue; |
| 504 | } |
Pau Espin Pedrol | 5891631 | 2021-05-11 14:40:41 +0200 | [diff] [blame] | 505 | } else if (!is_tlli_valid()) { |
| 506 | LOGPTBFUL(this, LOGL_NOTICE, "Missing TLLI within UL DATA.\n"); |
| 507 | m_window.invalidate_bsn(rdbi->bsn); |
| 508 | continue; |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | m_window.receive_bsn(rdbi->bsn); |
| 512 | } |
| 513 | |
| 514 | /* Raise V(Q) if possible, and retrieve LLC frames from blocks. |
| 515 | * This is looped until there is a gap (non received block) or |
| 516 | * the window is empty.*/ |
| 517 | const uint16_t v_q_beg = m_window.v_q(); |
| 518 | const uint16_t count = m_window.raise_v_q(); |
| 519 | |
| 520 | /* Retrieve LLC frames from blocks that are ready */ |
| 521 | for (uint16_t i = 0; i < count; ++i) { |
Jacob Erlbeck | 93c55d0 | 2015-12-23 16:29:07 +0100 | [diff] [blame] | 522 | uint16_t index = m_window.mod_sns(v_q_beg + i); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 523 | assemble_forward_llc(m_rlc.block(index)); |
| 524 | } |
| 525 | |
Pau Espin Pedrol | c33a024 | 2020-05-15 16:57:48 +0200 | [diff] [blame] | 526 | /* Last frame in buffer: */ |
| 527 | block = m_rlc.block(m_window.mod_sns(m_window.v_r() - 1)); |
| 528 | rdbi = &block->block_info; |
| 529 | |
| 530 | /* Check if we already received all data TBF had to send: */ |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 531 | if (this->state_is(TBF_ST_FLOW) /* still in flow state */ |
Pau Espin Pedrol | 9b63cd0 | 2021-05-11 14:54:40 +0200 | [diff] [blame] | 532 | && this->m_window.v_q() == this->m_window.v_r() /* if complete */ |
| 533 | && block->len) { /* if there was ever a last block received */ |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 534 | LOGPTBFUL(this, LOGL_DEBUG, |
| 535 | "No gaps in received block, last block: BSN=%d CV=%d\n", |
| 536 | rdbi->bsn, rdbi->cv); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 537 | if (rdbi->cv == 0) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 538 | LOGPTBFUL(this, LOGL_DEBUG, "Finished with UL TBF\n"); |
Pau Espin Pedrol | c32c4a3 | 2021-07-23 18:27:57 +0200 | [diff] [blame] | 539 | osmo_fsm_inst_dispatch(this->state_fsm.fi, TBF_EV_LAST_UL_DATA_RECVD, NULL); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 540 | /* Reset N3103 counter. */ |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 541 | this->n_reset(N3103); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | |
| 545 | /* If TLLI is included or if we received half of the window, we send |
| 546 | * an ack/nack */ |
Pau Espin Pedrol | 9b63cd0 | 2021-05-11 14:54:40 +0200 | [diff] [blame] | 547 | maybe_schedule_uplink_acknack(rlc, block->len && rdbi->cv == 0); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 548 | |
| 549 | return 0; |
| 550 | } |
| 551 | |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 552 | void gprs_rlcmac_ul_tbf::maybe_schedule_uplink_acknack( |
Pau Espin Pedrol | c33a024 | 2020-05-15 16:57:48 +0200 | [diff] [blame] | 553 | const gprs_rlc_data_info *rlc, bool countdown_finished) |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 554 | { |
Pau Espin Pedrol | 09afd6f | 2020-05-15 16:40:18 +0200 | [diff] [blame] | 555 | bool require_ack = false; |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 556 | bool have_ti = rlc->block_info[0].ti || |
| 557 | (rlc->num_data_blocks > 1 && rlc->block_info[1].ti); |
| 558 | |
Pau Espin Pedrol | 09afd6f | 2020-05-15 16:40:18 +0200 | [diff] [blame] | 559 | if (rlc->si) { |
| 560 | require_ack = true; |
| 561 | LOGPTBFUL(this, LOGL_NOTICE, |
| 562 | "Scheduling Ack/Nack, because MS is stalled.\n"); |
| 563 | } |
| 564 | if (have_ti) { |
| 565 | require_ack = true; |
| 566 | LOGPTBFUL(this, LOGL_DEBUG, |
| 567 | "Scheduling Ack/Nack, because TLLI is included.\n"); |
| 568 | } |
Pau Espin Pedrol | c33a024 | 2020-05-15 16:57:48 +0200 | [diff] [blame] | 569 | if (countdown_finished) { |
Pau Espin Pedrol | 09afd6f | 2020-05-15 16:40:18 +0200 | [diff] [blame] | 570 | require_ack = true; |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 571 | if (state_is(TBF_ST_FLOW)) |
Pau Espin Pedrol | c33a024 | 2020-05-15 16:57:48 +0200 | [diff] [blame] | 572 | LOGPTBFUL(this, LOGL_DEBUG, |
| 573 | "Scheduling Ack/Nack, because some data is missing and last block has CV==0.\n"); |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 574 | else if (state_is(TBF_ST_FINISHED)) |
Pau Espin Pedrol | c33a024 | 2020-05-15 16:57:48 +0200 | [diff] [blame] | 575 | LOGPTBFUL(this, LOGL_DEBUG, |
| 576 | "Scheduling final Ack/Nack, because all data was received and last block has CV==0.\n"); |
Pau Espin Pedrol | 09afd6f | 2020-05-15 16:40:18 +0200 | [diff] [blame] | 577 | } |
| 578 | if ((m_rx_counter % SEND_ACK_AFTER_FRAMES) == 0) { |
| 579 | require_ack = true; |
| 580 | LOGPTBFUL(this, LOGL_DEBUG, |
| 581 | "Scheduling Ack/Nack, because %d frames received.\n", |
| 582 | SEND_ACK_AFTER_FRAMES); |
| 583 | } |
| 584 | |
| 585 | if (!require_ack) |
| 586 | return; |
| 587 | |
| 588 | if (ul_ack_state_is(GPRS_RLCMAC_UL_ACK_NONE)) { |
| 589 | /* trigger sending at next RTS */ |
| 590 | TBF_SET_ACK_STATE(this, GPRS_RLCMAC_UL_ACK_SEND_ACK); |
| 591 | } else { |
| 592 | /* already triggered */ |
| 593 | LOGPTBFUL(this, LOGL_DEBUG, |
| 594 | "Sending Ack/Nack already scheduled, no need to re-schedule\n"); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 595 | } |
| 596 | } |
| 597 | |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 598 | /* Send Uplink unit-data to SGSN. */ |
| 599 | int gprs_rlcmac_ul_tbf::snd_ul_ud() |
| 600 | { |
| 601 | uint8_t qos_profile[3]; |
| 602 | struct msgb *llc_pdu; |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 603 | unsigned msg_len = NS_HDR_LEN + BSSGP_HDR_LEN + llc_frame_length(&m_llc); |
Pau Espin Pedrol | db5e339 | 2021-01-21 18:02:40 +0100 | [diff] [blame] | 604 | struct bssgp_bvc_ctx *bctx = bts->pcu->bssgp.bctx; |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 605 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 606 | LOGP(DBSSGP, LOGL_INFO, "LLC [PCU -> SGSN] %s len=%d\n", tbf_name(this), llc_frame_length(&m_llc)); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 607 | if (!bctx) { |
| 608 | LOGP(DBSSGP, LOGL_ERROR, "No bctx\n"); |
| 609 | m_llc.reset_frame_space(); |
| 610 | return -EIO; |
| 611 | } |
Pau Espin Pedrol | 488aa29 | 2019-09-25 17:48:35 +0200 | [diff] [blame] | 612 | |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 613 | llc_pdu = msgb_alloc_headroom(msg_len, msg_len,"llc_pdu"); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 614 | uint8_t *buf = msgb_push(llc_pdu, TL16V_GROSS_LEN(sizeof(uint8_t)*llc_frame_length(&m_llc))); |
| 615 | tl16v_put(buf, BSSGP_IE_LLC_PDU, sizeof(uint8_t)*llc_frame_length(&m_llc), m_llc.frame); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 616 | qos_profile[0] = QOS_PROFILE >> 16; |
| 617 | qos_profile[1] = QOS_PROFILE >> 8; |
| 618 | qos_profile[2] = QOS_PROFILE; |
| 619 | bssgp_tx_ul_ud(bctx, tlli(), qos_profile, llc_pdu); |
| 620 | |
| 621 | m_llc.reset_frame_space(); |
| 622 | return 0; |
| 623 | } |
| 624 | |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 625 | egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_second_seg( |
| 626 | const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block, |
| 627 | uint8_t *data, const uint8_t block_idx) |
| 628 | { |
| 629 | const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx]; |
| 630 | union split_block_status *spb_status = &block->spb_status; |
| 631 | uint8_t *rlc_data = &block->block[0]; |
| 632 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 633 | bts_do_rate_ctr_inc(bts, CTR_SPB_UL_SECOND_SEGMENT); |
sivasankari | da7250a | 2016-12-16 12:57:18 +0530 | [diff] [blame] | 634 | |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 635 | if (spb_status->block_status_ul & |
| 636 | EGPRS_RESEG_FIRST_SEG_RXD) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 637 | LOGPTBFUL(this, LOGL_DEBUG, |
| 638 | "Second seg is received first seg is already present set the status to complete\n"); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 639 | spb_status->block_status_ul = EGPRS_RESEG_DEFAULT; |
| 640 | |
| 641 | block->len += Decoding::rlc_copy_to_aligned_buffer(rlc, |
| 642 | block_idx, data, rlc_data + block->len); |
| 643 | block->block_info.data_len += rdbi->data_len; |
| 644 | } else if (spb_status->block_status_ul == EGPRS_RESEG_DEFAULT) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 645 | LOGPTBFUL(this, LOGL_DEBUG, |
| 646 | "Second seg is received first seg is not received set the status to second seg received\n"); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 647 | |
| 648 | block->len = Decoding::rlc_copy_to_aligned_buffer(rlc, |
| 649 | block_idx, data, |
| 650 | rlc_data + rlc->block_info[block_idx].data_len); |
| 651 | |
| 652 | spb_status->block_status_ul = EGPRS_RESEG_SECOND_SEG_RXD; |
| 653 | block->block_info = *rdbi; |
| 654 | } |
| 655 | return spb_status->block_status_ul; |
| 656 | } |
| 657 | |
| 658 | egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_first_seg( |
| 659 | const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block, |
| 660 | uint8_t *data, const uint8_t block_idx) |
| 661 | { |
| 662 | const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx]; |
| 663 | uint8_t *rlc_data = &block->block[0]; |
| 664 | union split_block_status *spb_status = &block->spb_status; |
| 665 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 666 | bts_do_rate_ctr_inc(bts, CTR_SPB_UL_FIRST_SEGMENT); |
sivasankari | da7250a | 2016-12-16 12:57:18 +0530 | [diff] [blame] | 667 | |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 668 | if (spb_status->block_status_ul & EGPRS_RESEG_SECOND_SEG_RXD) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 669 | LOGPTBFUL(this, LOGL_DEBUG, |
| 670 | "First seg is received second seg is already present set the status to complete\n"); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 671 | |
| 672 | block->len += Decoding::rlc_copy_to_aligned_buffer(rlc, |
| 673 | block_idx, data, rlc_data); |
| 674 | |
| 675 | block->block_info.data_len = block->len; |
| 676 | spb_status->block_status_ul = EGPRS_RESEG_DEFAULT; |
| 677 | } else if (spb_status->block_status_ul == EGPRS_RESEG_DEFAULT) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 678 | LOGPTBFUL(this, LOGL_DEBUG, |
| 679 | "First seg is received second seg is not received set the status to first seg received\n"); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 680 | |
| 681 | spb_status->block_status_ul = EGPRS_RESEG_FIRST_SEG_RXD; |
| 682 | block->len = Decoding::rlc_copy_to_aligned_buffer(rlc, |
| 683 | block_idx, data, rlc_data); |
| 684 | block->block_info = *rdbi; |
| 685 | } |
| 686 | return spb_status->block_status_ul; |
| 687 | } |
| 688 | |
| 689 | egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_spb( |
| 690 | const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block, |
| 691 | uint8_t *data, const uint8_t block_idx) |
| 692 | { |
| 693 | const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx]; |
| 694 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 695 | LOGPTBFUL(this, LOGL_DEBUG, |
| 696 | "Got SPB(%d) cs(%s) data block with BSN (%d), TFI(%d).\n", |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 697 | rdbi->spb, mcs_name(rlc->cs), rdbi->bsn, rlc->tfi); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 698 | |
| 699 | egprs_rlc_ul_reseg_bsn_state assemble_status = EGPRS_RESEG_INVALID; |
| 700 | |
| 701 | /* Section 10.4.8b of 44.060*/ |
| 702 | if (rdbi->spb == 2) |
| 703 | assemble_status = handle_egprs_ul_first_seg(rlc, |
| 704 | block, data, block_idx); |
| 705 | else if (rdbi->spb == 3) |
| 706 | assemble_status = handle_egprs_ul_second_seg(rlc, |
| 707 | block, data, block_idx); |
| 708 | else { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 709 | LOGPTBFUL(this, LOGL_ERROR, |
| 710 | "spb(%d) Not supported SPB for this EGPRS configuration\n", |
| 711 | rdbi->spb); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | /* |
| 715 | * When the block is successfully constructed out of segmented blocks |
| 716 | * upgrade the MCS to the type 2 |
| 717 | */ |
| 718 | if (assemble_status == EGPRS_RESEG_DEFAULT) { |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 719 | switch (rlc->cs) { |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 720 | case MCS3 : |
| 721 | block->cs_last = MCS6; |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 722 | LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS6\n"); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 723 | break; |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 724 | case MCS2 : |
| 725 | block->cs_last = MCS5; |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 726 | LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS5\n"); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 727 | break; |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 728 | case MCS1 : |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 729 | LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS4\n"); |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 730 | block->cs_last = MCS4; |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 731 | break; |
| 732 | default: |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 733 | LOGPTBFUL(this, LOGL_ERROR, |
| 734 | "cs(%s) Error in Upgrading to higher MCS\n", |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 735 | mcs_name(rlc->cs)); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 736 | break; |
| 737 | } |
| 738 | } |
| 739 | return assemble_status; |
| 740 | } |
Mrinal Mishra | f86307e | 2016-11-10 18:16:30 +0530 | [diff] [blame] | 741 | |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 742 | void gprs_rlcmac_ul_tbf::update_coding_scheme_counter_ul(enum CodingScheme cs) |
Mrinal Mishra | f86307e | 2016-11-10 18:16:30 +0530 | [diff] [blame] | 743 | { |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 744 | switch (cs) { |
| 745 | case CS1: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 746 | bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS1); |
Pau Espin Pedrol | 9c1db17 | 2021-06-04 17:05:51 +0200 | [diff] [blame] | 747 | rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_gprs_ctrs, TBF_CTR_GPRS_UL_CS1)); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 748 | break; |
| 749 | case CS2: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 750 | bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS2); |
Pau Espin Pedrol | 9c1db17 | 2021-06-04 17:05:51 +0200 | [diff] [blame] | 751 | rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_gprs_ctrs, TBF_CTR_GPRS_UL_CS2)); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 752 | break; |
| 753 | case CS3: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 754 | bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS3); |
Pau Espin Pedrol | 9c1db17 | 2021-06-04 17:05:51 +0200 | [diff] [blame] | 755 | rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_gprs_ctrs, TBF_CTR_GPRS_UL_CS3)); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 756 | break; |
| 757 | case CS4: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 758 | bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS4); |
Pau Espin Pedrol | 9c1db17 | 2021-06-04 17:05:51 +0200 | [diff] [blame] | 759 | rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_gprs_ctrs, TBF_CTR_GPRS_UL_CS4)); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 760 | break; |
| 761 | case MCS1: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 762 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS1); |
Pau Espin Pedrol | 9c1db17 | 2021-06-04 17:05:51 +0200 | [diff] [blame] | 763 | rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS1)); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 764 | break; |
| 765 | case MCS2: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 766 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS2); |
Pau Espin Pedrol | 9c1db17 | 2021-06-04 17:05:51 +0200 | [diff] [blame] | 767 | rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS2)); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 768 | break; |
| 769 | case MCS3: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 770 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS3); |
Pau Espin Pedrol | 9c1db17 | 2021-06-04 17:05:51 +0200 | [diff] [blame] | 771 | rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS3)); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 772 | break; |
| 773 | case MCS4: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 774 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS4); |
Pau Espin Pedrol | 9c1db17 | 2021-06-04 17:05:51 +0200 | [diff] [blame] | 775 | rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS4)); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 776 | break; |
| 777 | case MCS5: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 778 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS5); |
Pau Espin Pedrol | 9c1db17 | 2021-06-04 17:05:51 +0200 | [diff] [blame] | 779 | rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS5)); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 780 | break; |
| 781 | case MCS6: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 782 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS6); |
Pau Espin Pedrol | 9c1db17 | 2021-06-04 17:05:51 +0200 | [diff] [blame] | 783 | rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS6)); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 784 | break; |
| 785 | case MCS7: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 786 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS7); |
Pau Espin Pedrol | 9c1db17 | 2021-06-04 17:05:51 +0200 | [diff] [blame] | 787 | rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS7)); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 788 | break; |
| 789 | case MCS8: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 790 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS8); |
Pau Espin Pedrol | 9c1db17 | 2021-06-04 17:05:51 +0200 | [diff] [blame] | 791 | rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS8)); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 792 | break; |
| 793 | case MCS9: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 794 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS9); |
Pau Espin Pedrol | 9c1db17 | 2021-06-04 17:05:51 +0200 | [diff] [blame] | 795 | rate_ctr_inc(rate_ctr_group_get_ctr(m_ul_egprs_ctrs, TBF_CTR_EGPRS_UL_MCS9)); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 796 | break; |
| 797 | default: |
| 798 | LOGPTBFUL(this, LOGL_ERROR, "attempting to update rate counters for unsupported (M)CS %s\n", |
| 799 | mcs_name(cs)); |
Mrinal Mishra | f86307e | 2016-11-10 18:16:30 +0530 | [diff] [blame] | 800 | } |
| 801 | } |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 802 | |
Max | 9d7357e | 2017-12-14 15:02:33 +0100 | [diff] [blame] | 803 | void gprs_rlcmac_ul_tbf::set_window_size() |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 804 | { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 805 | const struct gprs_rlcmac_bts *b = bts; |
Max | 34513fe | 2018-12-11 16:47:30 +0100 | [diff] [blame] | 806 | uint16_t ws = egprs_window_size(b, ul_slots()); |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 807 | LOGPTBFUL(this, LOGL_INFO, "setting EGPRS UL window size to %u, base(%u) slots(%u) ws_pdch(%u)\n", |
Pau Espin Pedrol | 519d071 | 2021-01-14 14:30:03 +0100 | [diff] [blame] | 808 | ws, bts->pcu->vty.ws_base, pcu_bitcount(ul_slots()), bts->pcu->vty.ws_pdch); |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 809 | m_window.set_ws(ws); |
| 810 | } |
Pau Espin Pedrol | 9767e44 | 2020-10-23 21:11:41 +0200 | [diff] [blame] | 811 | |
Pau Espin Pedrol | b3f2397 | 2020-10-23 21:00:23 +0200 | [diff] [blame] | 812 | gprs_rlc_window *gprs_rlcmac_ul_tbf::window() |
Pau Espin Pedrol | 9767e44 | 2020-10-23 21:11:41 +0200 | [diff] [blame] | 813 | { |
| 814 | return &m_window; |
| 815 | } |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 816 | |
Pau Espin Pedrol | 0b998b1 | 2021-03-24 14:45:43 +0100 | [diff] [blame] | 817 | void gprs_rlcmac_ul_tbf::usf_timeout() |
| 818 | { |
Pau Espin Pedrol | cfb61d9 | 2021-07-26 17:17:02 +0200 | [diff] [blame^] | 819 | if (n_inc(N3101)) |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 820 | osmo_fsm_inst_dispatch(this->state_fsm.fi, TBF_EV_MAX_N3101, NULL); |
Pau Espin Pedrol | 0b998b1 | 2021-03-24 14:45:43 +0100 | [diff] [blame] | 821 | } |
| 822 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 823 | struct gprs_rlcmac_ul_tbf *as_ul_tbf(struct gprs_rlcmac_tbf *tbf) |
| 824 | { |
| 825 | if (tbf && tbf->direction == GPRS_RLCMAC_UL_TBF) |
| 826 | return static_cast<gprs_rlcmac_ul_tbf *>(tbf); |
| 827 | else |
| 828 | return NULL; |
| 829 | } |
Pau Espin Pedrol | 0b998b1 | 2021-03-24 14:45:43 +0100 | [diff] [blame] | 830 | |
| 831 | void tbf_usf_timeout(struct gprs_rlcmac_ul_tbf *tbf) |
| 832 | { |
| 833 | tbf->usf_timeout(); |
| 834 | } |