blob: c45db44e2a1ce95f017b9e8202a82c095d5aefa0 [file] [log] [blame]
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +02001/*
2 * Copyright (C) 2013 by Holger Hans Peter Freyther
3 * Copyright (C) 2019 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020014 */
15
16#pragma once
17
18#ifdef __cplusplus
19
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +020020#include <stdbool.h>
21
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020022#include "tbf.h"
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +020023
24#ifdef __cplusplus
25extern "C" {
26#endif
27#include <tbf_ul_ack_fsm.h>
28#ifdef __cplusplus
29}
30#endif
31
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020032/*
33 * TBF instance
34 */
35
36enum tbf_gprs_ul_counters {
37 TBF_CTR_GPRS_UL_CS1,
38 TBF_CTR_GPRS_UL_CS2,
39 TBF_CTR_GPRS_UL_CS3,
40 TBF_CTR_GPRS_UL_CS4,
41};
42
43enum tbf_egprs_ul_counters {
44 TBF_CTR_EGPRS_UL_MCS1,
45 TBF_CTR_EGPRS_UL_MCS2,
46 TBF_CTR_EGPRS_UL_MCS3,
47 TBF_CTR_EGPRS_UL_MCS4,
48 TBF_CTR_EGPRS_UL_MCS5,
49 TBF_CTR_EGPRS_UL_MCS6,
50 TBF_CTR_EGPRS_UL_MCS7,
51 TBF_CTR_EGPRS_UL_MCS8,
52 TBF_CTR_EGPRS_UL_MCS9,
53};
54
Pau Espin Pedrol7bd92a32021-03-24 13:14:09 +010055/* Used in ul_tbf->m_usf[] to flag unassigned USF on a given TS: */
56#define USF_INVALID 0xFF
57
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020058struct gprs_rlcmac_ul_tbf : public gprs_rlcmac_tbf {
Pau Espin Pedrol2182e622021-01-14 16:48:38 +010059 gprs_rlcmac_ul_tbf(struct gprs_rlcmac_bts *bts, GprsMs *ms);
Pau Espin Pedrol131deb02021-07-26 18:24:14 +020060 ~gprs_rlcmac_ul_tbf();
Pau Espin Pedrolb3f23972020-10-23 21:00:23 +020061 gprs_rlc_window *window();
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020062 /* blocks were acked */
63 int rcv_data_block_acknowledged(
64 const struct gprs_rlc_data_info *rlc,
65 uint8_t *data, struct pcu_l1_meas *meas);
66
67
68 /* TODO: extract LLC class? */
69 int assemble_forward_llc(const gprs_rlc_data *data);
70 int snd_ul_ud();
71
72 egprs_rlc_ul_reseg_bsn_state handle_egprs_ul_spb(
73 const struct gprs_rlc_data_info *rlc,
74 struct gprs_rlc_data *block,
75 uint8_t *data, const uint8_t block_idx);
76
77 egprs_rlc_ul_reseg_bsn_state handle_egprs_ul_first_seg(
78 const struct gprs_rlc_data_info *rlc,
79 struct gprs_rlc_data *block,
80 uint8_t *data, const uint8_t block_idx);
81
82 egprs_rlc_ul_reseg_bsn_state handle_egprs_ul_second_seg(
83 const struct gprs_rlc_data_info *rlc,
84 struct gprs_rlc_data *block,
85 uint8_t *data, const uint8_t block_idx);
86
87 uint16_t window_size() const;
88 void set_window_size();
89 void update_coding_scheme_counter_ul(enum CodingScheme cs);
Pau Espin Pedrol0b998b12021-03-24 14:45:43 +010090 void usf_timeout();
Pau Espin Pedrol4b6f0bf2021-05-10 18:54:52 +020091 void contention_resolution_start();
92 void contention_resolution_success();
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020093
94 /* Please note that all variables here will be reset when changing
95 * from WAIT RELEASE back to FLOW state (re-use of TBF).
96 * All states that need reset must be in this struct, so this is why
97 * variables are in both (dl and ul) structs and not outside union.
98 */
99 int32_t m_rx_counter; /* count all received blocks */
Pau Espin Pedrol7bd92a32021-03-24 13:14:09 +0100100 uint8_t m_usf[8]; /* list USFs per PDCH (timeslot), initialized to USF_INVALID */
Pau Espin Pedrol0f859562022-10-31 10:51:20 +0100101 bool m_contention_resolution_done; /* set after done */
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +0200102
103 struct rate_ctr_group *m_ul_gprs_ctrs;
104 struct rate_ctr_group *m_ul_egprs_ctrs;
105
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +0200106 struct tbf_ul_ass_fsm_ctx ul_ack_fsm;
107
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +0200108protected:
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200109 void maybe_schedule_uplink_acknack(const gprs_rlc_data_info *rlc, bool countdown_finished);
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +0200110
111 /* Please note that all variables below will be reset when changing
112 * from WAIT RELEASE back to FLOW state (re-use of TBF).
113 * All states that need reset must be in this struct, so this is why
114 * variables are in both (dl and ul) structs and not outside union.
115 */
116 gprs_rlc_ul_window m_window;
117};
118
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +0200119inline uint16_t gprs_rlcmac_ul_tbf::window_size() const
120{
121 return m_window.ws();
122}
123
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200124struct gprs_rlcmac_ul_tbf *handle_tbf_reject(struct gprs_rlcmac_bts *bts,
Pau Espin Pedrol54742f22021-04-26 16:48:34 +0200125 GprsMs *ms, uint8_t trx_no, uint8_t ts_no);
Pau Espin Pedrol442198c2020-10-23 22:30:04 +0200126
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100127#else /* ifdef __cplusplus */
128struct gprs_rlcmac_ul_tbf;
129#endif
130
131
132#ifdef __cplusplus
133extern "C" {
134#endif
Pau Espin Pedrolbda7bb72022-10-31 14:33:09 +0100135struct gprs_rlcmac_ul_tbf *ul_tbf_alloc(struct gprs_rlcmac_bts *bts, struct GprsMs *ms, int8_t use_trx, bool single_slot);
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100136void update_tbf_ta(struct gprs_rlcmac_ul_tbf *tbf, int8_t ta_delta);
137void set_tbf_ta(struct gprs_rlcmac_ul_tbf *tbf, uint8_t ta);
Pau Espin Pedrolcc30b052022-10-27 15:25:55 +0200138struct gprs_rlcmac_ul_tbf *tbf_as_ul_tbf(struct gprs_rlcmac_tbf *tbf);
Pau Espin Pedrol1e1275f2022-11-17 20:57:34 +0100139const struct gprs_rlcmac_ul_tbf *tbf_as_ul_tbf_const(const struct gprs_rlcmac_tbf *tbf);
Pau Espin Pedrol0b998b12021-03-24 14:45:43 +0100140void tbf_usf_timeout(struct gprs_rlcmac_ul_tbf *tbf);
Pau Espin Pedrol94386132022-10-28 19:50:09 +0200141void ul_tbf_contention_resolution_start(struct gprs_rlcmac_ul_tbf *tbf);
142void ul_tbf_contention_resolution_success(struct gprs_rlcmac_ul_tbf *tbf);
Pau Espin Pedrol49a2f402021-07-27 17:33:07 +0200143bool ul_tbf_contention_resolution_done(const struct gprs_rlcmac_ul_tbf *tbf);
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +0200144struct osmo_fsm_inst *tbf_ul_ack_fi(const struct gprs_rlcmac_ul_tbf *tbf);
Pau Espin Pedrol6ad11a62021-07-27 12:27:08 +0200145
Pau Espin Pedrolbd1f01f2022-10-27 15:19:39 +0200146static inline struct gprs_rlcmac_tbf *ul_tbf_as_tbf(struct gprs_rlcmac_ul_tbf *ul_tbf)
147{
148 return (struct gprs_rlcmac_tbf *)ul_tbf;
149}
150
151static inline const struct gprs_rlcmac_tbf *ul_tbf_as_tbf_const(const struct gprs_rlcmac_ul_tbf *ul_tbf)
152{
153 return (const struct gprs_rlcmac_tbf *)ul_tbf;
154}
155
156#define LOGPTBFUL(ul_tbf, level, fmt, args...) LOGP(DTBFUL, level, "%s " fmt, tbf_name(ul_tbf_as_tbf_const(ul_tbf)), ## args)
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100157#ifdef __cplusplus
158}
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +0200159#endif