blob: 9dbbe51db6b8824f4e8237bc2524fd4db2ba7031 [file] [log] [blame]
Holger Hans Peter Freyther17c31ce2013-08-24 18:31:27 +02001/*
2 * Copyright (C) 2013 by Holger Hans Peter Freyther
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#pragma once
20
Daniel Willmannafa72f52014-01-15 17:06:19 +010021#ifdef __cplusplus
22
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +020023#include "gprs_rlcmac.h"
Holger Hans Peter Freytherbe570812013-11-07 08:01:49 +010024#include "llc.h"
Holger Hans Peter Freyther6b5660c2013-11-23 16:10:48 +010025#include "rlc.h"
Daniel Willmanneb100242014-08-08 11:43:53 +020026#include <gprs_debug.h>
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +020027
Holger Hans Peter Freyther17c31ce2013-08-24 18:31:27 +020028#include <stdint.h>
29
Holger Hans Peter Freyther1702f102013-10-20 08:44:02 +020030struct bssgp_bvc_ctx;
Holger Hans Peter Freyther77e05972013-11-06 19:16:43 +010031struct rlc_ul_header;
Holger Hans Peter Freyther096f6f92013-11-07 07:21:06 +010032struct msgb;
Jacob Erlbeckfecece02015-05-08 12:13:08 +020033class GprsMs;
Holger Hans Peter Freyther1702f102013-10-20 08:44:02 +020034
Holger Hans Peter Freyther9e21d842013-10-16 17:48:12 +020035/*
36 * TBF instance
37 */
38
Holger Hans Peter Freyther9e21d842013-10-16 17:48:12 +020039#define Tassign_agch 0,200000 /* waiting after IMM.ASS confirm */
40#define Tassign_pacch 2,0 /* timeout for pacch assigment */
41
42enum gprs_rlcmac_tbf_state {
43 GPRS_RLCMAC_NULL = 0, /* new created TBF */
44 GPRS_RLCMAC_ASSIGN, /* wait for downlink assignment */
45 GPRS_RLCMAC_FLOW, /* RLC/MAC flow, resource needed */
46 GPRS_RLCMAC_FINISHED, /* flow finished, wait for release */
47 GPRS_RLCMAC_WAIT_RELEASE,/* wait for release or restart of DL TBF */
48 GPRS_RLCMAC_RELEASING, /* releasing, wait to free TBI/USF */
49};
50
51enum gprs_rlcmac_tbf_poll_state {
52 GPRS_RLCMAC_POLL_NONE = 0,
53 GPRS_RLCMAC_POLL_SCHED, /* a polling was scheduled */
54};
55
56enum gprs_rlcmac_tbf_dl_ass_state {
57 GPRS_RLCMAC_DL_ASS_NONE = 0,
58 GPRS_RLCMAC_DL_ASS_SEND_ASS, /* send downlink assignment on next RTS */
59 GPRS_RLCMAC_DL_ASS_WAIT_ACK, /* wait for PACKET CONTROL ACK */
60};
61
62enum gprs_rlcmac_tbf_ul_ass_state {
63 GPRS_RLCMAC_UL_ASS_NONE = 0,
64 GPRS_RLCMAC_UL_ASS_SEND_ASS, /* send uplink assignment on next RTS */
65 GPRS_RLCMAC_UL_ASS_WAIT_ACK, /* wait for PACKET CONTROL ACK */
66};
67
68enum gprs_rlcmac_tbf_ul_ack_state {
69 GPRS_RLCMAC_UL_ACK_NONE = 0,
70 GPRS_RLCMAC_UL_ACK_SEND_ACK, /* send acknowledge on next RTS */
71 GPRS_RLCMAC_UL_ACK_WAIT_ACK, /* wait for PACKET CONTROL ACK */
72};
73
74enum gprs_rlcmac_tbf_direction {
75 GPRS_RLCMAC_DL_TBF,
76 GPRS_RLCMAC_UL_TBF
77};
78
79#define GPRS_RLCMAC_FLAG_CCCH 0 /* assignment on CCCH */
80#define GPRS_RLCMAC_FLAG_PACCH 1 /* assignment on PACCH */
81#define GPRS_RLCMAC_FLAG_UL_DATA 2 /* uplink data received */
82#define GPRS_RLCMAC_FLAG_DL_ACK 3 /* downlink acknowledge received */
83#define GPRS_RLCMAC_FLAG_TO_UL_ACK 4
84#define GPRS_RLCMAC_FLAG_TO_DL_ACK 5
85#define GPRS_RLCMAC_FLAG_TO_UL_ASS 6
86#define GPRS_RLCMAC_FLAG_TO_DL_ASS 7
87#define GPRS_RLCMAC_FLAG_TO_MASK 0xf0 /* timeout bits */
88
Daniel Willmann1b3864f2014-07-30 13:25:19 +020089struct llist_pods {
90 struct llist_head list;
91 void *back;
92};
93
94#define llist_pods_entry(ptr, type) \
95 ((type *)(container_of(ptr, struct llist_pods, list)->back))
96
97/**
98 * llist_pods_for_each_entry - like llist_for_each_entry, but uses
99 * struct llist_pods ->back to access the entry.
100 * This is necessary for non-PODS classes because container_of is
101 * not guaranteed to work anymore. */
102#define llist_pods_for_each_entry(pos, head, member, lpods) \
103 for (lpods = llist_entry((head)->next, typeof(struct llist_pods), list), \
104 pos = ((typeof(pos))lpods->back), \
105 prefetch(pos->member.list.next); \
106 &lpods->list != (head); \
107 lpods = llist_entry(lpods->list.next, typeof(struct llist_pods), list), \
108 pos = ((typeof(pos))lpods->back),\
109 prefetch(pos->member.list.next))
110
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200111struct gprs_rlcmac_tbf {
Holger Hans Peter Freyther964ddb62013-10-16 17:53:23 +0200112
113 static void free_all(struct gprs_rlcmac_trx *trx);
Holger Hans Peter Freyther4f6a4e5d2013-10-16 17:58:46 +0200114 static void free_all(struct gprs_rlcmac_pdch *pdch);
Holger Hans Peter Freyther964ddb62013-10-16 17:53:23 +0200115
Holger Hans Peter Freyther1c344e22013-10-16 18:33:18 +0200116 bool state_is(enum gprs_rlcmac_tbf_state rhs) const;
117 bool state_is_not(enum gprs_rlcmac_tbf_state rhs) const;
118 void set_state(enum gprs_rlcmac_tbf_state new_state);
Daniel Willmann08e57c82014-08-15 18:11:57 +0200119 const char *state_name() const;
Holger Hans Peter Freyther1c344e22013-10-16 18:33:18 +0200120
Jacob Erlbeckadcdf152015-03-03 14:45:55 +0100121 const char *name() const;
122
Holger Hans Peter Freyther2db7e7e2013-10-26 20:45:35 +0200123 struct msgb *create_dl_ass(uint32_t fn);
Holger Hans Peter Freytherae03f222013-10-26 21:20:51 +0200124 struct msgb *create_ul_ass(uint32_t fn);
Holger Hans Peter Freyther2db7e7e2013-10-26 20:45:35 +0200125
Jacob Erlbeckfecece02015-05-08 12:13:08 +0200126 GprsMs *ms();
127 void set_ms(GprsMs *ms);
128
Holger Hans Peter Freyther8f399de2013-12-25 20:22:35 +0100129 uint8_t tsc() const;
Holger Hans Peter Freythera1da2512013-11-07 07:32:51 +0100130
Holger Hans Peter Freyther7380bab2013-10-16 18:09:19 +0200131 int rlcmac_diag();
Holger Hans Peter Freyther964ddb62013-10-16 17:53:23 +0200132
Holger Hans Peter Freytheraa9c3262013-10-26 17:49:36 +0200133 int update();
Holger Hans Peter Freytheraf8094d2013-10-26 17:56:15 +0200134 void handle_timeout();
Holger Hans Peter Freyther86300bb2013-10-26 18:01:35 +0200135 void stop_timer();
136 void stop_t3191();
Holger Hans Peter Freytheraa9c3262013-10-26 17:49:36 +0200137
Holger Hans Peter Freytherd9262b32013-10-26 20:12:59 +0200138 void poll_timeout();
139
Holger Hans Peter Freyther474685e2013-10-27 17:01:14 +0100140 /** tlli handling */
141 void update_tlli(uint32_t tlli);
142 uint32_t tlli() const;
143 bool is_tlli_valid() const;
Holger Hans Peter Freyther474685e2013-10-27 17:01:14 +0100144
Jacob Erlbeckfecece02015-05-08 12:13:08 +0200145 /** MS updating */
Jacob Erlbeckbe0cbc12015-05-18 14:35:11 +0200146 void update_ms(uint32_t tlli, enum gprs_rlcmac_tbf_direction);
Jacob Erlbeckfecece02015-05-08 12:13:08 +0200147
Holger Hans Peter Freyther34f6e5e2013-10-27 20:31:47 +0100148 uint8_t tfi() const;
149
Holger Hans Peter Freyther5464c9b2013-10-27 20:57:35 +0100150 const char *imsi() const;
151 void assign_imsi(const char *imsi);
152
Daniel Willmanne4818152014-08-15 16:52:09 +0200153 void set_new_tbf(gprs_rlcmac_tbf *tbf);
154 gprs_rlcmac_tbf *new_tbf() const;
155
Holger Hans Peter Freythera0047992014-01-16 10:07:20 +0100156 time_t created_ts() const;
Daniel Willmann80367aa2014-01-15 17:40:28 +0100157
Holger Hans Peter Freyther7a5f3c22013-11-26 13:08:12 +0100158 /* attempt to make things a bit more fair */
159 void rotate_in_list();
160
Daniel Willmann1b3864f2014-07-30 13:25:19 +0200161 struct llist_pods list;
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200162 uint32_t state_flags;
163 enum gprs_rlcmac_tbf_direction direction;
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200164 struct gprs_rlcmac_trx *trx;
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200165 uint8_t first_ts; /* first TS used by TBF */
166 uint8_t first_common_ts; /* first TS that the phone can send and
167 reveive simultaniously */
168 uint8_t control_ts; /* timeslot control messages and polling */
169 uint8_t ms_class;
170 struct gprs_rlcmac_pdch *pdch[8]; /* list of PDCHs allocated to TBF */
171 uint16_t ta;
Holger Hans Peter Freyther28e53782013-11-06 20:23:56 +0100172
173 gprs_llc m_llc;
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200174
175 enum gprs_rlcmac_tbf_dl_ass_state dl_ass_state;
176 enum gprs_rlcmac_tbf_ul_ass_state ul_ass_state;
177 enum gprs_rlcmac_tbf_ul_ack_state ul_ack_state;
178
Daniel Willmanne4818152014-08-15 16:52:09 +0200179 gprs_rlcmac_tbf *m_new_tbf;
Jacob Erlbeck08fe76a2015-02-23 15:10:20 +0100180 gprs_rlcmac_tbf *m_old_tbf; /* reverse pointer for m_new_tbf */
Daniel Willmanne4818152014-08-15 16:52:09 +0200181
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200182 enum gprs_rlcmac_tbf_poll_state poll_state;
183 uint32_t poll_fn; /* frame number to poll */
184
Holger Hans Peter Freyther9241fd02013-11-13 19:51:55 +0100185 gprs_rlc m_rlc;
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200186
187 uint8_t n3105; /* N3105 counter */
188
189 struct osmo_timer_list timer;
190 unsigned int T; /* Txxxx number */
191 unsigned int num_T_exp; /* number of consecutive T expirations */
192
193 struct osmo_gsm_timer_list gsm_timer;
194 unsigned int fT; /* fTxxxx number */
195 unsigned int num_fT_exp; /* number of consecutive fT expirations */
196
197 struct {
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200198 struct timeval rssi_tv; /* timestamp for rssi calculation */
199 int32_t rssi_sum; /* sum of rssi values */
200 int rssi_num; /* number of rssi values added since rssi_tv */
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200201 } meas;
202
203 uint8_t cs; /* current coding scheme */
204
Holger Hans Peter Freyther1c344e22013-10-16 18:33:18 +0200205 /* these should become protected but only after gprs_rlcmac_data.c
206 * stops to iterate over all tbf in its current form */
207 enum gprs_rlcmac_tbf_state state;
Holger Hans Peter Freyther9f0c1d22013-10-19 21:24:34 +0200208
Daniel Willmann73191a42014-05-30 17:58:00 +0200209 /* Remember if the tbf was in wait_release state when we want to
210 * schedule a new dl assignment */
211 uint8_t was_releasing;
212
Daniel Willmanncf1fae72014-05-30 17:58:01 +0200213 /* Can/should we upgrade this tbf to use multiple slots? */
214 uint8_t upgrade_to_multislot;
215
Holger Hans Peter Freyther9f0c1d22013-10-19 21:24:34 +0200216 /* store the BTS this TBF belongs to */
217 BTS *bts;
Holger Hans Peter Freytherd9262b32013-10-26 20:12:59 +0200218
Holger Hans Peter Freyther474685e2013-10-27 17:01:14 +0100219 /*
220 * private fields. We can't make it private as it is breaking the
221 * llist macros.
222 */
Holger Hans Peter Freyther34f6e5e2013-10-27 20:31:47 +0100223 uint8_t m_tfi;
Holger Hans Peter Freythera0047992014-01-16 10:07:20 +0100224 time_t m_created_ts;
Holger Hans Peter Freyther474685e2013-10-27 17:01:14 +0100225
Holger Hans Peter Freyther5464c9b2013-10-27 20:57:35 +0100226 /* store IMSI for look-up and PCH retransmission */
227 char m_imsi[16];
228
Holger Hans Peter Freytherd9262b32013-10-26 20:12:59 +0200229protected:
230 gprs_rlcmac_bts *bts_data() const;
Holger Hans Peter Freyther474685e2013-10-27 17:01:14 +0100231
Holger Hans Peter Freyther4c06d912013-11-25 23:05:26 +0100232 int extract_tlli(const uint8_t *data, const size_t len);
233
Daniel Willmanneb100242014-08-08 11:43:53 +0200234 static const char *tbf_state_name[6];
Jacob Erlbeckadcdf152015-03-03 14:45:55 +0100235
Jacob Erlbeckfecece02015-05-08 12:13:08 +0200236 class GprsMs *m_ms;
Jacob Erlbeckadcdf152015-03-03 14:45:55 +0100237private:
238 mutable char m_name_buf[60];
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200239};
240
Holger Hans Peter Freyther17c31ce2013-08-24 18:31:27 +0200241
Daniel Willmann0d12a2f2014-07-10 17:44:07 +0200242struct gprs_rlcmac_ul_tbf *tbf_alloc_ul(struct gprs_rlcmac_bts *bts,
Holger Hans Peter Freyther86921282013-08-24 21:26:42 +0200243 int8_t use_trx, uint8_t ms_class,
244 uint32_t tlli, uint8_t ta, struct gprs_rlcmac_tbf *dl_tbf);
Holger Hans Peter Freyther9e21d842013-10-16 17:48:12 +0200245
Daniel Willmann48aa0b02014-07-16 18:54:10 +0200246struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_tbf(struct gprs_rlcmac_bts *bts,
Holger Hans Peter Freyther9e21d842013-10-16 17:48:12 +0200247 struct gprs_rlcmac_tbf *old_tbf,
Daniel Willmann48aa0b02014-07-16 18:54:10 +0200248 uint8_t tfi, uint8_t trx,
249 uint8_t ms_class, uint8_t single_slot);
250
251struct gprs_rlcmac_dl_tbf *tbf_alloc_dl_tbf(struct gprs_rlcmac_bts *bts,
252 struct gprs_rlcmac_tbf *old_tbf,
253 uint8_t tfi, uint8_t trx,
Holger Hans Peter Freyther9e21d842013-10-16 17:48:12 +0200254 uint8_t ms_class, uint8_t single_slot);
255
Holger Hans Peter Freyther9e21d842013-10-16 17:48:12 +0200256void tbf_free(struct gprs_rlcmac_tbf *tbf);
257
Holger Hans Peter Freyther9e21d842013-10-16 17:48:12 +0200258int tbf_assign_control_ts(struct gprs_rlcmac_tbf *tbf);
259
Holger Hans Peter Freyther9e21d842013-10-16 17:48:12 +0200260void tbf_timer_start(struct gprs_rlcmac_tbf *tbf, unsigned int T,
261 unsigned int seconds, unsigned int microseconds);
262
Holger Hans Peter Freyther1c344e22013-10-16 18:33:18 +0200263inline bool gprs_rlcmac_tbf::state_is(enum gprs_rlcmac_tbf_state rhs) const
264{
265 return state == rhs;
266}
267
268inline bool gprs_rlcmac_tbf::state_is_not(enum gprs_rlcmac_tbf_state rhs) const
269{
270 return state != rhs;
271}
272
Daniel Willmanneb100242014-08-08 11:43:53 +0200273const char *tbf_name(gprs_rlcmac_tbf *tbf);
274
Daniel Willmann08e57c82014-08-15 18:11:57 +0200275inline const char *gprs_rlcmac_tbf::state_name() const
276{
277 return tbf_state_name[state];
278}
279
Holger Hans Peter Freyther1c344e22013-10-16 18:33:18 +0200280inline void gprs_rlcmac_tbf::set_state(enum gprs_rlcmac_tbf_state new_state)
281{
Daniel Willmanneb100242014-08-08 11:43:53 +0200282 LOGP(DRLCMAC, LOGL_DEBUG, "%s changes state from %s to %s\n",
283 tbf_name(this),
284 tbf_state_name[state], tbf_state_name[new_state]);
Holger Hans Peter Freyther1c344e22013-10-16 18:33:18 +0200285 state = new_state;
286}
Holger Hans Peter Freytherbd449f52013-10-27 16:39:36 +0100287
Jacob Erlbeckfecece02015-05-08 12:13:08 +0200288inline GprsMs *gprs_rlcmac_tbf::ms()
289{
290 return m_ms;
291}
292
Holger Hans Peter Freyther474685e2013-10-27 17:01:14 +0100293inline bool gprs_rlcmac_tbf::is_tlli_valid() const
294{
Jacob Erlbeck767193e2015-05-20 12:06:46 +0200295 return tlli() != 0;
Holger Hans Peter Freyther474685e2013-10-27 17:01:14 +0100296}
297
Holger Hans Peter Freyther34f6e5e2013-10-27 20:31:47 +0100298inline uint8_t gprs_rlcmac_tbf::tfi() const
299{
300 return m_tfi;
301}
302
Holger Hans Peter Freyther5464c9b2013-10-27 20:57:35 +0100303inline const char *gprs_rlcmac_tbf::imsi() const
304{
305 return m_imsi;
306}
307
Daniel Willmanne4818152014-08-15 16:52:09 +0200308inline gprs_rlcmac_tbf *gprs_rlcmac_tbf::new_tbf() const
309{
310 return m_new_tbf;
311}
312
Holger Hans Peter Freythera0047992014-01-16 10:07:20 +0100313inline time_t gprs_rlcmac_tbf::created_ts() const
Daniel Willmann80367aa2014-01-15 17:40:28 +0100314{
Holger Hans Peter Freythera0047992014-01-16 10:07:20 +0100315 return m_created_ts;
Daniel Willmann80367aa2014-01-15 17:40:28 +0100316}
317
Daniel Willmann078bb712014-07-10 17:44:06 +0200318struct gprs_rlcmac_dl_tbf : public gprs_rlcmac_tbf {
Jacob Erlbeckd0261b72015-04-02 13:58:09 +0200319 void cleanup();
320
Daniel Willmann30168882014-08-07 12:48:29 +0200321 /* dispatch Unitdata.DL messages */
322 static int handle(struct gprs_rlcmac_bts *bts,
Jacob Erlbeck93990462015-05-15 15:50:43 +0200323 const uint32_t tlli, const uint32_t old_tlli,
324 const char *imsi, const uint8_t ms_class,
Daniel Willmann30168882014-08-07 12:48:29 +0200325 const uint16_t delay_csec, const uint8_t *data, const uint16_t len);
326
Daniel Willmann538ac5b2014-07-30 19:12:27 +0200327 int append_data(const uint8_t ms_class,
328 const uint16_t pdu_delay_csec,
329 const uint8_t *data, const uint16_t len);
330
Daniel Willmann6c813fc2014-07-30 19:12:27 +0200331 int rcvd_dl_ack(uint8_t final, uint8_t ssn, uint8_t *rbb);
Daniel Willmannb8f26012014-07-30 19:12:28 +0200332 struct msgb *create_dl_acked_block(uint32_t fn, uint8_t ts);
Jacob Erlbeck7c444152015-03-12 12:08:54 +0100333 void request_dl_ack();
Jacob Erlbeckeceb9102015-03-20 14:41:50 +0100334 bool need_control_ts() const;
335 bool have_data() const;
Jacob Erlbeck005ee7f2015-03-20 14:53:54 +0100336 int frames_since_last_poll(unsigned fn) const;
Jacob Erlbeck3bed5d12015-03-19 11:22:38 +0100337 int frames_since_last_drain(unsigned fn) const;
338 bool keep_open(unsigned fn) const;
Jacob Erlbeckeceb9102015-03-20 14:41:50 +0100339
340 bool is_control_ts(uint8_t ts) const {
341 return ts == control_ts;
342 }
Daniel Willmannb8f26012014-07-30 19:12:28 +0200343
Daniel Willmanncf706b02014-08-07 17:35:22 +0200344 /* TODO: add the gettimeofday as parameter */
345 struct msgb *llc_dequeue(bssgp_bvc_ctx *bctx);
346
Daniel Willmann6a8a1dc2014-08-07 15:14:08 +0200347 /* Please note that all variables here will be reset when changing
348 * from WAIT RELEASE back to FLOW state (re-use of TBF).
349 * All states that need reset must be in this struct, so this is why
350 * variables are in both (dl and ul) structs and not outside union.
351 */
Daniel Willmann7e994e32014-08-07 15:49:21 +0200352 gprs_rlc_dl_window m_window;
353 int32_t m_tx_counter; /* count all transmitted blocks */
354 uint8_t m_wait_confirm; /* wait for CCCH IMM.ASS cnf */
Jacob Erlbeck7c444152015-03-12 12:08:54 +0100355 bool m_dl_ack_requested;
Jacob Erlbeck005ee7f2015-03-20 14:53:54 +0100356 int32_t m_last_dl_poll_fn;
Jacob Erlbeck3bed5d12015-03-19 11:22:38 +0100357 int32_t m_last_dl_drained_fn;
Daniel Willmann6a8a1dc2014-08-07 15:14:08 +0200358
Daniel Willmann418a4232014-08-08 11:21:04 +0200359 struct {
360 struct timeval dl_bw_tv; /* timestamp for dl bw calculation */
361 uint32_t dl_bw_octets; /* number of octets since bw_tv */
362
363 struct timeval dl_loss_tv; /* timestamp for loss calculation */
364 uint16_t dl_loss_lost; /* sum of lost packets */
365 uint16_t dl_loss_received; /* sum of received packets */
366 } m_bw;
367
Daniel Willmannb8f26012014-07-30 19:12:28 +0200368protected:
369 struct msgb *create_new_bsn(const uint32_t fn, const uint8_t ts);
370 struct msgb *create_dl_acked_block(const uint32_t fn, const uint8_t ts,
Jacob Erlbeck7c444152015-03-12 12:08:54 +0100371 const int index);
Daniel Willmann30168882014-08-07 12:48:29 +0200372 int update_window(const uint8_t ssn, const uint8_t *rbb);
373 int maybe_start_new_window();
374 bool dl_window_stalled() const;
375 void reuse_tbf(const uint8_t *data, const uint16_t len);
Jacob Erlbeckd0261b72015-04-02 13:58:09 +0200376 void start_llc_timer();
377
378 struct osmo_timer_list m_llc_timer;
Daniel Willmann078bb712014-07-10 17:44:06 +0200379};
380
381struct gprs_rlcmac_ul_tbf : public gprs_rlcmac_tbf {
Daniel Willmann350f64d2014-08-07 14:54:11 +0200382 struct msgb *create_ul_ack(uint32_t fn);
383
384 /* blocks were acked */
385 int rcv_data_block_acknowledged(const uint8_t *data, size_t len, int8_t rssi);
386
Daniel Willmanne2732e22014-08-07 17:32:01 +0200387 /* TODO: extract LLC class? */
388 int assemble_forward_llc(const gprs_rlc_data *data);
389 int snd_ul_ud();
390
Daniel Willmann6a8a1dc2014-08-07 15:14:08 +0200391 /* Please note that all variables here will be reset when changing
392 * from WAIT RELEASE back to FLOW state (re-use of TBF).
393 * All states that need reset must be in this struct, so this is why
394 * variables are in both (dl and ul) structs and not outside union.
395 */
Daniel Willmann7e994e32014-08-07 15:49:21 +0200396 gprs_rlc_ul_window m_window;
397 int32_t m_rx_counter; /* count all received blocks */
398 uint8_t m_n3103; /* N3103 counter */
399 uint8_t m_usf[8]; /* list USFs per PDCH (timeslot) */
400 uint8_t m_contention_resolution_done; /* set after done */
401 uint8_t m_final_ack_sent; /* set if we sent final ack */
Daniel Willmann6a8a1dc2014-08-07 15:14:08 +0200402
Daniel Willmann350f64d2014-08-07 14:54:11 +0200403protected:
404 void maybe_schedule_uplink_acknack(const rlc_ul_header *rh);
Daniel Willmann078bb712014-07-10 17:44:06 +0200405};
406
Daniel Willmannafa72f52014-01-15 17:06:19 +0100407#endif
Holger Hans Peter Freyther321f3c32013-11-23 16:06:54 +0100408
Daniel Willmannafa72f52014-01-15 17:06:19 +0100409#ifdef __cplusplus
410extern "C" {
411#endif
412#include <osmocom/vty/command.h>
413#include <osmocom/vty/vty.h>
414
Jacob Erlbeckc0c580c2015-04-30 15:59:01 +0200415 void tbf_print_vty_info(struct vty *vty, struct llist_head *tbf);
Daniel Willmannafa72f52014-01-15 17:06:19 +0100416#ifdef __cplusplus
417}
418#endif