blob: d18c516e51a5f9eec0d16fa968dc531b46adc7dd [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
Ivan Kluchnikovc5d8c272012-06-04 21:55:02 +040032#define LLC_MAX_LEN 1543
Ivan Kluchnikovbceb3fb2012-06-05 16:56:27 +040033#define UL_RLC_DATA_BLOCK_LEN 23
Ivan Kluchnikovc5d8c272012-06-04 21:55:02 +040034
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040035enum gprs_rlcmac_tbf_state {
36 GPRS_RLCMAC_WAIT_DATA_SEQ_START,
37 GPRS_RLCMAC_WAIT_NEXT_DATA_BLOCK,
38 GPRS_RLCMAC_WAIT_NEXT_DATA_SEQ
39};
40
41enum gprs_rlcmac_tbf_direction {
42 GPRS_RLCMAC_DL_TBF,
43 GPRS_RLCMAC_UL_TBF
44};
45
46struct gprs_rlcmac_tbf {
47 struct llist_head list;
48 enum gprs_rlcmac_tbf_state state;
49 enum gprs_rlcmac_tbf_direction direction;
50 uint8_t tfi;
51 uint32_t tlli;
Ivan Kluchnikovc5d8c272012-06-04 21:55:02 +040052 uint8_t rlc_data[LLC_MAX_LEN];
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040053 uint16_t data_index;
54 uint8_t bsn;
Andreas Eversberg0aed6542012-06-23 10:33:16 +020055 uint8_t trx, ts, tsc;
56 uint16_t arfcn, ta;
Ivan Kluchnikov61a33f72012-04-12 15:22:06 +040057
58 struct osmo_timer_list timer;
59 unsigned int T; /* Txxxx number */
60 unsigned int num_T_exp; /* number of consecutive T expirations */
61
62 struct osmo_gsm_timer_list gsm_timer;
63 unsigned int fT; /* fTxxxx number */
64 unsigned int num_fT_exp; /* number of consecutive fT expirations */
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040065};
66
67extern struct llist_head gprs_rlcmac_tbfs;
68
69int tfi_alloc();
70
Andreas Eversberg0aed6542012-06-23 10:33:16 +020071struct gprs_rlcmac_tbf *tbf_alloc(uint8_t tfi, uint8_t trx, uint8_t ts);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040072
Andreas Eversberg0aed6542012-06-23 10:33:16 +020073struct gprs_rlcmac_tbf *tbf_by_tfi(uint8_t tfi);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040074
Andreas Eversberg0aed6542012-06-23 10:33:16 +020075struct gprs_rlcmac_tbf *tbf_by_tlli(uint8_t tlli);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040076
Andreas Eversberg0aed6542012-06-23 10:33:16 +020077void tbf_free(struct gprs_rlcmac_tbf *tbf);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040078
79/* TS 44.060 Section 10.4.7 Table 10.4.7.1: Payload Type field */
80enum gprs_rlcmac_block_type {
81 GPRS_RLCMAC_DATA_BLOCK = 0x0,
82 GPRS_RLCMAC_CONTROL_BLOCK = 0x1,
83 GPRS_RLCMAC_CONTROL_BLOCK_OPT = 0x2,
84 GPRS_RLCMAC_RESERVED = 0x3
85};
86
87void gprs_rlcmac_tx_ul_ack(uint8_t tfi, uint32_t tlli, RlcMacUplinkDataBlock_t * ul_data_block);
88
89void gprs_rlcmac_data_block_parse(gprs_rlcmac_tbf* tbf, RlcMacUplinkDataBlock_t * ul_data_block);
90
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +040091int gprs_rlcmac_rcv_data_block(bitvec *rlc_block);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040092
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +040093int gprs_rlcmac_rcv_control_block(bitvec *rlc_block);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040094
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +040095void gprs_rlcmac_rcv_block(bitvec *rlc_block);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040096
Andreas Eversberg0aed6542012-06-23 10:33:16 +020097void gprs_rlcmac_rcv_rts_block(uint8_t trx, uint8_t ts, uint16_t arfcn,
98 uint32_t fn, uint8_t block_nr);
99
100int gprs_rlcmac_rcv_rach(uint8_t ra, uint32_t Fn, int16_t qta);
Ivan Kluchnikov5310d452012-04-17 22:00:31 +0400101
Ivan Kluchnikovc320d862012-03-18 15:04:48 +0400102void 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 +0400103
104int gprs_rlcmac_segment_llc_pdu(struct gprs_rlcmac_tbf *tbf);
105
106void gprs_rlcmac_tx_ul_ud(gprs_rlcmac_tbf *tbf);
107
Ivan Kluchnikovc320d862012-03-18 15:04:48 +0400108void gprs_rlcmac_downlink_assignment(gprs_rlcmac_tbf *tbf);
109
Ivan Kluchnikov9c795ab2012-05-24 23:12:59 +0400110void gprs_rlcmac_packet_downlink_assignment(gprs_rlcmac_tbf *tbf);
111
112
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400113#endif // GPRS_RLCMAC_H