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. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | */ |
| 20 | #pragma once |
| 21 | |
| 22 | #include <osmocom/core/fsm.h> |
| 23 | #include <osmocom/core/tdef.h> |
| 24 | |
| 25 | #include <gprs_pcu.h> |
| 26 | |
| 27 | struct gprs_rlcmac_tbf; |
| 28 | |
| 29 | enum tbf_fsm_event { |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 30 | TBF_EV_ASSIGN_ADD_CCCH, /* An assignment is sent over CCCH and confirmation from MS is pending */ |
| 31 | TBF_EV_ASSIGN_ADD_PACCH, /* An assignment is sent over PACCH and confirmation from MS is pending */ |
Pau Espin Pedrol | 720e19e | 2021-07-22 19:56:37 +0200 | [diff] [blame] | 32 | TBF_EV_ASSIGN_ACK_PACCH, /* We received a CTRL ACK confirming assignment started on PACCH */ |
| 33 | TBF_EV_ASSIGN_READY_CCCH, /* TBF Start Time timer triggered */ |
Pau Espin Pedrol | 3225290 | 2021-07-29 16:44:11 +0200 | [diff] [blame] | 34 | TBF_EV_ASSIGN_PCUIF_CNF, /* Transmission of IMM.ASS for DL TBF to the MS confirmed by BTS over PCUIF */ |
| 35 | TBF_EV_DL_ACKNACK_MISS, /* DL TBF: We polled for DL ACK/NACK but we received none (POLL timeout) */ |
Pau Espin Pedrol | c32c4a3 | 2021-07-23 18:27:57 +0200 | [diff] [blame] | 36 | TBF_EV_LAST_DL_DATA_SENT, /* DL TBF sends RLCMAC block containing last DL avilable data buffered */ |
| 37 | TBF_EV_LAST_UL_DATA_RECVD, /* UL TBF sends RLCMAC block containing last UL data (cv=0) */ |
Pau Espin Pedrol | efcb046 | 2021-07-26 12:33:39 +0200 | [diff] [blame] | 38 | TBF_EV_FINAL_ACK_RECVD, /* DL ACK/NACK with FINAL_ACK=1 received from MS */ |
Pau Espin Pedrol | 7a2b65e | 2021-10-11 19:18:13 +0200 | [diff] [blame] | 39 | TBF_EV_FINAL_UL_ACK_CONFIRMED, /* UL TBF: MS ACKs (CtrlAck or PktResReq) our UL ACK/NACK w/ FinalAckInd=1 */ |
Pau Espin Pedrol | 55f600b | 2021-07-26 15:54:39 +0200 | [diff] [blame] | 40 | TBF_EV_MAX_N3101, /* MAX N3101 (max usf timeout) reached (UL TBF) */ |
| 41 | TBF_EV_MAX_N3103, /* MAX N3103 (max Pkt Ctrl Ack for last UL ACK/NACK timeout) reached (UL TBF) */ |
| 42 | TBF_EV_MAX_N3105, /* MAX N3105 (max poll timeout) reached (UL/DL TBF) */ |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | enum tbf_fsm_states { |
Pau Espin Pedrol | 0043005 | 2021-10-12 12:04:03 +0200 | [diff] [blame] | 46 | TBF_ST_NEW = 0, /* new created TBF */ |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 47 | TBF_ST_ASSIGN, /* wait for downlink assignment */ |
| 48 | TBF_ST_FLOW, /* RLC/MAC flow, resource needed */ |
| 49 | TBF_ST_FINISHED, /* flow finished, wait for release */ |
| 50 | TBF_ST_WAIT_RELEASE,/* wait for release or restart of DL TBF */ |
| 51 | TBF_ST_RELEASING, /* releasing, wait to free TBI/USF */ |
| 52 | }; |
| 53 | |
| 54 | struct tbf_fsm_ctx { |
| 55 | struct osmo_fsm_inst *fi; |
| 56 | struct gprs_rlcmac_tbf* tbf; /* back pointer */ |
Pau Espin Pedrol | 33e8007 | 2021-07-22 19:20:50 +0200 | [diff] [blame] | 57 | uint32_t state_flags; |
Pau Espin Pedrol | cfb61d9 | 2021-07-26 17:17:02 +0200 | [diff] [blame] | 58 | 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] | 59 | }; |
| 60 | |
| 61 | extern const struct osmo_tdef_state_timeout tbf_fsm_timeouts[32]; |
Pau Espin Pedrol | 628d881 | 2021-07-29 13:46:34 +0200 | [diff] [blame] | 62 | /* Transition to a state, using the T timer defined in tbf_fsm_timeouts. |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 63 | * The actual timeout value is in turn obtained from conn->T_defs. |
| 64 | * Assumes local variable fi exists. */ |
| 65 | #define tbf_fsm_state_chg(fi, NEXT_STATE) \ |
| 66 | osmo_tdef_fsm_inst_state_chg(fi, NEXT_STATE, \ |
| 67 | tbf_fsm_timeouts, \ |
| 68 | the_pcu->T_defs, \ |
| 69 | -1) |
| 70 | |
| 71 | extern struct osmo_fsm tbf_fsm; |