blob: 5c198d3e730e284dc091999a15a222021ba280d5 [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 Erlbeck20f6fd12015-06-08 11:05:45 +020033struct pcu_l1_meas;
Jacob Erlbeckfecece02015-05-08 12:13:08 +020034class GprsMs;
Holger Hans Peter Freyther1702f102013-10-20 08:44:02 +020035
Holger Hans Peter Freyther9e21d842013-10-16 17:48:12 +020036/*
37 * TBF instance
38 */
39
Holger Hans Peter Freyther9e21d842013-10-16 17:48:12 +020040#define Tassign_agch 0,200000 /* waiting after IMM.ASS confirm */
41#define Tassign_pacch 2,0 /* timeout for pacch assigment */
42
43enum gprs_rlcmac_tbf_state {
44 GPRS_RLCMAC_NULL = 0, /* new created TBF */
45 GPRS_RLCMAC_ASSIGN, /* wait for downlink assignment */
46 GPRS_RLCMAC_FLOW, /* RLC/MAC flow, resource needed */
47 GPRS_RLCMAC_FINISHED, /* flow finished, wait for release */
48 GPRS_RLCMAC_WAIT_RELEASE,/* wait for release or restart of DL TBF */
49 GPRS_RLCMAC_RELEASING, /* releasing, wait to free TBI/USF */
50};
51
52enum gprs_rlcmac_tbf_poll_state {
53 GPRS_RLCMAC_POLL_NONE = 0,
54 GPRS_RLCMAC_POLL_SCHED, /* a polling was scheduled */
55};
56
57enum gprs_rlcmac_tbf_dl_ass_state {
58 GPRS_RLCMAC_DL_ASS_NONE = 0,
59 GPRS_RLCMAC_DL_ASS_SEND_ASS, /* send downlink assignment on next RTS */
60 GPRS_RLCMAC_DL_ASS_WAIT_ACK, /* wait for PACKET CONTROL ACK */
61};
62
63enum gprs_rlcmac_tbf_ul_ass_state {
64 GPRS_RLCMAC_UL_ASS_NONE = 0,
65 GPRS_RLCMAC_UL_ASS_SEND_ASS, /* send uplink assignment on next RTS */
66 GPRS_RLCMAC_UL_ASS_WAIT_ACK, /* wait for PACKET CONTROL ACK */
67};
68
69enum gprs_rlcmac_tbf_ul_ack_state {
70 GPRS_RLCMAC_UL_ACK_NONE = 0,
71 GPRS_RLCMAC_UL_ACK_SEND_ACK, /* send acknowledge on next RTS */
72 GPRS_RLCMAC_UL_ACK_WAIT_ACK, /* wait for PACKET CONTROL ACK */
73};
74
75enum gprs_rlcmac_tbf_direction {
76 GPRS_RLCMAC_DL_TBF,
77 GPRS_RLCMAC_UL_TBF
78};
79
80#define GPRS_RLCMAC_FLAG_CCCH 0 /* assignment on CCCH */
81#define GPRS_RLCMAC_FLAG_PACCH 1 /* assignment on PACCH */
82#define GPRS_RLCMAC_FLAG_UL_DATA 2 /* uplink data received */
83#define GPRS_RLCMAC_FLAG_DL_ACK 3 /* downlink acknowledge received */
84#define GPRS_RLCMAC_FLAG_TO_UL_ACK 4
85#define GPRS_RLCMAC_FLAG_TO_DL_ACK 5
86#define GPRS_RLCMAC_FLAG_TO_UL_ASS 6
87#define GPRS_RLCMAC_FLAG_TO_DL_ASS 7
88#define GPRS_RLCMAC_FLAG_TO_MASK 0xf0 /* timeout bits */
89
Daniel Willmann1b3864f2014-07-30 13:25:19 +020090struct llist_pods {
91 struct llist_head list;
92 void *back;
93};
94
95#define llist_pods_entry(ptr, type) \
96 ((type *)(container_of(ptr, struct llist_pods, list)->back))
97
98/**
99 * llist_pods_for_each_entry - like llist_for_each_entry, but uses
100 * struct llist_pods ->back to access the entry.
101 * This is necessary for non-PODS classes because container_of is
102 * not guaranteed to work anymore. */
103#define llist_pods_for_each_entry(pos, head, member, lpods) \
104 for (lpods = llist_entry((head)->next, typeof(struct llist_pods), list), \
105 pos = ((typeof(pos))lpods->back), \
106 prefetch(pos->member.list.next); \
107 &lpods->list != (head); \
108 lpods = llist_entry(lpods->list.next, typeof(struct llist_pods), list), \
109 pos = ((typeof(pos))lpods->back),\
110 prefetch(pos->member.list.next))
111
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200112struct gprs_rlcmac_tbf {
Holger Hans Peter Freyther964ddb62013-10-16 17:53:23 +0200113
114 static void free_all(struct gprs_rlcmac_trx *trx);
Holger Hans Peter Freyther4f6a4e5d2013-10-16 17:58:46 +0200115 static void free_all(struct gprs_rlcmac_pdch *pdch);
Holger Hans Peter Freyther964ddb62013-10-16 17:53:23 +0200116
Holger Hans Peter Freyther1c344e22013-10-16 18:33:18 +0200117 bool state_is(enum gprs_rlcmac_tbf_state rhs) const;
118 bool state_is_not(enum gprs_rlcmac_tbf_state rhs) const;
119 void set_state(enum gprs_rlcmac_tbf_state new_state);
Daniel Willmann08e57c82014-08-15 18:11:57 +0200120 const char *state_name() const;
Holger Hans Peter Freyther1c344e22013-10-16 18:33:18 +0200121
Jacob Erlbeckadcdf152015-03-03 14:45:55 +0100122 const char *name() const;
123
Holger Hans Peter Freyther2db7e7e2013-10-26 20:45:35 +0200124 struct msgb *create_dl_ass(uint32_t fn);
Holger Hans Peter Freytherae03f222013-10-26 21:20:51 +0200125 struct msgb *create_ul_ass(uint32_t fn);
Holger Hans Peter Freyther2db7e7e2013-10-26 20:45:35 +0200126
Jacob Erlbeck10ed7952015-06-02 11:37:22 +0200127 GprsMs *ms() const;
Jacob Erlbeckfecece02015-05-08 12:13:08 +0200128 void set_ms(GprsMs *ms);
129
Holger Hans Peter Freyther8f399de2013-12-25 20:22:35 +0100130 uint8_t tsc() const;
Holger Hans Peter Freythera1da2512013-11-07 07:32:51 +0100131
Holger Hans Peter Freyther7380bab2013-10-16 18:09:19 +0200132 int rlcmac_diag();
Holger Hans Peter Freyther964ddb62013-10-16 17:53:23 +0200133
Jacob Erlbecke0c734d2015-07-03 14:03:33 +0200134 int update();
Holger Hans Peter Freytheraf8094d2013-10-26 17:56:15 +0200135 void handle_timeout();
Holger Hans Peter Freyther86300bb2013-10-26 18:01:35 +0200136 void stop_timer();
137 void stop_t3191();
Holger Hans Peter Freytheraa9c3262013-10-26 17:49:36 +0200138
Holger Hans Peter Freytherd9262b32013-10-26 20:12:59 +0200139 void poll_timeout();
140
Holger Hans Peter Freyther474685e2013-10-27 17:01:14 +0100141 /** tlli handling */
Holger Hans Peter Freyther474685e2013-10-27 17:01:14 +0100142 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);
Jacob Erlbeck9200ce62015-05-22 17:48:04 +0200152 uint8_t ta() const;
153 void set_ta(uint8_t);
Jacob Erlbeckbefc7602015-06-02 12:33:30 +0200154 uint8_t ms_class() const;
155 void set_ms_class(uint8_t);
Jacob Erlbecka700dd92015-06-02 16:00:41 +0200156 uint8_t current_cs() const;
Jacob Erlbeck6dbe8222015-05-29 10:37:09 +0200157 gprs_llc_queue *llc_queue();
158 const gprs_llc_queue *llc_queue() const;
Holger Hans Peter Freyther5464c9b2013-10-27 20:57:35 +0100159
Holger Hans Peter Freythera0047992014-01-16 10:07:20 +0100160 time_t created_ts() const;
Jacob Erlbeck617c7122015-06-30 09:18:30 +0200161 uint8_t dl_slots() const;
162 uint8_t ul_slots() const;
Daniel Willmann80367aa2014-01-15 17:40:28 +0100163
Holger Hans Peter Freyther7a5f3c22013-11-26 13:08:12 +0100164 /* attempt to make things a bit more fair */
165 void rotate_in_list();
166
Daniel Willmann1b3864f2014-07-30 13:25:19 +0200167 struct llist_pods list;
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200168 uint32_t state_flags;
169 enum gprs_rlcmac_tbf_direction direction;
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200170 struct gprs_rlcmac_trx *trx;
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200171 uint8_t first_ts; /* first TS used by TBF */
172 uint8_t first_common_ts; /* first TS that the phone can send and
173 reveive simultaniously */
174 uint8_t control_ts; /* timeslot control messages and polling */
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200175 struct gprs_rlcmac_pdch *pdch[8]; /* list of PDCHs allocated to TBF */
Holger Hans Peter Freyther28e53782013-11-06 20:23:56 +0100176
177 gprs_llc m_llc;
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200178
179 enum gprs_rlcmac_tbf_dl_ass_state dl_ass_state;
180 enum gprs_rlcmac_tbf_ul_ass_state ul_ass_state;
181 enum gprs_rlcmac_tbf_ul_ack_state ul_ack_state;
182
183 enum gprs_rlcmac_tbf_poll_state poll_state;
184 uint32_t poll_fn; /* frame number to poll */
185
Holger Hans Peter Freyther9241fd02013-11-13 19:51:55 +0100186 gprs_rlc m_rlc;
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200187
188 uint8_t n3105; /* N3105 counter */
189
190 struct osmo_timer_list timer;
191 unsigned int T; /* Txxxx number */
192 unsigned int num_T_exp; /* number of consecutive T expirations */
193
194 struct osmo_gsm_timer_list gsm_timer;
195 unsigned int fT; /* fTxxxx number */
196 unsigned int num_fT_exp; /* number of consecutive fT expirations */
197
198 struct {
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200199 struct timeval rssi_tv; /* timestamp for rssi calculation */
200 int32_t rssi_sum; /* sum of rssi values */
201 int rssi_num; /* number of rssi values added since rssi_tv */
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200202 } meas;
203
Holger Hans Peter Freyther1c344e22013-10-16 18:33:18 +0200204 /* these should become protected but only after gprs_rlcmac_data.c
205 * stops to iterate over all tbf in its current form */
206 enum gprs_rlcmac_tbf_state state;
Holger Hans Peter Freyther9f0c1d22013-10-19 21:24:34 +0200207
Daniel Willmann73191a42014-05-30 17:58:00 +0200208 /* Remember if the tbf was in wait_release state when we want to
209 * schedule a new dl assignment */
210 uint8_t was_releasing;
211
Daniel Willmanncf1fae72014-05-30 17:58:01 +0200212 /* Can/should we upgrade this tbf to use multiple slots? */
213 uint8_t upgrade_to_multislot;
214
Holger Hans Peter Freyther9f0c1d22013-10-19 21:24:34 +0200215 /* store the BTS this TBF belongs to */
216 BTS *bts;
Holger Hans Peter Freytherd9262b32013-10-26 20:12:59 +0200217
Holger Hans Peter Freyther474685e2013-10-27 17:01:14 +0100218 /*
219 * private fields. We can't make it private as it is breaking the
220 * llist macros.
221 */
Holger Hans Peter Freyther34f6e5e2013-10-27 20:31:47 +0100222 uint8_t m_tfi;
Holger Hans Peter Freythera0047992014-01-16 10:07:20 +0100223 time_t m_created_ts;
Holger Hans Peter Freyther474685e2013-10-27 17:01:14 +0100224
Holger Hans Peter Freytherd9262b32013-10-26 20:12:59 +0200225protected:
226 gprs_rlcmac_bts *bts_data() const;
Holger Hans Peter Freyther474685e2013-10-27 17:01:14 +0100227
Holger Hans Peter Freyther4c06d912013-11-25 23:05:26 +0100228 int extract_tlli(const uint8_t *data, const size_t len);
229
Daniel Willmanneb100242014-08-08 11:43:53 +0200230 static const char *tbf_state_name[6];
Jacob Erlbeckadcdf152015-03-03 14:45:55 +0100231
Jacob Erlbeckfecece02015-05-08 12:13:08 +0200232 class GprsMs *m_ms;
Jacob Erlbeck9200ce62015-05-22 17:48:04 +0200233
Jacob Erlbeckbefc7602015-06-02 12:33:30 +0200234 /* Fields to take the TA/MS class values if no MS is associated */
Jacob Erlbeck9200ce62015-05-22 17:48:04 +0200235 uint8_t m_ta;
Jacob Erlbeckbefc7602015-06-02 12:33:30 +0200236 uint8_t m_ms_class;
Jacob Erlbeck6dbe8222015-05-29 10:37:09 +0200237
Jacob Erlbeckadcdf152015-03-03 14:45:55 +0100238private:
239 mutable char m_name_buf[60];
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +0200240};
241
Holger Hans Peter Freyther17c31ce2013-08-24 18:31:27 +0200242
Daniel Willmann0d12a2f2014-07-10 17:44:07 +0200243struct gprs_rlcmac_ul_tbf *tbf_alloc_ul(struct gprs_rlcmac_bts *bts,
Holger Hans Peter Freyther86921282013-08-24 21:26:42 +0200244 int8_t use_trx, uint8_t ms_class,
Jacob Erlbecke2e004e2015-06-18 17:16:26 +0200245 uint32_t tlli, uint8_t ta, GprsMs *ms);
Holger Hans Peter Freyther9e21d842013-10-16 17:48:12 +0200246
Daniel Willmann48aa0b02014-07-16 18:54:10 +0200247struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_tbf(struct gprs_rlcmac_bts *bts,
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200248 GprsMs *ms, int8_t use_trx,
Daniel Willmann48aa0b02014-07-16 18:54:10 +0200249 uint8_t ms_class, uint8_t single_slot);
250
251struct gprs_rlcmac_dl_tbf *tbf_alloc_dl_tbf(struct gprs_rlcmac_bts *bts,
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200252 GprsMs *ms, int8_t use_trx,
Holger Hans Peter Freyther9e21d842013-10-16 17:48:12 +0200253 uint8_t ms_class, uint8_t single_slot);
254
Holger Hans Peter Freyther9e21d842013-10-16 17:48:12 +0200255void tbf_free(struct gprs_rlcmac_tbf *tbf);
256
Holger Hans Peter Freyther9e21d842013-10-16 17:48:12 +0200257int tbf_assign_control_ts(struct gprs_rlcmac_tbf *tbf);
258
Holger Hans Peter Freyther9e21d842013-10-16 17:48:12 +0200259void tbf_timer_start(struct gprs_rlcmac_tbf *tbf, unsigned int T,
260 unsigned int seconds, unsigned int microseconds);
261
Holger Hans Peter Freyther1c344e22013-10-16 18:33:18 +0200262inline bool gprs_rlcmac_tbf::state_is(enum gprs_rlcmac_tbf_state rhs) const
263{
264 return state == rhs;
265}
266
267inline bool gprs_rlcmac_tbf::state_is_not(enum gprs_rlcmac_tbf_state rhs) const
268{
269 return state != rhs;
270}
271
Daniel Willmanneb100242014-08-08 11:43:53 +0200272const char *tbf_name(gprs_rlcmac_tbf *tbf);
273
Daniel Willmann08e57c82014-08-15 18:11:57 +0200274inline const char *gprs_rlcmac_tbf::state_name() const
275{
276 return tbf_state_name[state];
277}
278
Holger Hans Peter Freyther1c344e22013-10-16 18:33:18 +0200279inline void gprs_rlcmac_tbf::set_state(enum gprs_rlcmac_tbf_state new_state)
280{
Daniel Willmanneb100242014-08-08 11:43:53 +0200281 LOGP(DRLCMAC, LOGL_DEBUG, "%s changes state from %s to %s\n",
282 tbf_name(this),
283 tbf_state_name[state], tbf_state_name[new_state]);
Holger Hans Peter Freyther1c344e22013-10-16 18:33:18 +0200284 state = new_state;
285}
Holger Hans Peter Freytherbd449f52013-10-27 16:39:36 +0100286
Jacob Erlbeck10ed7952015-06-02 11:37:22 +0200287inline GprsMs *gprs_rlcmac_tbf::ms() const
Jacob Erlbeckfecece02015-05-08 12:13:08 +0200288{
289 return m_ms;
290}
291
Holger Hans Peter Freyther474685e2013-10-27 17:01:14 +0100292inline bool gprs_rlcmac_tbf::is_tlli_valid() const
293{
Jacob Erlbeck767193e2015-05-20 12:06:46 +0200294 return tlli() != 0;
Holger Hans Peter Freyther474685e2013-10-27 17:01:14 +0100295}
296
Holger Hans Peter Freyther34f6e5e2013-10-27 20:31:47 +0100297inline uint8_t gprs_rlcmac_tbf::tfi() const
298{
299 return m_tfi;
300}
301
Holger Hans Peter Freythera0047992014-01-16 10:07:20 +0100302inline time_t gprs_rlcmac_tbf::created_ts() const
Daniel Willmann80367aa2014-01-15 17:40:28 +0100303{
Holger Hans Peter Freythera0047992014-01-16 10:07:20 +0100304 return m_created_ts;
Daniel Willmann80367aa2014-01-15 17:40:28 +0100305}
306
Daniel Willmann078bb712014-07-10 17:44:06 +0200307struct gprs_rlcmac_dl_tbf : public gprs_rlcmac_tbf {
Jacob Erlbeckd0261b72015-04-02 13:58:09 +0200308 void cleanup();
309
Daniel Willmann30168882014-08-07 12:48:29 +0200310 /* dispatch Unitdata.DL messages */
311 static int handle(struct gprs_rlcmac_bts *bts,
Jacob Erlbeck93990462015-05-15 15:50:43 +0200312 const uint32_t tlli, const uint32_t old_tlli,
313 const char *imsi, const uint8_t ms_class,
Daniel Willmann30168882014-08-07 12:48:29 +0200314 const uint16_t delay_csec, const uint8_t *data, const uint16_t len);
315
Daniel Willmann538ac5b2014-07-30 19:12:27 +0200316 int append_data(const uint8_t ms_class,
317 const uint16_t pdu_delay_csec,
318 const uint8_t *data, const uint16_t len);
319
Daniel Willmann6c813fc2014-07-30 19:12:27 +0200320 int rcvd_dl_ack(uint8_t final, uint8_t ssn, uint8_t *rbb);
Daniel Willmannb8f26012014-07-30 19:12:28 +0200321 struct msgb *create_dl_acked_block(uint32_t fn, uint8_t ts);
Jacob Erlbeck7c444152015-03-12 12:08:54 +0100322 void request_dl_ack();
Jacob Erlbeckeceb9102015-03-20 14:41:50 +0100323 bool need_control_ts() const;
324 bool have_data() const;
Jacob Erlbeck005ee7f2015-03-20 14:53:54 +0100325 int frames_since_last_poll(unsigned fn) const;
Jacob Erlbeck3bed5d12015-03-19 11:22:38 +0100326 int frames_since_last_drain(unsigned fn) const;
327 bool keep_open(unsigned fn) const;
Jacob Erlbeckeceb9102015-03-20 14:41:50 +0100328
329 bool is_control_ts(uint8_t ts) const {
330 return ts == control_ts;
331 }
Daniel Willmannb8f26012014-07-30 19:12:28 +0200332
Daniel Willmanncf706b02014-08-07 17:35:22 +0200333 /* TODO: add the gettimeofday as parameter */
334 struct msgb *llc_dequeue(bssgp_bvc_ctx *bctx);
335
Daniel Willmann6a8a1dc2014-08-07 15:14:08 +0200336 /* Please note that all variables here will be reset when changing
337 * from WAIT RELEASE back to FLOW state (re-use of TBF).
338 * All states that need reset must be in this struct, so this is why
339 * variables are in both (dl and ul) structs and not outside union.
340 */
Daniel Willmann7e994e32014-08-07 15:49:21 +0200341 gprs_rlc_dl_window m_window;
342 int32_t m_tx_counter; /* count all transmitted blocks */
343 uint8_t m_wait_confirm; /* wait for CCCH IMM.ASS cnf */
Jacob Erlbeck7c444152015-03-12 12:08:54 +0100344 bool m_dl_ack_requested;
Jacob Erlbeck005ee7f2015-03-20 14:53:54 +0100345 int32_t m_last_dl_poll_fn;
Jacob Erlbeck3bed5d12015-03-19 11:22:38 +0100346 int32_t m_last_dl_drained_fn;
Daniel Willmann6a8a1dc2014-08-07 15:14:08 +0200347
Daniel Willmann418a4232014-08-08 11:21:04 +0200348 struct {
349 struct timeval dl_bw_tv; /* timestamp for dl bw calculation */
350 uint32_t dl_bw_octets; /* number of octets since bw_tv */
351
352 struct timeval dl_loss_tv; /* timestamp for loss calculation */
353 uint16_t dl_loss_lost; /* sum of lost packets */
354 uint16_t dl_loss_received; /* sum of received packets */
355 } m_bw;
356
Daniel Willmannb8f26012014-07-30 19:12:28 +0200357protected:
358 struct msgb *create_new_bsn(const uint32_t fn, const uint8_t ts);
359 struct msgb *create_dl_acked_block(const uint32_t fn, const uint8_t ts,
Jacob Erlbeck7c444152015-03-12 12:08:54 +0100360 const int index);
Daniel Willmann30168882014-08-07 12:48:29 +0200361 int update_window(const uint8_t ssn, const uint8_t *rbb);
362 int maybe_start_new_window();
363 bool dl_window_stalled() const;
Jacob Erlbeck409efa12015-06-12 14:06:09 +0200364 void reuse_tbf();
Jacob Erlbeckd0261b72015-04-02 13:58:09 +0200365 void start_llc_timer();
Jacob Erlbeck1751c622015-06-04 12:12:32 +0200366 int analyse_errors(char *show_rbb, uint8_t ssn);
Jacob Erlbeck409efa12015-06-12 14:06:09 +0200367 void schedule_next_frame();
Jacob Erlbeckd0261b72015-04-02 13:58:09 +0200368
369 struct osmo_timer_list m_llc_timer;
Daniel Willmann078bb712014-07-10 17:44:06 +0200370};
371
372struct gprs_rlcmac_ul_tbf : public gprs_rlcmac_tbf {
Daniel Willmann350f64d2014-08-07 14:54:11 +0200373 struct msgb *create_ul_ack(uint32_t fn);
374
375 /* blocks were acked */
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +0200376 int rcv_data_block_acknowledged(const uint8_t *data, size_t len,
377 struct pcu_l1_meas *meas);
Daniel Willmann350f64d2014-08-07 14:54:11 +0200378
Daniel Willmanne2732e22014-08-07 17:32:01 +0200379 /* TODO: extract LLC class? */
380 int assemble_forward_llc(const gprs_rlc_data *data);
381 int snd_ul_ud();
382
Daniel Willmann6a8a1dc2014-08-07 15:14:08 +0200383 /* Please note that all variables here will be reset when changing
384 * from WAIT RELEASE back to FLOW state (re-use of TBF).
385 * All states that need reset must be in this struct, so this is why
386 * variables are in both (dl and ul) structs and not outside union.
387 */
Daniel Willmann7e994e32014-08-07 15:49:21 +0200388 gprs_rlc_ul_window m_window;
389 int32_t m_rx_counter; /* count all received blocks */
390 uint8_t m_n3103; /* N3103 counter */
391 uint8_t m_usf[8]; /* list USFs per PDCH (timeslot) */
392 uint8_t m_contention_resolution_done; /* set after done */
393 uint8_t m_final_ack_sent; /* set if we sent final ack */
Daniel Willmann6a8a1dc2014-08-07 15:14:08 +0200394
Daniel Willmann350f64d2014-08-07 14:54:11 +0200395protected:
396 void maybe_schedule_uplink_acknack(const rlc_ul_header *rh);
Daniel Willmann078bb712014-07-10 17:44:06 +0200397};
398
Jacob Erlbeckac89a552015-06-29 14:18:46 +0200399inline enum gprs_rlcmac_tbf_direction reverse(enum gprs_rlcmac_tbf_direction dir)
400{
401 return (enum gprs_rlcmac_tbf_direction)
402 ((int)GPRS_RLCMAC_UL_TBF - (int)dir + (int)GPRS_RLCMAC_DL_TBF);
403}
Daniel Willmannafa72f52014-01-15 17:06:19 +0100404#endif
Holger Hans Peter Freyther321f3c32013-11-23 16:06:54 +0100405
Daniel Willmannafa72f52014-01-15 17:06:19 +0100406#ifdef __cplusplus
407extern "C" {
408#endif
409#include <osmocom/vty/command.h>
410#include <osmocom/vty/vty.h>
411
Jacob Erlbeckc0c580c2015-04-30 15:59:01 +0200412 void tbf_print_vty_info(struct vty *vty, struct llist_head *tbf);
Daniel Willmannafa72f52014-01-15 17:06:19 +0100413#ifdef __cplusplus
414}
415#endif