Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 1 | /* tbf_dl_fsm.c |
| 2 | * |
| 3 | * Copyright (C) 2021-2022 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. |
| 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 | |
| 28 | #include <bts_pch_timer.h> |
| 29 | |
| 30 | #define X(s) (1 << (s)) |
| 31 | |
| 32 | const struct osmo_tdef_state_timeout tbf_dl_fsm_timeouts[32] = { |
| 33 | [TBF_ST_NEW] = {}, |
| 34 | [TBF_ST_ASSIGN] = { }, |
| 35 | [TBF_ST_FLOW] = { }, |
| 36 | [TBF_ST_FINISHED] = {}, |
| 37 | [TBF_ST_WAIT_RELEASE] = {}, |
| 38 | [TBF_ST_RELEASING] = {}, |
| 39 | }; |
| 40 | |
| 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_dl_fsm_state_chg(fi, NEXT_STATE) \ |
| 45 | osmo_tdef_fsm_inst_state_chg(fi, NEXT_STATE, \ |
| 46 | tbf_dl_fsm_timeouts, \ |
| 47 | the_pcu->T_defs, \ |
| 48 | -1) |
| 49 | |
| 50 | static void mod_ass_type(struct tbf_dl_fsm_ctx *ctx, uint8_t t, bool set) |
| 51 | { |
| 52 | const char *ch = "UNKNOWN"; |
| 53 | bool prev_set = ctx->state_flags & (1 << t); |
| 54 | |
| 55 | switch (t) { |
| 56 | case GPRS_RLCMAC_FLAG_CCCH: |
| 57 | ch = "CCCH"; |
| 58 | break; |
| 59 | case GPRS_RLCMAC_FLAG_PACCH: |
| 60 | ch = "PACCH"; |
| 61 | break; |
| 62 | default: |
Pau Espin Pedrol | 83a0892 | 2022-12-12 19:46:01 +0100 | [diff] [blame] | 63 | LOGPTBFDL(ctx->dl_tbf, LOGL_ERROR, |
| 64 | "attempted to %sset unexpected ass. type %d - FIXME!\n", |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 65 | set ? "" : "un", t); |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | if (set && prev_set) |
Pau Espin Pedrol | 83a0892 | 2022-12-12 19:46:01 +0100 | [diff] [blame] | 70 | LOGPTBFDL(ctx->dl_tbf, LOGL_ERROR, |
| 71 | "attempted to set ass. type %s which is already set.\n", ch); |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 72 | else if (!set && !prev_set) |
| 73 | return; |
| 74 | |
Pau Espin Pedrol | 83a0892 | 2022-12-12 19:46:01 +0100 | [diff] [blame] | 75 | LOGPTBFDL(ctx->dl_tbf, LOGL_INFO, "%sset ass. type %s [prev CCCH:%u, PACCH:%u]\n", |
| 76 | set ? "" : "un", ch, |
| 77 | !!(ctx->state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH)), |
| 78 | !!(ctx->state_flags & (1 << GPRS_RLCMAC_FLAG_PACCH))); |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 79 | |
| 80 | if (set) { |
| 81 | ctx->state_flags |= (1 << t); |
| 82 | } else { |
| 83 | ctx->state_flags &= GPRS_RLCMAC_FLAG_TO_MASK; /* keep to flags */ |
| 84 | ctx->state_flags &= ~(1 << t); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | |
| 89 | static void st_new(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 90 | { |
| 91 | struct tbf_dl_fsm_ctx *ctx = (struct tbf_dl_fsm_ctx *)fi->priv; |
| 92 | switch (event) { |
| 93 | case TBF_EV_ASSIGN_ADD_CCCH: |
| 94 | mod_ass_type(ctx, GPRS_RLCMAC_FLAG_CCCH, true); |
| 95 | tbf_dl_fsm_state_chg(fi, TBF_ST_ASSIGN); |
| 96 | break; |
| 97 | case TBF_EV_ASSIGN_ADD_PACCH: |
| 98 | mod_ass_type(ctx, GPRS_RLCMAC_FLAG_PACCH, true); |
| 99 | tbf_dl_fsm_state_chg(fi, TBF_ST_ASSIGN); |
| 100 | break; |
| 101 | default: |
| 102 | OSMO_ASSERT(0); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | static void st_assign_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state) |
| 107 | { |
| 108 | struct tbf_dl_fsm_ctx *ctx = (struct tbf_dl_fsm_ctx *)fi->priv; |
| 109 | unsigned long val; |
| 110 | unsigned int sec, micro; |
| 111 | |
| 112 | /* If assignment for this TBF is happening on PACCH, that means the |
| 113 | * actual Assignment procedure (tx/rx) is happening on another TBF (eg |
| 114 | * Ul TBF vs DL TBF). Hence we add a security timer here to free it in |
| 115 | * case the other TBF doesn't succeed in informing (assigning) the MS |
| 116 | * about this TBF, or simply because the scheduler takes too long to |
| 117 | * schedule it. This timer can probably be dropped once we make the |
| 118 | * other TBF always signal us assignment failure (we already get |
| 119 | * assignment success through TBF_EV_ASSIGN_ACK_PACCH) */ |
| 120 | if (ctx->state_flags & (1 << GPRS_RLCMAC_FLAG_PACCH)) { |
| 121 | fi->T = -2001; |
| 122 | val = osmo_tdef_get(the_pcu->T_defs, fi->T, OSMO_TDEF_MS, -1); |
| 123 | sec = val / 1000; |
| 124 | micro = (val % 1000) * 1000; |
Pau Espin Pedrol | 83a0892 | 2022-12-12 19:46:01 +0100 | [diff] [blame] | 125 | LOGPTBFDL(ctx->dl_tbf, LOGL_DEBUG, |
| 126 | "Starting timer X2001 [assignment (PACCH)] with %u sec. %u microsec\n", |
| 127 | sec, micro); |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 128 | osmo_timer_schedule(&fi->timer, sec, micro); |
| 129 | } else { |
| 130 | /* GPRS_RLCMAC_FLAG_CCCH is set, so here we submitted an DL Ass |
| 131 | * through PCUIF on CCCH */ |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | static void st_assign(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 136 | { |
| 137 | struct tbf_dl_fsm_ctx *ctx = (struct tbf_dl_fsm_ctx *)fi->priv; |
| 138 | unsigned long val; |
| 139 | unsigned int sec, micro; |
| 140 | |
| 141 | switch (event) { |
| 142 | case TBF_EV_ASSIGN_ADD_CCCH: |
| 143 | mod_ass_type(ctx, GPRS_RLCMAC_FLAG_CCCH, true); |
| 144 | break; |
| 145 | case TBF_EV_ASSIGN_ADD_PACCH: |
| 146 | mod_ass_type(ctx, GPRS_RLCMAC_FLAG_PACCH, true); |
| 147 | break; |
| 148 | case TBF_EV_ASSIGN_ACK_PACCH: |
| 149 | tbf_assign_control_ts(ctx->tbf); |
| 150 | if (ctx->state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH)) { |
| 151 | /* We now know that the PACCH really existed */ |
Pau Espin Pedrol | 83a0892 | 2022-12-12 19:46:01 +0100 | [diff] [blame] | 152 | LOGPTBFDL(ctx->dl_tbf, LOGL_INFO, |
| 153 | "The TBF has been confirmed on the PACCH, " |
| 154 | "changed type from CCCH to PACCH\n"); |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 155 | mod_ass_type(ctx, GPRS_RLCMAC_FLAG_CCCH, false); |
| 156 | mod_ass_type(ctx, GPRS_RLCMAC_FLAG_PACCH, true); |
| 157 | } |
| 158 | tbf_dl_fsm_state_chg(fi, TBF_ST_FLOW); |
| 159 | break; |
| 160 | case TBF_EV_ASSIGN_PCUIF_CNF: |
| 161 | /* BTS informs us it sent Imm Ass for DL TBF over CCCH. We now |
| 162 | * have to wait for X2002 to trigger (meaning MS is already |
| 163 | * listening on PDCH) in order to move to FLOW state and start |
| 164 | * transmitting data to it. When X2002 triggers (see cb timer |
| 165 | * end of the file) it will send TBF_EV_ASSIGN_READY_CCCH back |
| 166 | * to us here. */ |
| 167 | fi->T = -2002; |
| 168 | val = osmo_tdef_get(the_pcu->T_defs, fi->T, OSMO_TDEF_MS, -1); |
| 169 | sec = val / 1000; |
| 170 | micro = (val % 1000) * 1000; |
Pau Espin Pedrol | 83a0892 | 2022-12-12 19:46:01 +0100 | [diff] [blame] | 171 | LOGPTBFDL(ctx->dl_tbf, LOGL_DEBUG, |
| 172 | "Starting timer X2002 [assignment (AGCH)] with %u sec. %u microsec\n", |
| 173 | sec, micro); |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 174 | osmo_timer_schedule(&fi->timer, sec, micro); |
| 175 | break; |
| 176 | case TBF_EV_ASSIGN_READY_CCCH: |
| 177 | /* change state to FLOW, so scheduler will start transmission */ |
| 178 | tbf_dl_fsm_state_chg(fi, TBF_ST_FLOW); |
| 179 | break; |
| 180 | case TBF_EV_MAX_N3105: |
| 181 | /* We are going to release, so abort any Pkt Ul Ass pending to be scheduled: */ |
| 182 | osmo_fsm_inst_dispatch(tbf_ul_ass_fi(ctx->tbf), TBF_UL_ASS_EV_ABORT, NULL); |
| 183 | ctx->T_release = 3195; |
| 184 | tbf_dl_fsm_state_chg(fi, TBF_ST_RELEASING); |
| 185 | break; |
| 186 | default: |
| 187 | OSMO_ASSERT(0); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | static void st_flow(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 192 | { |
| 193 | struct tbf_dl_fsm_ctx *ctx = (struct tbf_dl_fsm_ctx *)fi->priv; |
| 194 | |
| 195 | switch (event) { |
| 196 | case TBF_EV_DL_ACKNACK_MISS: |
| 197 | /* DL TBF: we missed a DL ACK/NACK. If we started assignment |
| 198 | * over CCCH and never received any DL ACK/NACK yet, it means we |
| 199 | * don't even know if the MS successfully received the Imm Ass on |
| 200 | * CCCH and hence is listening on PDCH. Let's better refrain |
| 201 | * from continuing and start assignment on CCCH again */ |
| 202 | if ((ctx->state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH)) |
| 203 | && !(ctx->state_flags & (1 << GPRS_RLCMAC_FLAG_DL_ACK))) { |
| 204 | struct GprsMs *ms = tbf_ms(ctx->tbf); |
Pau Espin Pedrol | 83a0892 | 2022-12-12 19:46:01 +0100 | [diff] [blame] | 205 | LOGPTBFDL(ctx->dl_tbf, LOGL_DEBUG, |
| 206 | "Re-send downlink assignment on PCH (IMSI=%s)\n", |
| 207 | ms_imsi_is_valid(ms) ? ms_imsi(ms) : ""); |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 208 | tbf_dl_fsm_state_chg(fi, TBF_ST_ASSIGN); |
| 209 | /* send immediate assignment */ |
Pau Espin Pedrol | 83a0892 | 2022-12-12 19:46:01 +0100 | [diff] [blame] | 210 | bts_snd_dl_ass(ms->bts, ctx->dl_tbf); |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 211 | } |
| 212 | break; |
| 213 | case TBF_EV_LAST_DL_DATA_SENT: |
| 214 | /* All data has been sent or received, change state to FINISHED */ |
| 215 | tbf_dl_fsm_state_chg(fi, TBF_ST_FINISHED); |
| 216 | break; |
| 217 | case TBF_EV_FINAL_ACK_RECVD: |
| 218 | /* We received Final Ack (DL ACK/NACK) from MS. move to |
| 219 | * WAIT_RELEASE, we wait there for release or re-use the TBF in |
| 220 | * case we receive more DL data to tx */ |
| 221 | tbf_dl_fsm_state_chg(fi, TBF_ST_WAIT_RELEASE); |
| 222 | break; |
| 223 | case TBF_EV_MAX_N3105: |
| 224 | ctx->T_release = 3195; |
| 225 | tbf_dl_fsm_state_chg(fi, TBF_ST_RELEASING); |
| 226 | break; |
| 227 | default: |
| 228 | OSMO_ASSERT(0); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | static void st_finished(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 233 | { |
| 234 | struct tbf_dl_fsm_ctx *ctx = (struct tbf_dl_fsm_ctx *)fi->priv; |
| 235 | |
| 236 | switch (event) { |
| 237 | case TBF_EV_DL_ACKNACK_MISS: |
| 238 | OSMO_ASSERT(tbf_direction(ctx->tbf) == GPRS_RLCMAC_DL_TBF); |
| 239 | break; |
| 240 | case TBF_EV_FINAL_ACK_RECVD: |
| 241 | /* We received Final Ack (DL ACK/NACK) from MS. move to |
| 242 | * WAIT_RELEASE, we wait there for release or re-use the TBF in |
| 243 | * case we receive more DL data to tx */ |
| 244 | tbf_dl_fsm_state_chg(fi, TBF_ST_WAIT_RELEASE); |
| 245 | break; |
| 246 | case TBF_EV_MAX_N3105: |
| 247 | ctx->T_release = 3195; |
| 248 | tbf_dl_fsm_state_chg(fi, TBF_ST_RELEASING); |
| 249 | break; |
| 250 | default: |
| 251 | OSMO_ASSERT(0); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | static void st_wait_release_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state) |
| 256 | { |
| 257 | struct tbf_dl_fsm_ctx *ctx = (struct tbf_dl_fsm_ctx *)fi->priv; |
| 258 | unsigned long val_s, val_ms, val_us; |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 259 | |
| 260 | fi->T = 3193; |
| 261 | val_ms = osmo_tdef_get(tbf_ms(ctx->tbf)->bts->T_defs_bts, fi->T, OSMO_TDEF_MS, -1); |
| 262 | val_s = val_ms / 1000; |
| 263 | val_us = (val_ms % 1000) * 1000; |
Pau Espin Pedrol | 83a0892 | 2022-12-12 19:46:01 +0100 | [diff] [blame] | 264 | LOGPTBFDL(ctx->dl_tbf, LOGL_DEBUG, "starting timer T%u with %lu sec. %lu microsec\n", |
| 265 | fi->T, val_s, val_us); |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 266 | osmo_timer_schedule(&fi->timer, val_s, val_us); |
| 267 | |
| 268 | mod_ass_type(ctx, GPRS_RLCMAC_FLAG_CCCH, false); |
| 269 | } |
| 270 | |
| 271 | static void st_wait_release(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 272 | { |
| 273 | struct tbf_dl_fsm_ctx *ctx = (struct tbf_dl_fsm_ctx *)fi->priv; |
| 274 | switch (event) { |
| 275 | case TBF_EV_FINAL_ACK_RECVD: |
| 276 | /* ignore, duplicate ACK, we already know about since we are in WAIT_RELEASE */ |
| 277 | break; |
| 278 | case TBF_EV_MAX_N3105: |
| 279 | ctx->T_release = 3195; |
| 280 | tbf_dl_fsm_state_chg(fi, TBF_ST_RELEASING); |
| 281 | break; |
| 282 | default: |
| 283 | OSMO_ASSERT(0); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | static void st_releasing_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state) |
| 288 | { |
| 289 | struct tbf_dl_fsm_ctx *ctx = (struct tbf_dl_fsm_ctx *)fi->priv; |
| 290 | unsigned long val; |
| 291 | |
| 292 | if (!ctx->T_release) |
| 293 | return; |
| 294 | |
| 295 | /* In general we should end up here with an assigned timer in ctx->T_release. Possible values are: |
| 296 | * T3195: Wait for reuse of TFI(s) when there is no response from the MS |
| 297 | * (radio failure or cell change) for this TBF/MBMS radio bearer. |
| 298 | * T3169: Wait for reuse of USF and TFI(s) after the MS uplink assignment for this TBF is invalid. |
| 299 | */ |
| 300 | val = osmo_tdef_get(tbf_ms(ctx->tbf)->bts->T_defs_bts, ctx->T_release, OSMO_TDEF_S, -1); |
| 301 | fi->T = ctx->T_release; |
Pau Espin Pedrol | 83a0892 | 2022-12-12 19:46:01 +0100 | [diff] [blame] | 302 | LOGPTBFDL(ctx->dl_tbf, LOGL_DEBUG, "starting timer T%u with %lu sec. %u microsec\n", |
| 303 | ctx->T_release, val, 0); |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 304 | osmo_timer_schedule(&fi->timer, val, 0); |
| 305 | } |
| 306 | |
| 307 | static void st_releasing(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 308 | { |
| 309 | struct tbf_dl_fsm_ctx *ctx = (struct tbf_dl_fsm_ctx *)fi->priv; |
| 310 | switch (event) { |
| 311 | case TBF_EV_DL_ACKNACK_MISS: |
| 312 | OSMO_ASSERT(tbf_direction(ctx->tbf) == GPRS_RLCMAC_DL_TBF); |
| 313 | /* Ignore, we don't care about missed DL ACK/NACK poll timeouts |
| 314 | * anymore, we are already releasing the TBF */ |
| 315 | break; |
| 316 | default: |
| 317 | OSMO_ASSERT(0); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | static void handle_timeout_X2002(struct osmo_fsm_inst *fi) |
| 322 | { |
| 323 | struct tbf_dl_fsm_ctx *ctx = (struct tbf_dl_fsm_ctx *)fi->priv; |
Pau Espin Pedrol | b7a2b59 | 2022-12-13 14:43:59 +0100 | [diff] [blame] | 324 | int rc; |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 325 | |
Pau Espin Pedrol | b7a2b59 | 2022-12-13 14:43:59 +0100 | [diff] [blame] | 326 | if (fi->state != TBF_ST_ASSIGN) { |
Pau Espin Pedrol | 83a0892 | 2022-12-12 19:46:01 +0100 | [diff] [blame] | 327 | LOGPTBFDL(ctx->dl_tbf, LOGL_NOTICE, "Continue flow after IMM.ASS confirm\n"); |
Pau Espin Pedrol | b7a2b59 | 2022-12-13 14:43:59 +0100 | [diff] [blame] | 328 | return; |
| 329 | } |
| 330 | |
| 331 | /* state TBF_ST_ASSIGN: */ |
| 332 | tbf_assign_control_ts(ctx->tbf); |
| 333 | |
| 334 | if (!tbf_can_upgrade_to_multislot(ctx->tbf)) { |
| 335 | /* change state to FLOW, so scheduler will start transmission */ |
| 336 | osmo_fsm_inst_dispatch(fi, TBF_EV_ASSIGN_READY_CCCH, NULL); |
| 337 | return; |
| 338 | } |
| 339 | |
| 340 | /* This tbf can be upgraded to use multiple DL timeslots and now that there is already |
| 341 | * one slot assigned send another DL assignment via PDCH. |
| 342 | */ |
| 343 | |
| 344 | /* keep TO flags */ |
| 345 | ctx->state_flags &= GPRS_RLCMAC_FLAG_TO_MASK; |
| 346 | |
| 347 | rc = dl_tbf_upgrade_to_multislot(ctx->dl_tbf); |
Pau Espin Pedrol | 4a09054 | 2022-12-13 14:48:31 +0100 | [diff] [blame] | 348 | if (rc < 0) |
Pau Espin Pedrol | b7a2b59 | 2022-12-13 14:43:59 +0100 | [diff] [blame] | 349 | tbf_free(ctx->tbf); |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | static int tbf_dl_fsm_timer_cb(struct osmo_fsm_inst *fi) |
| 353 | { |
| 354 | struct tbf_dl_fsm_ctx *ctx = (struct tbf_dl_fsm_ctx *)fi->priv; |
| 355 | switch (fi->T) { |
| 356 | case -2002: |
| 357 | handle_timeout_X2002(fi); |
| 358 | break; |
| 359 | case -2001: |
Pau Espin Pedrol | 83a0892 | 2022-12-12 19:46:01 +0100 | [diff] [blame] | 360 | LOGPTBFDL(ctx->dl_tbf, LOGL_NOTICE, "releasing due to PACCH assignment timeout.\n"); |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 361 | /* fall-through */ |
| 362 | case 3169: |
| 363 | case 3193: |
| 364 | case 3195: |
| 365 | tbf_free(ctx->tbf); |
| 366 | break; |
| 367 | default: |
| 368 | OSMO_ASSERT(0); |
| 369 | } |
| 370 | return 0; |
| 371 | } |
| 372 | |
| 373 | static struct osmo_fsm_state tbf_dl_fsm_states[] = { |
| 374 | [TBF_ST_NEW] = { |
| 375 | .in_event_mask = |
| 376 | X(TBF_EV_ASSIGN_ADD_CCCH) | |
| 377 | X(TBF_EV_ASSIGN_ADD_PACCH), |
| 378 | .out_state_mask = |
| 379 | X(TBF_ST_ASSIGN) | |
| 380 | X(TBF_ST_RELEASING), |
| 381 | .name = "NEW", |
| 382 | .action = st_new, |
| 383 | }, |
| 384 | [TBF_ST_ASSIGN] = { |
| 385 | .in_event_mask = |
| 386 | X(TBF_EV_ASSIGN_ADD_CCCH) | |
| 387 | X(TBF_EV_ASSIGN_ADD_PACCH) | |
| 388 | X(TBF_EV_ASSIGN_ACK_PACCH) | |
| 389 | X(TBF_EV_ASSIGN_PCUIF_CNF) | |
| 390 | X(TBF_EV_ASSIGN_READY_CCCH) | |
| 391 | X(TBF_EV_MAX_N3105), |
| 392 | .out_state_mask = |
| 393 | X(TBF_ST_FLOW) | |
| 394 | X(TBF_ST_FINISHED) | |
| 395 | X(TBF_ST_RELEASING), |
| 396 | .name = "ASSIGN", |
| 397 | .action = st_assign, |
| 398 | .onenter = st_assign_on_enter, |
| 399 | }, |
| 400 | [TBF_ST_FLOW] = { |
| 401 | .in_event_mask = |
| 402 | X(TBF_EV_DL_ACKNACK_MISS) | |
| 403 | X(TBF_EV_LAST_DL_DATA_SENT) | |
| 404 | X(TBF_EV_FINAL_ACK_RECVD) | |
| 405 | X(TBF_EV_MAX_N3105), |
| 406 | .out_state_mask = |
| 407 | X(TBF_ST_ASSIGN) | |
| 408 | X(TBF_ST_FINISHED) | |
| 409 | X(TBF_ST_WAIT_RELEASE) | |
| 410 | X(TBF_ST_RELEASING), |
| 411 | .name = "FLOW", |
| 412 | .action = st_flow, |
| 413 | }, |
| 414 | [TBF_ST_FINISHED] = { |
| 415 | .in_event_mask = |
| 416 | X(TBF_EV_DL_ACKNACK_MISS) | |
| 417 | X(TBF_EV_FINAL_ACK_RECVD) | |
| 418 | X(TBF_EV_MAX_N3105), |
| 419 | .out_state_mask = |
| 420 | X(TBF_ST_WAIT_RELEASE) | |
| 421 | X(TBF_ST_RELEASING), |
| 422 | .name = "FINISHED", |
| 423 | .action = st_finished, |
| 424 | }, |
| 425 | [TBF_ST_WAIT_RELEASE] = { |
| 426 | .in_event_mask = |
| 427 | X(TBF_EV_FINAL_ACK_RECVD) | |
| 428 | X(TBF_EV_MAX_N3105), |
| 429 | .out_state_mask = |
| 430 | X(TBF_ST_RELEASING), |
| 431 | .name = "WAIT_RELEASE", |
| 432 | .action = st_wait_release, |
| 433 | .onenter = st_wait_release_on_enter, |
| 434 | }, |
| 435 | [TBF_ST_RELEASING] = { |
| 436 | .in_event_mask = |
| 437 | X(TBF_EV_DL_ACKNACK_MISS), |
| 438 | .out_state_mask = |
| 439 | 0, |
| 440 | .name = "RELEASING", |
| 441 | .action = st_releasing, |
| 442 | .onenter = st_releasing_on_enter, |
| 443 | }, |
| 444 | }; |
| 445 | |
| 446 | struct osmo_fsm tbf_dl_fsm = { |
| 447 | .name = "DL_TBF", |
| 448 | .states = tbf_dl_fsm_states, |
| 449 | .num_states = ARRAY_SIZE(tbf_dl_fsm_states), |
| 450 | .timer_cb = tbf_dl_fsm_timer_cb, |
| 451 | .log_subsys = DTBFDL, |
| 452 | .event_names = tbf_fsm_event_names, |
| 453 | }; |
| 454 | |
| 455 | static __attribute__((constructor)) void tbf_dl_fsm_init(void) |
| 456 | { |
| 457 | OSMO_ASSERT(osmo_fsm_register(&tbf_dl_fsm) == 0); |
| 458 | } |