blob: 50d2e84cec3d11aca889ddd8ec93a2a277917991 [file] [log] [blame]
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001/* gprs_rlcmac.h
2 *
3 * Copyright (C) 2012 Ivan Klyuchnikov
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#ifndef GPRS_RLCMAC_H
21#define GPRS_RLCMAC_H
22
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +040023#include <bitvector.h>
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040024#include <gsm_rlcmac.h>
Ivan Kluchnikov61a33f72012-04-12 15:22:06 +040025#include <gsm_timer.h>
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040026
27extern "C" {
28#include <osmocom/core/linuxlist.h>
Ivan Kluchnikov61a33f72012-04-12 15:22:06 +040029#include <osmocom/core/timer.h>
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040030}
31
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020032/*
33 * PDCH instanc
34 */
35
36struct gprs_rlcmac_tbf;
37
38struct gprs_rlcmac_pdch {
39 uint8_t enable; /* TS is enabled */
40 uint8_t tsc; /* TSC of this slot */
41 uint8_t next_ul_tfi; /* next uplink TBF/TFI to schedule (0..31) */
42 uint8_t next_dl_tfi; /* next downlink TBF/TFI to schedule (0..31) */
43 struct gprs_rlcmac_tbf *tbf[32]; /* array of TBF pointers, by TFI */
44};
45
46struct gprs_rlcmac_trx {
47 uint16_t arfcn;
48 struct gprs_rlcmac_pdch pdch[8];
49};
50
51struct gprs_rlcmac_bts {
52 struct gprs_rlcmac_trx trx[8];
53};
54
55extern struct gprs_rlcmac_bts *gprs_rlcmac_bts;
56
57/*
58 * TBF instance
59 */
60
Ivan Kluchnikovc5d8c272012-06-04 21:55:02 +040061#define LLC_MAX_LEN 1543
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020062#define RLC_MAX_SNS 128 /* GPRS, must be power of 2 */
63#define RLC_MAX_WS 64 /* max window size */
64#define RLC_MAX_LEN 52 /* CS-4 */
Ivan Kluchnikovbceb3fb2012-06-05 16:56:27 +040065#define UL_RLC_DATA_BLOCK_LEN 23
Ivan Kluchnikovc5d8c272012-06-04 21:55:02 +040066
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020067#define T3169 6 /* 5 seconds + one second, because we don't use
68 * counters before starting timer. */
69#define N3103_MAX 4 /* how many tries to poll PACKET CONTROL ACK */
70
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040071enum gprs_rlcmac_tbf_state {
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020072 GPRS_RLCMAC_FLOW, /* RLC/MAC flow, ressource needed */
73 GPRS_RLCMAC_FINISHED, /* flow finished, wait for release */
74 GPRS_RLCMAC_RELEASING, /* releasing, wait to free TBI/USF */
75};
76
77enum gprs_rlcmac_tbf_poll_state {
78 GPRS_RLCMAC_POLL_NONE = 0,
79 GPRS_RLCMAC_POLL_SCHED, /* a polling was scheduled */
80};
81
82enum gprs_rlcmac_tbf_ul_substate {
83 GPRS_RLCMAC_UL_NONE = 0,
84 GPRS_RLCMAC_UL_SEND_ACK, /* send acknowledge on next RTS */
85 GPRS_RLCMAC_UL_WAIT_POLL, /* wait for PACKET CONTROL ACK */
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040086};
87
88enum gprs_rlcmac_tbf_direction {
89 GPRS_RLCMAC_DL_TBF,
90 GPRS_RLCMAC_UL_TBF
91};
92
93struct gprs_rlcmac_tbf {
94 struct llist_head list;
95 enum gprs_rlcmac_tbf_state state;
96 enum gprs_rlcmac_tbf_direction direction;
97 uint8_t tfi;
98 uint32_t tlli;
Andreas Eversberg5dac2f02012-06-27 15:52:04 +020099 uint8_t tlli_valid;
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200100 uint8_t trx, ts, tsc;
101 uint16_t arfcn, ta;
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200102 uint8_t llc_frame[LLC_MAX_LEN];
103 uint16_t llc_index;
104
105 enum gprs_rlcmac_tbf_poll_state poll_state;
106 uint32_t poll_fn;
107
108 uint16_t bsn; /* block sequence number */
109 uint16_t ws; /* window size */
110 uint16_t sns; /* sequence number space */
111 union {
112 struct {
113 uint16_t v_s; /* send state */
114 uint16_t v_a; /* ack state */
115 char v_b[RLC_MAX_SNS/2]; /* acknowledge state array */
116 } dl;
117 struct {
118 uint16_t v_r; /* receive state */
119 uint16_t v_q; /* receive window state */
120 char v_n[RLC_MAX_SNS/2]; /* receive state array */
121 int32_t rx_counter; /* count all received blocks */
122 enum gprs_rlcmac_tbf_ul_substate substate;
123 uint8_t usf; /* USF */
124 uint8_t n3103; /* N3103 counter */
125 } ul;
126 } dir;
127 uint8_t rlc_block[RLC_MAX_SNS/2][RLC_MAX_LEN]; /* block history */
128 uint8_t rlc_block_len[RLC_MAX_SNS/2]; /* block len of history */
Ivan Kluchnikov61a33f72012-04-12 15:22:06 +0400129
130 struct osmo_timer_list timer;
131 unsigned int T; /* Txxxx number */
132 unsigned int num_T_exp; /* number of consecutive T expirations */
133
134 struct osmo_gsm_timer_list gsm_timer;
135 unsigned int fT; /* fTxxxx number */
136 unsigned int num_fT_exp; /* number of consecutive fT expirations */
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400137};
138
139extern struct llist_head gprs_rlcmac_tbfs;
140
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200141int tfi_alloc(uint8_t *_trx, uint8_t *_ts);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400142
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200143struct gprs_rlcmac_tbf *tbf_alloc(uint8_t tfi, uint8_t trx, uint8_t ts);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400144
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200145struct gprs_rlcmac_tbf *tbf_by_tfi(uint8_t tfi);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400146
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200147struct gprs_rlcmac_tbf *tbf_by_tlli(uint8_t tlli);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400148
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200149void tbf_free(struct gprs_rlcmac_tbf *tbf);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400150
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200151void tbf_timer_start(struct gprs_rlcmac_tbf *tbf, unsigned int T,
152 unsigned int seconds);
153
154void tbf_timer_stop(struct gprs_rlcmac_tbf *tbf);
155
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400156/* TS 44.060 Section 10.4.7 Table 10.4.7.1: Payload Type field */
157enum gprs_rlcmac_block_type {
158 GPRS_RLCMAC_DATA_BLOCK = 0x0,
159 GPRS_RLCMAC_CONTROL_BLOCK = 0x1,
160 GPRS_RLCMAC_CONTROL_BLOCK_OPT = 0x2,
161 GPRS_RLCMAC_RESERVED = 0x3
162};
163
164void gprs_rlcmac_tx_ul_ack(uint8_t tfi, uint32_t tlli, RlcMacUplinkDataBlock_t * ul_data_block);
165
166void gprs_rlcmac_data_block_parse(gprs_rlcmac_tbf* tbf, RlcMacUplinkDataBlock_t * ul_data_block);
167
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400168int gprs_rlcmac_rcv_data_block(bitvec *rlc_block);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400169
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400170int gprs_rlcmac_rcv_control_block(bitvec *rlc_block);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400171
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200172int gprs_rlcmac_rcv_block(uint8_t *data, uint8_t len, uint32_t fn);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400173
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200174int gprs_rlcmac_rcv_rts_block(uint8_t trx, uint8_t ts, uint16_t arfcn,
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200175 uint32_t fn, uint8_t block_nr);
176
177int gprs_rlcmac_rcv_rach(uint8_t ra, uint32_t Fn, int16_t qta);
Ivan Kluchnikov5310d452012-04-17 22:00:31 +0400178
Ivan Kluchnikovc320d862012-03-18 15:04:48 +0400179void gprs_rlcmac_tx_dl_data_block(uint32_t tlli, uint8_t tfi, uint8_t *pdu, int start_index, int end_index, uint8_t bsn, uint8_t fbi);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400180
181int gprs_rlcmac_segment_llc_pdu(struct gprs_rlcmac_tbf *tbf);
182
183void gprs_rlcmac_tx_ul_ud(gprs_rlcmac_tbf *tbf);
184
Ivan Kluchnikovc320d862012-03-18 15:04:48 +0400185void gprs_rlcmac_downlink_assignment(gprs_rlcmac_tbf *tbf);
186
Ivan Kluchnikov9c795ab2012-05-24 23:12:59 +0400187void gprs_rlcmac_packet_downlink_assignment(gprs_rlcmac_tbf *tbf);
188
Andreas Eversberg5dac2f02012-06-27 15:52:04 +0200189void gprs_rlcmac_enqueue_block(bitvec *block, int len);
190
191int gprs_rlcmac_rcv_data_block_acknowledged(uint8_t *data, uint8_t len);
192
193struct msgb *gprs_rlcmac_send_uplink_ack(struct gprs_rlcmac_tbf *tbf,
194 uint32_t fn);
Ivan Kluchnikov9c795ab2012-05-24 23:12:59 +0400195
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400196#endif // GPRS_RLCMAC_H