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> |
| 24 | #include <rlc.h> |
| 25 | #include <encoding.h> |
| 26 | #include <gprs_rlcmac.h> |
| 27 | #include <gprs_debug.h> |
| 28 | #include <gprs_bssgp_pcu.h> |
| 29 | #include <decoding.h> |
Jacob Erlbeck | 20f6fd1 | 2015-06-08 11:05:45 +0200 | [diff] [blame] | 30 | #include <pcu_l1_if.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 31 | #include <gprs_coding_scheme.h> |
| 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> |
| 42 | #include <osmocom/core/utils.h> |
| 43 | #include <osmocom/gprs/gprs_bssgp_bss.h> |
| 44 | #include <osmocom/gprs/protocol/gsm_08_18.h> |
| 45 | #include <osmocom/gsm/tlv.h> |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 46 | #include "coding_scheme.h" |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | #include <errno.h> |
| 50 | #include <string.h> |
| 51 | |
| 52 | /* After receiving these frames, we send ack/nack. */ |
| 53 | #define SEND_ACK_AFTER_FRAMES 20 |
| 54 | |
| 55 | extern void *tall_pcu_ctx; |
| 56 | |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 57 | /* |
| 58 | * Store received block data in LLC message(s) and forward to SGSN |
| 59 | * if complete. |
| 60 | */ |
| 61 | int gprs_rlcmac_ul_tbf::assemble_forward_llc(const gprs_rlc_data *_data) |
| 62 | { |
| 63 | const uint8_t *data = _data->block; |
| 64 | uint8_t len = _data->len; |
Jacob Erlbeck | f2ba4cb | 2016-01-07 18:59:28 +0100 | [diff] [blame] | 65 | const struct gprs_rlc_data_block_info *rdbi = &_data->block_info; |
Aravind Sirsikar | 9149552 | 2016-07-12 14:17:12 +0530 | [diff] [blame] | 66 | GprsCodingScheme cs = _data->cs_last; |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 67 | |
| 68 | Decoding::RlcData frames[16], *frame; |
| 69 | int i, num_frames = 0; |
| 70 | uint32_t dummy_tlli; |
| 71 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 72 | LOGPTBFUL(this, LOGL_DEBUG, "Assembling frames: (len=%d)\n", len); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 73 | |
| 74 | num_frames = Decoding::rlc_data_from_ul_data( |
Alexander Couzens | ce936f3 | 2016-05-24 14:45:41 +0200 | [diff] [blame] | 75 | rdbi, cs, data, &(frames[0]), ARRAY_SIZE(frames), |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 76 | &dummy_tlli); |
| 77 | |
| 78 | /* create LLC frames */ |
| 79 | for (i = 0; i < num_frames; i++) { |
| 80 | frame = frames + i; |
| 81 | |
Aravind Sirsikar | 22a9019 | 2016-09-15 17:24:49 +0530 | [diff] [blame] | 82 | if (frame->length) { |
| 83 | bts->rlc_ul_payload_bytes(frame->length); |
Alexander Couzens | 7fdbf89 | 2016-05-21 19:45:23 +0200 | [diff] [blame] | 84 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 85 | LOGPTBFUL(this, LOGL_DEBUG, "Frame %d " |
Aravind Sirsikar | 22a9019 | 2016-09-15 17:24:49 +0530 | [diff] [blame] | 86 | "starts at offset %d, " |
| 87 | "length=%d, is_complete=%d\n", |
| 88 | i + 1, frame->offset, frame->length, |
| 89 | frame->is_complete); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 90 | |
Aravind Sirsikar | 22a9019 | 2016-09-15 17:24:49 +0530 | [diff] [blame] | 91 | m_llc.append_frame(data + frame->offset, frame->length); |
| 92 | m_llc.consume(frame->length); |
| 93 | } |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 94 | |
| 95 | if (frame->is_complete) { |
| 96 | /* send frame to SGSN */ |
Max | 0fdaa9d | 2018-01-30 16:03:10 +0100 | [diff] [blame] | 97 | LOGPTBFUL(this, LOGL_DEBUG, "complete UL frame len=%d\n", m_llc.frame_length()); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 98 | snd_ul_ud(); |
Alexander Couzens | 7fdbf89 | 2016-05-21 19:45:23 +0200 | [diff] [blame] | 99 | bts->llc_ul_bytes(m_llc.frame_length()); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 100 | m_llc.reset(); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | |
Max | fd13f6c | 2017-07-07 14:29:36 +0200 | [diff] [blame] | 107 | bool gprs_rlcmac_ul_tbf::ctrl_ack_to_toggle() |
| 108 | { |
Max | 8dce1de | 2018-01-02 14:17:04 +0100 | [diff] [blame] | 109 | if (check_n_clear(GPRS_RLCMAC_FLAG_TO_UL_ACK)) |
Max | fd13f6c | 2017-07-07 14:29:36 +0200 | [diff] [blame] | 110 | return true; /* GPRS_RLCMAC_FLAG_TO_UL_ACK was set, now cleared */ |
Max | fd13f6c | 2017-07-07 14:29:36 +0200 | [diff] [blame] | 111 | |
| 112 | state_flags |= (1 << GPRS_RLCMAC_FLAG_TO_UL_ACK); |
| 113 | return false; /* GPRS_RLCMAC_FLAG_TO_UL_ACK was unset, now set */ |
| 114 | } |
| 115 | |
| 116 | bool gprs_rlcmac_ul_tbf::handle_ctrl_ack() |
| 117 | { |
| 118 | /* check if this control ack belongs to packet uplink ack */ |
Max | 088c7df | 2018-01-23 20:16:23 +0100 | [diff] [blame] | 119 | if (ul_ack_state_is(GPRS_RLCMAC_UL_ACK_WAIT_ACK)) { |
| 120 | TBF_SET_ACK_STATE(this, GPRS_RLCMAC_UL_ACK_NONE); |
Max | fd13f6c | 2017-07-07 14:29:36 +0200 | [diff] [blame] | 121 | return true; |
| 122 | } |
| 123 | |
| 124 | return false; |
| 125 | } |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 126 | |
Jacob Erlbeck | 5a3c84d | 2016-01-22 17:25:38 +0100 | [diff] [blame] | 127 | 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] | 128 | { |
| 129 | int final = (state_is(GPRS_RLCMAC_FINISHED)); |
| 130 | struct msgb *msg; |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 131 | int rc; |
| 132 | unsigned int rrbp = 0; |
| 133 | uint32_t new_poll_fn = 0; |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 134 | |
| 135 | if (final) { |
Max | cac6b66 | 2018-01-24 11:00:17 +0100 | [diff] [blame] | 136 | if (poll_scheduled() && ul_ack_state_is(GPRS_RLCMAC_UL_ACK_WAIT_ACK)) { |
Max | c21f007 | 2017-12-15 17:36:45 +0100 | [diff] [blame] | 137 | LOGPTBFUL(this, LOGL_DEBUG, |
| 138 | "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] | 139 | return NULL; |
| 140 | } |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 141 | |
| 142 | rc = check_polling(fn, ts, &new_poll_fn, &rrbp); |
| 143 | if (rc < 0) |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 144 | return NULL; |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | msg = msgb_alloc(23, "rlcmac_ul_ack"); |
| 148 | if (!msg) |
| 149 | return NULL; |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 150 | bitvec *ack_vec = bitvec_alloc(23, tall_pcu_ctx); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 151 | if (!ack_vec) { |
| 152 | msgb_free(msg); |
| 153 | return NULL; |
| 154 | } |
Max | 7426c5f | 2019-02-18 20:42:42 +0100 | [diff] [blame] | 155 | bitvec_unhex(ack_vec, DUMMY_VEC); |
Alexander Couzens | 3a499f3 | 2019-06-16 15:25:30 +0200 | [diff] [blame] | 156 | Encoding::write_packet_uplink_ack(ack_vec, this, final, rrbp); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 157 | bitvec_pack(ack_vec, msgb_put(msg, 23)); |
| 158 | bitvec_free(ack_vec); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 159 | |
| 160 | /* now we must set this flag, so we are allowed to assign downlink |
| 161 | * TBF on PACCH. it is only allowed when TLLI is acknowledged. */ |
| 162 | m_contention_resolution_done = 1; |
| 163 | |
| 164 | if (final) { |
Max | f60cf62 | 2017-07-10 14:40:09 +0200 | [diff] [blame] | 165 | set_polling(new_poll_fn, ts, GPRS_RLCMAC_POLL_UL_ACK); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 166 | /* waiting for final acknowledge */ |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 167 | m_final_ack_sent = 1; |
| 168 | } else |
Max | 088c7df | 2018-01-23 20:16:23 +0100 | [diff] [blame] | 169 | TBF_SET_ACK_STATE(this, GPRS_RLCMAC_UL_ACK_NONE); |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 170 | |
| 171 | return msg; |
| 172 | } |
| 173 | |
Alexander Couzens | 2fcfc29 | 2016-05-24 14:40:03 +0200 | [diff] [blame] | 174 | /*! \brief receive data from PDCH/L1 */ |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 175 | int gprs_rlcmac_ul_tbf::rcv_data_block_acknowledged( |
Jacob Erlbeck | f2ba4cb | 2016-01-07 18:59:28 +0100 | [diff] [blame] | 176 | const struct gprs_rlc_data_info *rlc, |
Jacob Erlbeck | fc1b3e6 | 2016-01-11 09:58:11 +0100 | [diff] [blame] | 177 | uint8_t *data, struct pcu_l1_meas *meas) |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 178 | { |
| 179 | int8_t rssi = meas->have_rssi ? meas->rssi : 0; |
| 180 | |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 181 | const uint16_t ws = m_window.ws(); |
| 182 | |
| 183 | this->state_flags |= (1 << GPRS_RLCMAC_FLAG_UL_DATA); |
| 184 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 185 | LOGPTBFUL(this, LOGL_DEBUG, "UL DATA TFI=%d received (V(Q)=%d .. " |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 186 | "V(R)=%d)\n", rlc->tfi, this->m_window.v_q(), |
| 187 | this->m_window.v_r()); |
| 188 | |
| 189 | /* process RSSI */ |
| 190 | gprs_rlcmac_rssi(this, rssi); |
| 191 | |
| 192 | /* store measurement values */ |
| 193 | if (ms()) |
| 194 | ms()->update_l1_meas(meas); |
| 195 | |
| 196 | uint32_t new_tlli = 0; |
| 197 | unsigned int block_idx; |
| 198 | |
| 199 | /* restart T3169 */ |
Pau Espin Pedrol | 28f160e | 2019-09-05 14:48:35 +0200 | [diff] [blame] | 200 | T_START(this, T3169, 3169, "acked (data)", true); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 201 | |
| 202 | /* Increment RX-counter */ |
| 203 | this->m_rx_counter++; |
Mrinal Mishra | f86307e | 2016-11-10 18:16:30 +0530 | [diff] [blame] | 204 | update_coding_scheme_counter_ul(rlc->cs); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 205 | /* Loop over num_blocks */ |
| 206 | for (block_idx = 0; block_idx < rlc->num_data_blocks; block_idx++) { |
| 207 | int num_chunks; |
| 208 | uint8_t *rlc_data; |
Jacob Erlbeck | f2ba4cb | 2016-01-07 18:59:28 +0100 | [diff] [blame] | 209 | const struct gprs_rlc_data_block_info *rdbi = |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 210 | &rlc->block_info[block_idx]; |
| 211 | bool need_rlc_data = false; |
| 212 | struct gprs_rlc_data *block; |
| 213 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 214 | LOGPTBFUL(this, LOGL_DEBUG, |
| 215 | "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] | 216 | mcs_name(rlc->cs), |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 217 | rdbi->cv, rdbi->bsn, rdbi->spb, |
| 218 | rdbi->pi, rdbi->e, rdbi->ti, |
| 219 | rlc->data_offs_bits[block_idx]); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 220 | |
| 221 | /* Check whether the block needs to be decoded */ |
| 222 | |
| 223 | if (!m_window.is_in_window(rdbi->bsn)) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 224 | LOGPTBFUL(this, LOGL_DEBUG, "BSN %d out of window %d..%d (it's normal)\n", |
| 225 | rdbi->bsn, |
| 226 | 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] | 227 | } else if (m_window.is_received(rdbi->bsn)) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 228 | LOGPTBFUL(this, LOGL_DEBUG, |
| 229 | "BSN %d already received\n", rdbi->bsn); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 230 | } else { |
| 231 | need_rlc_data = true; |
| 232 | } |
| 233 | |
| 234 | if (!is_tlli_valid()) { |
| 235 | if (!rdbi->ti) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 236 | LOGPTBFUL(this, LOGL_NOTICE, "Missing TLLI within UL DATA.\n"); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 237 | continue; |
| 238 | } |
| 239 | need_rlc_data = true; |
| 240 | } |
| 241 | |
| 242 | if (!need_rlc_data) |
| 243 | continue; |
| 244 | |
| 245 | /* Store block and meta info to BSN buffer */ |
| 246 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 247 | LOGPTBFUL(this, LOGL_DEBUG, "BSN %d storing in window (%d..%d)\n", |
| 248 | rdbi->bsn, m_window.v_q(), |
| 249 | m_window.mod_sns(m_window.v_q() + ws - 1)); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 250 | block = m_rlc.block(rdbi->bsn); |
Aravind Sirsikar | 550a541 | 2016-06-14 18:59:18 +0530 | [diff] [blame] | 251 | OSMO_ASSERT(rdbi->data_len <= sizeof(block->block)); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 252 | rlc_data = &(block->block[0]); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 253 | |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 254 | if (rdbi->spb) { |
| 255 | egprs_rlc_ul_reseg_bsn_state assemble_status; |
| 256 | |
| 257 | assemble_status = handle_egprs_ul_spb(rlc, |
| 258 | block, data, block_idx); |
| 259 | |
| 260 | if (assemble_status != EGPRS_RESEG_DEFAULT) |
| 261 | return 0; |
| 262 | } else { |
| 263 | block->block_info = *rdbi; |
| 264 | block->cs_last = rlc->cs; |
| 265 | block->len = |
| 266 | Decoding::rlc_copy_to_aligned_buffer(rlc, |
| 267 | block_idx, data, rlc_data); |
| 268 | } |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 269 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 270 | LOGPTBFUL(this, LOGL_DEBUG, |
| 271 | "data_length=%d, data=%s\n", |
| 272 | block->len, osmo_hexdump(rlc_data, block->len)); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 273 | /* Get/Handle TLLI */ |
| 274 | if (rdbi->ti) { |
| 275 | num_chunks = Decoding::rlc_data_from_ul_data( |
| 276 | rdbi, rlc->cs, rlc_data, NULL, 0, &new_tlli); |
| 277 | |
| 278 | if (num_chunks < 0) { |
| 279 | bts->decode_error(); |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 280 | LOGPTBFUL(this, LOGL_NOTICE, |
| 281 | "Failed to decode TLLI of %s UL DATA TFI=%d.\n", |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 282 | mcs_name(rlc->cs), rlc->tfi); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 283 | m_window.invalidate_bsn(rdbi->bsn); |
| 284 | continue; |
| 285 | } |
| 286 | if (!this->is_tlli_valid()) { |
| 287 | if (!new_tlli) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 288 | LOGPTBFUL(this, LOGL_NOTICE, |
| 289 | "TLLI = 0 within UL DATA.\n"); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 290 | m_window.invalidate_bsn(rdbi->bsn); |
| 291 | continue; |
| 292 | } |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 293 | LOGPTBFUL(this, LOGL_INFO, |
| 294 | "Decoded premier TLLI=0x%08x of UL DATA TFI=%d.\n", |
| 295 | tlli(), rlc->tfi); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 296 | set_tlli_from_ul(new_tlli); |
| 297 | } else if (new_tlli && new_tlli != tlli()) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 298 | LOGPTBFUL(this, LOGL_NOTICE, |
| 299 | "TLLI mismatch on UL DATA TFI=%d. (Ignoring due to contention resolution)\n", |
| 300 | rlc->tfi); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 301 | m_window.invalidate_bsn(rdbi->bsn); |
| 302 | continue; |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | m_window.receive_bsn(rdbi->bsn); |
| 307 | } |
| 308 | |
| 309 | /* Raise V(Q) if possible, and retrieve LLC frames from blocks. |
| 310 | * This is looped until there is a gap (non received block) or |
| 311 | * the window is empty.*/ |
| 312 | const uint16_t v_q_beg = m_window.v_q(); |
| 313 | const uint16_t count = m_window.raise_v_q(); |
| 314 | |
| 315 | /* Retrieve LLC frames from blocks that are ready */ |
| 316 | for (uint16_t i = 0; i < count; ++i) { |
Jacob Erlbeck | 93c55d0 | 2015-12-23 16:29:07 +0100 | [diff] [blame] | 317 | uint16_t index = m_window.mod_sns(v_q_beg + i); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 318 | assemble_forward_llc(m_rlc.block(index)); |
| 319 | } |
| 320 | |
| 321 | /* Check CV of last frame in buffer */ |
| 322 | if (this->state_is(GPRS_RLCMAC_FLOW) /* still in flow state */ |
| 323 | && this->m_window.v_q() == this->m_window.v_r()) { /* if complete */ |
| 324 | struct gprs_rlc_data *block = |
Jacob Erlbeck | 93c55d0 | 2015-12-23 16:29:07 +0100 | [diff] [blame] | 325 | m_rlc.block(m_window.mod_sns(m_window.v_r() - 1)); |
Jacob Erlbeck | f2ba4cb | 2016-01-07 18:59:28 +0100 | [diff] [blame] | 326 | const struct gprs_rlc_data_block_info *rdbi = |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 327 | &block->block_info; |
| 328 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 329 | LOGPTBFUL(this, LOGL_DEBUG, |
| 330 | "No gaps in received block, last block: BSN=%d CV=%d\n", |
| 331 | rdbi->bsn, rdbi->cv); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 332 | if (rdbi->cv == 0) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 333 | LOGPTBFUL(this, LOGL_DEBUG, "Finished with UL TBF\n"); |
Max | 2399b1d | 2018-01-12 15:48:12 +0100 | [diff] [blame] | 334 | TBF_SET_STATE(this, GPRS_RLCMAC_FINISHED); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 335 | /* Reset N3103 counter. */ |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 336 | this->n_reset(N3103); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
| 340 | /* If TLLI is included or if we received half of the window, we send |
| 341 | * an ack/nack */ |
| 342 | maybe_schedule_uplink_acknack(rlc); |
| 343 | |
| 344 | return 0; |
| 345 | } |
| 346 | |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 347 | void gprs_rlcmac_ul_tbf::maybe_schedule_uplink_acknack( |
Jacob Erlbeck | f2ba4cb | 2016-01-07 18:59:28 +0100 | [diff] [blame] | 348 | const gprs_rlc_data_info *rlc) |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 349 | { |
| 350 | bool have_ti = rlc->block_info[0].ti || |
| 351 | (rlc->num_data_blocks > 1 && rlc->block_info[1].ti); |
| 352 | |
| 353 | if (rlc->si || have_ti || state_is(GPRS_RLCMAC_FINISHED) || |
| 354 | (m_rx_counter % SEND_ACK_AFTER_FRAMES) == 0) |
| 355 | { |
| 356 | if (rlc->si) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 357 | LOGPTBFUL(this, LOGL_NOTICE, |
| 358 | "Scheduling Ack/Nack, because MS is stalled.\n"); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 359 | } |
| 360 | if (have_ti) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 361 | LOGPTBFUL(this, LOGL_DEBUG, |
| 362 | "Scheduling Ack/Nack, because TLLI is included.\n"); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 363 | } |
| 364 | if (state_is(GPRS_RLCMAC_FINISHED)) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 365 | LOGPTBFUL(this, LOGL_DEBUG, |
| 366 | "Scheduling Ack/Nack, because last block has CV==0.\n"); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 367 | } |
| 368 | if ((m_rx_counter % SEND_ACK_AFTER_FRAMES) == 0) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 369 | LOGPTBFUL(this, LOGL_DEBUG, |
| 370 | "Scheduling Ack/Nack, because %d frames received.\n", |
| 371 | SEND_ACK_AFTER_FRAMES); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 372 | } |
Max | 088c7df | 2018-01-23 20:16:23 +0100 | [diff] [blame] | 373 | if (ul_ack_state_is(GPRS_RLCMAC_UL_ACK_NONE)) { |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 374 | /* trigger sending at next RTS */ |
Max | 088c7df | 2018-01-23 20:16:23 +0100 | [diff] [blame] | 375 | TBF_SET_ACK_STATE(this, GPRS_RLCMAC_UL_ACK_SEND_ACK); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 376 | } else { |
| 377 | /* already triggered */ |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 378 | LOGPTBFUL(this, LOGL_DEBUG, |
| 379 | "Sending Ack/Nack is already triggered, don't schedule!\n"); |
Jacob Erlbeck | b3100e1 | 2015-12-14 13:36:13 +0100 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | } |
| 383 | |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 384 | /* Send Uplink unit-data to SGSN. */ |
| 385 | int gprs_rlcmac_ul_tbf::snd_ul_ud() |
| 386 | { |
| 387 | uint8_t qos_profile[3]; |
| 388 | struct msgb *llc_pdu; |
| 389 | unsigned msg_len = NS_HDR_LEN + BSSGP_HDR_LEN + m_llc.frame_length(); |
| 390 | struct bssgp_bvc_ctx *bctx = gprs_bssgp_pcu_current_bctx(); |
| 391 | |
| 392 | LOGP(DBSSGP, LOGL_INFO, "LLC [PCU -> SGSN] %s len=%d\n", tbf_name(this), m_llc.frame_length()); |
| 393 | if (!bctx) { |
| 394 | LOGP(DBSSGP, LOGL_ERROR, "No bctx\n"); |
| 395 | m_llc.reset_frame_space(); |
| 396 | return -EIO; |
| 397 | } |
| 398 | |
| 399 | llc_pdu = msgb_alloc_headroom(msg_len, msg_len,"llc_pdu"); |
| 400 | uint8_t *buf = msgb_push(llc_pdu, TL16V_GROSS_LEN(sizeof(uint8_t)*m_llc.frame_length())); |
| 401 | tl16v_put(buf, BSSGP_IE_LLC_PDU, sizeof(uint8_t)*m_llc.frame_length(), m_llc.frame); |
| 402 | qos_profile[0] = QOS_PROFILE >> 16; |
| 403 | qos_profile[1] = QOS_PROFILE >> 8; |
| 404 | qos_profile[2] = QOS_PROFILE; |
| 405 | bssgp_tx_ul_ud(bctx, tlli(), qos_profile, llc_pdu); |
| 406 | |
| 407 | m_llc.reset_frame_space(); |
| 408 | return 0; |
| 409 | } |
| 410 | |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 411 | egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_second_seg( |
| 412 | const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block, |
| 413 | uint8_t *data, const uint8_t block_idx) |
| 414 | { |
| 415 | const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx]; |
| 416 | union split_block_status *spb_status = &block->spb_status; |
| 417 | uint8_t *rlc_data = &block->block[0]; |
| 418 | |
sivasankari | da7250a | 2016-12-16 12:57:18 +0530 | [diff] [blame] | 419 | bts->spb_uplink_second_segment(); |
| 420 | |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 421 | if (spb_status->block_status_ul & |
| 422 | EGPRS_RESEG_FIRST_SEG_RXD) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 423 | LOGPTBFUL(this, LOGL_DEBUG, |
| 424 | "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] | 425 | spb_status->block_status_ul = EGPRS_RESEG_DEFAULT; |
| 426 | |
| 427 | block->len += Decoding::rlc_copy_to_aligned_buffer(rlc, |
| 428 | block_idx, data, rlc_data + block->len); |
| 429 | block->block_info.data_len += rdbi->data_len; |
| 430 | } else if (spb_status->block_status_ul == EGPRS_RESEG_DEFAULT) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 431 | LOGPTBFUL(this, LOGL_DEBUG, |
| 432 | "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] | 433 | |
| 434 | block->len = Decoding::rlc_copy_to_aligned_buffer(rlc, |
| 435 | block_idx, data, |
| 436 | rlc_data + rlc->block_info[block_idx].data_len); |
| 437 | |
| 438 | spb_status->block_status_ul = EGPRS_RESEG_SECOND_SEG_RXD; |
| 439 | block->block_info = *rdbi; |
| 440 | } |
| 441 | return spb_status->block_status_ul; |
| 442 | } |
| 443 | |
| 444 | egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_first_seg( |
| 445 | const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block, |
| 446 | uint8_t *data, const uint8_t block_idx) |
| 447 | { |
| 448 | const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx]; |
| 449 | uint8_t *rlc_data = &block->block[0]; |
| 450 | union split_block_status *spb_status = &block->spb_status; |
| 451 | |
sivasankari | da7250a | 2016-12-16 12:57:18 +0530 | [diff] [blame] | 452 | bts->spb_uplink_first_segment(); |
| 453 | |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 454 | if (spb_status->block_status_ul & EGPRS_RESEG_SECOND_SEG_RXD) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 455 | LOGPTBFUL(this, LOGL_DEBUG, |
| 456 | "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] | 457 | |
| 458 | block->len += Decoding::rlc_copy_to_aligned_buffer(rlc, |
| 459 | block_idx, data, rlc_data); |
| 460 | |
| 461 | block->block_info.data_len = block->len; |
| 462 | spb_status->block_status_ul = EGPRS_RESEG_DEFAULT; |
| 463 | } else if (spb_status->block_status_ul == EGPRS_RESEG_DEFAULT) { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 464 | LOGPTBFUL(this, LOGL_DEBUG, |
| 465 | "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] | 466 | |
| 467 | spb_status->block_status_ul = EGPRS_RESEG_FIRST_SEG_RXD; |
| 468 | block->len = Decoding::rlc_copy_to_aligned_buffer(rlc, |
| 469 | block_idx, data, rlc_data); |
| 470 | block->block_info = *rdbi; |
| 471 | } |
| 472 | return spb_status->block_status_ul; |
| 473 | } |
| 474 | |
| 475 | egprs_rlc_ul_reseg_bsn_state gprs_rlcmac_ul_tbf::handle_egprs_ul_spb( |
| 476 | const struct gprs_rlc_data_info *rlc, struct gprs_rlc_data *block, |
| 477 | uint8_t *data, const uint8_t block_idx) |
| 478 | { |
| 479 | const gprs_rlc_data_block_info *rdbi = &rlc->block_info[block_idx]; |
| 480 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 481 | LOGPTBFUL(this, LOGL_DEBUG, |
| 482 | "Got SPB(%d) cs(%s) data block with BSN (%d), TFI(%d).\n", |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 483 | rdbi->spb, mcs_name(rlc->cs), rdbi->bsn, rlc->tfi); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 484 | |
| 485 | egprs_rlc_ul_reseg_bsn_state assemble_status = EGPRS_RESEG_INVALID; |
| 486 | |
| 487 | /* Section 10.4.8b of 44.060*/ |
| 488 | if (rdbi->spb == 2) |
| 489 | assemble_status = handle_egprs_ul_first_seg(rlc, |
| 490 | block, data, block_idx); |
| 491 | else if (rdbi->spb == 3) |
| 492 | assemble_status = handle_egprs_ul_second_seg(rlc, |
| 493 | block, data, block_idx); |
| 494 | else { |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 495 | LOGPTBFUL(this, LOGL_ERROR, |
| 496 | "spb(%d) Not supported SPB for this EGPRS configuration\n", |
| 497 | rdbi->spb); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | /* |
| 501 | * When the block is successfully constructed out of segmented blocks |
| 502 | * upgrade the MCS to the type 2 |
| 503 | */ |
| 504 | if (assemble_status == EGPRS_RESEG_DEFAULT) { |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 505 | switch (CodingScheme(rlc->cs)) { |
| 506 | case MCS3 : |
| 507 | block->cs_last = MCS6; |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 508 | LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS6\n"); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 509 | break; |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 510 | case MCS2 : |
| 511 | block->cs_last = MCS5; |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 512 | LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS5\n"); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 513 | break; |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 514 | case MCS1 : |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 515 | LOGPTBFUL(this, LOGL_DEBUG, "Upgrading to MCS4\n"); |
Max | bea2edb | 2019-03-06 17:04:59 +0100 | [diff] [blame] | 516 | block->cs_last = MCS4; |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 517 | break; |
| 518 | default: |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 519 | LOGPTBFUL(this, LOGL_ERROR, |
| 520 | "cs(%s) Error in Upgrading to higher MCS\n", |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 521 | mcs_name(rlc->cs)); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 522 | break; |
| 523 | } |
| 524 | } |
| 525 | return assemble_status; |
| 526 | } |
Mrinal Mishra | f86307e | 2016-11-10 18:16:30 +0530 | [diff] [blame] | 527 | |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 528 | 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] | 529 | { |
Max | fb59a93 | 2019-03-13 18:40:19 +0100 | [diff] [blame] | 530 | switch (cs) { |
| 531 | case CS1: |
| 532 | bts->gprs_ul_cs1(); |
| 533 | rate_ctr_inc(&m_ul_gprs_ctrs->ctr[TBF_CTR_GPRS_UL_CS1]); |
| 534 | break; |
| 535 | case CS2: |
| 536 | bts->gprs_ul_cs2(); |
| 537 | rate_ctr_inc(&m_ul_gprs_ctrs->ctr[TBF_CTR_GPRS_UL_CS2]); |
| 538 | break; |
| 539 | case CS3: |
| 540 | bts->gprs_ul_cs3(); |
| 541 | rate_ctr_inc(&m_ul_gprs_ctrs->ctr[TBF_CTR_GPRS_UL_CS3]); |
| 542 | break; |
| 543 | case CS4: |
| 544 | bts->gprs_ul_cs4(); |
| 545 | rate_ctr_inc(&m_ul_gprs_ctrs->ctr[TBF_CTR_GPRS_UL_CS4]); |
| 546 | break; |
| 547 | case MCS1: |
| 548 | bts->egprs_ul_mcs1(); |
| 549 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS1]); |
| 550 | break; |
| 551 | case MCS2: |
| 552 | bts->egprs_ul_mcs2(); |
| 553 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS2]); |
| 554 | break; |
| 555 | case MCS3: |
| 556 | bts->egprs_ul_mcs3(); |
| 557 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS3]); |
| 558 | break; |
| 559 | case MCS4: |
| 560 | bts->egprs_ul_mcs4(); |
| 561 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS4]); |
| 562 | break; |
| 563 | case MCS5: |
| 564 | bts->egprs_ul_mcs5(); |
| 565 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS5]); |
| 566 | break; |
| 567 | case MCS6: |
| 568 | bts->egprs_ul_mcs6(); |
| 569 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS6]); |
| 570 | break; |
| 571 | case MCS7: |
| 572 | bts->egprs_ul_mcs7(); |
| 573 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS7]); |
| 574 | break; |
| 575 | case MCS8: |
| 576 | bts->egprs_ul_mcs8(); |
| 577 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS8]); |
| 578 | break; |
| 579 | case MCS9: |
| 580 | bts->egprs_ul_mcs9(); |
| 581 | rate_ctr_inc(&m_ul_egprs_ctrs->ctr[TBF_CTR_EGPRS_UL_MCS9]); |
| 582 | break; |
| 583 | default: |
| 584 | LOGPTBFUL(this, LOGL_ERROR, "attempting to update rate counters for unsupported (M)CS %s\n", |
| 585 | mcs_name(cs)); |
Mrinal Mishra | f86307e | 2016-11-10 18:16:30 +0530 | [diff] [blame] | 586 | } |
| 587 | } |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 588 | |
Max | 9d7357e | 2017-12-14 15:02:33 +0100 | [diff] [blame] | 589 | void gprs_rlcmac_ul_tbf::set_window_size() |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 590 | { |
Max | 34513fe | 2018-12-11 16:47:30 +0100 | [diff] [blame] | 591 | const struct gprs_rlcmac_bts *b = bts->bts_data(); |
| 592 | uint16_t ws = egprs_window_size(b, ul_slots()); |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 593 | LOGPTBFUL(this, LOGL_INFO, "setting EGPRS UL window size to %u, base(%u) slots(%u) ws_pdch(%u)\n", |
Max | 34513fe | 2018-12-11 16:47:30 +0100 | [diff] [blame] | 594 | ws, b->ws_base, pcu_bitcount(ul_slots()), b->ws_pdch); |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 595 | m_window.set_ws(ws); |
| 596 | } |