Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1 | /* 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 Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 23 | #include <bitvector.h> |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 24 | #include <gsm_rlcmac.h> |
Ivan Kluchnikov | 61a33f7 | 2012-04-12 15:22:06 +0400 | [diff] [blame] | 25 | #include <gsm_timer.h> |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 26 | |
| 27 | extern "C" { |
| 28 | #include <osmocom/core/linuxlist.h> |
Ivan Kluchnikov | 61a33f7 | 2012-04-12 15:22:06 +0400 | [diff] [blame] | 29 | #include <osmocom/core/timer.h> |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 30 | } |
| 31 | |
Ivan Kluchnikov | c5d8c27 | 2012-06-04 21:55:02 +0400 | [diff] [blame] | 32 | #define LLC_MAX_LEN 1543 |
Ivan Kluchnikov | bceb3fb | 2012-06-05 16:56:27 +0400 | [diff] [blame] | 33 | #define UL_RLC_DATA_BLOCK_LEN 23 |
Ivan Kluchnikov | c5d8c27 | 2012-06-04 21:55:02 +0400 | [diff] [blame] | 34 | |
Ivan Kluchnikov | a9e6dc5 | 2012-06-17 08:30:06 +0400 | [diff] [blame] | 35 | enum gprs_rlcmac_tbf_stage { |
| 36 | TBF_ESTABLISH, |
| 37 | TBF_DATA_TRANSFER, |
| 38 | TBF_RELEASE |
| 39 | }; |
| 40 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 41 | enum gprs_rlcmac_tbf_state { |
Ivan Kluchnikov | a9e6dc5 | 2012-06-17 08:30:06 +0400 | [diff] [blame] | 42 | WAIT_ESTABLISH, |
| 43 | CCCH_ESTABLISH, |
| 44 | PACCH_ESTABLISH, |
| 45 | FINISH_ESTABLISH, |
| 46 | WAIT_DATA_TRANSFER, |
| 47 | DATA_TRANSFER, |
| 48 | FINISH_DATA_TRANSFER, |
| 49 | RELEASE |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | enum gprs_rlcmac_tbf_direction { |
| 53 | GPRS_RLCMAC_DL_TBF, |
| 54 | GPRS_RLCMAC_UL_TBF |
| 55 | }; |
| 56 | |
Ivan Kluchnikov | a9e6dc5 | 2012-06-17 08:30:06 +0400 | [diff] [blame] | 57 | struct tbf_llc_pdu { |
| 58 | struct llist_head list; |
| 59 | uint8_t num; |
| 60 | uint8_t data[LLC_MAX_LEN]; |
| 61 | uint16_t len; |
| 62 | }; |
| 63 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 64 | struct gprs_rlcmac_tbf { |
| 65 | struct llist_head list; |
| 66 | enum gprs_rlcmac_tbf_state state; |
Ivan Kluchnikov | a9e6dc5 | 2012-06-17 08:30:06 +0400 | [diff] [blame] | 67 | enum gprs_rlcmac_tbf_stage stage; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 68 | enum gprs_rlcmac_tbf_direction direction; |
Ivan Kluchnikov | a9e6dc5 | 2012-06-17 08:30:06 +0400 | [diff] [blame] | 69 | struct gprs_rlcmac_tbf *next_tbf; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 70 | uint8_t tfi; |
| 71 | uint32_t tlli; |
Ivan Kluchnikov | a9e6dc5 | 2012-06-17 08:30:06 +0400 | [diff] [blame] | 72 | |
| 73 | struct llist_head llc_pdus; |
| 74 | struct tbf_llc_pdu llc_pdu; |
| 75 | uint8_t llc_pdu_list_len; |
Ivan Kluchnikov | c5d8c27 | 2012-06-04 21:55:02 +0400 | [diff] [blame] | 76 | uint8_t rlc_data[LLC_MAX_LEN]; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 77 | uint16_t data_index; |
| 78 | uint8_t bsn; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 79 | uint8_t trx, ts, tsc; |
| 80 | uint16_t arfcn, ta; |
Ivan Kluchnikov | 61a33f7 | 2012-04-12 15:22:06 +0400 | [diff] [blame] | 81 | |
| 82 | struct osmo_timer_list timer; |
| 83 | unsigned int T; /* Txxxx number */ |
| 84 | unsigned int num_T_exp; /* number of consecutive T expirations */ |
| 85 | |
| 86 | struct osmo_gsm_timer_list gsm_timer; |
| 87 | unsigned int fT; /* fTxxxx number */ |
| 88 | unsigned int num_fT_exp; /* number of consecutive fT expirations */ |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 89 | }; |
| 90 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 91 | /* TS 44.060 Section 10.4.7 Table 10.4.7.1: Payload Type field */ |
| 92 | enum gprs_rlcmac_block_type { |
| 93 | GPRS_RLCMAC_DATA_BLOCK = 0x0, |
| 94 | GPRS_RLCMAC_CONTROL_BLOCK = 0x1, |
| 95 | GPRS_RLCMAC_CONTROL_BLOCK_OPT = 0x2, |
| 96 | GPRS_RLCMAC_RESERVED = 0x3 |
| 97 | }; |
| 98 | |
Ivan Kluchnikov | a9e6dc5 | 2012-06-17 08:30:06 +0400 | [diff] [blame] | 99 | extern struct llist_head gprs_rlcmac_tbfs; |
| 100 | |
Ivan Kluchnikov | cf7b3a5 | 2012-06-26 16:54:22 +0400 | [diff] [blame] | 101 | int select_pdch(uint8_t *_trx, uint8_t *_ts); |
| 102 | |
Ivan Kluchnikov | a9e6dc5 | 2012-06-17 08:30:06 +0400 | [diff] [blame] | 103 | int tfi_alloc(); |
| 104 | |
| 105 | static struct gprs_rlcmac_tbf *tbf_by_tfi(uint8_t tfi, gprs_rlcmac_tbf_direction dir); |
| 106 | |
| 107 | static struct gprs_rlcmac_tbf *tbf_by_tlli(uint32_t tlli, gprs_rlcmac_tbf_direction dir); |
| 108 | |
| 109 | static void tbf_free(struct gprs_rlcmac_tbf *tbf); |
| 110 | |
| 111 | static struct tbf_llc_pdu *tbf_llc_pdu_by_num(struct llist_head llc_pdus, uint8_t num); |
| 112 | |
| 113 | int tbf_add_llc_pdu(struct gprs_rlcmac_tbf *tbf, uint8_t *data, uint16_t llc_pdu_len); |
| 114 | |
| 115 | struct gprs_rlcmac_tbf *tbf_alloc(gprs_rlcmac_tbf_direction dir, uint32_t tlli = 0); |
| 116 | |
Ivan Kluchnikov | cf7b3a5 | 2012-06-26 16:54:22 +0400 | [diff] [blame] | 117 | int tbf_ul_establish(struct gprs_rlcmac_tbf *tbf, uint8_t ra, uint32_t Fn, uint16_t qta); |
Ivan Kluchnikov | a9e6dc5 | 2012-06-17 08:30:06 +0400 | [diff] [blame] | 118 | |
| 119 | int tbf_dl_establish(struct gprs_rlcmac_tbf *tbf, uint8_t *imsi = NULL); |
| 120 | |
| 121 | int tbf_ul_data_transfer(struct gprs_rlcmac_tbf *tbf, RlcMacUplinkDataBlock_t * ul_data_block); |
| 122 | |
| 123 | int tbf_dl_data_transfer(struct gprs_rlcmac_tbf *tbf, uint8_t *llc_pdu = NULL, uint16_t llc_pdu_len = 0); |
| 124 | |
| 125 | int tbf_ul_release(struct gprs_rlcmac_tbf *tbf); |
| 126 | |
| 127 | int tbf_dl_release(struct gprs_rlcmac_tbf *tbf); |
| 128 | |
| 129 | static void tbf_timer_start(struct gprs_rlcmac_tbf *tbf, unsigned int T, unsigned int seconds); |
| 130 | |
| 131 | static void tbf_gsm_timer_start(struct gprs_rlcmac_tbf *tbf, unsigned int fT, int frames); |
| 132 | |
Ivan Kluchnikov | cf7b3a5 | 2012-06-26 16:54:22 +0400 | [diff] [blame] | 133 | int write_immediate_assignment(bitvec * dest, uint8_t downlink, uint8_t ra, uint32_t fn, uint8_t ta, uint16_t arfcn, uint8_t ts, uint8_t tsc, uint8_t tfi, uint32_t tlli = 0); |
Ivan Kluchnikov | a9e6dc5 | 2012-06-17 08:30:06 +0400 | [diff] [blame] | 134 | |
Ivan Kluchnikov | 34460b8 | 2012-06-27 18:41:04 +0400 | [diff] [blame^] | 135 | void gprs_rlcmac_tx_ul_ack(uint8_t tfi, uint32_t tlli, uint8_t ti, uint8_t bsn); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 136 | |
| 137 | void gprs_rlcmac_data_block_parse(gprs_rlcmac_tbf* tbf, RlcMacUplinkDataBlock_t * ul_data_block); |
| 138 | |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 139 | int gprs_rlcmac_rcv_data_block(bitvec *rlc_block); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 140 | |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 141 | int gprs_rlcmac_rcv_control_block(bitvec *rlc_block); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 142 | |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 143 | void gprs_rlcmac_rcv_block(bitvec *rlc_block); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 144 | |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 145 | void gprs_rlcmac_rcv_rts_block(uint8_t trx, uint8_t ts, uint16_t arfcn, |
| 146 | uint32_t fn, uint8_t block_nr); |
| 147 | |
| 148 | int gprs_rlcmac_rcv_rach(uint8_t ra, uint32_t Fn, int16_t qta); |
Ivan Kluchnikov | 5310d45 | 2012-04-17 22:00:31 +0400 | [diff] [blame] | 149 | |
Ivan Kluchnikov | a9e6dc5 | 2012-06-17 08:30:06 +0400 | [diff] [blame] | 150 | int gprs_rlcmac_tx_llc_pdus(struct gprs_rlcmac_tbf *tbf); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 151 | |
| 152 | void gprs_rlcmac_tx_ul_ud(gprs_rlcmac_tbf *tbf); |
| 153 | |
Ivan Kluchnikov | c320d86 | 2012-03-18 15:04:48 +0400 | [diff] [blame] | 154 | void gprs_rlcmac_downlink_assignment(gprs_rlcmac_tbf *tbf); |
| 155 | |
Ivan Kluchnikov | 9c795ab | 2012-05-24 23:12:59 +0400 | [diff] [blame] | 156 | void gprs_rlcmac_packet_downlink_assignment(gprs_rlcmac_tbf *tbf); |
| 157 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 158 | #endif // GPRS_RLCMAC_H |