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> |
| 23 | #include <tbf.h> |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 24 | #include <tbf_ul.h> |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 25 | #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 Erlbeck | 20f6fd1 | 2015-06-08 11:05:45 +0200 | [diff] [blame] | 31 | #include <pcu_l1_if.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 32 | #include <gprs_ms.h> |
| 33 | #include <llc.h> |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 34 | #include "pcu_utils.h" |
| 35 | |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 36 | extern "C" { |
| 37 | #include <osmocom/core/msgb.h> |
| 38 | #include <osmocom/core/talloc.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 39 | #include <osmocom/core/bitvec.h> |
| 40 | #include <osmocom/core/logging.h> |
| 41 | #include <osmocom/core/rate_ctr.h> |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 42 | #include <osmocom/core/stats.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 43 | #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> |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 47 | #include "coding_scheme.h" |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 48 | } |
| 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 | |
| 56 | extern void *tall_pcu_ctx; |
| 57 | |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 58 | static 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 | |
| 65 | static 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 | |
| 77 | static 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 | |
| 85 | static 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 | |
| 93 | static int ul_tbf_dtor(struct gprs_rlcmac_ul_tbf *tbf) |
| 94 | { |
| 95 | tbf->~gprs_rlcmac_ul_tbf(); |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | struct 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 Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 106 | LOGP(DTBF, LOGL_DEBUG, "********** UL-TBF starts here **********\n"); |
| 107 | LOGP(DTBF, LOGL_INFO, "Allocating UL TBF: MS_CLASS=%d/%d\n", |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 108 | ms_ms_class(ms), ms_egprs_ms_class(ms)); |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 109 | |
| 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 Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 114 | new (tbf) gprs_rlcmac_ul_tbf(bts, ms); |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 115 | |
| 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 Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 137 | llist_add_tail(tbf_bts_list(tbf), &bts->ul_tbfs); |
| 138 | bts_do_rate_ctr_inc(tbf->bts, CTR_TBF_UL_ALLOCATED); |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 139 | |
| 140 | return tbf; |
| 141 | } |
| 142 | |
| 143 | |
| 144 | gprs_rlcmac_ul_tbf *tbf_alloc_ul(struct gprs_rlcmac_bts *bts, GprsMs *ms, int8_t use_trx, |
| 145 | uint32_t tlli) |
| 146 | { |
| 147 | struct gprs_rlcmac_ul_tbf *tbf; |
| 148 | |
| 149 | /* FIXME: Copy and paste with tbf_new_dl_assignment */ |
| 150 | /* create new TBF, use same TRX as DL TBF */ |
| 151 | /* use multislot class of downlink TBF */ |
| 152 | tbf = tbf_alloc_ul_tbf(bts, ms, use_trx, false); |
| 153 | if (!tbf) { |
| 154 | LOGP(DTBF, LOGL_NOTICE, "No PDCH resource\n"); |
| 155 | /* FIXME: send reject */ |
| 156 | return NULL; |
| 157 | } |
| 158 | tbf->m_contention_resolution_done = 1; |
| 159 | TBF_SET_ASS_ON(tbf, GPRS_RLCMAC_FLAG_PACCH, false); |
| 160 | T_START(tbf, T3169, 3169, "allocation (UL-TBF)", true); |
| 161 | tbf->update_ms(tlli, GPRS_RLCMAC_UL_TBF); |
| 162 | OSMO_ASSERT(tbf->ms()); |
| 163 | |
| 164 | return tbf; |
| 165 | } |
| 166 | |
| 167 | struct gprs_rlcmac_ul_tbf *handle_tbf_reject(struct gprs_rlcmac_bts *bts, |
| 168 | GprsMs *ms, uint32_t tlli, uint8_t trx_no, uint8_t ts) |
| 169 | { |
| 170 | struct gprs_rlcmac_ul_tbf *ul_tbf = NULL; |
| 171 | struct gprs_rlcmac_trx *trx = &bts->trx[trx_no]; |
| 172 | |
| 173 | if (!ms) |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 174 | ms = bts_alloc_ms(bts, 0, 0); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 175 | ms_set_tlli(ms, tlli); |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 176 | |
| 177 | ul_tbf = talloc(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf); |
| 178 | if (!ul_tbf) |
| 179 | return ul_tbf; |
| 180 | |
| 181 | talloc_set_destructor(ul_tbf, ul_tbf_dtor); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 182 | new (ul_tbf) gprs_rlcmac_ul_tbf(bts, ms); |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 183 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 184 | llist_add(tbf_bts_list((struct gprs_rlcmac_tbf *)ul_tbf), &bts->ul_tbfs); |
| 185 | bts_do_rate_ctr_inc(ul_tbf->bts, CTR_TBF_UL_ALLOCATED); |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 186 | TBF_SET_ASS_ON(ul_tbf, GPRS_RLCMAC_FLAG_PACCH, false); |
| 187 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 188 | ms_attach_tbf(ms, ul_tbf); |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 189 | ul_tbf->update_ms(tlli, GPRS_RLCMAC_UL_TBF); |
| 190 | TBF_SET_ASS_STATE_UL(ul_tbf, GPRS_RLCMAC_UL_ASS_SEND_ASS_REJ); |
| 191 | ul_tbf->control_ts = ts; |
| 192 | ul_tbf->trx = trx; |
| 193 | ul_tbf->m_ctrs = rate_ctr_group_alloc(ul_tbf, &tbf_ctrg_desc, next_tbf_ctr_group_id++); |
| 194 | ul_tbf->m_ul_egprs_ctrs = rate_ctr_group_alloc(ul_tbf, |
| 195 | &tbf_ul_egprs_ctrg_desc, |
| 196 | ul_tbf->m_ctrs->idx); |
| 197 | ul_tbf->m_ul_gprs_ctrs = rate_ctr_group_alloc(ul_tbf, |
| 198 | &tbf_ul_gprs_ctrg_desc, |
| 199 | ul_tbf->m_ctrs->idx); |
| 200 | if (!ul_tbf->m_ctrs || !ul_tbf->m_ul_egprs_ctrs || !ul_tbf->m_ul_gprs_ctrs) { |
| 201 | LOGPTBF(ul_tbf, LOGL_ERROR, "Cound not allocate TBF UL rate counters\n"); |
| 202 | talloc_free(ul_tbf); |
| 203 | return NULL; |
| 204 | } |
| 205 | |
| 206 | return ul_tbf; |
| 207 | } |
| 208 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 209 | 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] | 210 | gprs_rlcmac_tbf(bts_, ms, GPRS_RLCMAC_UL_TBF), |
Pau Espin Pedrol | bddf1ad | 2019-09-26 14:41:18 +0200 | [diff] [blame] | 211 | m_rx_counter(0), |
| 212 | m_contention_resolution_done(0), |
| 213 | m_final_ack_sent(0), |
| 214 | m_ul_gprs_ctrs(NULL), |
| 215 | m_ul_egprs_ctrs(NULL) |
| 216 | { |
| 217 | memset(&m_usf, 0, sizeof(m_usf)); |
| 218 | } |
| 219 | |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 220 | /* |
| 221 | * Store received block data in LLC message(s) and forward to SGSN |
| 222 | * if complete. |
| 223 | */ |
| 224 | int gprs_rlcmac_ul_tbf::assemble_forward_llc(const gprs_rlc_data *_data) |
| 225 | { |
| 226 | const uint8_t *data = _data->block; |
| 227 | uint8_t len = _data->len; |
Jacob Erlbeck | f2ba4cb | 2016-01-07 18:59:28 +0100 | [diff] [blame] | 228 | const struct gprs_rlc_data_block_info *rdbi = &_data->block_info; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 229 | enum CodingScheme cs = _data->cs_last; |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 230 | |
| 231 | Decoding::RlcData frames[16], *frame; |
| 232 | int i, num_frames = 0; |
| 233 | uint32_t dummy_tlli; |
| 234 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 235 | LOGPTBFUL(this, LOGL_DEBUG, "Assembling frames: (len=%d)\n", len); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 236 | |
| 237 | num_frames = Decoding::rlc_data_from_ul_data( |
Alexander Couzens | ce936f3 | 2016-05-24 14:45:41 +0200 | [diff] [blame] | 238 | rdbi, cs, data, &(frames[0]), ARRAY_SIZE(frames), |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 239 | &dummy_tlli); |
| 240 | |
| 241 | /* create LLC frames */ |
| 242 | for (i = 0; i < num_frames; i++) { |
| 243 | frame = frames + i; |
| 244 | |
Aravind Sirsikar | 22a9019 | 2016-09-15 17:24:49 +0530 | [diff] [blame] | 245 | if (frame->length) { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 246 | 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] | 247 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 248 | LOGPTBFUL(this, LOGL_DEBUG, "Frame %d " |
Aravind Sirsikar | 22a9019 | 2016-09-15 17:24:49 +0530 | [diff] [blame] | 249 | "starts at offset %d, " |
| 250 | "length=%d, is_complete=%d\n", |
| 251 | i + 1, frame->offset, frame->length, |
| 252 | frame->is_complete); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 253 | |
Aravind Sirsikar | 22a9019 | 2016-09-15 17:24:49 +0530 | [diff] [blame] | 254 | m_llc.append_frame(data + frame->offset, frame->length); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 255 | llc_consume(&m_llc, frame->length); |
Aravind Sirsikar | 22a9019 | 2016-09-15 17:24:49 +0530 | [diff] [blame] | 256 | } |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 257 | |
| 258 | if (frame->is_complete) { |
| 259 | /* send frame to SGSN */ |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 260 | 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] | 261 | snd_ul_ud(); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 262 | 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] | 263 | m_llc.reset(); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | |
Max | fd13f6c | 2017-07-07 14:29:36 +0200 | [diff] [blame] | 270 | bool gprs_rlcmac_ul_tbf::ctrl_ack_to_toggle() |
| 271 | { |
Max | 8dce1de | 2018-01-02 14:17:04 +0100 | [diff] [blame] | 272 | if (check_n_clear(GPRS_RLCMAC_FLAG_TO_UL_ACK)) |
Max | fd13f6c | 2017-07-07 14:29:36 +0200 | [diff] [blame] | 273 | return true; /* GPRS_RLCMAC_FLAG_TO_UL_ACK was set, now cleared */ |
Max | fd13f6c | 2017-07-07 14:29:36 +0200 | [diff] [blame] | 274 | |
| 275 | state_flags |= (1 << GPRS_RLCMAC_FLAG_TO_UL_ACK); |
| 276 | return false; /* GPRS_RLCMAC_FLAG_TO_UL_ACK was unset, now set */ |
| 277 | } |
| 278 | |
| 279 | bool gprs_rlcmac_ul_tbf::handle_ctrl_ack() |
| 280 | { |
| 281 | /* check if this control ack belongs to packet uplink ack */ |
Max | 088c7df | 2018-01-23 20:16:23 +0100 | [diff] [blame] | 282 | if (ul_ack_state_is(GPRS_RLCMAC_UL_ACK_WAIT_ACK)) { |
| 283 | TBF_SET_ACK_STATE(this, GPRS_RLCMAC_UL_ACK_NONE); |
Max | fd13f6c | 2017-07-07 14:29:36 +0200 | [diff] [blame] | 284 | return true; |
| 285 | } |
| 286 | |
| 287 | return false; |
| 288 | } |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 289 | |
Jacob Erlbeck | 5a3c84d | 2016-01-22 17:25:38 +0100 | [diff] [blame] | 290 | 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] | 291 | { |
| 292 | int final = (state_is(GPRS_RLCMAC_FINISHED)); |
| 293 | struct msgb *msg; |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 294 | int rc; |
| 295 | unsigned int rrbp = 0; |
| 296 | uint32_t new_poll_fn = 0; |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 297 | |
| 298 | if (final) { |
Max | cac6b66 | 2018-01-24 11:00:17 +0100 | [diff] [blame] | 299 | if (poll_scheduled() && ul_ack_state_is(GPRS_RLCMAC_UL_ACK_WAIT_ACK)) { |
Max | c21f007 | 2017-12-15 17:36:45 +0100 | [diff] [blame] | 300 | LOGPTBFUL(this, LOGL_DEBUG, |
| 301 | "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] | 302 | return NULL; |
| 303 | } |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 304 | |
| 305 | rc = check_polling(fn, ts, &new_poll_fn, &rrbp); |
| 306 | if (rc < 0) |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 307 | return NULL; |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | msg = msgb_alloc(23, "rlcmac_ul_ack"); |
| 311 | if (!msg) |
| 312 | return NULL; |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 313 | bitvec *ack_vec = bitvec_alloc(23, tall_pcu_ctx); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 314 | if (!ack_vec) { |
| 315 | msgb_free(msg); |
| 316 | return NULL; |
| 317 | } |
Max | 7426c5f | 2019-02-18 20:42:42 +0100 | [diff] [blame] | 318 | bitvec_unhex(ack_vec, DUMMY_VEC); |
Alexander Couzens | 3a499f3 | 2019-06-16 15:25:30 +0200 | [diff] [blame] | 319 | Encoding::write_packet_uplink_ack(ack_vec, this, final, rrbp); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 320 | bitvec_pack(ack_vec, msgb_put(msg, 23)); |
| 321 | bitvec_free(ack_vec); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 322 | |
| 323 | /* now we must set this flag, so we are allowed to assign downlink |
| 324 | * TBF on PACCH. it is only allowed when TLLI is acknowledged. */ |
| 325 | m_contention_resolution_done = 1; |
| 326 | |
| 327 | if (final) { |
Max | f60cf62 | 2017-07-10 14:40:09 +0200 | [diff] [blame] | 328 | set_polling(new_poll_fn, ts, GPRS_RLCMAC_POLL_UL_ACK); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 329 | /* waiting for final acknowledge */ |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 330 | m_final_ack_sent = 1; |
| 331 | } else |
Max | 088c7df | 2018-01-23 20:16:23 +0100 | [diff] [blame] | 332 | TBF_SET_ACK_STATE(this, GPRS_RLCMAC_UL_ACK_NONE); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 333 | |
| 334 | return msg; |
| 335 | } |
| 336 | |
Alexander Couzens | 2fcfc29 | 2016-05-24 14:40:03 +0200 | [diff] [blame] | 337 | /*! \brief receive data from PDCH/L1 */ |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 338 | int gprs_rlcmac_ul_tbf::rcv_data_block_acknowledged( |
Jacob Erlbeck | f2ba4cb | 2016-01-07 18:59:28 +0100 | [diff] [blame] | 339 | const struct gprs_rlc_data_info *rlc, |
Jacob Erlbeck | fc1b3e6 | 2016-01-11 09:58:11 +0100 | [diff] [blame] | 340 | uint8_t *data, struct pcu_l1_meas *meas) |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 341 | { |
Pau Espin Pedrol | c33a024 | 2020-05-15 16:57:48 +0200 | [diff] [blame] | 342 | const struct gprs_rlc_data_block_info *rdbi; |
| 343 | struct gprs_rlc_data *block; |
| 344 | |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 345 | int8_t rssi = meas->have_rssi ? meas->rssi : 0; |
| 346 | |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 347 | const uint16_t ws = m_window.ws(); |
| 348 | |
| 349 | this->state_flags |= (1 << GPRS_RLCMAC_FLAG_UL_DATA); |
| 350 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 351 | LOGPTBFUL(this, LOGL_DEBUG, "UL DATA TFI=%d received (V(Q)=%d .. " |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 352 | "V(R)=%d)\n", rlc->tfi, this->m_window.v_q(), |
| 353 | this->m_window.v_r()); |
| 354 | |
| 355 | /* process RSSI */ |
| 356 | gprs_rlcmac_rssi(this, rssi); |
| 357 | |
| 358 | /* store measurement values */ |
| 359 | if (ms()) |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 360 | ms_update_l1_meas(ms(), meas); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 361 | |
Vadim Yanitskiy | cb98894 | 2020-11-08 13:27:35 +0700 | [diff] [blame] | 362 | uint32_t new_tlli = GSM_RESERVED_TMSI; |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 363 | unsigned int block_idx; |
| 364 | |
| 365 | /* restart T3169 */ |
Pau Espin Pedrol | 28f160e | 2019-09-05 14:48:35 +0200 | [diff] [blame] | 366 | T_START(this, T3169, 3169, "acked (data)", true); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 367 | |
| 368 | /* Increment RX-counter */ |
| 369 | this->m_rx_counter++; |
Mrinal Mishra | f86307e | 2016-11-10 18:16:30 +0530 | [diff] [blame] | 370 | update_coding_scheme_counter_ul(rlc->cs); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 371 | /* Loop over num_blocks */ |
| 372 | for (block_idx = 0; block_idx < rlc->num_data_blocks; block_idx++) { |
| 373 | int num_chunks; |
| 374 | uint8_t *rlc_data; |
Pau Espin Pedrol | c33a024 | 2020-05-15 16:57:48 +0200 | [diff] [blame] | 375 | rdbi = &rlc->block_info[block_idx]; |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 376 | bool need_rlc_data = false; |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 377 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 378 | LOGPTBFUL(this, LOGL_DEBUG, |
| 379 | "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] | 380 | mcs_name(rlc->cs), |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 381 | rdbi->cv, rdbi->bsn, rdbi->spb, |
| 382 | rdbi->pi, rdbi->e, rdbi->ti, |
| 383 | rlc->data_offs_bits[block_idx]); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 384 | |
| 385 | /* Check whether the block needs to be decoded */ |
| 386 | |
| 387 | if (!m_window.is_in_window(rdbi->bsn)) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 388 | LOGPTBFUL(this, LOGL_DEBUG, "BSN %d out of window %d..%d (it's normal)\n", |
| 389 | rdbi->bsn, |
| 390 | m_window.v_q(), m_window.mod_sns(m_window.v_q() + ws - 1)); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 391 | } else if (m_window.is_received(rdbi->bsn)) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 392 | LOGPTBFUL(this, LOGL_DEBUG, |
| 393 | "BSN %d already received\n", rdbi->bsn); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 394 | } else { |
| 395 | need_rlc_data = true; |
| 396 | } |
| 397 | |
| 398 | if (!is_tlli_valid()) { |
| 399 | if (!rdbi->ti) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 400 | LOGPTBFUL(this, LOGL_NOTICE, "Missing TLLI within UL DATA.\n"); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 401 | continue; |
| 402 | } |
| 403 | need_rlc_data = true; |
| 404 | } |
| 405 | |
| 406 | if (!need_rlc_data) |
| 407 | continue; |
| 408 | |
| 409 | /* Store block and meta info to BSN buffer */ |
| 410 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 411 | LOGPTBFUL(this, LOGL_DEBUG, "BSN %d storing in window (%d..%d)\n", |
| 412 | rdbi->bsn, m_window.v_q(), |
| 413 | m_window.mod_sns(m_window.v_q() + ws - 1)); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 414 | block = m_rlc.block(rdbi->bsn); |
Aravind Sirsikar | 550a541 | 2016-06-14 18:59:18 +0530 | [diff] [blame] | 415 | OSMO_ASSERT(rdbi->data_len <= sizeof(block->block)); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 416 | rlc_data = &(block->block[0]); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 417 | |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 418 | if (rdbi->spb) { |
| 419 | egprs_rlc_ul_reseg_bsn_state assemble_status; |
| 420 | |
| 421 | assemble_status = handle_egprs_ul_spb(rlc, |
| 422 | block, data, block_idx); |
| 423 | |
| 424 | if (assemble_status != EGPRS_RESEG_DEFAULT) |
| 425 | return 0; |
| 426 | } else { |
| 427 | block->block_info = *rdbi; |
| 428 | block->cs_last = rlc->cs; |
| 429 | block->len = |
| 430 | Decoding::rlc_copy_to_aligned_buffer(rlc, |
| 431 | block_idx, data, rlc_data); |
| 432 | } |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 433 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 434 | LOGPTBFUL(this, LOGL_DEBUG, |
| 435 | "data_length=%d, data=%s\n", |
| 436 | block->len, osmo_hexdump(rlc_data, block->len)); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 437 | /* Get/Handle TLLI */ |
| 438 | if (rdbi->ti) { |
| 439 | num_chunks = Decoding::rlc_data_from_ul_data( |
| 440 | rdbi, rlc->cs, rlc_data, NULL, 0, &new_tlli); |
| 441 | |
| 442 | if (num_chunks < 0) { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 443 | bts_do_rate_ctr_inc(bts, CTR_DECODE_ERRORS); |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 444 | LOGPTBFUL(this, LOGL_NOTICE, |
| 445 | "Failed to decode TLLI of %s UL DATA TFI=%d.\n", |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 446 | mcs_name(rlc->cs), rlc->tfi); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 447 | m_window.invalidate_bsn(rdbi->bsn); |
| 448 | continue; |
| 449 | } |
| 450 | if (!this->is_tlli_valid()) { |
Vadim Yanitskiy | cb98894 | 2020-11-08 13:27:35 +0700 | [diff] [blame] | 451 | if (new_tlli == GSM_RESERVED_TMSI) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 452 | LOGPTBFUL(this, LOGL_NOTICE, |
Vadim Yanitskiy | cb98894 | 2020-11-08 13:27:35 +0700 | [diff] [blame] | 453 | "TLLI is 0x%08x within UL DATA?!?\n", |
| 454 | new_tlli); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 455 | m_window.invalidate_bsn(rdbi->bsn); |
| 456 | continue; |
| 457 | } |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 458 | LOGPTBFUL(this, LOGL_INFO, |
| 459 | "Decoded premier TLLI=0x%08x of UL DATA TFI=%d.\n", |
Vadim Yanitskiy | 3f27fb5 | 2020-04-20 11:26:12 +0700 | [diff] [blame] | 460 | new_tlli, rlc->tfi); |
Pau Espin Pedrol | d21e961 | 2020-06-26 14:20:37 +0200 | [diff] [blame] | 461 | update_ms(new_tlli, GPRS_RLCMAC_UL_TBF); |
Vadim Yanitskiy | cb98894 | 2020-11-08 13:27:35 +0700 | [diff] [blame] | 462 | } else if (new_tlli != GSM_RESERVED_TMSI && new_tlli != tlli()) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 463 | LOGPTBFUL(this, LOGL_NOTICE, |
Pau Espin Pedrol | 305763d | 2020-11-06 20:03:24 +0100 | [diff] [blame] | 464 | "Decoded TLLI=%08x mismatch on UL DATA TFI=%d. (Ignoring due to contention resolution)\n", |
| 465 | new_tlli, rlc->tfi); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 466 | m_window.invalidate_bsn(rdbi->bsn); |
| 467 | continue; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | m_window.receive_bsn(rdbi->bsn); |
| 472 | } |
| 473 | |
| 474 | /* Raise V(Q) if possible, and retrieve LLC frames from blocks. |
| 475 | * This is looped until there is a gap (non received block) or |
| 476 | * the window is empty.*/ |
| 477 | const uint16_t v_q_beg = m_window.v_q(); |
| 478 | const uint16_t count = m_window.raise_v_q(); |
| 479 | |
| 480 | /* Retrieve LLC frames from blocks that are ready */ |
| 481 | for (uint16_t i = 0; i < count; ++i) { |
Jacob Erlbeck | 93c55d0 | 2015-12-23 16:29:07 +0100 | [diff] [blame] | 482 | uint16_t index = m_window.mod_sns(v_q_beg + i); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 483 | assemble_forward_llc(m_rlc.block(index)); |
| 484 | } |
| 485 | |
Pau Espin Pedrol | c33a024 | 2020-05-15 16:57:48 +0200 | [diff] [blame] | 486 | /* Last frame in buffer: */ |
| 487 | block = m_rlc.block(m_window.mod_sns(m_window.v_r() - 1)); |
| 488 | rdbi = &block->block_info; |
| 489 | |
| 490 | /* Check if we already received all data TBF had to send: */ |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 491 | if (this->state_is(GPRS_RLCMAC_FLOW) /* still in flow state */ |
| 492 | && this->m_window.v_q() == this->m_window.v_r()) { /* if complete */ |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 493 | LOGPTBFUL(this, LOGL_DEBUG, |
| 494 | "No gaps in received block, last block: BSN=%d CV=%d\n", |
| 495 | rdbi->bsn, rdbi->cv); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 496 | if (rdbi->cv == 0) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 497 | LOGPTBFUL(this, LOGL_DEBUG, "Finished with UL TBF\n"); |
Max | 2399b1d | 2018-01-12 15:48:12 +0100 | [diff] [blame] | 498 | TBF_SET_STATE(this, GPRS_RLCMAC_FINISHED); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 499 | /* Reset N3103 counter. */ |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 500 | this->n_reset(N3103); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | |
| 504 | /* If TLLI is included or if we received half of the window, we send |
| 505 | * an ack/nack */ |
Pau Espin Pedrol | c33a024 | 2020-05-15 16:57:48 +0200 | [diff] [blame] | 506 | maybe_schedule_uplink_acknack(rlc, rdbi->cv == 0); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 511 | void gprs_rlcmac_ul_tbf::maybe_schedule_uplink_acknack( |
Pau Espin Pedrol | c33a024 | 2020-05-15 16:57:48 +0200 | [diff] [blame] | 512 | const gprs_rlc_data_info *rlc, bool countdown_finished) |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 513 | { |
Pau Espin Pedrol | 09afd6f | 2020-05-15 16:40:18 +0200 | [diff] [blame] | 514 | bool require_ack = false; |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 515 | bool have_ti = rlc->block_info[0].ti || |
| 516 | (rlc->num_data_blocks > 1 && rlc->block_info[1].ti); |
| 517 | |
Pau Espin Pedrol | 09afd6f | 2020-05-15 16:40:18 +0200 | [diff] [blame] | 518 | if (rlc->si) { |
| 519 | require_ack = true; |
| 520 | LOGPTBFUL(this, LOGL_NOTICE, |
| 521 | "Scheduling Ack/Nack, because MS is stalled.\n"); |
| 522 | } |
| 523 | if (have_ti) { |
| 524 | require_ack = true; |
| 525 | LOGPTBFUL(this, LOGL_DEBUG, |
| 526 | "Scheduling Ack/Nack, because TLLI is included.\n"); |
| 527 | } |
Pau Espin Pedrol | c33a024 | 2020-05-15 16:57:48 +0200 | [diff] [blame] | 528 | if (countdown_finished) { |
Pau Espin Pedrol | 09afd6f | 2020-05-15 16:40:18 +0200 | [diff] [blame] | 529 | require_ack = true; |
Pau Espin Pedrol | c33a024 | 2020-05-15 16:57:48 +0200 | [diff] [blame] | 530 | if (state_is(GPRS_RLCMAC_FLOW)) |
| 531 | LOGPTBFUL(this, LOGL_DEBUG, |
| 532 | "Scheduling Ack/Nack, because some data is missing and last block has CV==0.\n"); |
| 533 | else if (state_is(GPRS_RLCMAC_FINISHED)) |
| 534 | LOGPTBFUL(this, LOGL_DEBUG, |
| 535 | "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] | 536 | } |
| 537 | if ((m_rx_counter % SEND_ACK_AFTER_FRAMES) == 0) { |
| 538 | require_ack = true; |
| 539 | LOGPTBFUL(this, LOGL_DEBUG, |
| 540 | "Scheduling Ack/Nack, because %d frames received.\n", |
| 541 | SEND_ACK_AFTER_FRAMES); |
| 542 | } |
| 543 | |
| 544 | if (!require_ack) |
| 545 | return; |
| 546 | |
| 547 | if (ul_ack_state_is(GPRS_RLCMAC_UL_ACK_NONE)) { |
| 548 | /* trigger sending at next RTS */ |
| 549 | TBF_SET_ACK_STATE(this, GPRS_RLCMAC_UL_ACK_SEND_ACK); |
| 550 | } else { |
| 551 | /* already triggered */ |
| 552 | LOGPTBFUL(this, LOGL_DEBUG, |
| 553 | "Sending Ack/Nack already scheduled, no need to re-schedule\n"); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 557 | /* Send Uplink unit-data to SGSN. */ |
| 558 | int gprs_rlcmac_ul_tbf::snd_ul_ud() |
| 559 | { |
| 560 | uint8_t qos_profile[3]; |
| 561 | struct msgb *llc_pdu; |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 562 | 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] | 563 | struct bssgp_bvc_ctx *bctx = bts->pcu->bssgp.bctx; |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 564 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 565 | 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] | 566 | if (!bctx) { |
| 567 | LOGP(DBSSGP, LOGL_ERROR, "No bctx\n"); |
| 568 | m_llc.reset_frame_space(); |
| 569 | return -EIO; |
| 570 | } |
Pau Espin Pedrol | 488aa29 | 2019-09-25 17:48:35 +0200 | [diff] [blame] | 571 | |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 572 | llc_pdu = msgb_alloc_headroom(msg_len, msg_len,"llc_pdu"); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 573 | uint8_t *buf = msgb_push(llc_pdu, TL16V_GROSS_LEN(sizeof(uint8_t)*llc_frame_length(&m_llc))); |
| 574 | 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] | 575 | qos_profile[0] = QOS_PROFILE >> 16; |
| 576 | qos_profile[1] = QOS_PROFILE >> 8; |
| 577 | qos_profile[2] = QOS_PROFILE; |
| 578 | bssgp_tx_ul_ud(bctx, tlli(), qos_profile, llc_pdu); |
| 579 | |
| 580 | m_llc.reset_frame_space(); |
| 581 | return 0; |
| 582 | } |
| 583 | |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 584 | egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_second_seg( |
| 585 | const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block, |
| 586 | uint8_t *data, const uint8_t block_idx) |
| 587 | { |
| 588 | const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx]; |
| 589 | union split_block_status *spb_status = &block->spb_status; |
| 590 | uint8_t *rlc_data = &block->block[0]; |
| 591 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 592 | bts_do_rate_ctr_inc(bts, CTR_SPB_UL_SECOND_SEGMENT); |
sivasankari | da7250a | 2016-12-16 12:57:18 +0530 | [diff] [blame] | 593 | |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 594 | if (spb_status->block_status_ul & |
| 595 | EGPRS_RESEG_FIRST_SEG_RXD) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 596 | LOGPTBFUL(this, LOGL_DEBUG, |
| 597 | "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] | 598 | spb_status->block_status_ul = EGPRS_RESEG_DEFAULT; |
| 599 | |
| 600 | block->len += Decoding::rlc_copy_to_aligned_buffer(rlc, |
| 601 | block_idx, data, rlc_data + block->len); |
| 602 | block->block_info.data_len += rdbi->data_len; |
| 603 | } else if (spb_status->block_status_ul == EGPRS_RESEG_DEFAULT) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 604 | LOGPTBFUL(this, LOGL_DEBUG, |
| 605 | "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] | 606 | |
| 607 | block->len = Decoding::rlc_copy_to_aligned_buffer(rlc, |
| 608 | block_idx, data, |
| 609 | rlc_data + rlc->block_info[block_idx].data_len); |
| 610 | |
| 611 | spb_status->block_status_ul = EGPRS_RESEG_SECOND_SEG_RXD; |
| 612 | block->block_info = *rdbi; |
| 613 | } |
| 614 | return spb_status->block_status_ul; |
| 615 | } |
| 616 | |
| 617 | egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_first_seg( |
| 618 | const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block, |
| 619 | uint8_t *data, const uint8_t block_idx) |
| 620 | { |
| 621 | const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx]; |
| 622 | uint8_t *rlc_data = &block->block[0]; |
| 623 | union split_block_status *spb_status = &block->spb_status; |
| 624 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 625 | bts_do_rate_ctr_inc(bts, CTR_SPB_UL_FIRST_SEGMENT); |
sivasankari | da7250a | 2016-12-16 12:57:18 +0530 | [diff] [blame] | 626 | |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 627 | if (spb_status->block_status_ul & EGPRS_RESEG_SECOND_SEG_RXD) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 628 | LOGPTBFUL(this, LOGL_DEBUG, |
| 629 | "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] | 630 | |
| 631 | block->len += Decoding::rlc_copy_to_aligned_buffer(rlc, |
| 632 | block_idx, data, rlc_data); |
| 633 | |
| 634 | block->block_info.data_len = block->len; |
| 635 | spb_status->block_status_ul = EGPRS_RESEG_DEFAULT; |
| 636 | } else if (spb_status->block_status_ul == EGPRS_RESEG_DEFAULT) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 637 | LOGPTBFUL(this, LOGL_DEBUG, |
| 638 | "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] | 639 | |
| 640 | spb_status->block_status_ul = EGPRS_RESEG_FIRST_SEG_RXD; |
| 641 | block->len = Decoding::rlc_copy_to_aligned_buffer(rlc, |
| 642 | block_idx, data, rlc_data); |
| 643 | block->block_info = *rdbi; |
| 644 | } |
| 645 | return spb_status->block_status_ul; |
| 646 | } |
| 647 | |
| 648 | egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_spb( |
| 649 | const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block, |
| 650 | uint8_t *data, const uint8_t block_idx) |
| 651 | { |
| 652 | const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx]; |
| 653 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 654 | LOGPTBFUL(this, LOGL_DEBUG, |
| 655 | "Got SPB(%d) cs(%s) data block with BSN (%d), TFI(%d).\n", |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 656 | rdbi->spb, mcs_name(rlc->cs), rdbi->bsn, rlc->tfi); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 657 | |
| 658 | egprs_rlc_ul_reseg_bsn_state assemble_status = EGPRS_RESEG_INVALID; |
| 659 | |
| 660 | /* Section 10.4.8b of 44.060*/ |
| 661 | if (rdbi->spb == 2) |
| 662 | assemble_status = handle_egprs_ul_first_seg(rlc, |
| 663 | block, data, block_idx); |
| 664 | else if (rdbi->spb == 3) |
| 665 | assemble_status = handle_egprs_ul_second_seg(rlc, |
| 666 | block, data, block_idx); |
| 667 | else { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 668 | LOGPTBFUL(this, LOGL_ERROR, |
| 669 | "spb(%d) Not supported SPB for this EGPRS configuration\n", |
| 670 | rdbi->spb); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | /* |
| 674 | * When the block is successfully constructed out of segmented blocks |
| 675 | * upgrade the MCS to the type 2 |
| 676 | */ |
| 677 | if (assemble_status == EGPRS_RESEG_DEFAULT) { |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 678 | switch (rlc->cs) { |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 679 | case MCS3 : |
| 680 | block->cs_last = MCS6; |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 681 | LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS6\n"); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 682 | break; |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 683 | case MCS2 : |
| 684 | block->cs_last = MCS5; |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 685 | LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS5\n"); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 686 | break; |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 687 | case MCS1 : |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 688 | LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS4\n"); |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 689 | block->cs_last = MCS4; |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 690 | break; |
| 691 | default: |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 692 | LOGPTBFUL(this, LOGL_ERROR, |
| 693 | "cs(%s) Error in Upgrading to higher MCS\n", |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 694 | mcs_name(rlc->cs)); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 695 | break; |
| 696 | } |
| 697 | } |
| 698 | return assemble_status; |
| 699 | } |
Mrinal Mishra | f86307e | 2016-11-10 18:16:30 +0530 | [diff] [blame] | 700 | |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 701 | 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] | 702 | { |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 703 | switch (cs) { |
| 704 | case CS1: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 705 | bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS1); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 706 | rate_ctr_inc(&m_ul_gprs_ctrs->ctr[TBF_CTR_GPRS_UL_CS1]); |
| 707 | break; |
| 708 | case CS2: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 709 | bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS2); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 710 | rate_ctr_inc(&m_ul_gprs_ctrs->ctr[TBF_CTR_GPRS_UL_CS2]); |
| 711 | break; |
| 712 | case CS3: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 713 | bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS3); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 714 | rate_ctr_inc(&m_ul_gprs_ctrs->ctr[TBF_CTR_GPRS_UL_CS3]); |
| 715 | break; |
| 716 | case CS4: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 717 | bts_do_rate_ctr_inc(bts, CTR_GPRS_UL_CS4); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 718 | rate_ctr_inc(&m_ul_gprs_ctrs->ctr[TBF_CTR_GPRS_UL_CS4]); |
| 719 | break; |
| 720 | case MCS1: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 721 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS1); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 722 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS1]); |
| 723 | break; |
| 724 | case MCS2: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 725 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS2); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 726 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS2]); |
| 727 | break; |
| 728 | case MCS3: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 729 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS3); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 730 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS3]); |
| 731 | break; |
| 732 | case MCS4: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 733 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS4); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 734 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS4]); |
| 735 | break; |
| 736 | case MCS5: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 737 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS5); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 738 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS5]); |
| 739 | break; |
| 740 | case MCS6: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 741 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS6); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 742 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS6]); |
| 743 | break; |
| 744 | case MCS7: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 745 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS7); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 746 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS7]); |
| 747 | break; |
| 748 | case MCS8: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 749 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS8); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 750 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS8]); |
| 751 | break; |
| 752 | case MCS9: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 753 | bts_do_rate_ctr_inc(bts, CTR_EGPRS_UL_MCS9); |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 754 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS9]); |
| 755 | break; |
| 756 | default: |
| 757 | LOGPTBFUL(this, LOGL_ERROR, "attempting to update rate counters for unsupported (M)CS %s\n", |
| 758 | mcs_name(cs)); |
Mrinal Mishra | f86307e | 2016-11-10 18:16:30 +0530 | [diff] [blame] | 759 | } |
| 760 | } |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 761 | |
Max | 9d7357e | 2017-12-14 15:02:33 +0100 | [diff] [blame] | 762 | void gprs_rlcmac_ul_tbf::set_window_size() |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 763 | { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 764 | const struct gprs_rlcmac_bts *b = bts; |
Max | 34513fe | 2018-12-11 16:47:30 +0100 | [diff] [blame] | 765 | uint16_t ws = egprs_window_size(b, ul_slots()); |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 766 | 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] | 767 | 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] | 768 | m_window.set_ws(ws); |
| 769 | } |
Pau Espin Pedrol | 9767e44 | 2020-10-23 21:11:41 +0200 | [diff] [blame] | 770 | |
Pau Espin Pedrol | b3f2397 | 2020-10-23 21:00:23 +0200 | [diff] [blame] | 771 | gprs_rlc_window *gprs_rlcmac_ul_tbf::window() |
Pau Espin Pedrol | 9767e44 | 2020-10-23 21:11:41 +0200 | [diff] [blame] | 772 | { |
| 773 | return &m_window; |
| 774 | } |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 775 | |
| 776 | struct gprs_rlcmac_ul_tbf *as_ul_tbf(struct gprs_rlcmac_tbf *tbf) |
| 777 | { |
| 778 | if (tbf && tbf->direction == GPRS_RLCMAC_UL_TBF) |
| 779 | return static_cast<gprs_rlcmac_ul_tbf *>(tbf); |
| 780 | else |
| 781 | return NULL; |
| 782 | } |