2022-03-31 18:22:05 +00:00
|
|
|
/* 3GPP TS 44.064
|
2013-11-07 07:01:49 +00:00
|
|
|
* Copyright (C) 2013 by Holger Hans Peter Freyther
|
2022-03-31 17:36:12 +00:00
|
|
|
* Copyright (C) 2022 by by Sysmocom s.f.m.c. GmbH
|
2013-11-07 07:01:49 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
|
|
|
#ifdef __cplusplus
|
2015-06-15 09:19:13 +00:00
|
|
|
extern "C" {
|
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
|
|
|
#endif
|
2015-06-15 09:19:13 +00:00
|
|
|
|
2013-11-07 07:01:49 +00:00
|
|
|
#include <stdint.h>
|
2013-11-07 07:15:58 +00:00
|
|
|
#include <string.h>
|
2020-03-11 13:04:52 +00:00
|
|
|
#include <time.h>
|
2013-11-07 07:01:49 +00:00
|
|
|
|
2022-03-31 18:22:05 +00:00
|
|
|
#include <osmocom/core/endian.h>
|
2022-03-31 17:36:12 +00:00
|
|
|
#include <osmocom/core/linuxlist.h>
|
|
|
|
#include <osmocom/core/msgb.h>
|
2022-03-31 18:22:05 +00:00
|
|
|
#include <osmocom/core/endian.h>
|
2022-03-31 17:36:12 +00:00
|
|
|
|
2022-04-04 11:45:56 +00:00
|
|
|
#include "gprs_codel.h"
|
|
|
|
|
2013-11-07 07:01:49 +00:00
|
|
|
#define LLC_MAX_LEN 1543
|
|
|
|
|
2021-01-14 15:48:38 +00:00
|
|
|
struct gprs_rlcmac_bts;
|
2022-04-04 11:45:56 +00:00
|
|
|
struct GprsMs;
|
2015-06-02 09:28:07 +00:00
|
|
|
|
2022-03-31 18:22:05 +00:00
|
|
|
struct gprs_llc_hdr {
|
|
|
|
#if OSMO_IS_LITTLE_ENDIAN
|
|
|
|
union { /* 5.2, 6.2.0 */
|
|
|
|
uint8_t address;
|
|
|
|
uint8_t sapi:4, unused:2, c_r:1, pd:1;
|
|
|
|
#elif OSMO_IS_BIG_ENDIAN
|
|
|
|
/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
|
|
|
|
union {
|
|
|
|
uint8_t address;
|
|
|
|
uint8_t pd:1, c_r:1, unused:2, sapi:4;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
uint8_t control[0];
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
2013-11-07 07:01:49 +00:00
|
|
|
/**
|
|
|
|
* I represent the LLC data to a MS
|
|
|
|
*/
|
|
|
|
struct gprs_llc {
|
|
|
|
uint8_t frame[LLC_MAX_LEN]; /* current DL or UL frame */
|
2022-03-31 17:08:07 +00:00
|
|
|
uint16_t index; /* current write/read position of frame */
|
|
|
|
uint16_t length; /* len of current DL LLC_frame, 0 == no frame */
|
2015-05-29 08:37:09 +00:00
|
|
|
};
|
2022-03-31 17:36:12 +00:00
|
|
|
bool llc_is_user_data_frame(const uint8_t *data, size_t len);
|
|
|
|
|
|
|
|
void llc_init(struct gprs_llc *llc);
|
|
|
|
void llc_reset(struct gprs_llc *llc);
|
|
|
|
void llc_reset_frame_space(struct gprs_llc *llc);
|
|
|
|
|
|
|
|
void llc_put_frame(struct gprs_llc *llc, const uint8_t *data, size_t len);
|
|
|
|
void llc_put_dummy_frame(struct gprs_llc *llc, size_t req_len);
|
|
|
|
void llc_append_frame(struct gprs_llc *llc, const uint8_t *data, size_t len);
|
2015-05-29 08:37:09 +00:00
|
|
|
|
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
|
|
|
static inline uint16_t llc_chunk_size(const struct gprs_llc *llc)
|
2013-11-07 07:15:58 +00:00
|
|
|
{
|
2022-03-31 17:08:07 +00:00
|
|
|
return llc->length - llc->index;
|
2013-11-13 15:56:15 +00:00
|
|
|
}
|
|
|
|
|
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
|
|
|
static inline uint16_t llc_remaining_space(const struct gprs_llc *llc)
|
2013-11-13 15:56:15 +00:00
|
|
|
{
|
2022-03-31 17:08:07 +00:00
|
|
|
return LLC_MAX_LEN - llc->length;
|
2013-11-13 15:56:15 +00:00
|
|
|
}
|
|
|
|
|
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
|
|
|
static inline uint16_t llc_frame_length(const struct gprs_llc *llc)
|
2013-11-13 15:56:15 +00:00
|
|
|
{
|
2022-03-31 17:08:07 +00:00
|
|
|
return llc->length;
|
2013-11-13 15:56:15 +00:00
|
|
|
}
|
|
|
|
|
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
|
|
|
static inline void llc_consume(struct gprs_llc *llc, size_t len)
|
2013-11-13 15:56:15 +00:00
|
|
|
{
|
2022-03-31 17:08:07 +00:00
|
|
|
llc->index += len;
|
2013-11-07 07:15:58 +00:00
|
|
|
}
|
|
|
|
|
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
|
|
|
static inline void llc_consume_data(struct gprs_llc *llc, uint8_t *data, size_t len)
|
2013-11-07 07:15:58 +00:00
|
|
|
{
|
|
|
|
/* copy and increment index */
|
2022-03-31 17:08:07 +00:00
|
|
|
memcpy(data, llc->frame + llc->index, len);
|
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
|
|
|
llc_consume(llc, len);
|
2013-11-07 07:15:58 +00:00
|
|
|
}
|
2013-11-13 15:56:15 +00:00
|
|
|
|
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
|
|
|
static inline bool llc_fits_in_current_frame(const struct gprs_llc *llc, uint8_t chunk_size)
|
2013-11-13 15:56:15 +00:00
|
|
|
{
|
2022-03-31 17:08:07 +00:00
|
|
|
return llc->length + chunk_size <= LLC_MAX_LEN;
|
2013-11-13 15:56:15 +00:00
|
|
|
}
|
2015-05-29 08:37:09 +00:00
|
|
|
|
2022-03-31 17:47:33 +00:00
|
|
|
struct MetaInfo {
|
|
|
|
struct timespec recv_time;
|
|
|
|
struct timespec expire_time;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* I store the LLC frames that come from the SGSN.
|
|
|
|
*/
|
2022-03-31 18:22:05 +00:00
|
|
|
enum gprs_llc_queue_prio { /* lowest value has highest prio */
|
|
|
|
LLC_QUEUE_PRIO_GMM = 0, /* SAPI 1 */
|
|
|
|
LLC_QUEUE_PRIO_TOM_SMS, /* SAPI 2,7,8 */
|
|
|
|
LLC_QUEUE_PRIO_OTHER, /* Other SAPIs */
|
|
|
|
_LLC_QUEUE_PRIO_SIZE /* used to calculate size of enum */
|
|
|
|
};
|
2022-04-04 11:45:56 +00:00
|
|
|
struct gprs_llc_prio_queue {
|
|
|
|
struct gprs_codel codel_state;
|
|
|
|
struct llist_head queue; /* queued LLC DL data. See enum gprs_llc_queue_prio. */
|
|
|
|
};
|
2022-03-31 17:47:33 +00:00
|
|
|
struct gprs_llc_queue {
|
2022-04-04 11:45:56 +00:00
|
|
|
struct GprsMs *ms; /* backpointer */
|
2022-03-31 17:47:33 +00:00
|
|
|
uint32_t avg_queue_delay; /* Average delay of data going through the queue */
|
|
|
|
size_t queue_size;
|
|
|
|
size_t queue_octets;
|
2022-04-04 11:45:56 +00:00
|
|
|
bool use_codel;
|
|
|
|
struct gprs_llc_prio_queue pq[_LLC_QUEUE_PRIO_SIZE]; /* queued LLC DL data. See enum gprs_llc_queue_prio. */
|
2022-03-31 17:47:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void llc_queue_calc_pdu_lifetime(struct gprs_rlcmac_bts *bts, const uint16_t pdu_delay_csec,
|
|
|
|
struct timespec *tv);
|
|
|
|
bool llc_queue_is_frame_expired(const struct timespec *tv_now, const struct timespec *tv);
|
|
|
|
|
2022-04-04 11:45:56 +00:00
|
|
|
void llc_queue_init(struct gprs_llc_queue *q, struct GprsMs *ms);
|
2022-03-31 17:47:33 +00:00
|
|
|
void llc_queue_clear(struct gprs_llc_queue *q, struct gprs_rlcmac_bts *bts);
|
2022-04-04 11:45:56 +00:00
|
|
|
void llc_queue_set_codel_interval(struct gprs_llc_queue *q, unsigned int interval);
|
2022-03-31 17:47:33 +00:00
|
|
|
void llc_queue_move_and_merge(struct gprs_llc_queue *q, struct gprs_llc_queue *o);
|
|
|
|
void llc_queue_enqueue(struct gprs_llc_queue *q, struct msgb *llc_msg, const struct timespec *expire_time);
|
2022-04-04 11:45:56 +00:00
|
|
|
struct msgb *llc_queue_dequeue(struct gprs_llc_queue *q);
|
2022-03-31 17:47:33 +00:00
|
|
|
|
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
|
|
|
static inline size_t llc_queue_size(const struct gprs_llc_queue *q)
|
2015-05-29 08:37:09 +00:00
|
|
|
{
|
2022-03-31 17:08:07 +00:00
|
|
|
return q->queue_size;
|
2015-05-29 08:37:09 +00:00
|
|
|
}
|
2015-06-15 09:05:44 +00:00
|
|
|
|
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
|
|
|
static inline size_t llc_queue_octets(const struct gprs_llc_queue *q)
|
2015-06-15 09:05:44 +00:00
|
|
|
{
|
2022-03-31 17:08:07 +00:00
|
|
|
return q->queue_octets;
|
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2015-06-15 09:05:44 +00:00
|
|
|
}
|
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
|
|
|
#endif
|