2013-10-26 15:32:04 +00:00
|
|
|
/* rlc header descriptions
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Ivan Klyuchnikov
|
|
|
|
* Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
#pragma once
|
2021-01-18 16:14:14 +00:00
|
|
|
#ifdef __cplusplus
|
2020-05-18 09:35:35 +00:00
|
|
|
extern "C" {
|
2021-01-18 16:14:14 +00:00
|
|
|
#endif
|
2015-12-08 14:14:05 +00:00
|
|
|
|
2021-01-18 16:14:14 +00:00
|
|
|
#include "coding_scheme.h"
|
2015-12-14 10:13:30 +00:00
|
|
|
#include <osmocom/core/endian.h>
|
|
|
|
|
2021-01-18 16:14:14 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-10-26 15:32:04 +00:00
|
|
|
#include <stdint.h>
|
2018-05-16 13:20:39 +00:00
|
|
|
#include <string.h>
|
2013-10-26 15:32:04 +00:00
|
|
|
|
2015-12-28 12:51:44 +00:00
|
|
|
#define RLC_GPRS_SNS 128 /* GPRS, must be power of 2 */
|
|
|
|
#define RLC_GPRS_WS 64 /* max window size */
|
|
|
|
#define RLC_EGPRS_MIN_WS 64 /* min window size */
|
|
|
|
#define RLC_EGPRS_MAX_WS 1024 /* min window size */
|
|
|
|
#define RLC_EGPRS_SNS 2048 /* EGPRS, must be power of 2 */
|
edge: Send a second BSN block in an RLC message if possible
Currently only one BSN block is encoded in each RLC data message,
even if MSC7-9 are used, which transport two independant (except for a
max BSN delta of 512) BSN blocks. In that case, the same block is
just put twice into the same message.
The current create_dl_acked_block(fn, ts) method handles
block selection (resend, new BSN, dummy block, ...) and restart
handling in one method and is too complex to extend it accordingly.
Therefore this commit move the block selection/creation handling into
a new method (take_next_bsn) which delivers the next BSN along with a
hint, whether it may be combined with another block. In that case,
the function can be called a second time (this time with a valid
previous BSN, that's the one returned by the first call) to get the
second BSN. The real block generation method
create_dl_acked_block(fn, ts, index, index2) is then called with both
BSNs as indices (the second must be -1, if there is only one BSN).
Note that every BSN returned by take_next_bsn should be passed to
create_dl_acked_block to avoid state inconsistencies.
Sponsored-by: On-Waves ehf
2016-02-02 17:12:46 +00:00
|
|
|
#define RLC_EGPRS_MAX_BSN_DELTA 512
|
2015-12-28 12:51:44 +00:00
|
|
|
#define RLC_MAX_SNS RLC_EGPRS_SNS
|
2016-02-05 16:07:12 +00:00
|
|
|
#define RLC_MAX_WS RLC_EGPRS_MAX_WS
|
2015-12-28 12:51:44 +00:00
|
|
|
#define RLC_MAX_LEN 74 /* MCS-9 data unit */
|
2013-11-23 15:10:48 +00:00
|
|
|
|
2021-01-14 15:48:38 +00:00
|
|
|
struct gprs_rlcmac_bts;
|
2013-11-23 15:10:48 +00:00
|
|
|
|
2013-12-28 20:16:13 +00:00
|
|
|
/* The state of a BSN in the send/receive window */
|
|
|
|
enum gprs_rlc_ul_bsn_state {
|
|
|
|
GPRS_RLC_UL_BSN_INVALID,
|
|
|
|
GPRS_RLC_UL_BSN_RECEIVED,
|
|
|
|
GPRS_RLC_UL_BSN_MISSING,
|
|
|
|
GPRS_RLC_UL_BSN_MAX,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum gprs_rlc_dl_bsn_state {
|
|
|
|
GPRS_RLC_DL_BSN_INVALID,
|
|
|
|
GPRS_RLC_DL_BSN_NACKED,
|
|
|
|
GPRS_RLC_DL_BSN_ACKED,
|
|
|
|
GPRS_RLC_DL_BSN_UNACKED,
|
|
|
|
GPRS_RLC_DL_BSN_RESEND,
|
|
|
|
GPRS_RLC_DL_BSN_MAX,
|
|
|
|
};
|
|
|
|
|
2016-07-26 11:43:59 +00:00
|
|
|
/*
|
|
|
|
* EGPRS resegment status information for UL
|
|
|
|
* When only first split block is received bsn state
|
|
|
|
* will be set to EGPRS_RESEG_FIRST_SEG_RXD and when
|
|
|
|
* only second segment is received the state will be
|
|
|
|
* set to EGPRS_RESEG_SECOND_SEG_RXD. When both Split
|
|
|
|
* blocks are received the state will be set to
|
|
|
|
* EGPRS_RESEG_DEFAULT
|
|
|
|
* The EGPRS resegmentation feature allows MS to retransmit
|
|
|
|
* RLC blocks of HeaderType1, HeaderType2 by segmenting
|
|
|
|
* them to 2 HeaderType3 blocks(Example MCS5 will be
|
|
|
|
* retransmitted as 2 MCS2 blocks). Table 10.4.8b.1 of 44.060
|
|
|
|
* explains the possible values of SPB in HeadrType3 for UL
|
|
|
|
* direction. When the MCS is changed at the PCU, PCU directs the
|
|
|
|
* changed MCS to MS by PUAN or UPLINK ASSIGNMENT message along
|
|
|
|
* with RESEGMENT flag, Then MS may decide to retransmit the
|
|
|
|
* blocks by resegmenting it based on Table 8.1.1.1 of 44.060.
|
|
|
|
* The retransmission MCS is calculated based on current MCS of
|
|
|
|
* the Block and demanded MCS by PCU. Section 10.3a.4.3 of 44.060
|
|
|
|
* shows the HeadrType3 with SPB field present in it
|
|
|
|
*/
|
|
|
|
enum egprs_rlc_ul_reseg_bsn_state {
|
|
|
|
EGPRS_RESEG_DEFAULT = 0,
|
|
|
|
EGPRS_RESEG_FIRST_SEG_RXD = 0x01,
|
|
|
|
EGPRS_RESEG_SECOND_SEG_RXD = 0x02,
|
|
|
|
EGPRS_RESEG_INVALID = 0x04
|
|
|
|
};
|
|
|
|
|
2016-08-16 11:02:59 +00:00
|
|
|
/*
|
|
|
|
* EGPRS resegment status information for DL
|
|
|
|
* When only first segment is sent, bsn state
|
|
|
|
* will be set to EGPRS_RESEG_FIRST_SEG_SENT and when
|
|
|
|
* second segment is sent the state will be
|
|
|
|
* set to EGPRS_RESEG_SECOND_SEG_SENT.
|
|
|
|
* EGPRS_RESEG_DL_INVALID is set to 8 considering there is a scope for
|
|
|
|
* 3rd segment according to Table 10.4.8b.2 of 44.060
|
|
|
|
* The EGPRS resegmentation feature allows PCU to retransmit
|
|
|
|
* RLC blocks of HeaderType1, HeaderType2 by segmenting
|
|
|
|
* them to 2 HeaderType3 blocks(Example MCS5 will be
|
|
|
|
* retransmitted as 2 MCS2 blocks). Table 10.4.8b.2 of 44.060
|
|
|
|
* explains the possible values of SPB in HeadrType3 for DL
|
|
|
|
* direction.The PCU decides to retransmit the
|
|
|
|
* blocks by resegmenting it based on Table 8.1.1.1 of 44.060.
|
|
|
|
* The retransmission MCS is calculated based on current MCS of
|
|
|
|
* the Block and demanded MCS by PCU. Section 10.3a.3.3 of 44.060
|
|
|
|
* shows the HeadrType3 with SPB field present in it
|
|
|
|
*/
|
|
|
|
enum egprs_rlc_dl_reseg_bsn_state {
|
|
|
|
EGPRS_RESEG_DL_DEFAULT = 0,
|
|
|
|
EGPRS_RESEG_FIRST_SEG_SENT = 0x01,
|
|
|
|
EGPRS_RESEG_SECOND_SEG_SENT = 0x02,
|
|
|
|
EGPRS_RESEG_DL_INVALID = 0x08
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Table 10.4.8b.2 of 44.060 */
|
|
|
|
enum egprs_rlcmac_dl_spb {
|
|
|
|
EGPRS_RLCMAC_DL_NO_RETX = 0,
|
|
|
|
EGPRS_RLCMAC_DL_FIRST_SEG = 2,
|
|
|
|
EGPRS_RLCMAC_DL_SEC_SEG = 3,
|
|
|
|
};
|
|
|
|
|
2016-03-23 12:59:45 +00:00
|
|
|
/*
|
|
|
|
* Valid puncturing scheme values
|
|
|
|
* TS 44.060 10.4.8a.3.1, 10.4.8a.2.1, 10.4.8a.1.1
|
|
|
|
*/
|
|
|
|
enum egprs_puncturing_values {
|
|
|
|
EGPRS_PS_1,
|
|
|
|
EGPRS_PS_2,
|
|
|
|
EGPRS_PS_3,
|
|
|
|
EGPRS_PS_INVALID,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* EGPRS_MAX_PS_NUM_2 is valid for MCS 1,2,5,6.
|
|
|
|
* And EGPRS_MAX_PS_NUM_3 is valid for MCS 3,4,7,8,9
|
|
|
|
* TS 44.060 10.4.8a.3.1, 10.4.8a.2.1, 10.4.8a.1.1
|
|
|
|
*/
|
|
|
|
enum egprs_puncturing_types {
|
|
|
|
EGPRS_MAX_PS_NUM_2 = 2,
|
|
|
|
EGPRS_MAX_PS_NUM_3,
|
|
|
|
EGPRS_MAX_PS_NUM_INVALID,
|
|
|
|
};
|
2013-11-26 20:43:58 +00:00
|
|
|
|
|
|
|
static inline uint16_t mod_sns_half()
|
|
|
|
{
|
|
|
|
return (RLC_MAX_SNS / 2) - 1;
|
|
|
|
}
|
|
|
|
|
2016-01-07 17:59:28 +00:00
|
|
|
struct gprs_rlc_data_block_info {
|
2015-12-08 14:14:05 +00:00
|
|
|
unsigned int data_len; /* EGPRS: N2, GPRS: N2-2, N-2 */
|
|
|
|
unsigned int bsn;
|
|
|
|
unsigned int ti;
|
|
|
|
unsigned int e;
|
2016-01-11 11:53:08 +00:00
|
|
|
unsigned int cv; /* FBI == 1 <=> CV == 0 */
|
2015-12-08 14:14:05 +00:00
|
|
|
unsigned int pi;
|
|
|
|
unsigned int spb;
|
|
|
|
};
|
|
|
|
|
2016-01-07 17:59:28 +00:00
|
|
|
struct gprs_rlc_data_info {
|
2020-05-18 09:35:35 +00:00
|
|
|
enum CodingScheme cs;
|
2015-12-08 14:14:05 +00:00
|
|
|
unsigned int r;
|
|
|
|
unsigned int si;
|
|
|
|
unsigned int tfi;
|
|
|
|
unsigned int cps;
|
|
|
|
unsigned int rsb;
|
2016-01-11 11:53:08 +00:00
|
|
|
unsigned int usf;
|
|
|
|
unsigned int es_p;
|
|
|
|
unsigned int rrbp;
|
|
|
|
unsigned int pr;
|
2017-12-21 11:11:33 +00:00
|
|
|
uint8_t num_data_blocks; /* this can actually be only 0, 1, 2: enforced in gprs_rlc_data_header_init() */
|
2016-02-03 17:28:04 +00:00
|
|
|
unsigned int with_padding;
|
2015-12-08 14:14:05 +00:00
|
|
|
unsigned int data_offs_bits[2];
|
2016-01-07 17:59:28 +00:00
|
|
|
struct gprs_rlc_data_block_info block_info[2];
|
2015-12-08 14:14:05 +00:00
|
|
|
};
|
|
|
|
|
2016-07-26 11:43:59 +00:00
|
|
|
/* holds the current status of the block w.r.t UL/DL split blocks */
|
|
|
|
union split_block_status {
|
|
|
|
egprs_rlc_ul_reseg_bsn_state block_status_ul;
|
2016-08-16 11:02:59 +00:00
|
|
|
egprs_rlc_dl_reseg_bsn_state block_status_dl;
|
2016-07-26 11:43:59 +00:00
|
|
|
};
|
|
|
|
|
2013-11-23 15:10:48 +00:00
|
|
|
struct gprs_rlc_data {
|
2016-05-30 17:53:13 +00:00
|
|
|
/* block data including LI headers */
|
2013-11-23 15:10:48 +00:00
|
|
|
uint8_t block[RLC_MAX_LEN];
|
2016-05-30 17:53:13 +00:00
|
|
|
/* block data len including LI headers*/
|
2013-11-23 15:10:48 +00:00
|
|
|
uint8_t len;
|
2015-06-04 10:12:32 +00:00
|
|
|
|
2016-01-07 17:59:28 +00:00
|
|
|
struct gprs_rlc_data_block_info block_info;
|
2016-07-12 08:47:12 +00:00
|
|
|
/*
|
|
|
|
* cs_current_trans is variable to hold the cs_last value for
|
|
|
|
* current transmission. cs_current_trans is same as cs_last during
|
|
|
|
* transmission case. during retransmission cs_current_trans is
|
|
|
|
* fetched from egprs_mcs_retx_tbl table based on
|
|
|
|
* cs and demanded cs.reference is 44.060 Table
|
|
|
|
* 8.1.1.1 and Table 8.1.1.2
|
|
|
|
* For UL. cs_last shall be used everywhere.
|
|
|
|
*/
|
2020-05-18 09:35:35 +00:00
|
|
|
enum CodingScheme cs_current_trans;
|
|
|
|
enum CodingScheme cs_last;
|
2016-03-23 12:59:45 +00:00
|
|
|
|
2016-08-16 11:02:59 +00:00
|
|
|
/*
|
|
|
|
* The MCS of initial transmission of a BSN
|
|
|
|
* This variable is used for split block
|
|
|
|
* processing in DL
|
|
|
|
*/
|
2020-05-18 09:35:35 +00:00
|
|
|
enum CodingScheme cs_init;
|
2016-08-16 11:02:59 +00:00
|
|
|
|
2016-03-23 12:59:45 +00:00
|
|
|
/* puncturing scheme value to be used for next transmission*/
|
|
|
|
enum egprs_puncturing_values next_ps;
|
2016-07-26 11:43:59 +00:00
|
|
|
|
|
|
|
/* holds the status of the block w.r.t UL/DL split blocks*/
|
|
|
|
union split_block_status spb_status;
|
2013-11-23 15:10:48 +00:00
|
|
|
};
|
|
|
|
|
2020-05-18 09:02:39 +00:00
|
|
|
uint8_t *prepare(struct gprs_rlc_data *rlc, size_t block_data_length);
|
|
|
|
|
2016-01-11 10:15:45 +00:00
|
|
|
void gprs_rlc_data_info_init_dl(struct gprs_rlc_data_info *rlc,
|
2020-05-18 09:35:35 +00:00
|
|
|
enum CodingScheme cs, bool with_padding, const unsigned int spb);
|
2016-01-11 10:15:45 +00:00
|
|
|
void gprs_rlc_data_info_init_ul(struct gprs_rlc_data_info *rlc,
|
2020-05-18 09:35:35 +00:00
|
|
|
enum CodingScheme cs, bool with_padding);
|
2016-01-11 10:15:45 +00:00
|
|
|
void gprs_rlc_data_block_info_init(struct gprs_rlc_data_block_info *rdbi,
|
2020-05-18 09:35:35 +00:00
|
|
|
enum CodingScheme cs, bool with_padding, const unsigned int spb);
|
|
|
|
unsigned int gprs_rlc_mcs_cps(enum CodingScheme cs, enum egprs_puncturing_values
|
2017-12-21 11:11:33 +00:00
|
|
|
punct, enum egprs_puncturing_values punct2, bool with_padding);
|
2020-05-18 09:35:35 +00:00
|
|
|
void gprs_rlc_mcs_cps_decode(unsigned int cps, enum CodingScheme cs,
|
2016-02-03 17:31:19 +00:00
|
|
|
int *punct, int *punct2, int *with_padding);
|
2016-03-23 12:59:47 +00:00
|
|
|
enum egprs_puncturing_values gprs_get_punct_scheme(enum egprs_puncturing_values
|
2020-05-18 09:35:35 +00:00
|
|
|
punct, const enum CodingScheme &cs,
|
|
|
|
const enum CodingScheme &cs_current_trans,
|
2016-08-22 11:51:10 +00:00
|
|
|
const enum egprs_rlcmac_dl_spb spb);
|
2016-03-23 12:59:47 +00:00
|
|
|
void gprs_update_punct_scheme(enum egprs_puncturing_values *punct,
|
2020-05-18 09:35:35 +00:00
|
|
|
const enum CodingScheme &cs);
|
2013-11-23 15:10:48 +00:00
|
|
|
/*
|
|
|
|
* I hold the currently transferred blocks and will provide
|
|
|
|
* the routines to manipulate these arrays.
|
|
|
|
*/
|
|
|
|
struct gprs_rlc {
|
2018-05-16 13:20:39 +00:00
|
|
|
void init();
|
2013-11-26 20:43:58 +00:00
|
|
|
gprs_rlc_data *block(int bsn);
|
|
|
|
gprs_rlc_data m_blocks[RLC_MAX_SNS/2];
|
2013-11-23 15:10:48 +00:00
|
|
|
};
|
|
|
|
|
2013-12-28 17:24:42 +00:00
|
|
|
/**
|
|
|
|
* TODO: for GPRS/EDGE maybe make sns a template parameter
|
|
|
|
* so we create specialized versions...
|
|
|
|
*/
|
|
|
|
struct gprs_rlc_v_b {
|
|
|
|
/* Check for an individual frame */
|
|
|
|
bool is_unacked(int bsn) const;
|
|
|
|
bool is_nacked(int bsn) const;
|
|
|
|
bool is_acked(int bsn) const;
|
|
|
|
bool is_resend(int bsn) const;
|
|
|
|
bool is_invalid(int bsn) const;
|
2013-12-28 20:16:13 +00:00
|
|
|
gprs_rlc_dl_bsn_state get_state(int bsn) const;
|
2013-12-28 17:24:42 +00:00
|
|
|
|
|
|
|
/* Mark a RLC frame for something */
|
|
|
|
void mark_unacked(int bsn);
|
|
|
|
void mark_nacked(int bsn);
|
|
|
|
void mark_acked(int bsn);
|
|
|
|
void mark_resend(int bsn);
|
|
|
|
void mark_invalid(int bsn);
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2013-12-28 20:16:13 +00:00
|
|
|
bool is_state(int bsn, const gprs_rlc_dl_bsn_state state) const;
|
|
|
|
void mark(int bsn, const gprs_rlc_dl_bsn_state state);
|
2013-12-28 17:24:42 +00:00
|
|
|
|
2013-12-28 20:16:13 +00:00
|
|
|
gprs_rlc_dl_bsn_state m_v_b[RLC_MAX_SNS/2]; /* acknowledge state array */
|
2013-12-28 17:24:42 +00:00
|
|
|
};
|
|
|
|
|
2013-11-24 19:36:36 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-28 18:15:40 +00:00
|
|
|
* TODO: The UL/DL code could/should share a base class.
|
2013-11-24 19:36:36 +00:00
|
|
|
*/
|
2016-01-19 13:07:33 +00:00
|
|
|
class gprs_rlc_window {
|
|
|
|
public:
|
|
|
|
gprs_rlc_window();
|
|
|
|
|
2013-11-24 19:36:36 +00:00
|
|
|
const uint16_t mod_sns() const;
|
2015-12-23 15:29:07 +00:00
|
|
|
const uint16_t mod_sns(uint16_t bsn) const;
|
2013-11-24 19:36:36 +00:00
|
|
|
const uint16_t sns() const;
|
|
|
|
const uint16_t ws() const;
|
|
|
|
|
2016-01-19 13:07:33 +00:00
|
|
|
void set_sns(uint16_t sns);
|
|
|
|
void set_ws(uint16_t ws);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
uint16_t m_sns;
|
|
|
|
uint16_t m_ws;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gprs_rlc_dl_window: public gprs_rlc_window {
|
|
|
|
void reset();
|
|
|
|
|
2013-11-24 19:36:36 +00:00
|
|
|
bool window_stalled() const;
|
|
|
|
bool window_empty() const;
|
|
|
|
|
|
|
|
void increment_send();
|
|
|
|
void raise(int moves);
|
|
|
|
|
|
|
|
const uint16_t v_s() const;
|
|
|
|
const uint16_t v_s_mod(int offset) const;
|
|
|
|
const uint16_t v_a() const;
|
2016-11-02 10:11:48 +00:00
|
|
|
const uint16_t distance() const;
|
2013-11-24 19:36:36 +00:00
|
|
|
|
2013-12-28 17:24:42 +00:00
|
|
|
/* Methods to manage reception */
|
2017-12-13 17:25:36 +00:00
|
|
|
int resend_needed() const;
|
2013-12-28 17:24:42 +00:00
|
|
|
int mark_for_resend();
|
2021-01-14 15:48:38 +00:00
|
|
|
void update(struct gprs_rlcmac_bts *bts, char *show_rbb, uint16_t ssn,
|
2013-12-28 17:24:42 +00:00
|
|
|
uint16_t *lost, uint16_t *received);
|
2021-01-14 15:48:38 +00:00
|
|
|
void update(struct gprs_rlcmac_bts *bts, const struct bitvec *rbb,
|
2016-02-05 16:07:12 +00:00
|
|
|
uint16_t first_bsn, uint16_t *lost,
|
|
|
|
uint16_t *received);
|
2013-12-28 17:24:42 +00:00
|
|
|
int move_window();
|
2014-01-15 11:45:56 +00:00
|
|
|
void show_state(char *show_rbb);
|
2013-12-28 17:24:42 +00:00
|
|
|
int count_unacked();
|
|
|
|
|
2013-11-24 19:36:36 +00:00
|
|
|
uint16_t m_v_s; /* send state */
|
|
|
|
uint16_t m_v_a; /* ack state */
|
2013-12-28 17:24:42 +00:00
|
|
|
|
|
|
|
gprs_rlc_v_b m_v_b;
|
2015-12-28 12:46:32 +00:00
|
|
|
|
|
|
|
gprs_rlc_dl_window();
|
2013-11-24 19:36:36 +00:00
|
|
|
};
|
|
|
|
|
2013-12-28 12:59:24 +00:00
|
|
|
struct gprs_rlc_v_n {
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
void mark_received(int bsn);
|
|
|
|
void mark_missing(int bsn);
|
|
|
|
|
|
|
|
bool is_received(int bsn) const;
|
|
|
|
|
2013-12-28 20:16:13 +00:00
|
|
|
gprs_rlc_ul_bsn_state state(int bsn) const;
|
2013-12-28 12:59:24 +00:00
|
|
|
private:
|
2013-12-28 20:16:13 +00:00
|
|
|
bool is_state(int bsn, const gprs_rlc_ul_bsn_state state) const;
|
|
|
|
void mark(int bsn, const gprs_rlc_ul_bsn_state state);
|
|
|
|
gprs_rlc_ul_bsn_state m_v_n[RLC_MAX_SNS/2]; /* receive state array */
|
2013-12-28 12:59:24 +00:00
|
|
|
};
|
|
|
|
|
2016-01-19 13:07:33 +00:00
|
|
|
struct gprs_rlc_ul_window: public gprs_rlc_window {
|
2013-11-24 19:36:36 +00:00
|
|
|
const uint16_t v_r() const;
|
|
|
|
const uint16_t v_q() const;
|
|
|
|
|
2017-01-24 10:23:35 +00:00
|
|
|
const void set_v_r(int);
|
|
|
|
const void set_v_q(int);
|
2017-12-15 10:08:58 +00:00
|
|
|
void reset_state();
|
2017-01-24 10:23:35 +00:00
|
|
|
|
2013-11-27 16:08:35 +00:00
|
|
|
const uint16_t ssn() const;
|
|
|
|
|
2015-12-23 15:40:56 +00:00
|
|
|
bool is_in_window(uint16_t bsn) const;
|
|
|
|
bool is_received(uint16_t bsn) const;
|
2013-11-24 21:43:03 +00:00
|
|
|
|
2013-12-28 12:59:24 +00:00
|
|
|
void update_rbb(char *rbb);
|
2017-01-16 10:11:21 +00:00
|
|
|
uint16_t update_egprs_rbb(uint8_t *rbb);
|
2013-12-28 12:57:31 +00:00
|
|
|
void raise_v_r_to(int moves);
|
2013-12-28 12:59:24 +00:00
|
|
|
void raise_v_r(const uint16_t bsn);
|
|
|
|
uint16_t raise_v_q();
|
2013-11-25 22:26:06 +00:00
|
|
|
|
2013-11-25 22:51:19 +00:00
|
|
|
void raise_v_q(int);
|
2013-11-24 19:36:36 +00:00
|
|
|
|
2015-12-14 10:43:04 +00:00
|
|
|
void receive_bsn(const uint16_t bsn);
|
2015-12-14 10:54:29 +00:00
|
|
|
bool invalidate_bsn(const uint16_t bsn);
|
2013-12-28 13:41:00 +00:00
|
|
|
|
2013-11-24 19:36:36 +00:00
|
|
|
uint16_t m_v_r; /* receive state */
|
|
|
|
uint16_t m_v_q; /* receive window state */
|
2013-12-28 12:59:24 +00:00
|
|
|
|
|
|
|
gprs_rlc_v_n m_v_n;
|
2015-12-28 12:46:32 +00:00
|
|
|
|
|
|
|
gprs_rlc_ul_window();
|
2013-11-24 19:36:36 +00:00
|
|
|
};
|
|
|
|
|
2013-10-26 15:32:04 +00:00
|
|
|
extern "C" {
|
2021-02-01 12:06:45 +00:00
|
|
|
/* TS 44.060 10.2.2 */
|
2013-10-26 15:32:04 +00:00
|
|
|
struct rlc_ul_header {
|
2021-02-04 11:59:27 +00:00
|
|
|
#if OSMO_IS_LITTLE_ENDIAN
|
2013-10-26 15:32:04 +00:00
|
|
|
uint8_t r:1,
|
|
|
|
si:1,
|
|
|
|
cv:4,
|
|
|
|
pt:2;
|
|
|
|
uint8_t ti:1,
|
|
|
|
tfi:5,
|
|
|
|
pi:1,
|
|
|
|
spare:1;
|
|
|
|
uint8_t e:1,
|
|
|
|
bsn:7;
|
2021-02-04 11:59:27 +00:00
|
|
|
#elif OSMO_IS_BIG_ENDIAN
|
|
|
|
/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
|
|
|
|
uint8_t pt:2, cv:4, si:1, r:1;
|
|
|
|
uint8_t spare:1, pi:1, tfi:5, ti:1;
|
|
|
|
uint8_t bsn:7, e:1;
|
|
|
|
#endif
|
2013-10-26 15:32:04 +00:00
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
struct rlc_dl_header {
|
2021-02-04 11:59:27 +00:00
|
|
|
#if OSMO_IS_LITTLE_ENDIAN
|
2013-10-26 15:32:04 +00:00
|
|
|
uint8_t usf:3,
|
|
|
|
s_p:1,
|
|
|
|
rrbp:2,
|
|
|
|
pt:2;
|
|
|
|
uint8_t fbi:1,
|
|
|
|
tfi:5,
|
|
|
|
pr:2;
|
|
|
|
uint8_t e:1,
|
|
|
|
bsn:7;
|
2021-02-04 11:59:27 +00:00
|
|
|
#elif OSMO_IS_BIG_ENDIAN
|
|
|
|
/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
|
|
|
|
uint8_t pt:2, rrbp:2, s_p:1, usf:3;
|
|
|
|
uint8_t pr:2, tfi:5, fbi:1;
|
|
|
|
uint8_t bsn:7, e:1;
|
|
|
|
#endif
|
2013-10-26 15:32:04 +00:00
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
struct rlc_li_field {
|
2021-02-04 11:59:27 +00:00
|
|
|
#if OSMO_IS_LITTLE_ENDIAN
|
2013-10-26 15:32:04 +00:00
|
|
|
uint8_t e:1,
|
|
|
|
m:1,
|
|
|
|
li:6;
|
2021-02-04 11:59:27 +00:00
|
|
|
#elif OSMO_IS_BIG_ENDIAN
|
|
|
|
/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
|
|
|
|
uint8_t li:6, m:1, e:1;
|
|
|
|
#endif
|
2013-10-26 15:32:04 +00:00
|
|
|
} __attribute__ ((packed));
|
2015-12-08 14:14:05 +00:00
|
|
|
|
|
|
|
struct rlc_li_field_egprs {
|
2021-02-04 11:59:27 +00:00
|
|
|
#if OSMO_IS_LITTLE_ENDIAN
|
2015-12-08 14:14:05 +00:00
|
|
|
uint8_t e:1,
|
|
|
|
li:7;
|
2021-02-04 11:59:27 +00:00
|
|
|
#elif OSMO_IS_BIG_ENDIAN
|
|
|
|
/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
|
|
|
|
uint8_t li:7, e:1;
|
2015-12-14 10:13:30 +00:00
|
|
|
#endif
|
2021-02-04 11:59:27 +00:00
|
|
|
} __attribute__ ((packed));
|
2013-10-26 15:32:04 +00:00
|
|
|
}
|
2013-11-23 15:10:48 +00:00
|
|
|
|
2013-12-28 20:16:13 +00:00
|
|
|
inline bool gprs_rlc_v_b::is_state(int bsn, const gprs_rlc_dl_bsn_state type) const
|
2013-11-23 15:10:48 +00:00
|
|
|
{
|
2013-11-26 20:43:58 +00:00
|
|
|
return m_v_b[bsn & mod_sns_half()] == type;
|
2013-11-23 15:10:48 +00:00
|
|
|
}
|
|
|
|
|
2013-12-28 20:16:13 +00:00
|
|
|
inline void gprs_rlc_v_b::mark(int bsn, const gprs_rlc_dl_bsn_state type)
|
2013-11-23 15:10:48 +00:00
|
|
|
{
|
2013-11-26 20:43:58 +00:00
|
|
|
m_v_b[bsn & mod_sns_half()] = type;
|
2013-11-23 15:10:48 +00:00
|
|
|
}
|
|
|
|
|
2013-11-26 20:43:58 +00:00
|
|
|
inline bool gprs_rlc_v_b::is_nacked(int bsn) const
|
2013-11-23 15:10:48 +00:00
|
|
|
{
|
2013-12-28 20:16:13 +00:00
|
|
|
return is_state(bsn, GPRS_RLC_DL_BSN_NACKED);
|
2013-11-23 15:10:48 +00:00
|
|
|
}
|
|
|
|
|
2013-11-26 20:43:58 +00:00
|
|
|
inline bool gprs_rlc_v_b::is_acked(int bsn) const
|
2013-11-23 15:10:48 +00:00
|
|
|
{
|
2013-12-28 20:16:13 +00:00
|
|
|
return is_state(bsn, GPRS_RLC_DL_BSN_ACKED);
|
2013-11-23 15:10:48 +00:00
|
|
|
}
|
|
|
|
|
2013-11-26 20:43:58 +00:00
|
|
|
inline bool gprs_rlc_v_b::is_unacked(int bsn) const
|
2013-11-23 15:10:48 +00:00
|
|
|
{
|
2013-12-28 20:16:13 +00:00
|
|
|
return is_state(bsn, GPRS_RLC_DL_BSN_UNACKED);
|
2013-11-23 15:10:48 +00:00
|
|
|
}
|
|
|
|
|
2013-11-26 20:43:58 +00:00
|
|
|
inline bool gprs_rlc_v_b::is_resend(int bsn) const
|
2013-11-23 15:10:48 +00:00
|
|
|
{
|
2013-12-28 20:16:13 +00:00
|
|
|
return is_state(bsn, GPRS_RLC_DL_BSN_RESEND);
|
2013-11-23 15:10:48 +00:00
|
|
|
}
|
|
|
|
|
2013-11-26 20:43:58 +00:00
|
|
|
inline bool gprs_rlc_v_b::is_invalid(int bsn) const
|
2013-11-23 15:18:18 +00:00
|
|
|
{
|
2013-12-28 20:16:13 +00:00
|
|
|
return is_state(bsn, GPRS_RLC_DL_BSN_INVALID);
|
2013-11-23 15:18:18 +00:00
|
|
|
}
|
|
|
|
|
2013-12-28 20:16:13 +00:00
|
|
|
inline gprs_rlc_dl_bsn_state gprs_rlc_v_b::get_state(int bsn) const
|
2013-12-28 17:24:42 +00:00
|
|
|
{
|
|
|
|
return m_v_b[bsn & mod_sns_half()];
|
|
|
|
}
|
|
|
|
|
2013-11-26 20:43:58 +00:00
|
|
|
inline void gprs_rlc_v_b::mark_resend(int bsn)
|
2013-11-23 15:10:48 +00:00
|
|
|
{
|
2013-12-28 20:16:13 +00:00
|
|
|
return mark(bsn, GPRS_RLC_DL_BSN_RESEND);
|
2013-11-23 15:10:48 +00:00
|
|
|
}
|
|
|
|
|
2013-11-26 20:43:58 +00:00
|
|
|
inline void gprs_rlc_v_b::mark_unacked(int bsn)
|
2013-11-23 15:10:48 +00:00
|
|
|
{
|
2013-12-28 20:16:13 +00:00
|
|
|
return mark(bsn, GPRS_RLC_DL_BSN_UNACKED);
|
2013-11-23 15:10:48 +00:00
|
|
|
}
|
|
|
|
|
2013-11-26 20:43:58 +00:00
|
|
|
inline void gprs_rlc_v_b::mark_acked(int bsn)
|
2013-11-23 15:10:48 +00:00
|
|
|
{
|
2013-12-28 20:16:13 +00:00
|
|
|
return mark(bsn, GPRS_RLC_DL_BSN_ACKED);
|
2013-11-23 15:10:48 +00:00
|
|
|
}
|
|
|
|
|
2013-11-26 20:43:58 +00:00
|
|
|
inline void gprs_rlc_v_b::mark_nacked(int bsn)
|
2013-11-23 15:10:48 +00:00
|
|
|
{
|
2013-12-28 20:16:13 +00:00
|
|
|
return mark(bsn, GPRS_RLC_DL_BSN_NACKED);
|
2013-11-23 15:10:48 +00:00
|
|
|
}
|
|
|
|
|
2013-11-26 20:43:58 +00:00
|
|
|
inline void gprs_rlc_v_b::mark_invalid(int bsn)
|
2013-11-23 15:10:48 +00:00
|
|
|
{
|
2013-12-28 20:16:13 +00:00
|
|
|
return mark(bsn, GPRS_RLC_DL_BSN_INVALID);
|
2013-11-23 15:10:48 +00:00
|
|
|
}
|
2013-11-24 19:36:36 +00:00
|
|
|
|
2016-01-19 13:07:33 +00:00
|
|
|
inline gprs_rlc_window::gprs_rlc_window()
|
|
|
|
: m_sns(RLC_GPRS_SNS)
|
2015-12-28 12:51:44 +00:00
|
|
|
, m_ws(RLC_GPRS_WS)
|
2015-12-28 12:46:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-01-19 13:07:33 +00:00
|
|
|
inline const uint16_t gprs_rlc_window::sns() const
|
2013-11-24 19:36:36 +00:00
|
|
|
{
|
2015-12-28 12:51:44 +00:00
|
|
|
return m_sns;
|
2013-11-24 19:36:36 +00:00
|
|
|
}
|
|
|
|
|
2016-01-19 13:07:33 +00:00
|
|
|
inline const uint16_t gprs_rlc_window::ws() const
|
2013-11-24 19:36:36 +00:00
|
|
|
{
|
2015-12-28 12:51:44 +00:00
|
|
|
return m_ws;
|
2013-11-24 19:36:36 +00:00
|
|
|
}
|
|
|
|
|
2016-01-19 13:07:33 +00:00
|
|
|
inline const uint16_t gprs_rlc_window::mod_sns() const
|
2013-11-24 19:36:36 +00:00
|
|
|
{
|
|
|
|
return sns() - 1;
|
|
|
|
}
|
|
|
|
|
2016-01-19 13:07:33 +00:00
|
|
|
inline const uint16_t gprs_rlc_window::mod_sns(uint16_t bsn) const
|
2015-12-23 15:29:07 +00:00
|
|
|
{
|
|
|
|
return bsn & mod_sns();
|
|
|
|
}
|
|
|
|
|
2016-01-19 13:07:33 +00:00
|
|
|
inline gprs_rlc_dl_window::gprs_rlc_dl_window()
|
|
|
|
: m_v_s(0)
|
|
|
|
, m_v_a(0)
|
|
|
|
{
|
2018-01-15 10:28:40 +00:00
|
|
|
reset();
|
2016-01-19 13:07:33 +00:00
|
|
|
}
|
|
|
|
|
2013-11-24 19:36:36 +00:00
|
|
|
inline const uint16_t gprs_rlc_dl_window::v_s() const
|
|
|
|
{
|
|
|
|
return m_v_s;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const uint16_t gprs_rlc_dl_window::v_s_mod(int offset) const
|
|
|
|
{
|
2015-12-23 15:29:07 +00:00
|
|
|
return mod_sns(m_v_s + offset);
|
2013-11-24 19:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const uint16_t gprs_rlc_dl_window::v_a() const
|
|
|
|
{
|
|
|
|
return m_v_a;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool gprs_rlc_dl_window::window_stalled() const
|
|
|
|
{
|
2015-12-23 15:29:07 +00:00
|
|
|
return (mod_sns(m_v_s - m_v_a)) == ws();
|
2013-11-24 19:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool gprs_rlc_dl_window::window_empty() const
|
|
|
|
{
|
|
|
|
return m_v_s == m_v_a;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void gprs_rlc_dl_window::increment_send()
|
|
|
|
{
|
|
|
|
m_v_s = (m_v_s + 1) & mod_sns();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void gprs_rlc_dl_window::raise(int moves)
|
|
|
|
{
|
|
|
|
m_v_a = (m_v_a + moves) & mod_sns();
|
|
|
|
}
|
|
|
|
|
2016-11-02 10:11:48 +00:00
|
|
|
inline const uint16_t gprs_rlc_dl_window::distance() const
|
2013-11-24 19:36:36 +00:00
|
|
|
{
|
|
|
|
return (m_v_s - m_v_a) & mod_sns();
|
2013-11-24 21:43:03 +00:00
|
|
|
}
|
|
|
|
|
2015-12-28 12:46:32 +00:00
|
|
|
inline gprs_rlc_ul_window::gprs_rlc_ul_window()
|
|
|
|
: m_v_r(0)
|
|
|
|
, m_v_q(0)
|
|
|
|
{
|
2018-01-15 10:28:40 +00:00
|
|
|
m_v_n.reset();
|
2015-12-28 12:46:32 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 15:40:56 +00:00
|
|
|
inline bool gprs_rlc_ul_window::is_in_window(uint16_t bsn) const
|
2013-11-24 21:43:03 +00:00
|
|
|
{
|
|
|
|
uint16_t offset_v_q;
|
|
|
|
|
|
|
|
/* current block relative to lowest unreceived block */
|
|
|
|
offset_v_q = (bsn - m_v_q) & mod_sns();
|
|
|
|
/* If out of window (may happen if blocks below V(Q) are received
|
|
|
|
* again. */
|
|
|
|
return offset_v_q < ws();
|
2013-11-24 19:36:36 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 15:40:56 +00:00
|
|
|
inline bool gprs_rlc_ul_window::is_received(uint16_t bsn) const
|
2015-12-14 10:54:29 +00:00
|
|
|
{
|
|
|
|
uint16_t offset_v_r;
|
|
|
|
|
|
|
|
/* Offset to the end of the received window */
|
|
|
|
offset_v_r = (m_v_r - 1 - bsn) & mod_sns();
|
|
|
|
return is_in_window(bsn) && m_v_n.is_received(bsn) && offset_v_r < ws();
|
|
|
|
}
|
|
|
|
|
2017-12-15 10:08:58 +00:00
|
|
|
inline void gprs_rlc_ul_window::reset_state()
|
|
|
|
{
|
|
|
|
m_v_r = 0;
|
|
|
|
m_v_q = 0;
|
|
|
|
}
|
|
|
|
|
2017-01-24 10:23:35 +00:00
|
|
|
inline const void gprs_rlc_ul_window::set_v_r(int v_r)
|
|
|
|
{
|
|
|
|
m_v_r = v_r;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const void gprs_rlc_ul_window::set_v_q(int v_q)
|
|
|
|
{
|
|
|
|
m_v_q = v_q;
|
|
|
|
}
|
|
|
|
|
2013-11-24 19:36:36 +00:00
|
|
|
inline const uint16_t gprs_rlc_ul_window::v_r() const
|
|
|
|
{
|
|
|
|
return m_v_r;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const uint16_t gprs_rlc_ul_window::v_q() const
|
|
|
|
{
|
|
|
|
return m_v_q;
|
|
|
|
}
|
|
|
|
|
2013-11-27 16:08:35 +00:00
|
|
|
inline const uint16_t gprs_rlc_ul_window::ssn() const
|
|
|
|
{
|
|
|
|
return m_v_r;
|
|
|
|
}
|
|
|
|
|
2013-12-28 12:57:31 +00:00
|
|
|
inline void gprs_rlc_ul_window::raise_v_r_to(int moves)
|
2013-11-24 19:36:36 +00:00
|
|
|
{
|
2015-12-23 15:29:07 +00:00
|
|
|
m_v_r = mod_sns(m_v_r + moves);
|
2013-11-24 19:36:36 +00:00
|
|
|
}
|
|
|
|
|
2013-11-25 22:51:19 +00:00
|
|
|
inline void gprs_rlc_ul_window::raise_v_q(int incr)
|
2013-11-24 19:36:36 +00:00
|
|
|
{
|
2015-12-23 15:29:07 +00:00
|
|
|
m_v_q = mod_sns(m_v_q + incr);
|
2013-11-24 19:36:36 +00:00
|
|
|
}
|
2013-11-24 19:55:02 +00:00
|
|
|
|
2013-11-26 20:43:58 +00:00
|
|
|
inline void gprs_rlc_v_n::mark_received(int bsn)
|
|
|
|
{
|
2013-12-28 20:16:13 +00:00
|
|
|
return mark(bsn, GPRS_RLC_UL_BSN_RECEIVED);
|
2013-11-26 20:43:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void gprs_rlc_v_n::mark_missing(int bsn)
|
2013-11-24 19:55:02 +00:00
|
|
|
{
|
2013-12-28 20:16:13 +00:00
|
|
|
return mark(bsn, GPRS_RLC_UL_BSN_MISSING);
|
2013-11-24 19:55:02 +00:00
|
|
|
}
|
|
|
|
|
2013-11-26 20:43:58 +00:00
|
|
|
inline bool gprs_rlc_v_n::is_received(int bsn) const
|
2013-11-24 19:55:02 +00:00
|
|
|
{
|
2013-12-28 20:16:13 +00:00
|
|
|
return is_state(bsn, GPRS_RLC_UL_BSN_RECEIVED);
|
2013-11-24 19:55:02 +00:00
|
|
|
}
|
|
|
|
|
2013-12-28 20:16:13 +00:00
|
|
|
inline bool gprs_rlc_v_n::is_state(int bsn, gprs_rlc_ul_bsn_state type) const
|
2013-11-24 19:55:02 +00:00
|
|
|
{
|
2013-11-26 20:43:58 +00:00
|
|
|
return m_v_n[bsn & mod_sns_half()] == type;
|
2013-11-24 19:55:02 +00:00
|
|
|
}
|
|
|
|
|
2013-12-28 20:16:13 +00:00
|
|
|
inline void gprs_rlc_v_n::mark(int bsn, gprs_rlc_ul_bsn_state type)
|
2013-11-24 19:55:02 +00:00
|
|
|
{
|
2013-11-26 20:43:58 +00:00
|
|
|
m_v_n[bsn & mod_sns_half()] = type;
|
|
|
|
}
|
|
|
|
|
2013-12-28 20:16:13 +00:00
|
|
|
inline gprs_rlc_ul_bsn_state gprs_rlc_v_n::state(int bsn) const
|
2013-11-26 20:43:58 +00:00
|
|
|
{
|
2013-12-28 20:16:13 +00:00
|
|
|
return m_v_n[bsn & mod_sns_half()];
|
2013-11-24 19:55:02 +00:00
|
|
|
}
|
2013-11-26 20:43:58 +00:00
|
|
|
|
2018-05-16 13:20:39 +00:00
|
|
|
inline void gprs_rlc::init()
|
|
|
|
{
|
|
|
|
memset(m_blocks, 0, sizeof(m_blocks));
|
|
|
|
}
|
|
|
|
|
2013-11-26 20:43:58 +00:00
|
|
|
inline gprs_rlc_data *gprs_rlc::block(int bsn)
|
|
|
|
{
|
|
|
|
return &m_blocks[bsn & mod_sns_half()];
|
|
|
|
}
|