blob: cbaffa5cee830cd30e3226e0abadc0a2eb3fcfb6 [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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#pragma once
21
22#ifdef __cplusplus
23
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +020024#include <stdbool.h>
25
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020026#include "tbf.h"
27/*
28 * TBF instance
29 */
30
31enum tbf_gprs_ul_counters {
32 TBF_CTR_GPRS_UL_CS1,
33 TBF_CTR_GPRS_UL_CS2,
34 TBF_CTR_GPRS_UL_CS3,
35 TBF_CTR_GPRS_UL_CS4,
36};
37
38enum tbf_egprs_ul_counters {
39 TBF_CTR_EGPRS_UL_MCS1,
40 TBF_CTR_EGPRS_UL_MCS2,
41 TBF_CTR_EGPRS_UL_MCS3,
42 TBF_CTR_EGPRS_UL_MCS4,
43 TBF_CTR_EGPRS_UL_MCS5,
44 TBF_CTR_EGPRS_UL_MCS6,
45 TBF_CTR_EGPRS_UL_MCS7,
46 TBF_CTR_EGPRS_UL_MCS8,
47 TBF_CTR_EGPRS_UL_MCS9,
48};
49
50#define LOGPTBFUL(tbf, level, fmt, args...) LOGP(DTBFUL, level, "%s " fmt, tbf_name(tbf), ## args)
51
52struct gprs_rlcmac_ul_tbf : public gprs_rlcmac_tbf {
53 gprs_rlcmac_ul_tbf(BTS *bts);
Pau Espin Pedrolb3f23972020-10-23 21:00:23 +020054 gprs_rlc_window *window();
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020055 struct msgb *create_ul_ack(uint32_t fn, uint8_t ts);
56 bool ctrl_ack_to_toggle();
57 bool handle_ctrl_ack();
58 void enable_egprs();
59 /* blocks were acked */
60 int rcv_data_block_acknowledged(
61 const struct gprs_rlc_data_info *rlc,
62 uint8_t *data, struct pcu_l1_meas *meas);
63
64
65 /* TODO: extract LLC class? */
66 int assemble_forward_llc(const gprs_rlc_data *data);
67 int snd_ul_ud();
68
69 egprs_rlc_ul_reseg_bsn_state handle_egprs_ul_spb(
70 const struct gprs_rlc_data_info *rlc,
71 struct gprs_rlc_data *block,
72 uint8_t *data, const uint8_t block_idx);
73
74 egprs_rlc_ul_reseg_bsn_state handle_egprs_ul_first_seg(
75 const struct gprs_rlc_data_info *rlc,
76 struct gprs_rlc_data *block,
77 uint8_t *data, const uint8_t block_idx);
78
79 egprs_rlc_ul_reseg_bsn_state handle_egprs_ul_second_seg(
80 const struct gprs_rlc_data_info *rlc,
81 struct gprs_rlc_data *block,
82 uint8_t *data, const uint8_t block_idx);
83
84 uint16_t window_size() const;
85 void set_window_size();
86 void update_coding_scheme_counter_ul(enum CodingScheme cs);
87
88 /* Please note that all variables here will be reset when changing
89 * from WAIT RELEASE back to FLOW state (re-use of TBF).
90 * All states that need reset must be in this struct, so this is why
91 * variables are in both (dl and ul) structs and not outside union.
92 */
93 int32_t m_rx_counter; /* count all received blocks */
94 uint8_t m_usf[8]; /* list USFs per PDCH (timeslot) */
95 uint8_t m_contention_resolution_done; /* set after done */
96 uint8_t m_final_ack_sent; /* set if we sent final ack */
97
98 struct rate_ctr_group *m_ul_gprs_ctrs;
99 struct rate_ctr_group *m_ul_egprs_ctrs;
100
101protected:
Pau Espin Pedrolc33a0242020-05-15 16:57:48 +0200102 void maybe_schedule_uplink_acknack(const gprs_rlc_data_info *rlc, bool countdown_finished);
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +0200103
104 /* Please note that all variables below will be reset when changing
105 * from WAIT RELEASE back to FLOW state (re-use of TBF).
106 * All states that need reset must be in this struct, so this is why
107 * variables are in both (dl and ul) structs and not outside union.
108 */
109 gprs_rlc_ul_window m_window;
110};
111
112#ifdef __cplusplus
113extern "C" {
114#endif
115void update_tbf_ta(struct gprs_rlcmac_ul_tbf *tbf, int8_t ta_delta);
116void set_tbf_ta(struct gprs_rlcmac_ul_tbf *tbf, uint8_t ta);
117#ifdef __cplusplus
118}
119#endif
120
121inline uint16_t gprs_rlcmac_ul_tbf::window_size() const
122{
123 return m_window.ws();
124}
125
126inline void gprs_rlcmac_ul_tbf::enable_egprs()
127{
128 m_window.set_sns(RLC_EGPRS_SNS);
129 gprs_rlcmac_tbf::enable_egprs();
130}
131
132inline gprs_rlcmac_ul_tbf *as_ul_tbf(gprs_rlcmac_tbf *tbf)
133{
134 if (tbf && tbf->direction == GPRS_RLCMAC_UL_TBF)
135 return static_cast<gprs_rlcmac_ul_tbf *>(tbf);
136 else
137 return NULL;
138}
139
140#endif