Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 1 | /* tbf_fsm.h |
| 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 | #pragma once |
| 17 | |
| 18 | #include <osmocom/core/fsm.h> |
| 19 | #include <osmocom/core/tdef.h> |
| 20 | |
| 21 | #include <gprs_pcu.h> |
| 22 | |
| 23 | struct gprs_rlcmac_tbf; |
| 24 | |
| 25 | enum tbf_fsm_event { |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 26 | /* For both UL/DL TBF: */ |
| 27 | TBF_EV_ASSIGN_ADD_CCCH, /* An assignment is sent over CCCH and confirmation from MS is pending */ |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 28 | TBF_EV_ASSIGN_ADD_PACCH, /* An assignment is sent over PACCH and confirmation from MS is pending */ |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 29 | TBF_EV_ASSIGN_ACK_PACCH, /* We received a CTRL ACK confirming assignment started on PACCH */ |
| 30 | TBF_EV_MAX_N3105, /* MAX N3105 (max poll timeout) reached */ |
| 31 | |
| 32 | /* Only for DL TBF: */ |
Pau Espin Pedrol | 720e19e | 2021-07-22 19:56:37 +0200 | [diff] [blame] | 33 | TBF_EV_ASSIGN_READY_CCCH, /* TBF Start Time timer triggered */ |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 34 | TBF_EV_ASSIGN_PCUIF_CNF, /* Transmission of IMM.ASS for to the MS confirmed by BTS over PCUIF */ |
| 35 | TBF_EV_DL_ACKNACK_MISS, /* We polled for DL ACK/NACK but we received none (POLL timeout) */ |
| 36 | TBF_EV_LAST_DL_DATA_SENT, /* Network sends RLCMAC block containing last DL avilable data buffered */ |
Pau Espin Pedrol | efcb046 | 2021-07-26 12:33:39 +0200 | [diff] [blame] | 37 | TBF_EV_FINAL_ACK_RECVD, /* DL ACK/NACK with FINAL_ACK=1 received from MS */ |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 38 | |
| 39 | /* Only for UL TBF: */ |
| 40 | TBF_EV_FIRST_UL_DATA_RECVD, /* Received first UL data from MS. Equals to Contention Resolution completed on the network side */ |
| 41 | TBF_EV_CONTENTION_RESOLUTION_MS_SUCCESS, /* Contention resolution success at the mobile station side (first UL_ACK_NACK confirming TLLI is received at the MS) */ |
| 42 | TBF_EV_LAST_UL_DATA_RECVD, /* MS ends RLCMAC block containing last UL data (cv=0) */ |
| 43 | TBF_EV_FINAL_UL_ACK_CONFIRMED, /* MS ACKs (CtrlAck or PktResReq) our UL ACK/NACK w/ FinalAckInd=1. data = (bool) MS requests establishment of a new UL-TBF. */ |
| 44 | TBF_EV_MAX_N3101, /* MAX N3101 (max usf timeout) reached */ |
| 45 | TBF_EV_MAX_N3103, /* MAX N3103 (max Pkt Ctrl Ack for last UL ACK/NACK timeout) reached */ |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 46 | }; |
| 47 | |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 48 | extern const struct value_string tbf_fsm_event_names[]; |
| 49 | |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 50 | enum tbf_fsm_states { |
Pau Espin Pedrol | 0043005 | 2021-10-12 12:04:03 +0200 | [diff] [blame] | 51 | TBF_ST_NEW = 0, /* new created TBF */ |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 52 | TBF_ST_ASSIGN, /* wait for downlink assignment */ |
| 53 | TBF_ST_FLOW, /* RLC/MAC flow, resource needed */ |
| 54 | TBF_ST_FINISHED, /* flow finished, wait for release */ |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 55 | TBF_ST_WAIT_RELEASE,/* DL TBF: wait for release or restart */ |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 56 | TBF_ST_RELEASING, /* releasing, wait to free TBI/USF */ |
| 57 | }; |
| 58 | |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 59 | struct tbf_dl_fsm_ctx { |
Pau Espin Pedrol | 83a0892 | 2022-12-12 19:46:01 +0100 | [diff] [blame] | 60 | union { /* back pointer. union used to easily access superclass from ctx */ |
| 61 | struct gprs_rlcmac_tbf *tbf; |
| 62 | struct gprs_rlcmac_dl_tbf *dl_tbf; |
| 63 | }; |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 64 | uint32_t state_flags; |
Pau Espin Pedrol | cfb61d9 | 2021-07-26 17:17:02 +0200 | [diff] [blame] | 65 | unsigned int T_release; /* Timer to be used to end release: T3169 or T3195 */ |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 66 | }; |
| 67 | |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 68 | struct tbf_ul_fsm_ctx { |
Pau Espin Pedrol | cdc762a | 2022-12-12 19:58:37 +0100 | [diff] [blame] | 69 | union { /* back pointer. union used to easily access superclass from ctx */ |
| 70 | struct gprs_rlcmac_tbf *tbf; |
| 71 | struct gprs_rlcmac_ul_tbf *ul_tbf; |
| 72 | }; |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 73 | uint32_t state_flags; |
| 74 | unsigned int T_release; /* Timer to be used to end release: T3169 or T3195 */ |
| 75 | }; |
| 76 | |
| 77 | extern struct osmo_fsm tbf_dl_fsm; |
| 78 | extern struct osmo_fsm tbf_ul_fsm; |