Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 1 | /* tbf_fsm.c |
| 2 | * |
| 3 | * Copyright (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> |
| 4 | * Author: Pau Espin Pedrol <pespin@sysmocom.de> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version 2 |
| 9 | * of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <unistd.h> |
| 18 | |
| 19 | #include <talloc.h> |
| 20 | |
| 21 | #include <tbf_fsm.h> |
| 22 | #include <gprs_rlcmac.h> |
| 23 | #include <gprs_debug.h> |
| 24 | #include <gprs_ms.h> |
| 25 | #include <encoding.h> |
| 26 | #include <bts.h> |
| 27 | |
Pau Espin Pedrol | 338a5ae | 2022-10-28 18:47:44 +0200 | [diff] [blame] | 28 | #include <bts_pch_timer.h> |
| 29 | |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 30 | #define X(s) (1 << (s)) |
| 31 | |
| 32 | const struct osmo_tdef_state_timeout tbf_fsm_timeouts[32] = { |
Pau Espin Pedrol | 0043005 | 2021-10-12 12:04:03 +0200 | [diff] [blame] | 33 | [TBF_ST_NEW] = {}, |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 34 | [TBF_ST_ASSIGN] = { }, |
| 35 | [TBF_ST_FLOW] = { }, |
| 36 | [TBF_ST_FINISHED] = {}, |
| 37 | [TBF_ST_WAIT_RELEASE] = {}, |
| 38 | [TBF_ST_RELEASING] = {}, |
| 39 | }; |
| 40 | |
Pau Espin Pedrol | 06abd3e | 2022-11-17 20:25:40 +0100 | [diff] [blame] | 41 | /* Transition to a state, using the T timer defined in tbf_fsm_timeouts. |
| 42 | * The actual timeout value is in turn obtained from conn->T_defs. |
| 43 | * Assumes local variable fi exists. */ |
| 44 | #define tbf_fsm_state_chg(fi, NEXT_STATE) \ |
| 45 | osmo_tdef_fsm_inst_state_chg(fi, NEXT_STATE, \ |
| 46 | tbf_fsm_timeouts, \ |
| 47 | the_pcu->T_defs, \ |
| 48 | -1) |
| 49 | |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 50 | const struct value_string tbf_fsm_event_names[] = { |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 51 | { TBF_EV_ASSIGN_ADD_CCCH, "ASSIGN_ADD_CCCH" }, |
| 52 | { TBF_EV_ASSIGN_ADD_PACCH, "ASSIGN_ADD_PACCH" }, |
Pau Espin Pedrol | 720e19e | 2021-07-22 19:56:37 +0200 | [diff] [blame] | 53 | { TBF_EV_ASSIGN_ACK_PACCH, "ASSIGN_ACK_PACCH" }, |
| 54 | { TBF_EV_ASSIGN_READY_CCCH, "ASSIGN_READY_CCCH" }, |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 55 | { TBF_EV_ASSIGN_PCUIF_CNF, "ASSIGN_PCUIF_CNF" }, |
Pau Espin Pedrol | 338a5ae | 2022-10-28 18:47:44 +0200 | [diff] [blame] | 56 | { TBF_EV_FIRST_UL_DATA_RECVD, "FIRST_UL_DATA_RECVD" }, |
Pau Espin Pedrol | f38a47e | 2022-10-28 19:06:45 +0200 | [diff] [blame] | 57 | { TBF_EV_CONTENTION_RESOLUTION_MS_SUCCESS, "CONTENTION_RESOLUTION_MS_SUCCESS" }, |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 58 | { TBF_EV_DL_ACKNACK_MISS, "DL_ACKNACK_MISS" }, |
Pau Espin Pedrol | c32c4a3 | 2021-07-23 18:27:57 +0200 | [diff] [blame] | 59 | { TBF_EV_LAST_DL_DATA_SENT, "LAST_DL_DATA_SENT" }, |
| 60 | { TBF_EV_LAST_UL_DATA_RECVD, "LAST_UL_DATA_RECVD" }, |
Pau Espin Pedrol | efcb046 | 2021-07-26 12:33:39 +0200 | [diff] [blame] | 61 | { TBF_EV_FINAL_ACK_RECVD, "FINAL_ACK_RECVD" }, |
Pau Espin Pedrol | 7a2b65e | 2021-10-11 19:18:13 +0200 | [diff] [blame] | 62 | { TBF_EV_FINAL_UL_ACK_CONFIRMED, "FINAL_UL_ACK_CONFIRMED" }, |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 63 | { TBF_EV_MAX_N3101 , "MAX_N3101" }, |
| 64 | { TBF_EV_MAX_N3103 , "MAX_N3103" }, |
| 65 | { TBF_EV_MAX_N3105 , "MAX_N3105" }, |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 66 | { 0, NULL } |
| 67 | }; |
| 68 | |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 69 | static void mod_ass_type(struct tbf_fsm_ctx *ctx, uint8_t t, bool set) |
| 70 | { |
| 71 | const char *ch = "UNKNOWN"; |
| 72 | bool prev_set = ctx->state_flags & (1 << t); |
| 73 | |
| 74 | switch (t) { |
| 75 | case GPRS_RLCMAC_FLAG_CCCH: |
| 76 | ch = "CCCH"; |
| 77 | break; |
| 78 | case GPRS_RLCMAC_FLAG_PACCH: |
| 79 | ch = "PACCH"; |
| 80 | break; |
| 81 | default: |
| 82 | LOGPTBF(ctx->tbf, LOGL_ERROR, |
| 83 | "attempted to %sset unexpected ass. type %d - FIXME!\n", |
| 84 | set ? "" : "un", t); |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | if (set && prev_set) { |
| 89 | LOGPTBF(ctx->tbf, LOGL_ERROR, |
| 90 | "attempted to set ass. type %s which is already set.\n", ch); |
| 91 | } else if (!set && !prev_set) { |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | LOGPTBF(ctx->tbf, LOGL_INFO, "%sset ass. type %s [prev CCCH:%u, PACCH:%u]\n", |
| 96 | set ? "" : "un", ch, |
| 97 | !!(ctx->state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH)), |
| 98 | !!(ctx->state_flags & (1 << GPRS_RLCMAC_FLAG_PACCH))); |
| 99 | |
| 100 | if (set) { |
| 101 | ctx->state_flags |= (1 << t); |
| 102 | } else { |
| 103 | ctx->state_flags &= GPRS_RLCMAC_FLAG_TO_MASK; /* keep to flags */ |
| 104 | ctx->state_flags &= ~(1 << t); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | |
Pau Espin Pedrol | 0043005 | 2021-10-12 12:04:03 +0200 | [diff] [blame] | 109 | static void st_new(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 110 | { |
| 111 | struct tbf_fsm_ctx *ctx = (struct tbf_fsm_ctx *)fi->priv; |
| 112 | switch (event) { |
| 113 | case TBF_EV_ASSIGN_ADD_CCCH: |
| 114 | mod_ass_type(ctx, GPRS_RLCMAC_FLAG_CCCH, true); |
Pau Espin Pedrol | 9438613 | 2022-10-28 19:50:09 +0200 | [diff] [blame] | 115 | if (tbf_direction(ctx->tbf) == GPRS_RLCMAC_UL_TBF) { |
| 116 | struct gprs_rlcmac_ul_tbf *ul_tbf = tbf_as_ul_tbf(ctx->tbf); |
| 117 | tbf_fsm_state_chg(fi, TBF_ST_FLOW); |
| 118 | ul_tbf_contention_resolution_start(ul_tbf); |
| 119 | } else { |
| 120 | tbf_fsm_state_chg(fi, TBF_ST_ASSIGN); |
| 121 | } |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 122 | break; |
| 123 | case TBF_EV_ASSIGN_ADD_PACCH: |
| 124 | mod_ass_type(ctx, GPRS_RLCMAC_FLAG_PACCH, true); |
| 125 | tbf_fsm_state_chg(fi, TBF_ST_ASSIGN); |
| 126 | break; |
| 127 | default: |
| 128 | OSMO_ASSERT(0); |
| 129 | } |
| 130 | } |
| 131 | |
Pau Espin Pedrol | 9d67e72 | 2021-07-28 19:25:38 +0200 | [diff] [blame] | 132 | static void st_assign_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state) |
| 133 | { |
| 134 | struct tbf_fsm_ctx *ctx = (struct tbf_fsm_ctx *)fi->priv; |
| 135 | unsigned long val; |
| 136 | unsigned int sec, micro; |
| 137 | |
| 138 | /* If assignment for this TBF is happening on PACCH, that means the |
| 139 | * actual Assignment procedure (tx/rx) is happening on another TBF (eg |
| 140 | * Ul TBF vs DL TBF). Hence we add a security timer here to free it in |
| 141 | * case the other TBF doesn't succeed in informing (assigning) the MS |
| 142 | * about this TBF, or simply because the scheduler takes too long to |
| 143 | * schedule it. This timer can probably be dropped once we make the |
| 144 | * other TBF always signal us assignment failure (we already get |
| 145 | * assignment success through TBF_EV_ASSIGN_ACK_PACCH) */ |
| 146 | if (ctx->state_flags & (1 << GPRS_RLCMAC_FLAG_PACCH)) { |
| 147 | fi->T = -2001; |
| 148 | val = osmo_tdef_get(the_pcu->T_defs, fi->T, OSMO_TDEF_MS, -1); |
| 149 | sec = val / 1000; |
| 150 | micro = (val % 1000) * 1000; |
| 151 | LOGPTBF(ctx->tbf, LOGL_DEBUG, |
| 152 | "Starting timer X2001 [assignment (PACCH)] with %u sec. %u microsec\n", |
| 153 | sec, micro); |
| 154 | osmo_timer_schedule(&fi->timer, sec, micro); |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 155 | } else if (tbf_direction(ctx->tbf) == GPRS_RLCMAC_DL_TBF) { |
| 156 | /* GPRS_RLCMAC_FLAG_CCCH is set, so here we submitted an DL Ass through PCUIF on CCCH */ |
Pau Espin Pedrol | 9d67e72 | 2021-07-28 19:25:38 +0200 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 160 | static void st_assign(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 161 | { |
| 162 | struct tbf_fsm_ctx *ctx = (struct tbf_fsm_ctx *)fi->priv; |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 163 | unsigned long val; |
| 164 | unsigned int sec, micro; |
| 165 | |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 166 | switch (event) { |
| 167 | case TBF_EV_ASSIGN_ADD_CCCH: |
| 168 | mod_ass_type(ctx, GPRS_RLCMAC_FLAG_CCCH, true); |
| 169 | break; |
| 170 | case TBF_EV_ASSIGN_ADD_PACCH: |
| 171 | mod_ass_type(ctx, GPRS_RLCMAC_FLAG_PACCH, true); |
| 172 | break; |
Pau Espin Pedrol | 720e19e | 2021-07-22 19:56:37 +0200 | [diff] [blame] | 173 | case TBF_EV_ASSIGN_ACK_PACCH: |
Pau Espin Pedrol | ffe998c | 2021-10-12 19:32:28 +0200 | [diff] [blame] | 174 | tbf_assign_control_ts(ctx->tbf); |
Pau Espin Pedrol | 720e19e | 2021-07-22 19:56:37 +0200 | [diff] [blame] | 175 | if (ctx->state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH)) { |
| 176 | /* We now know that the PACCH really existed */ |
| 177 | LOGPTBF(ctx->tbf, LOGL_INFO, |
| 178 | "The TBF has been confirmed on the PACCH, " |
| 179 | "changed type from CCCH to PACCH\n"); |
| 180 | mod_ass_type(ctx, GPRS_RLCMAC_FLAG_CCCH, false); |
| 181 | mod_ass_type(ctx, GPRS_RLCMAC_FLAG_PACCH, true); |
| 182 | } |
| 183 | tbf_fsm_state_chg(fi, TBF_ST_FLOW); |
| 184 | break; |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 185 | case TBF_EV_ASSIGN_PCUIF_CNF: |
| 186 | /* BTS informs us it sent Imm Ass for DL TBF over CCCH. We now |
| 187 | * have to wait for X2002 to trigger (meaning MS is already |
| 188 | * listening on PDCH) in order to move to FLOW state and start |
| 189 | * transmitting data to it. When X2002 triggers (see cb timer |
| 190 | * end of the file) it will send TBF_EV_ASSIGN_READY_CCCH back |
| 191 | * to us here. */ |
| 192 | OSMO_ASSERT(tbf_direction(ctx->tbf) == GPRS_RLCMAC_DL_TBF); |
| 193 | fi->T = -2002; |
| 194 | val = osmo_tdef_get(the_pcu->T_defs, fi->T, OSMO_TDEF_MS, -1); |
| 195 | sec = val / 1000; |
| 196 | micro = (val % 1000) * 1000; |
| 197 | LOGPTBF(ctx->tbf, LOGL_DEBUG, |
| 198 | "Starting timer X2002 [assignment (AGCH)] with %u sec. %u microsec\n", |
| 199 | sec, micro); |
| 200 | osmo_timer_schedule(&fi->timer, sec, micro); |
| 201 | break; |
Pau Espin Pedrol | 720e19e | 2021-07-22 19:56:37 +0200 | [diff] [blame] | 202 | case TBF_EV_ASSIGN_READY_CCCH: |
| 203 | /* change state to FLOW, so scheduler will start transmission */ |
| 204 | tbf_fsm_state_chg(fi, TBF_ST_FLOW); |
| 205 | break; |
Pau Espin Pedrol | 85aa87b | 2021-10-12 14:02:52 +0200 | [diff] [blame] | 206 | case TBF_EV_MAX_N3105: |
Pau Espin Pedrol | b3291bc | 2021-10-14 19:21:38 +0200 | [diff] [blame] | 207 | /* We are going to release, so abort any Pkt Ul Ass pending to be scheduled: */ |
| 208 | osmo_fsm_inst_dispatch(tbf_ul_ass_fi(ctx->tbf), TBF_UL_ASS_EV_ABORT, NULL); |
Pau Espin Pedrol | 85aa87b | 2021-10-12 14:02:52 +0200 | [diff] [blame] | 209 | ctx->T_release = 3195; |
| 210 | tbf_fsm_state_chg(fi, TBF_ST_RELEASING); |
| 211 | break; |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 212 | default: |
| 213 | OSMO_ASSERT(0); |
| 214 | } |
| 215 | } |
| 216 | |
Pau Espin Pedrol | c32c4a3 | 2021-07-23 18:27:57 +0200 | [diff] [blame] | 217 | static void st_flow(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 218 | { |
Pau Espin Pedrol | cfb61d9 | 2021-07-26 17:17:02 +0200 | [diff] [blame] | 219 | struct tbf_fsm_ctx *ctx = (struct tbf_fsm_ctx *)fi->priv; |
Pau Espin Pedrol | 338a5ae | 2022-10-28 18:47:44 +0200 | [diff] [blame] | 220 | struct GprsMs *ms = tbf_ms(ctx->tbf); |
Pau Espin Pedrol | 677bebb | 2022-10-31 13:56:33 +0100 | [diff] [blame] | 221 | struct gprs_rlcmac_dl_tbf *dl_tbf = NULL; |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 222 | |
Pau Espin Pedrol | c32c4a3 | 2021-07-23 18:27:57 +0200 | [diff] [blame] | 223 | switch (event) { |
Pau Espin Pedrol | 338a5ae | 2022-10-28 18:47:44 +0200 | [diff] [blame] | 224 | case TBF_EV_FIRST_UL_DATA_RECVD: |
| 225 | OSMO_ASSERT(tbf_direction(ctx->tbf) == GPRS_RLCMAC_UL_TBF); |
| 226 | /* TS 44.060 7a.2.1.1: "The contention resolution is completed on |
| 227 | * the network side when the network receives an RLC data block that |
| 228 | * comprises the TLLI value that identifies the mobile station and the |
| 229 | * TFI value associated with the TBF." */ |
| 230 | bts_pch_timer_stop(ms->bts, ms); |
Pau Espin Pedrol | 677bebb | 2022-10-31 13:56:33 +0100 | [diff] [blame] | 231 | /* We may still have some DL-TBF waiting for assignment in PCH, |
| 232 | * which clearly won't happen since the MS is on PDCH now. Get rid |
| 233 | * of it, it will be re-assigned on PACCH when contention |
| 234 | * resolution at the MS side is done (1st UL ACK/NACK sent) */ |
| 235 | if ((dl_tbf = ms_dl_tbf(ms))) { |
| 236 | /* Get rid of previous finished UL TBF before providing a new one */ |
| 237 | LOGPTBFDL(dl_tbf, LOGL_NOTICE, |
| 238 | "Got first UL data while DL-TBF pending, killing it\n"); |
| 239 | tbf_free(dl_tbf_as_tbf(dl_tbf)); |
| 240 | dl_tbf = NULL; |
| 241 | } |
Pau Espin Pedrol | 338a5ae | 2022-10-28 18:47:44 +0200 | [diff] [blame] | 242 | break; |
Pau Espin Pedrol | f38a47e | 2022-10-28 19:06:45 +0200 | [diff] [blame] | 243 | case TBF_EV_CONTENTION_RESOLUTION_MS_SUCCESS: |
| 244 | OSMO_ASSERT(tbf_direction(ctx->tbf) == GPRS_RLCMAC_UL_TBF); |
| 245 | ul_tbf_contention_resolution_success(tbf_as_ul_tbf(ctx->tbf)); |
| 246 | break; |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 247 | case TBF_EV_DL_ACKNACK_MISS: |
Pau Espin Pedrol | 3f33929 | 2022-10-28 18:29:18 +0200 | [diff] [blame] | 248 | OSMO_ASSERT(tbf_direction(ctx->tbf) == GPRS_RLCMAC_DL_TBF); |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 249 | /* DL TBF: we missed a DL ACK/NACK. If we started assignment |
| 250 | * over CCCH and never received any DL ACK/NACK yet, it means we |
| 251 | * don't even know if the MS successfuly received the Imm Ass on |
| 252 | * CCCH and hence is listening on PDCH. Let's better refrain |
| 253 | * from continuing and start assignment on CCCH again */ |
| 254 | if ((ctx->state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH)) |
| 255 | && !(ctx->state_flags & (1 << GPRS_RLCMAC_FLAG_DL_ACK))) { |
| 256 | struct GprsMs *ms = tbf_ms(ctx->tbf); |
Pau Espin Pedrol | d06ec27 | 2021-07-30 15:03:21 +0200 | [diff] [blame] | 257 | LOGPTBF(ctx->tbf, LOGL_DEBUG, "Re-send downlink assignment on PCH (IMSI=%s)\n", |
Pau Espin Pedrol | 5deac14 | 2021-11-12 18:01:50 +0100 | [diff] [blame] | 258 | ms_imsi_is_valid(ms) ? ms_imsi(ms) : ""); |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 259 | tbf_fsm_state_chg(fi, TBF_ST_ASSIGN); |
| 260 | /* send immediate assignment */ |
Pau Espin Pedrol | 5deac14 | 2021-11-12 18:01:50 +0100 | [diff] [blame] | 261 | bts_snd_dl_ass(ms->bts, ctx->tbf); |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 262 | } |
| 263 | break; |
Pau Espin Pedrol | c32c4a3 | 2021-07-23 18:27:57 +0200 | [diff] [blame] | 264 | case TBF_EV_LAST_DL_DATA_SENT: |
| 265 | case TBF_EV_LAST_UL_DATA_RECVD: |
| 266 | /* All data has been sent or received, change state to FINISHED */ |
| 267 | tbf_fsm_state_chg(fi, TBF_ST_FINISHED); |
| 268 | break; |
Pau Espin Pedrol | efcb046 | 2021-07-26 12:33:39 +0200 | [diff] [blame] | 269 | case TBF_EV_FINAL_ACK_RECVD: |
Pau Espin Pedrol | 3f33929 | 2022-10-28 18:29:18 +0200 | [diff] [blame] | 270 | OSMO_ASSERT(tbf_direction(ctx->tbf) == GPRS_RLCMAC_DL_TBF); |
Pau Espin Pedrol | efcb046 | 2021-07-26 12:33:39 +0200 | [diff] [blame] | 271 | /* We received Final Ack (DL ACK/NACK) from MS. move to |
| 272 | WAIT_RELEASE, we wait there for release or re-use the TBF in |
| 273 | case we receive more DL data to tx */ |
| 274 | tbf_fsm_state_chg(fi, TBF_ST_WAIT_RELEASE); |
| 275 | break; |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 276 | case TBF_EV_MAX_N3101: |
Pau Espin Pedrol | cfb61d9 | 2021-07-26 17:17:02 +0200 | [diff] [blame] | 277 | ctx->T_release = 3169; |
| 278 | tbf_fsm_state_chg(fi, TBF_ST_RELEASING); |
| 279 | break; |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 280 | case TBF_EV_MAX_N3105: |
Pau Espin Pedrol | cfb61d9 | 2021-07-26 17:17:02 +0200 | [diff] [blame] | 281 | ctx->T_release = 3195; |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 282 | tbf_fsm_state_chg(fi, TBF_ST_RELEASING); |
| 283 | break; |
Pau Espin Pedrol | efcb046 | 2021-07-26 12:33:39 +0200 | [diff] [blame] | 284 | default: |
| 285 | OSMO_ASSERT(0); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | static void st_finished(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 290 | { |
Pau Espin Pedrol | cfb61d9 | 2021-07-26 17:17:02 +0200 | [diff] [blame] | 291 | struct tbf_fsm_ctx *ctx = (struct tbf_fsm_ctx *)fi->priv; |
Pau Espin Pedrol | 22b26d8 | 2022-10-26 15:44:14 +0200 | [diff] [blame] | 292 | struct GprsMs *ms; |
| 293 | bool new_ul_tbf_requested; |
| 294 | |
Pau Espin Pedrol | efcb046 | 2021-07-26 12:33:39 +0200 | [diff] [blame] | 295 | switch (event) { |
Pau Espin Pedrol | f38a47e | 2022-10-28 19:06:45 +0200 | [diff] [blame] | 296 | case TBF_EV_CONTENTION_RESOLUTION_MS_SUCCESS: |
| 297 | OSMO_ASSERT(tbf_direction(ctx->tbf) == GPRS_RLCMAC_UL_TBF); |
| 298 | /* UL TBF: If MS only sends 1 RLCMAC UL block, it can be that we |
| 299 | * end up in FINISHED state before sending the first UL ACK/NACK */ |
| 300 | ul_tbf_contention_resolution_success(tbf_as_ul_tbf(ctx->tbf)); |
| 301 | break; |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 302 | case TBF_EV_DL_ACKNACK_MISS: |
Pau Espin Pedrol | 3f33929 | 2022-10-28 18:29:18 +0200 | [diff] [blame] | 303 | OSMO_ASSERT(tbf_direction(ctx->tbf) == GPRS_RLCMAC_DL_TBF); |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 304 | break; |
Pau Espin Pedrol | efcb046 | 2021-07-26 12:33:39 +0200 | [diff] [blame] | 305 | case TBF_EV_FINAL_ACK_RECVD: |
Pau Espin Pedrol | 3f33929 | 2022-10-28 18:29:18 +0200 | [diff] [blame] | 306 | OSMO_ASSERT(tbf_direction(ctx->tbf) == GPRS_RLCMAC_DL_TBF); |
Pau Espin Pedrol | efcb046 | 2021-07-26 12:33:39 +0200 | [diff] [blame] | 307 | /* We received Final Ack (DL ACK/NACK) from MS. move to |
| 308 | WAIT_RELEASE, we wait there for release or re-use the TBF in |
| 309 | case we receive more DL data to tx */ |
| 310 | tbf_fsm_state_chg(fi, TBF_ST_WAIT_RELEASE); |
| 311 | break; |
Pau Espin Pedrol | 7a2b65e | 2021-10-11 19:18:13 +0200 | [diff] [blame] | 312 | case TBF_EV_FINAL_UL_ACK_CONFIRMED: |
Pau Espin Pedrol | 22b26d8 | 2022-10-26 15:44:14 +0200 | [diff] [blame] | 313 | OSMO_ASSERT(tbf_direction(ctx->tbf) == GPRS_RLCMAC_UL_TBF); |
| 314 | new_ul_tbf_requested = (bool)data; |
| 315 | /* Ref the MS, otherwise it may be freed after ul_tbf is |
| 316 | * detached when sending event below. */ |
| 317 | ms = tbf_ms(ctx->tbf); |
| 318 | ms_ref(ms); |
Pau Espin Pedrol | 7a2b65e | 2021-10-11 19:18:13 +0200 | [diff] [blame] | 319 | /* UL TBF ACKed our transmitted UL ACK/NACK with final Ack |
Pau Espin Pedrol | 22b26d8 | 2022-10-26 15:44:14 +0200 | [diff] [blame] | 320 | * Indicator set to '1'. We can free the TBF right away, the MS |
| 321 | * also just released its TBF on its side. */ |
| 322 | LOGPTBFUL(tbf_as_ul_tbf(ctx->tbf), LOGL_DEBUG, "[UPLINK] END\n"); |
Pau Espin Pedrol | 7a2b65e | 2021-10-11 19:18:13 +0200 | [diff] [blame] | 323 | tbf_free(ctx->tbf); |
Pau Espin Pedrol | 22b26d8 | 2022-10-26 15:44:14 +0200 | [diff] [blame] | 324 | /* Here fi, ctx and ctx->tbf are already freed! */ |
| 325 | /* TS 44.060 9.3.3.3.2: There might be LLC packets waiting in |
| 326 | * the queue but the DL TBF assignment might have been delayed |
| 327 | * because there was no way to reach the MS (because ul_tbf was |
| 328 | * in packet-active mode with FINISHED state). If MS is going |
| 329 | * back to packet-idle mode then we can assign the DL TBF on PCH |
| 330 | * now. */ |
| 331 | if (!new_ul_tbf_requested && ms_need_dl_tbf(ms)) |
Pau Espin Pedrol | 091642a | 2022-10-28 18:01:31 +0200 | [diff] [blame] | 332 | ms_new_dl_tbf_assigned_on_pch(ms); |
Pau Espin Pedrol | 22b26d8 | 2022-10-26 15:44:14 +0200 | [diff] [blame] | 333 | ms_unref(ms); |
Pau Espin Pedrol | 7a2b65e | 2021-10-11 19:18:13 +0200 | [diff] [blame] | 334 | break; |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 335 | case TBF_EV_MAX_N3103: |
Pau Espin Pedrol | cfb61d9 | 2021-07-26 17:17:02 +0200 | [diff] [blame] | 336 | ctx->T_release = 3169; |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 337 | tbf_fsm_state_chg(fi, TBF_ST_RELEASING); |
| 338 | break; |
| 339 | case TBF_EV_MAX_N3105: |
Pau Espin Pedrol | cfb61d9 | 2021-07-26 17:17:02 +0200 | [diff] [blame] | 340 | ctx->T_release = 3195; |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 341 | tbf_fsm_state_chg(fi, TBF_ST_RELEASING); |
| 342 | break; |
| 343 | default: |
| 344 | OSMO_ASSERT(0); |
| 345 | } |
| 346 | } |
| 347 | |
Pau Espin Pedrol | f48de62 | 2021-07-30 14:48:06 +0200 | [diff] [blame] | 348 | static void st_wait_release_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state) |
| 349 | { |
| 350 | struct tbf_fsm_ctx *ctx = (struct tbf_fsm_ctx *)fi->priv; |
| 351 | unsigned long val_s, val_ms, val_us; |
| 352 | OSMO_ASSERT(tbf_direction(ctx->tbf) == GPRS_RLCMAC_DL_TBF); |
| 353 | |
| 354 | fi->T = 3193; |
| 355 | val_ms = osmo_tdef_get(tbf_ms(ctx->tbf)->bts->T_defs_bts, fi->T, OSMO_TDEF_MS, -1); |
| 356 | val_s = val_ms / 1000; |
| 357 | val_us = (val_ms % 1000) * 1000; |
| 358 | LOGPTBF(ctx->tbf, LOGL_DEBUG, "starting timer T%u with %lu sec. %lu microsec\n", |
| 359 | fi->T, val_s, val_us); |
| 360 | osmo_timer_schedule(&fi->timer, val_s, val_us); |
| 361 | |
| 362 | mod_ass_type(ctx, GPRS_RLCMAC_FLAG_CCCH, false); |
| 363 | } |
| 364 | |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 365 | static void st_wait_release(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 366 | { |
Pau Espin Pedrol | cfb61d9 | 2021-07-26 17:17:02 +0200 | [diff] [blame] | 367 | struct tbf_fsm_ctx *ctx = (struct tbf_fsm_ctx *)fi->priv; |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 368 | switch (event) { |
| 369 | case TBF_EV_FINAL_ACK_RECVD: |
Pau Espin Pedrol | 3f33929 | 2022-10-28 18:29:18 +0200 | [diff] [blame] | 370 | OSMO_ASSERT(tbf_direction(ctx->tbf) == GPRS_RLCMAC_DL_TBF); |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 371 | /* ignore, duplicate ACK, we already know about since we are in WAIT_RELEASE */ |
| 372 | break; |
| 373 | case TBF_EV_MAX_N3101: |
Pau Espin Pedrol | cfb61d9 | 2021-07-26 17:17:02 +0200 | [diff] [blame] | 374 | ctx->T_release = 3169; |
| 375 | tbf_fsm_state_chg(fi, TBF_ST_RELEASING); |
| 376 | break; |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 377 | case TBF_EV_MAX_N3105: |
Pau Espin Pedrol | cfb61d9 | 2021-07-26 17:17:02 +0200 | [diff] [blame] | 378 | ctx->T_release = 3195; |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 379 | tbf_fsm_state_chg(fi, TBF_ST_RELEASING); |
| 380 | break; |
Pau Espin Pedrol | c32c4a3 | 2021-07-23 18:27:57 +0200 | [diff] [blame] | 381 | default: |
| 382 | OSMO_ASSERT(0); |
| 383 | } |
| 384 | } |
| 385 | |
Pau Espin Pedrol | cfb61d9 | 2021-07-26 17:17:02 +0200 | [diff] [blame] | 386 | static void st_releasing_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state) |
| 387 | { |
| 388 | struct tbf_fsm_ctx *ctx = (struct tbf_fsm_ctx *)fi->priv; |
| 389 | unsigned long val; |
| 390 | |
| 391 | if (!ctx->T_release) |
| 392 | return; |
| 393 | |
| 394 | /* In general we should end up here with an assigned timer in ctx->T_release. Possible values are: |
| 395 | * T3195: Wait for reuse of TFI(s) when there is no response from the MS |
| 396 | * (radio failure or cell change) for this TBF/MBMS radio bearer. |
| 397 | * T3169: Wait for reuse of USF and TFI(s) after the MS uplink assignment for this TBF is invalid. |
| 398 | */ |
| 399 | val = osmo_tdef_get(tbf_ms(ctx->tbf)->bts->T_defs_bts, ctx->T_release, OSMO_TDEF_S, -1); |
| 400 | fi->T = ctx->T_release; |
| 401 | LOGPTBF(ctx->tbf, LOGL_DEBUG, "starting timer T%u with %lu sec. %u microsec\n", |
| 402 | ctx->T_release, val, 0); |
| 403 | osmo_timer_schedule(&fi->timer, val, 0); |
| 404 | } |
| 405 | |
Pau Espin Pedrol | cee6b12 | 2021-09-28 16:49:33 +0200 | [diff] [blame] | 406 | static void st_releasing(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 407 | { |
Pau Espin Pedrol | 3f33929 | 2022-10-28 18:29:18 +0200 | [diff] [blame] | 408 | struct tbf_fsm_ctx *ctx = (struct tbf_fsm_ctx *)fi->priv; |
Pau Espin Pedrol | cee6b12 | 2021-09-28 16:49:33 +0200 | [diff] [blame] | 409 | switch (event) { |
| 410 | case TBF_EV_DL_ACKNACK_MISS: |
Pau Espin Pedrol | 3f33929 | 2022-10-28 18:29:18 +0200 | [diff] [blame] | 411 | OSMO_ASSERT(tbf_direction(ctx->tbf) == GPRS_RLCMAC_DL_TBF); |
Pau Espin Pedrol | cee6b12 | 2021-09-28 16:49:33 +0200 | [diff] [blame] | 412 | /* Ignore, we don't care about missed DL ACK/NACK poll timeouts |
| 413 | * anymore, we are already releasing the TBF */ |
| 414 | break; |
| 415 | default: |
| 416 | OSMO_ASSERT(0); |
| 417 | } |
| 418 | } |
| 419 | |
Pau Espin Pedrol | f197f15 | 2022-11-17 20:18:46 +0100 | [diff] [blame] | 420 | static void handle_timeout_X2002(struct osmo_fsm_inst *fi) |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 421 | { |
Pau Espin Pedrol | f197f15 | 2022-11-17 20:18:46 +0100 | [diff] [blame] | 422 | struct tbf_fsm_ctx *ctx = (struct tbf_fsm_ctx *)fi->priv; |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 423 | struct gprs_rlcmac_dl_tbf *dl_tbf = tbf_as_dl_tbf(ctx->tbf); |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 424 | |
Pau Espin Pedrol | 89a995a | 2021-10-18 14:25:17 +0200 | [diff] [blame] | 425 | /* X2002 is used only for DL TBF */ |
| 426 | OSMO_ASSERT(dl_tbf); |
| 427 | |
Pau Espin Pedrol | f197f15 | 2022-11-17 20:18:46 +0100 | [diff] [blame] | 428 | if (fi->state == TBF_ST_ASSIGN) { |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 429 | tbf_assign_control_ts(ctx->tbf); |
| 430 | |
| 431 | if (!tbf_can_upgrade_to_multislot(ctx->tbf)) { |
| 432 | /* change state to FLOW, so scheduler |
| 433 | * will start transmission */ |
Pau Espin Pedrol | f197f15 | 2022-11-17 20:18:46 +0100 | [diff] [blame] | 434 | osmo_fsm_inst_dispatch(fi, TBF_EV_ASSIGN_READY_CCCH, NULL); |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 435 | return; |
| 436 | } |
| 437 | |
| 438 | /* This tbf can be upgraded to use multiple DL |
| 439 | * timeslots and now that there is already one |
| 440 | * slot assigned send another DL assignment via |
| 441 | * PDCH. */ |
| 442 | |
| 443 | /* keep to flags */ |
| 444 | ctx->state_flags &= GPRS_RLCMAC_FLAG_TO_MASK; |
| 445 | |
| 446 | tbf_update(ctx->tbf); |
Pau Espin Pedrol | ee35008 | 2022-10-28 17:35:03 +0200 | [diff] [blame] | 447 | dl_tbf_trigger_ass_on_pacch(dl_tbf, ctx->tbf); |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 448 | } else |
| 449 | LOGPTBF(ctx->tbf, LOGL_NOTICE, "Continue flow after IMM.ASS confirm\n"); |
| 450 | } |
| 451 | |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 452 | static int tbf_fsm_timer_cb(struct osmo_fsm_inst *fi) |
| 453 | { |
Pau Espin Pedrol | cfb61d9 | 2021-07-26 17:17:02 +0200 | [diff] [blame] | 454 | struct tbf_fsm_ctx *ctx = (struct tbf_fsm_ctx *)fi->priv; |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 455 | switch (fi->T) { |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 456 | case -2002: |
Pau Espin Pedrol | f197f15 | 2022-11-17 20:18:46 +0100 | [diff] [blame] | 457 | handle_timeout_X2002(fi); |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 458 | break; |
Pau Espin Pedrol | 9d67e72 | 2021-07-28 19:25:38 +0200 | [diff] [blame] | 459 | case -2001: |
| 460 | LOGPTBF(ctx->tbf, LOGL_NOTICE, "releasing due to PACCH assignment timeout.\n"); |
| 461 | /* fall-through */ |
Pau Espin Pedrol | cfb61d9 | 2021-07-26 17:17:02 +0200 | [diff] [blame] | 462 | case 3169: |
Pau Espin Pedrol | f48de62 | 2021-07-30 14:48:06 +0200 | [diff] [blame] | 463 | case 3193: |
Pau Espin Pedrol | cfb61d9 | 2021-07-26 17:17:02 +0200 | [diff] [blame] | 464 | case 3195: |
| 465 | tbf_free(ctx->tbf); |
| 466 | break; |
| 467 | default: |
| 468 | OSMO_ASSERT(0); |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 469 | } |
| 470 | return 0; |
| 471 | } |
| 472 | |
| 473 | static struct osmo_fsm_state tbf_fsm_states[] = { |
Pau Espin Pedrol | 0043005 | 2021-10-12 12:04:03 +0200 | [diff] [blame] | 474 | [TBF_ST_NEW] = { |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 475 | .in_event_mask = |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 476 | X(TBF_EV_ASSIGN_ADD_CCCH) | |
| 477 | X(TBF_EV_ASSIGN_ADD_PACCH), |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 478 | .out_state_mask = |
| 479 | X(TBF_ST_ASSIGN) | |
| 480 | X(TBF_ST_FLOW) | |
| 481 | X(TBF_ST_RELEASING), |
Pau Espin Pedrol | 0043005 | 2021-10-12 12:04:03 +0200 | [diff] [blame] | 482 | .name = "NEW", |
| 483 | .action = st_new, |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 484 | }, |
| 485 | [TBF_ST_ASSIGN] = { |
| 486 | .in_event_mask = |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 487 | X(TBF_EV_ASSIGN_ADD_CCCH) | |
Pau Espin Pedrol | 720e19e | 2021-07-22 19:56:37 +0200 | [diff] [blame] | 488 | X(TBF_EV_ASSIGN_ADD_PACCH) | |
| 489 | X(TBF_EV_ASSIGN_ACK_PACCH) | |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 490 | X(TBF_EV_ASSIGN_PCUIF_CNF) | |
Pau Espin Pedrol | 85aa87b | 2021-10-12 14:02:52 +0200 | [diff] [blame] | 491 | X(TBF_EV_ASSIGN_READY_CCCH) | |
| 492 | X(TBF_EV_MAX_N3105), |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 493 | .out_state_mask = |
| 494 | X(TBF_ST_FLOW) | |
| 495 | X(TBF_ST_FINISHED) | |
| 496 | X(TBF_ST_RELEASING), |
| 497 | .name = "ASSIGN", |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 498 | .action = st_assign, |
Pau Espin Pedrol | 9d67e72 | 2021-07-28 19:25:38 +0200 | [diff] [blame] | 499 | .onenter = st_assign_on_enter, |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 500 | }, |
| 501 | [TBF_ST_FLOW] = { |
| 502 | .in_event_mask = |
Pau Espin Pedrol | 338a5ae | 2022-10-28 18:47:44 +0200 | [diff] [blame] | 503 | X(TBF_EV_FIRST_UL_DATA_RECVD) | |
Pau Espin Pedrol | f38a47e | 2022-10-28 19:06:45 +0200 | [diff] [blame] | 504 | X(TBF_EV_CONTENTION_RESOLUTION_MS_SUCCESS) | |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 505 | X(TBF_EV_DL_ACKNACK_MISS) | |
Pau Espin Pedrol | c32c4a3 | 2021-07-23 18:27:57 +0200 | [diff] [blame] | 506 | X(TBF_EV_LAST_DL_DATA_SENT) | |
Pau Espin Pedrol | efcb046 | 2021-07-26 12:33:39 +0200 | [diff] [blame] | 507 | X(TBF_EV_LAST_UL_DATA_RECVD) | |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 508 | X(TBF_EV_FINAL_ACK_RECVD) | |
| 509 | X(TBF_EV_MAX_N3101) | |
| 510 | X(TBF_EV_MAX_N3105), |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 511 | .out_state_mask = |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 512 | X(TBF_ST_ASSIGN) | |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 513 | X(TBF_ST_FINISHED) | |
| 514 | X(TBF_ST_WAIT_RELEASE) | |
| 515 | X(TBF_ST_RELEASING), |
| 516 | .name = "FLOW", |
Pau Espin Pedrol | c32c4a3 | 2021-07-23 18:27:57 +0200 | [diff] [blame] | 517 | .action = st_flow, |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 518 | }, |
| 519 | [TBF_ST_FINISHED] = { |
| 520 | .in_event_mask = |
Pau Espin Pedrol | f38a47e | 2022-10-28 19:06:45 +0200 | [diff] [blame] | 521 | X(TBF_EV_CONTENTION_RESOLUTION_MS_SUCCESS) | |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 522 | X(TBF_EV_DL_ACKNACK_MISS) | |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 523 | X(TBF_EV_FINAL_ACK_RECVD) | |
Pau Espin Pedrol | 7a2b65e | 2021-10-11 19:18:13 +0200 | [diff] [blame] | 524 | X(TBF_EV_FINAL_UL_ACK_CONFIRMED) | |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 525 | X(TBF_EV_MAX_N3103) | |
| 526 | X(TBF_EV_MAX_N3105), |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 527 | .out_state_mask = |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 528 | X(TBF_ST_WAIT_RELEASE) | |
| 529 | X(TBF_ST_RELEASING), |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 530 | .name = "FINISHED", |
Pau Espin Pedrol | efcb046 | 2021-07-26 12:33:39 +0200 | [diff] [blame] | 531 | .action = st_finished, |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 532 | }, |
| 533 | [TBF_ST_WAIT_RELEASE] = { |
| 534 | .in_event_mask = |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 535 | X(TBF_EV_FINAL_ACK_RECVD) | |
| 536 | X(TBF_EV_MAX_N3101) | |
| 537 | X(TBF_EV_MAX_N3105), |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 538 | .out_state_mask = |
| 539 | X(TBF_ST_RELEASING), |
| 540 | .name = "WAIT_RELEASE", |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 541 | .action = st_wait_release, |
Pau Espin Pedrol | f48de62 | 2021-07-30 14:48:06 +0200 | [diff] [blame] | 542 | .onenter = st_wait_release_on_enter, |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 543 | }, |
| 544 | [TBF_ST_RELEASING] = { |
| 545 | .in_event_mask = |
Pau Espin Pedrol | cee6b12 | 2021-09-28 16:49:33 +0200 | [diff] [blame] | 546 | X(TBF_EV_DL_ACKNACK_MISS), |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 547 | .out_state_mask = |
| 548 | 0, |
| 549 | .name = "RELEASING", |
Pau Espin Pedrol | cee6b12 | 2021-09-28 16:49:33 +0200 | [diff] [blame] | 550 | .action = st_releasing, |
Pau Espin Pedrol | cfb61d9 | 2021-07-26 17:17:02 +0200 | [diff] [blame] | 551 | .onenter = st_releasing_on_enter, |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 552 | }, |
| 553 | }; |
| 554 | |
| 555 | struct osmo_fsm tbf_fsm = { |
| 556 | .name = "TBF", |
| 557 | .states = tbf_fsm_states, |
| 558 | .num_states = ARRAY_SIZE(tbf_fsm_states), |
| 559 | .timer_cb = tbf_fsm_timer_cb, |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 560 | .log_subsys = DTBF, |
| 561 | .event_names = tbf_fsm_event_names, |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 562 | }; |
| 563 | |
| 564 | static __attribute__((constructor)) void tbf_fsm_init(void) |
| 565 | { |
| 566 | OSMO_ASSERT(osmo_fsm_register(&tbf_fsm) == 0); |
| 567 | } |