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 | |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame^] | 32 | /* |
| 33 | * PDCH instanc |
| 34 | */ |
| 35 | |
| 36 | struct gprs_rlcmac_tbf; |
| 37 | |
| 38 | struct 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 | |
| 46 | struct gprs_rlcmac_trx { |
| 47 | uint16_t arfcn; |
| 48 | struct gprs_rlcmac_pdch pdch[8]; |
| 49 | }; |
| 50 | |
| 51 | struct gprs_rlcmac_bts { |
| 52 | struct gprs_rlcmac_trx trx[8]; |
| 53 | }; |
| 54 | |
| 55 | extern struct gprs_rlcmac_bts *gprs_rlcmac_bts; |
| 56 | |
| 57 | /* |
| 58 | * TBF instance |
| 59 | */ |
| 60 | |
Ivan Kluchnikov | c5d8c27 | 2012-06-04 21:55:02 +0400 | [diff] [blame] | 61 | #define LLC_MAX_LEN 1543 |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame^] | 62 | #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 Kluchnikov | bceb3fb | 2012-06-05 16:56:27 +0400 | [diff] [blame] | 65 | #define UL_RLC_DATA_BLOCK_LEN 23 |
Ivan Kluchnikov | c5d8c27 | 2012-06-04 21:55:02 +0400 | [diff] [blame] | 66 | |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame^] | 67 | #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 Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 71 | enum gprs_rlcmac_tbf_state { |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame^] | 72 | 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 | |
| 77 | enum gprs_rlcmac_tbf_poll_state { |
| 78 | GPRS_RLCMAC_POLL_NONE = 0, |
| 79 | GPRS_RLCMAC_POLL_SCHED, /* a polling was scheduled */ |
| 80 | }; |
| 81 | |
| 82 | enum 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 Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | enum gprs_rlcmac_tbf_direction { |
| 89 | GPRS_RLCMAC_DL_TBF, |
| 90 | GPRS_RLCMAC_UL_TBF |
| 91 | }; |
| 92 | |
| 93 | struct 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 Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame^] | 99 | uint8_t tlli_valid; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 100 | uint8_t trx, ts, tsc; |
| 101 | uint16_t arfcn, ta; |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame^] | 102 | 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 Kluchnikov | 61a33f7 | 2012-04-12 15:22:06 +0400 | [diff] [blame] | 129 | |
| 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 Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | extern struct llist_head gprs_rlcmac_tbfs; |
| 140 | |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame^] | 141 | int tfi_alloc(uint8_t *_trx, uint8_t *_ts); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 142 | |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 143 | struct gprs_rlcmac_tbf *tbf_alloc(uint8_t tfi, uint8_t trx, uint8_t ts); |
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 | struct gprs_rlcmac_tbf *tbf_by_tfi(uint8_t tfi); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 146 | |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 147 | struct gprs_rlcmac_tbf *tbf_by_tlli(uint8_t tlli); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 148 | |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 149 | void tbf_free(struct gprs_rlcmac_tbf *tbf); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 150 | |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame^] | 151 | void tbf_timer_start(struct gprs_rlcmac_tbf *tbf, unsigned int T, |
| 152 | unsigned int seconds); |
| 153 | |
| 154 | void tbf_timer_stop(struct gprs_rlcmac_tbf *tbf); |
| 155 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 156 | /* TS 44.060 Section 10.4.7 Table 10.4.7.1: Payload Type field */ |
| 157 | enum 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 | |
| 164 | void gprs_rlcmac_tx_ul_ack(uint8_t tfi, uint32_t tlli, RlcMacUplinkDataBlock_t * ul_data_block); |
| 165 | |
| 166 | void gprs_rlcmac_data_block_parse(gprs_rlcmac_tbf* tbf, RlcMacUplinkDataBlock_t * ul_data_block); |
| 167 | |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 168 | int gprs_rlcmac_rcv_data_block(bitvec *rlc_block); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 169 | |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 170 | int gprs_rlcmac_rcv_control_block(bitvec *rlc_block); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 171 | |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame^] | 172 | int gprs_rlcmac_rcv_block(uint8_t *data, uint8_t len, uint32_t fn); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 173 | |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame^] | 174 | int gprs_rlcmac_rcv_rts_block(uint8_t trx, uint8_t ts, uint16_t arfcn, |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 175 | uint32_t fn, uint8_t block_nr); |
| 176 | |
| 177 | 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] | 178 | |
Ivan Kluchnikov | c320d86 | 2012-03-18 15:04:48 +0400 | [diff] [blame] | 179 | void 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 Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 180 | |
| 181 | int gprs_rlcmac_segment_llc_pdu(struct gprs_rlcmac_tbf *tbf); |
| 182 | |
| 183 | void gprs_rlcmac_tx_ul_ud(gprs_rlcmac_tbf *tbf); |
| 184 | |
Ivan Kluchnikov | c320d86 | 2012-03-18 15:04:48 +0400 | [diff] [blame] | 185 | void gprs_rlcmac_downlink_assignment(gprs_rlcmac_tbf *tbf); |
| 186 | |
Ivan Kluchnikov | 9c795ab | 2012-05-24 23:12:59 +0400 | [diff] [blame] | 187 | void gprs_rlcmac_packet_downlink_assignment(gprs_rlcmac_tbf *tbf); |
| 188 | |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame^] | 189 | void gprs_rlcmac_enqueue_block(bitvec *block, int len); |
| 190 | |
| 191 | int gprs_rlcmac_rcv_data_block_acknowledged(uint8_t *data, uint8_t len); |
| 192 | |
| 193 | struct msgb *gprs_rlcmac_send_uplink_ack(struct gprs_rlcmac_tbf *tbf, |
| 194 | uint32_t fn); |
Ivan Kluchnikov | 9c795ab | 2012-05-24 23:12:59 +0400 | [diff] [blame] | 195 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 196 | #endif // GPRS_RLCMAC_H |