blob: 8de7417495b4d39fb2f04d3a0bc2cc016e5f655c [file] [log] [blame]
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001/* gprs_rlcmac.h
2 *
3 * Copyright (C) 2012 Ivan Klyuchnikov
Holger Hans Peter Freytherd6bd91e2013-08-24 21:16:55 +02004 * Copyright (C) 2013 by Holger Hans Peter Freyther
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04005 *
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
21#ifndef GPRS_RLCMAC_H
22#define GPRS_RLCMAC_H
23
Andreas Eversberg8b761a32012-07-20 21:50:31 +020024#ifdef __cplusplus
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +040025#include <bitvector.h>
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040026#include <gsm_rlcmac.h>
Ivan Kluchnikov61a33f72012-04-12 15:22:06 +040027#include <gsm_timer.h>
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040028
29extern "C" {
30#include <osmocom/core/linuxlist.h>
Ivan Kluchnikov61a33f72012-04-12 15:22:06 +040031#include <osmocom/core/timer.h>
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040032}
Andreas Eversberg8b761a32012-07-20 21:50:31 +020033#endif
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040034
Andreas Eversbergb83e2a72012-10-07 15:26:00 +020035/* generate a diagram for debugging timing issues */
36//#define DEBUG_DIAGRAM
37
Andreas Eversberge6228b32012-07-03 13:36:03 +020038/* This special feature will delay assignment of downlink TBF by one second,
39 * in case there is already a TBF.
40 * This is usefull to debug downlink establishment during packet idle mode.
41 */
42//#define DEBUG_DL_ASS_IDLE
Ivan Kluchnikovc5d8c272012-06-04 21:55:02 +040043
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020044/*
45 * PDCH instanc
46 */
47
48struct gprs_rlcmac_tbf;
49
50struct gprs_rlcmac_pdch {
51 uint8_t enable; /* TS is enabled */
52 uint8_t tsc; /* TSC of this slot */
53 uint8_t next_ul_tfi; /* next uplink TBF/TFI to schedule (0..31) */
54 uint8_t next_dl_tfi; /* next downlink TBF/TFI to schedule (0..31) */
Andreas Eversbergb0c7ea72012-07-13 14:46:03 +020055 struct gprs_rlcmac_tbf *ul_tbf[32]; /* array of UL TBF, by UL TFI */
56 struct gprs_rlcmac_tbf *dl_tbf[32]; /* array of DL TBF, by DL TFI */
Andreas Eversberg2b914642012-07-19 13:06:26 +020057 struct llist_head paging_list; /* list of paging messages */
Andreas Eversberge6228b32012-07-03 13:36:03 +020058 uint32_t last_rts_fn; /* store last frame number of RTS */
Ivan Kluchnikova9e6dc52012-06-17 08:30:06 +040059};
60
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020061struct gprs_rlcmac_trx {
Andreas Eversberga23c7ee2012-12-18 10:47:28 +010062 void *fl1h;
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020063 uint16_t arfcn;
64 struct gprs_rlcmac_pdch pdch[8];
Andreas Eversbergadb2f182012-08-07 17:06:08 +020065 struct gprs_rlcmac_tbf *ul_tbf[32]; /* array of UL TBF, by UL TFI */
66 struct gprs_rlcmac_tbf *dl_tbf[32]; /* array of DL TBF, by DL TFI */
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020067};
68
69struct gprs_rlcmac_bts {
Andreas Eversberga23c7ee2012-12-18 10:47:28 +010070 uint8_t bsic;
Andreas Eversbergcd8a83a2012-09-23 06:41:21 +020071 uint8_t fc_interval;
Andreas Eversbergb3c6f6c2012-07-06 07:40:08 +020072 uint8_t cs1;
73 uint8_t cs2;
74 uint8_t cs3;
75 uint8_t cs4;
Andreas Eversberg499ff412012-10-03 14:21:36 +020076 uint8_t initial_cs_dl, initial_cs_ul;
Andreas Eversberg8b761a32012-07-20 21:50:31 +020077 uint8_t force_cs; /* 0=use from BTS 1=use from VTY */
Andreas Eversberg24131bf2012-07-21 11:09:58 +020078 uint16_t force_llc_lifetime; /* overrides lifetime from SGSN */
Andreas Eversbergb3c6f6c2012-07-06 07:40:08 +020079 uint8_t t3142;
80 uint8_t t3169;
81 uint8_t t3191;
82 uint16_t t3193_msec;
83 uint8_t t3195;
84 uint8_t n3101;
85 uint8_t n3103;
86 uint8_t n3105;
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020087 struct gprs_rlcmac_trx trx[8];
Holger Hans Peter Freytherb67a8a32013-07-28 18:55:14 +020088 int (*alloc_algorithm)(struct gprs_rlcmac_bts *bts,
89 struct gprs_rlcmac_tbf *old_tbf,
Andreas Eversbergf01929b2012-10-08 12:40:49 +020090 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single);
Andreas Eversberg592e04a2012-07-15 06:25:37 +020091 uint32_t alloc_algorithm_curst; /* options to customize algorithm */
Andreas Eversberg07e97cf2012-08-07 16:00:56 +020092 uint8_t force_two_phase;
Andreas Eversbergaafcbbb2012-09-27 09:20:45 +020093 uint8_t alpha, gamma;
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020094};
95
96extern struct gprs_rlcmac_bts *gprs_rlcmac_bts;
97
Andreas Eversberg8b761a32012-07-20 21:50:31 +020098#ifdef __cplusplus
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020099/*
100 * TBF instance
101 */
102
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400103#define LLC_MAX_LEN 1543
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200104#define RLC_MAX_SNS 128 /* GPRS, must be power of 2 */
105#define RLC_MAX_WS 64 /* max window size */
Andreas Eversberge6228b32012-07-03 13:36:03 +0200106#define RLC_MAX_LEN 54 /* CS-4 including spare bits */
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400107
Andreas Eversberga9be1542012-09-27 09:23:24 +0200108#define Tassign_agch 0,200000 /* waiting after IMM.ASS confirm */
Andreas Eversbergcbcd1242012-08-07 15:48:21 +0200109#define Tassign_pacch 2,0 /* timeout for pacch assigment */
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200110
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400111enum gprs_rlcmac_tbf_state {
Andreas Eversberge6228b32012-07-03 13:36:03 +0200112 GPRS_RLCMAC_NULL = 0, /* new created TBF */
113 GPRS_RLCMAC_ASSIGN, /* wait for downlink assignment */
Holger Hans Peter Freyther1115f592012-07-23 10:27:30 +0200114 GPRS_RLCMAC_FLOW, /* RLC/MAC flow, resource needed */
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200115 GPRS_RLCMAC_FINISHED, /* flow finished, wait for release */
Andreas Eversberge6228b32012-07-03 13:36:03 +0200116 GPRS_RLCMAC_WAIT_RELEASE,/* wait for release or restart of DL TBF */
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200117 GPRS_RLCMAC_RELEASING, /* releasing, wait to free TBI/USF */
118};
119
120enum gprs_rlcmac_tbf_poll_state {
121 GPRS_RLCMAC_POLL_NONE = 0,
122 GPRS_RLCMAC_POLL_SCHED, /* a polling was scheduled */
123};
124
Andreas Eversberge6228b32012-07-03 13:36:03 +0200125enum gprs_rlcmac_tbf_dl_ass_state {
126 GPRS_RLCMAC_DL_ASS_NONE = 0,
127 GPRS_RLCMAC_DL_ASS_SEND_ASS, /* send downlink assignment on next RTS */
128 GPRS_RLCMAC_DL_ASS_WAIT_ACK, /* wait for PACKET CONTROL ACK */
129};
130
131enum gprs_rlcmac_tbf_ul_ass_state {
132 GPRS_RLCMAC_UL_ASS_NONE = 0,
133 GPRS_RLCMAC_UL_ASS_SEND_ASS, /* send uplink assignment on next RTS */
134 GPRS_RLCMAC_UL_ASS_WAIT_ACK, /* wait for PACKET CONTROL ACK */
135};
136
137enum gprs_rlcmac_tbf_ul_ack_state {
138 GPRS_RLCMAC_UL_ACK_NONE = 0,
139 GPRS_RLCMAC_UL_ACK_SEND_ACK, /* send acknowledge on next RTS */
140 GPRS_RLCMAC_UL_ACK_WAIT_ACK, /* wait for PACKET CONTROL ACK */
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400141};
142
143enum gprs_rlcmac_tbf_direction {
144 GPRS_RLCMAC_DL_TBF,
145 GPRS_RLCMAC_UL_TBF
146};
147
Andreas Eversberg14db19e2012-08-06 15:03:03 +0200148#define GPRS_RLCMAC_FLAG_CCCH 0 /* assignment on CCCH */
149#define GPRS_RLCMAC_FLAG_PACCH 1 /* assignment on PACCH */
150#define GPRS_RLCMAC_FLAG_UL_DATA 2 /* uplink data received */
151#define GPRS_RLCMAC_FLAG_DL_ACK 3 /* downlink acknowledge received */
152#define GPRS_RLCMAC_FLAG_TO_UL_ACK 4
153#define GPRS_RLCMAC_FLAG_TO_DL_ACK 5
154#define GPRS_RLCMAC_FLAG_TO_UL_ASS 6
155#define GPRS_RLCMAC_FLAG_TO_DL_ASS 7
Andreas Eversberga9be1542012-09-27 09:23:24 +0200156#define GPRS_RLCMAC_FLAG_TO_MASK 0xf0 /* timeout bits */
Andreas Eversberg14db19e2012-08-06 15:03:03 +0200157
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400158struct gprs_rlcmac_tbf {
159 struct llist_head list;
160 enum gprs_rlcmac_tbf_state state;
Andreas Eversberg14db19e2012-08-06 15:03:03 +0200161 uint32_t state_flags;
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400162 enum gprs_rlcmac_tbf_direction direction;
163 uint8_t tfi;
164 uint32_t tlli;
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200165 uint8_t tlli_valid;
Andreas Eversbergb0c7ea72012-07-13 14:46:03 +0200166 uint8_t trx;
167 uint16_t arfcn;
168 uint8_t tsc;
Andreas Eversberg592e04a2012-07-15 06:25:37 +0200169 uint8_t first_ts; /* first TS used by TBF */
170 uint8_t first_common_ts; /* first TS that the phone can send and
171 reveive simultaniously */
172 uint8_t control_ts; /* timeslot control messages and polling */
Andreas Eversbergf298fa82012-07-13 14:50:57 +0200173 uint8_t ms_class;
Andreas Eversbergb0c7ea72012-07-13 14:46:03 +0200174 struct gprs_rlcmac_pdch *pdch[8]; /* list of PDCHs allocated to TBF */
175 uint16_t ta;
Andreas Eversberge6228b32012-07-03 13:36:03 +0200176 uint8_t llc_frame[LLC_MAX_LEN]; /* current DL or UL frame */
177 uint16_t llc_index; /* current write/read position of frame */
178 uint16_t llc_length; /* len of current DL LLC_frame, 0 == no frame */
Andreas Eversberg8b761a32012-07-20 21:50:31 +0200179 struct llist_head llc_queue; /* queued LLC DL data */
Andreas Eversberge6228b32012-07-03 13:36:03 +0200180
181 enum gprs_rlcmac_tbf_dl_ass_state dl_ass_state;
182 enum gprs_rlcmac_tbf_ul_ass_state ul_ass_state;
183 enum gprs_rlcmac_tbf_ul_ack_state ul_ack_state;
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200184
185 enum gprs_rlcmac_tbf_poll_state poll_state;
Andreas Eversbergb0c7ea72012-07-13 14:46:03 +0200186 uint32_t poll_fn; /* frame number to poll */
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200187
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200188 uint16_t ws; /* window size */
189 uint16_t sns; /* sequence number space */
Andreas Eversberge6228b32012-07-03 13:36:03 +0200190
191 /* Please note that all variables here will be reset when changing
192 * from WAIT RELEASE back to FLOW state (re-use of TBF).
193 * All states that need reset must be in this struct, so this is why
194 * variables are in both (dl and ul) structs and not outside union.
195 */
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200196 union {
197 struct {
Andreas Eversberge6228b32012-07-03 13:36:03 +0200198 uint16_t bsn; /* block sequence number */
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200199 uint16_t v_s; /* send state */
200 uint16_t v_a; /* ack state */
201 char v_b[RLC_MAX_SNS/2]; /* acknowledge state array */
Andreas Eversberge6228b32012-07-03 13:36:03 +0200202 int32_t tx_counter; /* count all transmitted blocks */
Andreas Eversberga9be1542012-09-27 09:23:24 +0200203 char imsi[16]; /* store IMSI for PCH retransmission */
204 uint8_t wait_confirm; /* wait for CCCH IMM.ASS cnf */
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200205 } dl;
206 struct {
Andreas Eversberge6228b32012-07-03 13:36:03 +0200207 uint16_t bsn; /* block sequence number */
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200208 uint16_t v_r; /* receive state */
209 uint16_t v_q; /* receive window state */
210 char v_n[RLC_MAX_SNS/2]; /* receive state array */
211 int32_t rx_counter; /* count all received blocks */
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200212 uint8_t n3103; /* N3103 counter */
Andreas Eversbergb0c7ea72012-07-13 14:46:03 +0200213 uint8_t usf[8]; /* list USFs per PDCH (timeslot) */
Andreas Eversberg08e93cd2012-07-26 08:13:06 +0200214 uint8_t contention_resolution_done; /* set after done */
215 uint8_t final_ack_sent; /* set if we sent final ack */
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200216 } ul;
217 } dir;
218 uint8_t rlc_block[RLC_MAX_SNS/2][RLC_MAX_LEN]; /* block history */
219 uint8_t rlc_block_len[RLC_MAX_SNS/2]; /* block len of history */
Ivan Kluchnikov61a33f72012-04-12 15:22:06 +0400220
Andreas Eversberg802bb6e2012-08-06 11:15:05 +0200221 uint8_t n3105; /* N3105 counter */
222
Ivan Kluchnikov61a33f72012-04-12 15:22:06 +0400223 struct osmo_timer_list timer;
224 unsigned int T; /* Txxxx number */
225 unsigned int num_T_exp; /* number of consecutive T expirations */
226
227 struct osmo_gsm_timer_list gsm_timer;
228 unsigned int fT; /* fTxxxx number */
229 unsigned int num_fT_exp; /* number of consecutive fT expirations */
Andreas Eversbergb3ded4c2012-07-24 10:47:24 +0200230
Andreas Eversberg050ace22013-03-16 16:22:02 +0100231 struct {
232 char imsi[16];
233
234 struct timeval dl_bw_tv; /* timestamp for dl bw calculation */
235 uint32_t dl_bw_octets; /* number of octets since bw_tv */
236
237 struct timeval rssi_tv; /* timestamp for rssi calculation */
238 int32_t rssi_sum; /* sum of rssi values */
239 int rssi_num; /* number of rssi values added since rssi_tv */
240
241 struct timeval dl_loss_tv; /* timestamp for loss calculation */
242 uint16_t dl_loss_lost; /* sum of lost packets */
243 uint16_t dl_loss_received; /* sum of received packets */
244
245 } meas;
Andreas Eversberg3b1332c2012-10-03 14:20:53 +0200246
247 uint8_t cs; /* current coding scheme */
Andreas Eversbergb83e2a72012-10-07 15:26:00 +0200248
249#ifdef DEBUG_DIAGRAM
250 int diag; /* number where TBF is presented in diagram */
251 int diag_new; /* used to format output of new TBF */
252#endif
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400253};
254
Andreas Eversbergb0c7ea72012-07-13 14:46:03 +0200255extern struct llist_head gprs_rlcmac_ul_tbfs; /* list of uplink TBFs */
256extern struct llist_head gprs_rlcmac_dl_tbfs; /* list of downlink TBFs */
Andreas Eversberg07e97cf2012-08-07 16:00:56 +0200257extern struct llist_head gprs_rlcmac_sbas; /* list of single block allocs */
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400258
Andreas Eversberg2b914642012-07-19 13:06:26 +0200259/*
260 * paging entry
261 */
262struct gprs_rlcmac_paging {
263 struct llist_head list;
264 uint8_t chan_needed;
265 uint8_t identity_lv[9];
266};
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400267
Andreas Eversberg07e97cf2012-08-07 16:00:56 +0200268/*
269 * single block allocation entry
270 */
271struct gprs_rlcmac_sba {
272 struct llist_head list;
273 uint8_t trx;
274 uint8_t ts;
275 uint32_t fn;
276 uint8_t ta;
277};
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400278
Andreas Eversberg3b1332c2012-10-03 14:20:53 +0200279/*
280 * coding scheme info
281 */
282struct gprs_rlcmac_cs {
283 uint8_t block_length;
284 uint8_t block_data;
285 uint8_t block_payload;
286};
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400287
Andreas Eversberg3b1332c2012-10-03 14:20:53 +0200288extern struct gprs_rlcmac_cs gprs_rlcmac_cs[];
Andreas Eversberge6228b32012-07-03 13:36:03 +0200289
Andreas Eversbergb83e2a72012-10-07 15:26:00 +0200290#ifdef DEBUG_DIAGRAM
291void debug_diagram(int diag, const char *format, ...);
292#else
293#define debug_diagram(a, b, args...) ;
294#endif
295
Andreas Eversberg050ace22013-03-16 16:22:02 +0100296int gprs_rlcmac_received_lost(struct gprs_rlcmac_tbf *tbf, uint16_t received,
297 uint16_t lost);
298
299int gprs_rlcmac_lost_rep(struct gprs_rlcmac_tbf *tbf);
300
301int gprs_rlcmac_meas_rep(Packet_Measurement_Report_t *pmr);
302
303int gprs_rlcmac_rssi(struct gprs_rlcmac_tbf *tbf, int8_t rssi);
304
305int gprs_rlcmac_rssi_rep(struct gprs_rlcmac_tbf *tbf);
306
307int gprs_rlcmac_dl_bw(struct gprs_rlcmac_tbf *tbf, uint16_t octets);
308
Andreas Eversberg07e97cf2012-08-07 16:00:56 +0200309int sba_alloc(uint8_t *_trx, uint8_t *_ts, uint32_t *_fn, uint8_t ta);
Andreas Eversberge6228b32012-07-03 13:36:03 +0200310
Andreas Eversberg07e97cf2012-08-07 16:00:56 +0200311struct gprs_rlcmac_sba *sba_find(uint8_t trx, uint8_t ts, uint32_t fn);
312
Holger Hans Peter Freytherd6bd91e2013-08-24 21:16:55 +0200313int tfi_find_free(struct gprs_rlcmac_bts *bts, enum gprs_rlcmac_tbf_direction dir,
Holger Hans Peter Freytherb67a8a32013-07-28 18:55:14 +0200314 uint8_t *_trx, int8_t use_trx);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400315
Holger Hans Peter Freytherb67a8a32013-07-28 18:55:14 +0200316struct gprs_rlcmac_tbf *tbf_alloc(struct gprs_rlcmac_bts *bts,
317 struct gprs_rlcmac_tbf *old_tbf,
Andreas Eversberg592e04a2012-07-15 06:25:37 +0200318 enum gprs_rlcmac_tbf_direction dir, uint8_t tfi, uint8_t trx,
Andreas Eversberg02d7cd22013-01-15 08:59:34 +0100319 uint8_t ms_class, uint8_t single_slot);
Andreas Eversbergf298fa82012-07-13 14:50:57 +0200320
Holger Hans Peter Freytherb67a8a32013-07-28 18:55:14 +0200321struct gprs_rlcmac_tbf *tbf_by_tfi(struct gprs_rlcmac_bts *bts,
322 uint8_t tfi, uint8_t trx,
Andreas Eversbergb0c7ea72012-07-13 14:46:03 +0200323 enum gprs_rlcmac_tbf_direction dir);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400324
Andreas Eversbergb0c7ea72012-07-13 14:46:03 +0200325struct gprs_rlcmac_tbf *tbf_by_tlli(uint32_t tlli,
326 enum gprs_rlcmac_tbf_direction dir);
Andreas Eversberge6228b32012-07-03 13:36:03 +0200327
Andreas Eversbergb0c7ea72012-07-13 14:46:03 +0200328struct gprs_rlcmac_tbf *tbf_by_poll_fn(uint32_t fn, uint8_t trx, uint8_t ts);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400329
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200330void tbf_free(struct gprs_rlcmac_tbf *tbf);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400331
Andreas Eversberg592e04a2012-07-15 06:25:37 +0200332int tbf_update(struct gprs_rlcmac_tbf *tbf);
333
334int tbf_assign_control_ts(struct gprs_rlcmac_tbf *tbf);
335
Andreas Eversberge6228b32012-07-03 13:36:03 +0200336void tbf_new_state(struct gprs_rlcmac_tbf *tbf,
337 enum gprs_rlcmac_tbf_state state);
338
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200339void tbf_timer_start(struct gprs_rlcmac_tbf *tbf, unsigned int T,
Andreas Eversberge6228b32012-07-03 13:36:03 +0200340 unsigned int seconds, unsigned int microseconds);
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200341
342void tbf_timer_stop(struct gprs_rlcmac_tbf *tbf);
343
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400344/* TS 44.060 Section 10.4.7 Table 10.4.7.1: Payload Type field */
345enum gprs_rlcmac_block_type {
346 GPRS_RLCMAC_DATA_BLOCK = 0x0,
347 GPRS_RLCMAC_CONTROL_BLOCK = 0x1,
348 GPRS_RLCMAC_CONTROL_BLOCK_OPT = 0x2,
349 GPRS_RLCMAC_RESERVED = 0x3
350};
351
Andreas Eversbergb0c7ea72012-07-13 14:46:03 +0200352int gprs_rlcmac_rcv_block(uint8_t trx, uint8_t ts, uint8_t *data, uint8_t len,
Andreas Eversberg570b44b2013-03-16 16:15:01 +0100353 uint32_t fn, int8_t rssi);
Ivan Kluchnikova9e6dc52012-06-17 08:30:06 +0400354
Andreas Eversberge6228b32012-07-03 13:36:03 +0200355int write_immediate_assignment(bitvec * dest, uint8_t downlink, uint8_t ra,
Andreas Eversberg07e97cf2012-08-07 16:00:56 +0200356 uint32_t ref_fn, uint8_t ta, uint16_t arfcn, uint8_t ts, uint8_t tsc,
Andreas Eversberge6228b32012-07-03 13:36:03 +0200357 uint8_t tfi, uint8_t usf, uint32_t tlli, uint8_t polling,
Andreas Eversbergafdd9e12012-10-07 17:08:55 +0200358 uint32_t fn, uint8_t single_block, uint8_t alpha, uint8_t gamma,
359 int8_t ta_idx);
Ivan Kluchnikovcf7b3a52012-06-26 16:54:22 +0400360
Andreas Eversberge6228b32012-07-03 13:36:03 +0200361void write_packet_uplink_assignment(bitvec * dest, uint8_t old_tfi,
Andreas Eversbergb0c7ea72012-07-13 14:46:03 +0200362 uint8_t old_downlink, uint32_t tlli, uint8_t use_tlli,
Andreas Eversbergaafcbbb2012-09-27 09:20:45 +0200363 struct gprs_rlcmac_tbf *tbf, uint8_t poll, uint8_t alpha,
Andreas Eversbergafdd9e12012-10-07 17:08:55 +0200364 uint8_t gamma, int8_t ta_idx);
Ivan Kluchnikova9e6dc52012-06-17 08:30:06 +0400365
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400366void write_packet_downlink_assignment(RlcMacDownlink_t * block, uint8_t old_tfi,
Andreas Eversbergaafcbbb2012-09-27 09:20:45 +0200367 uint8_t old_downlink, struct gprs_rlcmac_tbf *tbf, uint8_t poll,
Andreas Eversbergafdd9e12012-10-07 17:08:55 +0200368 uint8_t alpha, uint8_t gamma, int8_t ta_idx, uint8_t ta_ts);
Andreas Eversbergb0c7ea72012-07-13 14:46:03 +0200369
370
Ivan Kluchnikova9e6dc52012-06-17 08:30:06 +0400371
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400372void write_packet_uplink_ack(RlcMacDownlink_t * block, struct gprs_rlcmac_tbf *tbf,
Andreas Eversberge6228b32012-07-03 13:36:03 +0200373 uint8_t final);
Ivan Kluchnikova9e6dc52012-06-17 08:30:06 +0400374
Andreas Eversberg3e372d52012-07-06 09:28:15 +0200375int gprs_rlcmac_tx_ul_ud(gprs_rlcmac_tbf *tbf);
Ivan Kluchnikova9e6dc52012-06-17 08:30:06 +0400376
Andreas Eversberge6228b32012-07-03 13:36:03 +0200377void tbf_timer_cb(void *_tbf);
Ivan Kluchnikova9e6dc52012-06-17 08:30:06 +0400378
Andreas Eversberge6228b32012-07-03 13:36:03 +0200379int gprs_rlcmac_poll_timeout(struct gprs_rlcmac_tbf *tbf);
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200380
Andreas Eversberga004e6a2013-05-13 16:45:21 +0200381int gprs_rlcmac_sba_timeout(struct gprs_rlcmac_sba *sba);
382
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200383int gprs_rlcmac_rcv_rach(uint8_t ra, uint32_t Fn, int16_t qta);
Ivan Kluchnikov5310d452012-04-17 22:00:31 +0400384
Andreas Eversbergb0c7ea72012-07-13 14:46:03 +0200385int gprs_rlcmac_rcv_control_block(bitvec *rlc_block, uint8_t trx, uint8_t ts,
386 uint32_t fn);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400387
Andreas Eversberge6228b32012-07-03 13:36:03 +0200388struct msgb *gprs_rlcmac_send_packet_uplink_assignment(
389 struct gprs_rlcmac_tbf *tbf, uint32_t fn);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400390
Andreas Eversberge6228b32012-07-03 13:36:03 +0200391struct msgb *gprs_rlcmac_send_packet_downlink_assignment(
392 struct gprs_rlcmac_tbf *tbf, uint32_t fn);
Ivan Kluchnikovc320d862012-03-18 15:04:48 +0400393
Andreas Eversberg7f5352c2012-07-23 18:20:36 +0200394void gprs_rlcmac_trigger_downlink_assignment(struct gprs_rlcmac_tbf *tbf,
Holger Hans Peter Freyther52c911b2013-08-24 18:30:54 +0200395 struct gprs_rlcmac_tbf *old_tbf, const char *imsi);
Ivan Kluchnikovc7e7f682012-06-29 22:53:15 +0400396
Andreas Eversberge6228b32012-07-03 13:36:03 +0200397int gprs_rlcmac_downlink_ack(struct gprs_rlcmac_tbf *tbf, uint8_t final,
398 uint8_t ssn, uint8_t *rbb);
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200399
Andreas Eversberg8c3680d2012-10-08 12:30:56 +0200400int gprs_rlcmac_paging_request(uint8_t *ptmsi, uint16_t ptmsi_len,
401 const char *imsi);
402
Andreas Eversberg2b914642012-07-19 13:06:26 +0200403unsigned write_packet_paging_request(bitvec * dest);
404
405unsigned write_repeated_page_info(bitvec * dest, unsigned& wp, uint8_t len,
406 uint8_t *identity, uint8_t chan_needed);
407
Andreas Eversbergb0c7ea72012-07-13 14:46:03 +0200408int gprs_rlcmac_rcv_data_block_acknowledged(uint8_t trx, uint8_t ts,
Andreas Eversberg570b44b2013-03-16 16:15:01 +0100409 uint8_t *data, uint8_t len, int8_t rssi);
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200410
Andreas Eversberge6228b32012-07-03 13:36:03 +0200411struct msgb *gprs_rlcmac_send_data_block_acknowledged(
Andreas Eversberg592e04a2012-07-15 06:25:37 +0200412 struct gprs_rlcmac_tbf *tbf, uint32_t fn, uint8_t ts);
Andreas Eversberge6228b32012-07-03 13:36:03 +0200413
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200414struct msgb *gprs_rlcmac_send_uplink_ack(struct gprs_rlcmac_tbf *tbf,
415 uint32_t fn);
Ivan Kluchnikov9c795ab2012-05-24 23:12:59 +0400416
Andreas Eversberge6228b32012-07-03 13:36:03 +0200417int gprs_rlcmac_rcv_rts_block(uint8_t trx, uint8_t ts, uint16_t arfcn,
418 uint32_t fn, uint8_t block_nr);
419
Andreas Eversberga9be1542012-09-27 09:23:24 +0200420int gprs_rlcmac_imm_ass_cnf(uint8_t *data, uint32_t fn);
421
Andreas Eversberg2b914642012-07-19 13:06:26 +0200422int gprs_rlcmac_add_paging(uint8_t chan_needed, uint8_t *identity_lv);
423
424struct gprs_rlcmac_paging *gprs_rlcmac_dequeue_paging(
425 struct gprs_rlcmac_pdch *pdch);
426
427struct msgb *gprs_rlcmac_send_packet_paging_request(
428 struct gprs_rlcmac_pdch *pdch);
Andreas Eversberga1503fa2012-07-22 08:58:09 +0200429
Andreas Eversberga004e6a2013-05-13 16:45:21 +0200430int remember_timing_advance(uint32_t tlli, uint8_t ta);
431
432int recall_timing_advance(uint32_t tlli);
433
434int flush_timing_advance(void);
435
Andreas Eversberga1503fa2012-07-22 08:58:09 +0200436extern "C" {
437#endif
Holger Hans Peter Freytherb67a8a32013-07-28 18:55:14 +0200438int alloc_algorithm_a(struct gprs_rlcmac_bts *bts,
439 struct gprs_rlcmac_tbf *old_tbf,
Andreas Eversbergf01929b2012-10-08 12:40:49 +0200440 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single);
Andreas Eversberga1503fa2012-07-22 08:58:09 +0200441
Holger Hans Peter Freytherb67a8a32013-07-28 18:55:14 +0200442int alloc_algorithm_b(struct gprs_rlcmac_bts *bts,
443 struct gprs_rlcmac_tbf *old_tbf,
Andreas Eversbergf01929b2012-10-08 12:40:49 +0200444 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single);
Andreas Eversberga1503fa2012-07-22 08:58:09 +0200445#ifdef __cplusplus
446}
Andreas Eversberg8b761a32012-07-20 21:50:31 +0200447#endif
Andreas Eversberg2b914642012-07-19 13:06:26 +0200448
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400449#endif // GPRS_RLCMAC_H