aboutsummaryrefslogtreecommitdiffstats
path: root/src/llc.h
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@espeweb.net>2020-12-16 15:59:45 +0100
committerpespin <pespin@sysmocom.de>2021-01-05 10:34:25 +0000
commitda971ee5026479e869ed75d944404d398c548497 (patch)
tree30bf447c2d828264e51d09f5422ea05421c48d47 /src/llc.h
parent86fad1ec4e246110b9d8ae66fd7bc30e1cedb5de (diff)
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
Diffstat (limited to 'src/llc.h')
-rw-r--r--src/llc.h80
1 files changed, 40 insertions, 40 deletions
diff --git a/src/llc.h b/src/llc.h
index 3c2e57a9..72fa62ea 100644
--- a/src/llc.h
+++ b/src/llc.h
@@ -18,9 +18,13 @@
#pragma once
+#ifdef __cplusplus
extern "C" {
+#endif
#include <osmocom/core/linuxlist.h>
+#ifdef __cplusplus
}
+#endif
#include <stdint.h>
#include <string.h>
@@ -34,6 +38,8 @@ struct BTS;
* I represent the LLC data to a MS
*/
struct gprs_llc {
+
+#ifdef __cplusplus
static bool is_user_data_frame(uint8_t *data, size_t len);
void init();
@@ -43,92 +49,86 @@ struct gprs_llc {
void put_frame(const uint8_t *data, size_t len);
void put_dummy_frame(size_t req_len);
void append_frame(const uint8_t *data, size_t len);
-
- void consume(size_t len);
- void consume(uint8_t *data, size_t len);
-
- uint16_t chunk_size() const;
- uint16_t remaining_space() const;
- uint16_t frame_length() const;
-
- bool fits_in_current_frame(uint8_t size) const;
+#endif
uint8_t frame[LLC_MAX_LEN]; /* current DL or UL frame */
uint16_t m_index; /* current write/read position of frame */
uint16_t m_length; /* len of current DL LLC_frame, 0 == no frame */
};
+struct MetaInfo {
+ struct timespec recv_time;
+ struct timespec expire_time;
+};
/**
* I store the LLC frames that come from the SGSN.
*/
struct gprs_llc_queue {
- struct MetaInfo {
- struct timespec recv_time;
- struct timespec expire_time;
- };
-
+#ifdef __cplusplus
static void calc_pdu_lifetime(BTS *bts, const uint16_t pdu_delay_csec,
struct timespec *tv);
static bool is_frame_expired(const struct timespec *now,
const struct timespec *tv);
static bool is_user_data_frame(uint8_t *data, size_t len);
- void init();
-
void enqueue(struct msgb *llc_msg, const struct timespec *expire_time);
struct msgb *dequeue(const MetaInfo **info = 0);
- void clear(BTS *bts);
- void move_and_merge(gprs_llc_queue *o);
- size_t size() const;
- size_t octets() const;
-
-private:
+#endif
uint32_t m_avg_queue_delay; /* Average delay of data going through the queue */
size_t m_queue_size;
size_t m_queue_octets;
struct llist_head m_queue; /* queued LLC DL data */
-
};
+#ifdef __cplusplus
+extern "C" {
+#endif
+void llc_queue_init(struct gprs_llc_queue *q);
+void llc_queue_clear(struct gprs_llc_queue *q, struct BTS *bts);
+void llc_queue_move_and_merge(struct gprs_llc_queue *q, struct gprs_llc_queue *o);
-inline uint16_t gprs_llc::chunk_size() const
+static inline uint16_t llc_chunk_size(const struct gprs_llc *llc)
{
- return m_length - m_index;
+ return llc->m_length - llc->m_index;
}
-inline uint16_t gprs_llc::remaining_space() const
+static inline uint16_t llc_remaining_space(const struct gprs_llc *llc)
{
- return LLC_MAX_LEN - m_length;
+ return LLC_MAX_LEN - llc->m_length;
}
-inline uint16_t gprs_llc::frame_length() const
+static inline uint16_t llc_frame_length(const struct gprs_llc *llc)
{
- return m_length;
+ return llc->m_length;
}
-inline void gprs_llc::consume(size_t len)
+static inline void llc_consume(struct gprs_llc *llc, size_t len)
{
- m_index += len;
+ llc->m_index += len;
}
-inline void gprs_llc::consume(uint8_t *data, size_t len)
+static inline void llc_consume_data(struct gprs_llc *llc, uint8_t *data, size_t len)
{
/* copy and increment index */
- memcpy(data, frame + m_index, len);
- consume(len);
+ memcpy(data, llc->frame + llc->m_index, len);
+ llc_consume(llc, len);
}
-inline bool gprs_llc::fits_in_current_frame(uint8_t chunk_size) const
+static inline bool llc_fits_in_current_frame(const struct gprs_llc *llc, uint8_t chunk_size)
{
- return m_length + chunk_size <= LLC_MAX_LEN;
+ return llc->m_length + chunk_size <= LLC_MAX_LEN;
}
-inline size_t gprs_llc_queue::size() const
+static inline size_t llc_queue_size(const struct gprs_llc_queue *q)
{
- return m_queue_size;
+ return q->m_queue_size;
}
-inline size_t gprs_llc_queue::octets() const
+static inline size_t llc_queue_octets(const struct gprs_llc_queue *q)
{
- return m_queue_octets;
+ return q->m_queue_octets;
+}
+
+#ifdef __cplusplus
}
+#endif