Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 by Holger Hans Peter Freyther |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #pragma once |
| 20 | |
Daniel Willmann | afa72f5 | 2014-01-15 17:06:19 +0100 | [diff] [blame] | 21 | #ifdef __cplusplus |
| 22 | |
Pau Espin Pedrol | cd6c466 | 2020-09-22 13:41:00 +0200 | [diff] [blame] | 23 | #include <string> |
| 24 | |
Holger Hans Peter Freyther | be57081 | 2013-11-07 08:01:49 +0100 | [diff] [blame] | 25 | #include "llc.h" |
Holger Hans Peter Freyther | 6b5660c | 2013-11-23 16:10:48 +0100 | [diff] [blame] | 26 | #include "rlc.h" |
Jacob Erlbeck | 6835cea | 2015-08-21 15:24:02 +0200 | [diff] [blame] | 27 | #include "cxx_linuxlist.h" |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 28 | #include "pcu_utils.h" |
Daniel Willmann | eb10024 | 2014-08-08 11:43:53 +0200 | [diff] [blame] | 29 | #include <gprs_debug.h> |
Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 30 | #include <stdint.h> |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 31 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 32 | struct bssgp_bvc_ctx; |
| 33 | struct gprs_rlcmac_bts; |
| 34 | |
| 35 | #endif |
| 36 | |
| 37 | struct GprsMs; |
| 38 | |
| 39 | #ifdef __cplusplus |
Max | e66de5b | 2017-01-05 18:26:58 +0100 | [diff] [blame] | 40 | extern "C" { |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 41 | #endif |
Max | e66de5b | 2017-01-05 18:26:58 +0100 | [diff] [blame] | 42 | #include <osmocom/core/utils.h> |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 43 | #include <osmocom/core/linuxlist.h> |
| 44 | #include <osmocom/core/logging.h> |
| 45 | #include <osmocom/core/timer.h> |
Vadim Yanitskiy | cb98894 | 2020-11-08 13:27:35 +0700 | [diff] [blame] | 46 | #include <osmocom/gsm/gsm48.h> |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 47 | |
| 48 | #include "coding_scheme.h" |
Pau Espin Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 49 | #include <pdch_ul_controller.h> |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 50 | #include <tbf_fsm.h> |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 51 | #ifdef __cplusplus |
Max | e66de5b | 2017-01-05 18:26:58 +0100 | [diff] [blame] | 52 | } |
Vadim Yanitskiy | cef2f84 | 2019-10-09 21:52:50 +0700 | [diff] [blame] | 53 | #endif |
| 54 | |
Holger Hans Peter Freyther | 9e21d84 | 2013-10-16 17:48:12 +0200 | [diff] [blame] | 55 | /* |
| 56 | * TBF instance |
| 57 | */ |
| 58 | |
Holger Hans Peter Freyther | 9e21d84 | 2013-10-16 17:48:12 +0200 | [diff] [blame] | 59 | enum gprs_rlcmac_tbf_dl_ass_state { |
| 60 | GPRS_RLCMAC_DL_ASS_NONE = 0, |
| 61 | GPRS_RLCMAC_DL_ASS_SEND_ASS, /* send downlink assignment on next RTS */ |
| 62 | GPRS_RLCMAC_DL_ASS_WAIT_ACK, /* wait for PACKET CONTROL ACK */ |
| 63 | }; |
| 64 | |
Max | e66de5b | 2017-01-05 18:26:58 +0100 | [diff] [blame] | 65 | extern const struct value_string gprs_rlcmac_tbf_dl_ass_state_names[]; |
| 66 | |
Holger Hans Peter Freyther | 9e21d84 | 2013-10-16 17:48:12 +0200 | [diff] [blame] | 67 | enum gprs_rlcmac_tbf_ul_ass_state { |
| 68 | GPRS_RLCMAC_UL_ASS_NONE = 0, |
| 69 | GPRS_RLCMAC_UL_ASS_SEND_ASS, /* send uplink assignment on next RTS */ |
aravind sirsikar | ed3413e | 2016-11-11 17:15:10 +0530 | [diff] [blame] | 70 | GPRS_RLCMAC_UL_ASS_SEND_ASS_REJ, /* send assignment reject next RTS */ |
Holger Hans Peter Freyther | 9e21d84 | 2013-10-16 17:48:12 +0200 | [diff] [blame] | 71 | GPRS_RLCMAC_UL_ASS_WAIT_ACK, /* wait for PACKET CONTROL ACK */ |
| 72 | }; |
| 73 | |
Max | e66de5b | 2017-01-05 18:26:58 +0100 | [diff] [blame] | 74 | extern const struct value_string gprs_rlcmac_tbf_ul_ass_state_names[]; |
| 75 | |
Holger Hans Peter Freyther | 9e21d84 | 2013-10-16 17:48:12 +0200 | [diff] [blame] | 76 | enum gprs_rlcmac_tbf_ul_ack_state { |
| 77 | GPRS_RLCMAC_UL_ACK_NONE = 0, |
| 78 | GPRS_RLCMAC_UL_ACK_SEND_ACK, /* send acknowledge on next RTS */ |
| 79 | GPRS_RLCMAC_UL_ACK_WAIT_ACK, /* wait for PACKET CONTROL ACK */ |
| 80 | }; |
| 81 | |
Max | 088c7df | 2018-01-23 20:16:23 +0100 | [diff] [blame] | 82 | extern const struct value_string gprs_rlcmac_tbf_ul_ack_state_names[]; |
| 83 | |
Holger Hans Peter Freyther | 9e21d84 | 2013-10-16 17:48:12 +0200 | [diff] [blame] | 84 | enum gprs_rlcmac_tbf_direction { |
| 85 | GPRS_RLCMAC_DL_TBF, |
| 86 | GPRS_RLCMAC_UL_TBF |
| 87 | }; |
| 88 | |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 89 | enum tbf_rlc_counters { |
sivasankari | 5395073 | 2016-12-08 17:15:17 +0530 | [diff] [blame] | 90 | TBF_CTR_RLC_NACKED, |
| 91 | }; |
| 92 | |
| 93 | enum tbf_gprs_counters { |
| 94 | TBF_CTR_GPRS_DL_CS1, |
| 95 | TBF_CTR_GPRS_DL_CS2, |
| 96 | TBF_CTR_GPRS_DL_CS3, |
| 97 | TBF_CTR_GPRS_DL_CS4, |
| 98 | }; |
| 99 | |
| 100 | enum tbf_egprs_counters { |
| 101 | TBF_CTR_EGPRS_DL_MCS1, |
| 102 | TBF_CTR_EGPRS_DL_MCS2, |
| 103 | TBF_CTR_EGPRS_DL_MCS3, |
| 104 | TBF_CTR_EGPRS_DL_MCS4, |
| 105 | TBF_CTR_EGPRS_DL_MCS5, |
| 106 | TBF_CTR_EGPRS_DL_MCS6, |
| 107 | TBF_CTR_EGPRS_DL_MCS7, |
| 108 | TBF_CTR_EGPRS_DL_MCS8, |
| 109 | TBF_CTR_EGPRS_DL_MCS9, |
| 110 | }; |
| 111 | |
Pau Espin Pedrol | 442198c | 2020-10-23 22:30:04 +0200 | [diff] [blame] | 112 | extern const struct rate_ctr_group_desc tbf_ctrg_desc; |
| 113 | extern unsigned int next_tbf_ctr_group_id; |
| 114 | |
Max | 0524e38 | 2018-01-19 18:22:25 +0100 | [diff] [blame] | 115 | #define LOGPTBF(tbf, level, fmt, args...) LOGP(DTBF, level, "%s " fmt, tbf_name(tbf), ## args) |
Max | c21f007 | 2017-12-15 17:36:45 +0100 | [diff] [blame] | 116 | |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 117 | enum tbf_timers { |
Max | b2de1f7 | 2017-12-20 18:05:29 +0100 | [diff] [blame] | 118 | /* internal assign/reject timer */ |
| 119 | T0, |
| 120 | |
Pau Espin Pedrol | 4b6f0bf | 2021-05-10 18:54:52 +0200 | [diff] [blame] | 121 | /* Wait contention resolution success on UL TBFs assigned over CCCH */ |
| 122 | T3141, |
| 123 | |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 124 | /* Wait for reuse of USF and TFI(s) after the MS uplink assignment for this TBF is invalid. */ |
| 125 | T3169, |
| 126 | |
| 127 | /* Wait for reuse of TFI(s) after sending of the last RLC Data Block on this TBF. |
| 128 | Wait for reuse of TFI(s) after sending the PACKET TBF RELEASE for an MBMS radio bearer. */ |
| 129 | T3191, |
| 130 | |
| 131 | /* Wait for reuse of TFI(s) after reception of the final PACKET DOWNLINK ACK/NACK from the |
| 132 | MS for this TBF. */ |
| 133 | T3193, |
| 134 | |
| 135 | /* Wait for reuse of TFI(s) when there is no response from the MS |
| 136 | (radio failure or cell change) for this TBF/MBMS radio bearer. */ |
| 137 | T3195, |
| 138 | T_MAX |
| 139 | }; |
| 140 | |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 141 | enum tbf_counters { /* TBF counters from 3GPP TS 44.060 ยง13.4 */ |
| 142 | /* counters are reset when: */ |
| 143 | N3101, /* received a valid data block from mobile station in a block assigned for this USF */ |
| 144 | N3103, /* transmitting the final PACKET UPLINK ACK/NACK message */ |
| 145 | N3105, /* after sending a RRBP field in the downlink RLC data block, receives a valid RLC/MAC control message */ |
| 146 | N_MAX |
| 147 | }; |
| 148 | |
Holger Hans Peter Freyther | 9e21d84 | 2013-10-16 17:48:12 +0200 | [diff] [blame] | 149 | #define GPRS_RLCMAC_FLAG_CCCH 0 /* assignment on CCCH */ |
| 150 | #define GPRS_RLCMAC_FLAG_PACCH 1 /* assignment on PACCH */ |
| 151 | #define GPRS_RLCMAC_FLAG_UL_DATA 2 /* uplink data received */ |
| 152 | #define GPRS_RLCMAC_FLAG_DL_ACK 3 /* downlink acknowledge received */ |
| 153 | #define GPRS_RLCMAC_FLAG_TO_UL_ACK 4 |
| 154 | #define GPRS_RLCMAC_FLAG_TO_DL_ACK 5 |
| 155 | #define GPRS_RLCMAC_FLAG_TO_UL_ASS 6 |
| 156 | #define GPRS_RLCMAC_FLAG_TO_DL_ASS 7 |
| 157 | #define GPRS_RLCMAC_FLAG_TO_MASK 0xf0 /* timeout bits */ |
| 158 | |
Pau Espin Pedrol | 28f160e | 2019-09-05 14:48:35 +0200 | [diff] [blame] | 159 | #define T_START(tbf, t, T, r, f) tbf->t_start(t, T, r, f, __FILE__, __LINE__) |
Max | 467f633 | 2017-12-20 18:13:29 +0100 | [diff] [blame] | 160 | |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 161 | #define TBF_SET_STATE(t, st) do { tbf_fsm_state_chg(t->state_fsm.fi, st); } while(0) |
Max | 0e59980 | 2018-01-23 20:09:06 +0100 | [diff] [blame] | 162 | #define TBF_SET_ASS_STATE_DL(t, st) do { t->set_ass_state_dl(st, __FILE__, __LINE__); } while(0) |
| 163 | #define TBF_SET_ASS_STATE_UL(t, st) do { t->set_ass_state_ul(st, __FILE__, __LINE__); } while(0) |
Max | 088c7df | 2018-01-23 20:16:23 +0100 | [diff] [blame] | 164 | #define TBF_SET_ACK_STATE(t, st) do { t->set_ack_state(st, __FILE__, __LINE__); } while(0) |
Max | 2399b1d | 2018-01-12 15:48:12 +0100 | [diff] [blame] | 165 | |
Vadim Yanitskiy | cef2f84 | 2019-10-09 21:52:50 +0700 | [diff] [blame] | 166 | #ifdef __cplusplus |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 167 | extern "C" { |
| 168 | #endif |
| 169 | struct gprs_rlcmac_tbf; |
Pau Espin Pedrol | 57dcde4 | 2021-02-01 18:14:23 +0100 | [diff] [blame] | 170 | const char *tbf_name(const struct gprs_rlcmac_tbf *tbf); |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 171 | enum tbf_fsm_states tbf_state(const struct gprs_rlcmac_tbf *tbf); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 172 | enum gprs_rlcmac_tbf_direction tbf_direction(const struct gprs_rlcmac_tbf *tbf); |
| 173 | void tbf_set_ms(struct gprs_rlcmac_tbf *tbf, struct GprsMs *ms); |
| 174 | struct llist_head *tbf_ms_list(struct gprs_rlcmac_tbf *tbf); |
Pau Espin Pedrol | 1a1557a | 2021-05-13 18:39:36 +0200 | [diff] [blame] | 175 | struct llist_head *tbf_trx_list(struct gprs_rlcmac_tbf *tbf); |
Pau Espin Pedrol | 1e77ca8 | 2021-01-27 13:22:03 +0100 | [diff] [blame] | 176 | struct GprsMs *tbf_ms(const struct gprs_rlcmac_tbf *tbf); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 177 | bool tbf_timers_pending(struct gprs_rlcmac_tbf *tbf, enum tbf_timers t); |
| 178 | void tbf_free(struct gprs_rlcmac_tbf *tbf); |
| 179 | struct gprs_llc *tbf_llc(struct gprs_rlcmac_tbf *tbf); |
| 180 | uint8_t tbf_first_common_ts(const struct gprs_rlcmac_tbf *tbf); |
| 181 | uint8_t tbf_dl_slots(const struct gprs_rlcmac_tbf *tbf); |
| 182 | uint8_t tbf_ul_slots(const struct gprs_rlcmac_tbf *tbf); |
| 183 | bool tbf_is_tfi_assigned(const struct gprs_rlcmac_tbf *tbf); |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 184 | uint8_t tbf_tfi(const struct gprs_rlcmac_tbf *tbf); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 185 | int tbf_assign_control_ts(struct gprs_rlcmac_tbf *tbf); |
Pau Espin Pedrol | 952cb3d | 2021-02-01 14:52:48 +0100 | [diff] [blame] | 186 | int tbf_check_polling(const struct gprs_rlcmac_tbf *tbf, uint32_t fn, uint8_t ts, uint32_t *poll_fn, unsigned int *rrbp); |
Pau Espin Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 187 | void tbf_set_polling(struct gprs_rlcmac_tbf *tbf, uint32_t new_poll_fn, uint8_t ts, enum pdch_ulc_tbf_poll_reason t); |
Pau Espin Pedrol | 16e1678 | 2021-03-29 19:10:19 +0200 | [diff] [blame] | 188 | void tbf_poll_timeout(struct gprs_rlcmac_tbf *tbf, struct gprs_rlcmac_pdch *pdch, uint32_t poll_fn, enum pdch_ulc_tbf_poll_reason reason); |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 189 | void tbf_update_state_fsm_name(struct gprs_rlcmac_tbf *tbf); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 190 | #ifdef __cplusplus |
| 191 | } |
| 192 | #endif |
| 193 | |
| 194 | #ifdef __cplusplus |
Vadim Yanitskiy | cef2f84 | 2019-10-09 21:52:50 +0700 | [diff] [blame] | 195 | |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 196 | struct gprs_rlcmac_tbf { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 197 | gprs_rlcmac_tbf(struct gprs_rlcmac_bts *bts_, GprsMs *ms, gprs_rlcmac_tbf_direction dir); |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 198 | virtual ~gprs_rlcmac_tbf(); |
Holger Hans Peter Freyther | 964ddb6 | 2013-10-16 17:53:23 +0200 | [diff] [blame] | 199 | |
Pau Espin Pedrol | b3f2397 | 2020-10-23 21:00:23 +0200 | [diff] [blame] | 200 | virtual gprs_rlc_window *window() = 0; |
| 201 | |
Pau Espin Pedrol | e9f77d3 | 2020-10-23 18:41:40 +0200 | [diff] [blame] | 202 | int setup(int8_t use_trx, bool single_slot); |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 203 | bool state_is(enum tbf_fsm_states rhs) const; |
| 204 | bool state_is_not(enum tbf_fsm_states rhs) const; |
Max | 0e59980 | 2018-01-23 20:09:06 +0100 | [diff] [blame] | 205 | bool dl_ass_state_is(enum gprs_rlcmac_tbf_dl_ass_state rhs) const; |
| 206 | bool ul_ass_state_is(enum gprs_rlcmac_tbf_ul_ass_state rhs) const; |
Max | 088c7df | 2018-01-23 20:16:23 +0100 | [diff] [blame] | 207 | bool ul_ack_state_is(enum gprs_rlcmac_tbf_ul_ack_state rhs) const; |
Max | 0e59980 | 2018-01-23 20:09:06 +0100 | [diff] [blame] | 208 | void set_ass_state_dl(enum gprs_rlcmac_tbf_dl_ass_state new_state, const char *file, int line); |
| 209 | void set_ass_state_ul(enum gprs_rlcmac_tbf_ul_ass_state new_state, const char *file, int line); |
Max | 088c7df | 2018-01-23 20:16:23 +0100 | [diff] [blame] | 210 | void set_ack_state(enum gprs_rlcmac_tbf_ul_ack_state new_state, const char *file, int line); |
Max | cac6b66 | 2018-01-24 11:00:17 +0100 | [diff] [blame] | 211 | void poll_sched_set(const char *file, int line); |
| 212 | void poll_sched_unset(const char *file, int line); |
Max | 8dce1de | 2018-01-02 14:17:04 +0100 | [diff] [blame] | 213 | bool check_n_clear(uint8_t state_flag); |
Daniel Willmann | 08e57c8 | 2014-08-15 18:11:57 +0200 | [diff] [blame] | 214 | const char *state_name() const; |
Holger Hans Peter Freyther | 1c344e2 | 2013-10-16 18:33:18 +0200 | [diff] [blame] | 215 | |
Jacob Erlbeck | adcdf15 | 2015-03-03 14:45:55 +0100 | [diff] [blame] | 216 | const char *name() const; |
| 217 | |
Jacob Erlbeck | 5a3c84d | 2016-01-22 17:25:38 +0100 | [diff] [blame] | 218 | struct msgb *create_dl_ass(uint32_t fn, uint8_t ts); |
| 219 | struct msgb *create_ul_ass(uint32_t fn, uint8_t ts); |
aravind sirsikar | ed3413e | 2016-11-11 17:15:10 +0530 | [diff] [blame] | 220 | struct msgb *create_packet_access_reject(); |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 221 | |
Jacob Erlbeck | 10ed795 | 2015-06-02 11:37:22 +0200 | [diff] [blame] | 222 | GprsMs *ms() const; |
Jacob Erlbeck | fecece0 | 2015-05-08 12:13:08 +0200 | [diff] [blame] | 223 | void set_ms(GprsMs *ms); |
| 224 | |
Holger Hans Peter Freyther | 8f399de | 2013-12-25 20:22:35 +0100 | [diff] [blame] | 225 | uint8_t tsc() const; |
Holger Hans Peter Freyther | a1da251 | 2013-11-07 07:32:51 +0100 | [diff] [blame] | 226 | |
Pau Espin Pedrol | cd6c466 | 2020-09-22 13:41:00 +0200 | [diff] [blame] | 227 | std::string rlcmac_diag(); |
Holger Hans Peter Freyther | 964ddb6 | 2013-10-16 17:53:23 +0200 | [diff] [blame] | 228 | |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 229 | bool n_inc(enum tbf_counters n); |
| 230 | void n_reset(enum tbf_counters n); |
| 231 | |
Jacob Erlbeck | e0c734d | 2015-07-03 14:03:33 +0200 | [diff] [blame] | 232 | int update(); |
Holger Hans Peter Freyther | af8094d | 2013-10-26 17:56:15 +0200 | [diff] [blame] | 233 | void handle_timeout(); |
Max | ee5be3a | 2017-12-20 17:31:13 +0100 | [diff] [blame] | 234 | void stop_timers(const char *reason); |
| 235 | bool timers_pending(enum tbf_timers t); |
| 236 | void t_stop(enum tbf_timers t, const char *reason); |
Pau Espin Pedrol | 28f160e | 2019-09-05 14:48:35 +0200 | [diff] [blame] | 237 | void t_start(enum tbf_timers t, int T, const char *reason, bool force, |
Max | 467f633 | 2017-12-20 18:13:29 +0100 | [diff] [blame] | 238 | const char *file, unsigned line); |
Jacob Erlbeck | 91ff7d1 | 2015-09-01 11:20:29 +0200 | [diff] [blame] | 239 | int establish_dl_tbf_on_pacch(); |
Holger Hans Peter Freyther | aa9c326 | 2013-10-26 17:49:36 +0200 | [diff] [blame] | 240 | |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 241 | int check_polling(uint32_t fn, uint8_t ts, |
Pau Espin Pedrol | 57dcde4 | 2021-02-01 18:14:23 +0100 | [diff] [blame] | 242 | uint32_t *poll_fn, unsigned int *rrbp) const; |
Pau Espin Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 243 | void set_polling(uint32_t poll_fn, uint8_t ts, enum pdch_ulc_tbf_poll_reason reason); |
Pau Espin Pedrol | 16e1678 | 2021-03-29 19:10:19 +0200 | [diff] [blame] | 244 | void poll_timeout(struct gprs_rlcmac_pdch *pdch, uint32_t poll_fn, enum pdch_ulc_tbf_poll_reason reason); |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 245 | |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 246 | /** tlli handling */ |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 247 | uint32_t tlli() const; |
| 248 | bool is_tlli_valid() const; |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 249 | |
Jacob Erlbeck | fecece0 | 2015-05-08 12:13:08 +0200 | [diff] [blame] | 250 | /** MS updating */ |
Jacob Erlbeck | be0cbc1 | 2015-05-18 14:35:11 +0200 | [diff] [blame] | 251 | void update_ms(uint32_t tlli, enum gprs_rlcmac_tbf_direction); |
Jacob Erlbeck | fecece0 | 2015-05-08 12:13:08 +0200 | [diff] [blame] | 252 | |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 253 | uint8_t tfi() const; |
Jacob Erlbeck | 6b356a5 | 2016-01-29 16:39:21 +0100 | [diff] [blame] | 254 | bool is_tfi_assigned() const; |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 255 | |
Holger Hans Peter Freyther | 5464c9b | 2013-10-27 20:57:35 +0100 | [diff] [blame] | 256 | const char *imsi() const; |
Jacob Erlbeck | 9200ce6 | 2015-05-22 17:48:04 +0200 | [diff] [blame] | 257 | uint8_t ta() const; |
| 258 | void set_ta(uint8_t); |
Jacob Erlbeck | befc760 | 2015-06-02 12:33:30 +0200 | [diff] [blame] | 259 | uint8_t ms_class() const; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 260 | enum CodingScheme current_cs() const; |
Holger Hans Peter Freyther | 5464c9b | 2013-10-27 20:57:35 +0100 | [diff] [blame] | 261 | |
Holger Hans Peter Freyther | a004799 | 2014-01-16 10:07:20 +0100 | [diff] [blame] | 262 | time_t created_ts() const; |
Jacob Erlbeck | 617c712 | 2015-06-30 09:18:30 +0200 | [diff] [blame] | 263 | uint8_t dl_slots() const; |
| 264 | uint8_t ul_slots() const; |
Daniel Willmann | 80367aa | 2014-01-15 17:40:28 +0100 | [diff] [blame] | 265 | |
Jacob Erlbeck | 646da1b | 2016-01-22 17:41:33 +0100 | [diff] [blame] | 266 | bool is_control_ts(uint8_t ts) const; |
| 267 | |
Jacob Erlbeck | 5643f35 | 2015-11-27 16:17:40 +0100 | [diff] [blame] | 268 | /* EGPRS */ |
| 269 | bool is_egprs_enabled() const; |
Jacob Erlbeck | 5643f35 | 2015-11-27 16:17:40 +0100 | [diff] [blame] | 270 | |
Holger Hans Peter Freyther | 7a5f3c2 | 2013-11-26 13:08:12 +0100 | [diff] [blame] | 271 | /* attempt to make things a bit more fair */ |
| 272 | void rotate_in_list(); |
| 273 | |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 274 | enum gprs_rlcmac_tbf_direction direction; |
Holger Hans Peter Freyther | 743bafa | 2013-09-29 07:50:50 +0200 | [diff] [blame] | 275 | struct gprs_rlcmac_trx *trx; |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 276 | uint8_t first_ts; /* first TS used by TBF */ |
Pau Espin Pedrol | 01aef5e | 2020-09-22 19:08:57 +0200 | [diff] [blame] | 277 | uint8_t first_common_ts; /* first TS where the phone can send and |
| 278 | receive simultaniously */ |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 279 | uint8_t control_ts; /* timeslot control messages and polling */ |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 280 | struct gprs_rlcmac_pdch *pdch[8]; /* list of PDCHs allocated to TBF */ |
Holger Hans Peter Freyther | 28e5378 | 2013-11-06 20:23:56 +0100 | [diff] [blame] | 281 | |
| 282 | gprs_llc m_llc; |
Holger Hans Peter Freyther | 9241fd0 | 2013-11-13 19:51:55 +0100 | [diff] [blame] | 283 | gprs_rlc m_rlc; |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 284 | |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 285 | unsigned int fT; /* fTxxxx number */ |
| 286 | unsigned int num_fT_exp; /* number of consecutive fT expirations */ |
| 287 | |
Jacob Erlbeck | b6b3c7e | 2015-08-28 12:07:14 +0200 | [diff] [blame] | 288 | struct Meas { |
Stefan Sperling | f0f7df1 | 2018-05-25 15:12:30 +0200 | [diff] [blame] | 289 | struct timespec rssi_tv; /* timestamp for rssi calculation */ |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 290 | int32_t rssi_sum; /* sum of rssi values */ |
| 291 | int rssi_num; /* number of rssi values added since rssi_tv */ |
Jacob Erlbeck | b6b3c7e | 2015-08-28 12:07:14 +0200 | [diff] [blame] | 292 | |
| 293 | Meas(); |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 294 | } meas; |
| 295 | |
Daniel Willmann | 73191a4 | 2014-05-30 17:58:00 +0200 | [diff] [blame] | 296 | /* Remember if the tbf was in wait_release state when we want to |
| 297 | * schedule a new dl assignment */ |
| 298 | uint8_t was_releasing; |
| 299 | |
Daniel Willmann | cf1fae7 | 2014-05-30 17:58:01 +0200 | [diff] [blame] | 300 | /* Can/should we upgrade this tbf to use multiple slots? */ |
| 301 | uint8_t upgrade_to_multislot; |
| 302 | |
Holger Hans Peter Freyther | 9f0c1d2 | 2013-10-19 21:24:34 +0200 | [diff] [blame] | 303 | /* store the BTS this TBF belongs to */ |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 304 | struct gprs_rlcmac_bts *bts; |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 305 | |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 306 | /* |
| 307 | * private fields. We can't make it private as it is breaking the |
| 308 | * llist macros. |
| 309 | */ |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 310 | uint8_t m_tfi; |
Holger Hans Peter Freyther | a004799 | 2014-01-16 10:07:20 +0100 | [diff] [blame] | 311 | time_t m_created_ts; |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 312 | |
sivasankari | 5395073 | 2016-12-08 17:15:17 +0530 | [diff] [blame] | 313 | struct rate_ctr_group *m_ctrs; |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 314 | struct tbf_fsm_ctx state_fsm; |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 315 | struct llist_item m_ms_list; |
Pau Espin Pedrol | 1a1557a | 2021-05-13 18:39:36 +0200 | [diff] [blame] | 316 | struct llist_item m_trx_list; |
sivasankari | 5395073 | 2016-12-08 17:15:17 +0530 | [diff] [blame] | 317 | |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 318 | protected: |
Jacob Erlbeck | 28c40b1 | 2015-08-16 18:19:32 +0200 | [diff] [blame] | 319 | void merge_and_clear_ms(GprsMs *old_ms); |
Holger Hans Peter Freyther | 4c06d91 | 2013-11-25 23:05:26 +0100 | [diff] [blame] | 320 | |
Alexander Couzens | d38b92e | 2016-08-21 19:38:30 +0200 | [diff] [blame] | 321 | gprs_llc_queue *llc_queue(); |
| 322 | const gprs_llc_queue *llc_queue() const; |
| 323 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 324 | struct GprsMs *m_ms; |
Jacob Erlbeck | adcdf15 | 2015-03-03 14:45:55 +0100 | [diff] [blame] | 325 | private: |
Pau Espin Pedrol | e9f77d3 | 2020-10-23 18:41:40 +0200 | [diff] [blame] | 326 | void enable_egprs(); |
Max | 0e59980 | 2018-01-23 20:09:06 +0100 | [diff] [blame] | 327 | enum gprs_rlcmac_tbf_dl_ass_state dl_ass_state; |
| 328 | enum gprs_rlcmac_tbf_ul_ass_state ul_ass_state; |
Max | 088c7df | 2018-01-23 20:16:23 +0100 | [diff] [blame] | 329 | enum gprs_rlcmac_tbf_ul_ack_state ul_ack_state; |
Jacob Erlbeck | 5643f35 | 2015-11-27 16:17:40 +0100 | [diff] [blame] | 330 | bool m_egprs_enabled; |
Pau Espin Pedrol | ef1fe58 | 2019-09-05 14:40:24 +0200 | [diff] [blame] | 331 | struct osmo_timer_list Tarr[T_MAX]; |
| 332 | uint8_t Narr[N_MAX]; |
Jacob Erlbeck | adcdf15 | 2015-03-03 14:45:55 +0100 | [diff] [blame] | 333 | mutable char m_name_buf[60]; |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 334 | }; |
| 335 | |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 336 | inline bool gprs_rlcmac_tbf::state_is(enum tbf_fsm_states rhs) const |
Holger Hans Peter Freyther | 1c344e2 | 2013-10-16 18:33:18 +0200 | [diff] [blame] | 337 | { |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 338 | return tbf_state(this) == rhs; |
Holger Hans Peter Freyther | 1c344e2 | 2013-10-16 18:33:18 +0200 | [diff] [blame] | 339 | } |
| 340 | |
Max | 0e59980 | 2018-01-23 20:09:06 +0100 | [diff] [blame] | 341 | inline bool gprs_rlcmac_tbf::dl_ass_state_is(enum gprs_rlcmac_tbf_dl_ass_state rhs) const |
| 342 | { |
| 343 | return dl_ass_state == rhs; |
| 344 | } |
| 345 | |
| 346 | inline bool gprs_rlcmac_tbf::ul_ass_state_is(enum gprs_rlcmac_tbf_ul_ass_state rhs) const |
| 347 | { |
| 348 | return ul_ass_state == rhs; |
| 349 | } |
| 350 | |
Max | 088c7df | 2018-01-23 20:16:23 +0100 | [diff] [blame] | 351 | inline bool gprs_rlcmac_tbf::ul_ack_state_is(enum gprs_rlcmac_tbf_ul_ack_state rhs) const |
| 352 | { |
| 353 | return ul_ack_state == rhs; |
| 354 | } |
| 355 | |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 356 | inline bool gprs_rlcmac_tbf::state_is_not(enum tbf_fsm_states rhs) const |
Holger Hans Peter Freyther | 1c344e2 | 2013-10-16 18:33:18 +0200 | [diff] [blame] | 357 | { |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 358 | return tbf_state(this) != rhs; |
Holger Hans Peter Freyther | 1c344e2 | 2013-10-16 18:33:18 +0200 | [diff] [blame] | 359 | } |
| 360 | |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 361 | |
Daniel Willmann | 08e57c8 | 2014-08-15 18:11:57 +0200 | [diff] [blame] | 362 | inline const char *gprs_rlcmac_tbf::state_name() const |
| 363 | { |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 364 | return osmo_fsm_inst_state_name(state_fsm.fi); |
Daniel Willmann | 08e57c8 | 2014-08-15 18:11:57 +0200 | [diff] [blame] | 365 | } |
| 366 | |
Max | 0e59980 | 2018-01-23 20:09:06 +0100 | [diff] [blame] | 367 | inline void gprs_rlcmac_tbf::set_ass_state_dl(enum gprs_rlcmac_tbf_dl_ass_state new_state, const char *file, int line) |
| 368 | { |
| 369 | LOGPSRC(DTBF, LOGL_DEBUG, file, line, "%s changes DL ASS state from %s to %s\n", |
| 370 | tbf_name(this), |
| 371 | get_value_string(gprs_rlcmac_tbf_dl_ass_state_names, dl_ass_state), |
| 372 | get_value_string(gprs_rlcmac_tbf_dl_ass_state_names, new_state)); |
| 373 | dl_ass_state = new_state; |
| 374 | } |
| 375 | |
| 376 | inline void gprs_rlcmac_tbf::set_ass_state_ul(enum gprs_rlcmac_tbf_ul_ass_state new_state, const char *file, int line) |
| 377 | { |
| 378 | LOGPSRC(DTBF, LOGL_DEBUG, file, line, "%s changes UL ASS state from %s to %s\n", |
| 379 | tbf_name(this), |
| 380 | get_value_string(gprs_rlcmac_tbf_ul_ass_state_names, ul_ass_state), |
| 381 | get_value_string(gprs_rlcmac_tbf_ul_ass_state_names, new_state)); |
| 382 | ul_ass_state = new_state; |
| 383 | } |
| 384 | |
Max | 088c7df | 2018-01-23 20:16:23 +0100 | [diff] [blame] | 385 | inline void gprs_rlcmac_tbf::set_ack_state(enum gprs_rlcmac_tbf_ul_ack_state new_state, const char *file, int line) |
| 386 | { |
| 387 | LOGPSRC(DTBF, LOGL_DEBUG, file, line, "%s changes UL ACK state from %s to %s\n", |
| 388 | tbf_name(this), |
| 389 | get_value_string(gprs_rlcmac_tbf_ul_ack_state_names, ul_ack_state), |
| 390 | get_value_string(gprs_rlcmac_tbf_ul_ack_state_names, new_state)); |
| 391 | ul_ack_state = new_state; |
| 392 | } |
| 393 | |
Max | 8dce1de | 2018-01-02 14:17:04 +0100 | [diff] [blame] | 394 | inline bool gprs_rlcmac_tbf::check_n_clear(uint8_t state_flag) |
| 395 | { |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 396 | if ((state_fsm.state_flags & (1 << state_flag))) { |
| 397 | state_fsm.state_flags &= ~(1 << state_flag); |
Max | 8dce1de | 2018-01-02 14:17:04 +0100 | [diff] [blame] | 398 | return true; |
| 399 | } |
| 400 | |
| 401 | return false; |
| 402 | } |
| 403 | |
Jacob Erlbeck | 10ed795 | 2015-06-02 11:37:22 +0200 | [diff] [blame] | 404 | inline GprsMs *gprs_rlcmac_tbf::ms() const |
Jacob Erlbeck | fecece0 | 2015-05-08 12:13:08 +0200 | [diff] [blame] | 405 | { |
| 406 | return m_ms; |
| 407 | } |
| 408 | |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 409 | inline bool gprs_rlcmac_tbf::is_tlli_valid() const |
| 410 | { |
Vadim Yanitskiy | cb98894 | 2020-11-08 13:27:35 +0700 | [diff] [blame] | 411 | return tlli() != GSM_RESERVED_TMSI; |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 412 | } |
| 413 | |
Jacob Erlbeck | 6b356a5 | 2016-01-29 16:39:21 +0100 | [diff] [blame] | 414 | inline bool gprs_rlcmac_tbf::is_tfi_assigned() const |
| 415 | { |
| 416 | /* The TBF is established or has been assigned by a IMM.ASS for |
| 417 | * download */ |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 418 | return state_fsm.fi->state > TBF_ST_ASSIGN || |
Neels Hofmeyr | 4ea4526 | 2016-06-08 15:27:40 +0200 | [diff] [blame] | 419 | (direction == GPRS_RLCMAC_DL_TBF && |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 420 | state_fsm.fi->state == TBF_ST_ASSIGN && |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 421 | (state_fsm.state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH))); |
Jacob Erlbeck | 6b356a5 | 2016-01-29 16:39:21 +0100 | [diff] [blame] | 422 | } |
| 423 | |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 424 | inline uint8_t gprs_rlcmac_tbf::tfi() const |
| 425 | { |
| 426 | return m_tfi; |
| 427 | } |
| 428 | |
Holger Hans Peter Freyther | a004799 | 2014-01-16 10:07:20 +0100 | [diff] [blame] | 429 | inline time_t gprs_rlcmac_tbf::created_ts() const |
Daniel Willmann | 80367aa | 2014-01-15 17:40:28 +0100 | [diff] [blame] | 430 | { |
Holger Hans Peter Freyther | a004799 | 2014-01-16 10:07:20 +0100 | [diff] [blame] | 431 | return m_created_ts; |
Daniel Willmann | 80367aa | 2014-01-15 17:40:28 +0100 | [diff] [blame] | 432 | } |
| 433 | |
Jacob Erlbeck | 5643f35 | 2015-11-27 16:17:40 +0100 | [diff] [blame] | 434 | inline bool gprs_rlcmac_tbf::is_egprs_enabled() const |
| 435 | { |
| 436 | return m_egprs_enabled; |
| 437 | } |
| 438 | |
| 439 | inline void gprs_rlcmac_tbf::enable_egprs() |
| 440 | { |
| 441 | m_egprs_enabled = true; |
Pau Espin Pedrol | 7bde60f | 2020-10-23 21:21:09 +0200 | [diff] [blame] | 442 | window()->set_sns(RLC_EGPRS_SNS); |
Jacob Erlbeck | 5643f35 | 2015-11-27 16:17:40 +0100 | [diff] [blame] | 443 | } |
| 444 | |
Jacob Erlbeck | ac89a55 | 2015-06-29 14:18:46 +0200 | [diff] [blame] | 445 | inline enum gprs_rlcmac_tbf_direction reverse(enum gprs_rlcmac_tbf_direction dir) |
| 446 | { |
| 447 | return (enum gprs_rlcmac_tbf_direction) |
| 448 | ((int)GPRS_RLCMAC_UL_TBF - (int)dir + (int)GPRS_RLCMAC_DL_TBF); |
| 449 | } |
Jacob Erlbeck | aa9daa1 | 2015-12-28 18:49:12 +0100 | [diff] [blame] | 450 | |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 451 | uint16_t egprs_window_size(const struct gprs_rlcmac_bts *bts, uint8_t slots); |
Max | 9d7357e | 2017-12-14 15:02:33 +0100 | [diff] [blame] | 452 | |
Daniel Willmann | afa72f5 | 2014-01-15 17:06:19 +0100 | [diff] [blame] | 453 | #endif |