pespin has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-pcu/+/22295 )

Change subject: Convert gprs_bssgp_pcu.cpp to C
......................................................................

Convert gprs_bssgp_pcu.cpp to C

There's no real use of C++ in that file, and it causes problems when
using llist_head entry macros in future patches adding initial support
for multiple BTS in PCU object, so let's move it to plain C.

Change-Id: Ic771a89fd78b5e66151a5384f0ff6a8895589466
---
M src/Makefile.am
M src/decoding.cpp
M src/decoding.h
R src/gprs_bssgp_pcu.c
M src/gprs_bssgp_pcu.h
M src/gprs_rlcmac.h
M src/pdch.cpp
M src/rlc.h
M src/tbf_dl.cpp
M src/tbf_dl.h
M tests/rlcmac/RLCMACTest.cpp
M tests/tbf/TbfTest.cpp
12 files changed, 91 insertions(+), 59 deletions(-)

Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, approved
  osmith: Looks good to me, but someone else must approve



diff --git a/src/Makefile.am b/src/Makefile.am
index 05fac55..60f05a5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -42,7 +42,7 @@
        gprs_debug.cpp \
        csn1.c \
        gsm_rlcmac.c \
-       gprs_bssgp_pcu.cpp \
+       gprs_bssgp_pcu.c \
        gprs_rlcmac.cpp \
        gprs_rlcmac_sched.cpp \
        gprs_rlcmac_meas.cpp \
diff --git a/src/decoding.cpp b/src/decoding.cpp
index 0437994..e40496d 100644
--- a/src/decoding.cpp
+++ b/src/decoding.cpp
@@ -291,7 +291,7 @@
        return num_chunks;
 }

-uint8_t Decoding::get_ms_class_by_capability(MS_Radio_Access_capability_t *cap)
+uint8_t get_ms_class_by_capability(MS_Radio_Access_capability_t *cap)
 {
        int i;

@@ -306,7 +306,7 @@
        return 0;
 }

-uint8_t 
Decoding::get_egprs_ms_class_by_capability(MS_Radio_Access_capability_t *cap)
+uint8_t get_egprs_ms_class_by_capability(MS_Radio_Access_capability_t *cap)
 {
        int i;

diff --git a/src/decoding.h b/src/decoding.h
index 23d3e17..28af3c4 100644
--- a/src/decoding.h
+++ b/src/decoding.h
@@ -19,16 +19,23 @@
  */
 #pragma once

+#ifdef __cplusplus
 extern "C" {
-#include "gsm_rlcmac.h"
-}
+#endif

-#include "rlc.h"
+#include "gsm_rlcmac.h"
+#include "coding_scheme.h"
+
+#ifdef __cplusplus
+}
+#endif

 #include <stdint.h>

 struct bitvec;

+#ifdef __cplusplus
+
 class Decoding {
 public:
        /* represents (parts) LLC PDUs within one RLC Data block */
@@ -42,8 +49,6 @@
                const struct gprs_rlc_data_block_info *rdbi,
                enum CodingScheme cs, const uint8_t *data, RlcData *chunks,
                unsigned int chunks_size, uint32_t *tlli);
-       static uint8_t get_ms_class_by_capability(MS_Radio_Access_capability_t 
*cap);
-       static uint8_t 
get_egprs_ms_class_by_capability(MS_Radio_Access_capability_t *cap);

        static void extract_rbb(const uint8_t *rbb, char *extracted_rbb);
        static void extract_rbb(const struct bitvec *rbb, char *show_rbb);
@@ -82,3 +87,16 @@
                bitvec *bits, int *bsn_begin, int *bsn_end,
                gprs_rlc_dl_window *window);
 };
+
+#endif /* #ifdef __cplusplus */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+uint8_t get_ms_class_by_capability(MS_Radio_Access_capability_t *cap);
+uint8_t get_egprs_ms_class_by_capability(MS_Radio_Access_capability_t *cap);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/src/gprs_bssgp_pcu.cpp b/src/gprs_bssgp_pcu.c
similarity index 97%
rename from src/gprs_bssgp_pcu.cpp
rename to src/gprs_bssgp_pcu.c
index 997cb1b..288bc45 100644
--- a/src/gprs_bssgp_pcu.cpp
+++ b/src/gprs_bssgp_pcu.c
@@ -28,14 +28,15 @@
 #include <pdch.h>
 #include <decoding.h>

-extern "C" {
-       #include <osmocom/gsm/protocol/gsm_23_003.h>
-       #include <osmocom/gprs/protocol/gsm_08_16.h>
-       #include <osmocom/core/utils.h>
-       #include <osmocom/gsm/gsm48.h>
-       #include "coding_scheme.h"
-       #include "tbf_dl.h"
-}
+#include <osmocom/gprs/gprs_ns2.h>
+#include <osmocom/gsm/protocol/gsm_23_003.h>
+#include <osmocom/gprs/protocol/gsm_08_16.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/gsm/gsm48.h>
+#include "coding_scheme.h"
+#include "tbf_dl.h"
+#include "llc.h"
+#include "gprs_rlcmac.h"

 /* Tuning parameters for BSSGP flow control */
 #define FC_DEFAULT_LIFE_TIME_SECS 10           /* experimental value, 10s */
@@ -55,7 +56,7 @@

 static int parse_ra_cap(struct tlv_parsed *tp, MS_Radio_Access_capability_t 
*rac)
 {
-       bitvec *block;
+       struct bitvec *block;
        uint8_t cap_len;
        uint8_t *cap;

@@ -132,9 +133,8 @@
        /* parse ms radio access capability */
        if (parse_ra_cap(tp, &rac) >= 0) {
                /* Get the EGPRS class from the RA capability */
-               ms_class = Decoding::get_ms_class_by_capability(&rac);
-               egprs_ms_class =
-                       Decoding::get_egprs_ms_class_by_capability(&rac);
+               ms_class = get_ms_class_by_capability(&rac);
+               egprs_ms_class = get_egprs_ms_class_by_capability(&rac);
                LOGP(DBSSGP, LOGL_DEBUG, "Got downlink MS class %d/%d\n",
                        ms_class, egprs_ms_class);
        }
@@ -166,7 +166,7 @@

        LOGP(DBSSGP, LOGL_INFO, "LLC [SGSN -> PCU] = TLLI: 0x%08x IMSI: %s len: 
%d\n", tlli, mi_imsi.imsi, len);

-       return gprs_rlcmac_dl_tbf::handle(the_pcu->bssgp.bts, tlli, tlli_old, 
mi_imsi.imsi,
+       return dl_tbf_handle(the_pcu->bssgp.bts, tlli, tlli_old, mi_imsi.imsi,
                        ms_class, egprs_ms_class, delay_csec, data, len);
 }

@@ -620,7 +620,7 @@
                LOGP(DPCU, LOGL_DEBUG,
                     "NS: %s Unknown prim %s / %d from NS\n",
                     get_value_string(osmo_prim_op_names, oph->operation),
-                    gprs_ns2_prim_str((gprs_ns2_prim) oph->primitive), 
oph->primitive);
+                    gprs_ns2_prim_str((enum gprs_ns2_prim) oph->primitive), 
oph->primitive);
                break;
        }

@@ -654,7 +654,7 @@
                for (ts_no = 0; ts_no < ARRAY_SIZE(trx->pdch); ++ts_no) {
                        const struct gprs_rlcmac_pdch *pdch = &trx->pdch[ts_no];

-                       if (pdch->is_enabled())
+                       if (pdch->m_is_enabled)
                                num_pdch += 1;
                }
        }
@@ -853,7 +853,7 @@

        if (ms_leak_rate == 0) {
                int ms_num_pdch;
-               int max_pdch = gprs_alloc_max_dl_slots_per_ms(bts);
+               int max_pdch = gprs_alloc_max_dl_slots_per_ms(bts, 0);

                if (num_pdch < 0)
                        num_pdch = count_pdch(bts);
@@ -1029,8 +1029,9 @@
 static int ns_conf_vc_cb(struct gprs_ns2_vc *nsvc, void *ctx)
 {
        struct nsvc_cb *data = (struct nsvc_cb *) ctx;
+       unsigned int i;

-       for (unsigned int i = 0; i < PCU_IF_NUM_NSVC; i++) {
+       for (i = 0; i < PCU_IF_NUM_NSVC; i++) {
                if (!(data->valid & (1 << i)))
                        continue;
                if (data->found & (1 << i))
@@ -1070,7 +1071,8 @@
        } else if (the_pcu->vty.ns_dialect == NS2_DIALECT_SNS) {
                /* SNS: check if the initial nsvc is the same, if not recreate 
it */
                const struct osmo_sockaddr *initial = 
gprs_ns2_nse_sns_remote(bts->nse);
-               for (unsigned int i = 0; i < PCU_IF_NUM_NSVC; i++) {
+               unsigned int i;
+               for (i = 0; i < PCU_IF_NUM_NSVC; i++) {
                        if (!(valid & (1 << i)))
                                continue;

diff --git a/src/gprs_bssgp_pcu.h b/src/gprs_bssgp_pcu.h
index 080893f..df22541 100644
--- a/src/gprs_bssgp_pcu.h
+++ b/src/gprs_bssgp_pcu.h
@@ -21,7 +21,6 @@
 #ifndef GPRS_BSSGP_PCU_H
 #define GPRS_BSSGP_PCU_H

-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -40,6 +39,7 @@
 #include <gprs_debug.h>

 #include <time.h>
+#include <unistd.h>

 #define QOS_PROFILE 4
 #define BSSGP_HDR_LEN 53
diff --git a/src/gprs_rlcmac.h b/src/gprs_rlcmac.h
index d779d08..a5d1d30 100644
--- a/src/gprs_rlcmac.h
+++ b/src/gprs_rlcmac.h
@@ -22,16 +22,20 @@
 #define GPRS_RLCMAC_H

 #include <stdbool.h>
+#include <stdint.h>

-#ifdef __cplusplus
 #include <pcu_l1_if.h>

+#ifdef __cplusplus
 extern "C" {
+#endif
 #include <osmocom/core/linuxlist.h>
 #include <osmocom/core/timer.h>
 #include <osmocom/core/bitvec.h>
+#include <osmocom/gsm/gsm48.h>
 #include <osmocom/pcu/pcuif_proto.h>
 #include "gsm_rlcmac.h"
+#ifdef __cplusplus
 }
 #endif

@@ -92,17 +96,12 @@

 int gprs_rlcmac_tx_ul_ud(gprs_rlcmac_tbf *tbf);

-int gprs_rlcmac_paging_request(const struct osmo_mobile_identity *mi, uint16_t 
pgroup);
-
 struct msgb *gprs_rlcmac_app_info_msg(const struct gsm_pcu_if_app_info_req 
*req);

 int gprs_rlcmac_rcv_rts_block(struct gprs_rlcmac_bts *bts,
        uint8_t trx, uint8_t ts,
         uint32_t fn, uint8_t block_nr);

-int gprs_alloc_max_dl_slots_per_ms(const struct gprs_rlcmac_bts *bts,
-       uint8_t ms_class = 0);
-
 extern "C" {
 #endif
 int alloc_algorithm_a(struct gprs_rlcmac_bts *bts, struct GprsMs *ms, struct 
gprs_rlcmac_tbf *tbf, bool single,
@@ -113,8 +112,12 @@

 int alloc_algorithm_dynamic(struct gprs_rlcmac_bts *bts, struct GprsMs *ms, 
struct gprs_rlcmac_tbf *tbf, bool single,
                            int8_t use_trx);
+
+int gprs_rlcmac_paging_request(const struct osmo_mobile_identity *mi, uint16_t 
pgroup);
+int gprs_alloc_max_dl_slots_per_ms(const struct gprs_rlcmac_bts *bts, uint8_t 
ms_class);
 #ifdef __cplusplus
 }
 #endif

+
 #endif // GPRS_RLCMAC_H
diff --git a/src/pdch.cpp b/src/pdch.cpp
index 9dd4072..c48c63f 100644
--- a/src/pdch.cpp
+++ b/src/pdch.cpp
@@ -596,8 +596,8 @@

                if (request->Exist_MS_Radio_Access_capability2) {
                        uint8_t ms_class, egprs_ms_class;
-                       ms_class = 
Decoding::get_ms_class_by_capability(&request->MS_Radio_Access_capability2);
-                       egprs_ms_class = 
Decoding::get_egprs_ms_class_by_capability(&request->MS_Radio_Access_capability2);
+                       ms_class = 
get_ms_class_by_capability(&request->MS_Radio_Access_capability2);
+                       egprs_ms_class = 
get_egprs_ms_class_by_capability(&request->MS_Radio_Access_capability2);
                        if (ms_class)
                                ms_set_ms_class(ms, ms_class);
                        if (egprs_ms_class)
diff --git a/src/rlc.h b/src/rlc.h
index eb79430..187a70e 100644
--- a/src/rlc.h
+++ b/src/rlc.h
@@ -18,13 +18,17 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 #pragma once
-
+#ifdef __cplusplus
 extern "C" {
-#include "coding_scheme.h"
-}
+#endif

+#include "coding_scheme.h"
 #include <osmocom/core/endian.h>

+#ifdef __cplusplus
+}
+#endif
+
 #include <stdint.h>
 #include <string.h>

diff --git a/src/tbf_dl.cpp b/src/tbf_dl.cpp
index 962c31d..87c897f 100644
--- a/src/tbf_dl.cpp
+++ b/src/tbf_dl.cpp
@@ -278,11 +278,11 @@
 /**
  * TODO: split into unit test-able parts...
  */
-int gprs_rlcmac_dl_tbf::handle(struct gprs_rlcmac_bts *bts,
-               const uint32_t tlli, const uint32_t tlli_old, const char *imsi,
-               uint8_t ms_class, uint8_t egprs_ms_class,
-               const uint16_t delay_csec,
-               const uint8_t *data, const uint16_t len)
+int dl_tbf_handle(struct gprs_rlcmac_bts *bts,
+                 const uint32_t tlli, const uint32_t tlli_old, const char 
*imsi,
+                 uint8_t ms_class, uint8_t egprs_ms_class,
+                 const uint16_t delay_csec,
+                 const uint8_t *data, const uint16_t len)
 {
        struct gprs_rlcmac_dl_tbf *dl_tbf = NULL;
        int rc;
diff --git a/src/tbf_dl.h b/src/tbf_dl.h
index e29bb3f..58d863b 100644
--- a/src/tbf_dl.h
+++ b/src/tbf_dl.h
@@ -23,6 +23,8 @@

 #include "tbf.h"

+#include <stdint.h>
+
 /*
  * TBF instance
  */
@@ -42,12 +44,6 @@
        gprs_rlcmac_dl_tbf(struct gprs_rlcmac_bts *bts, GprsMs *ms);
        gprs_rlc_window *window();
        void cleanup();
-       /* dispatch Unitdata.DL messages */
-       static int handle(struct gprs_rlcmac_bts *bts,
-               const uint32_t tlli, const uint32_t old_tlli,
-               const char *imsi, const uint8_t ms_class,
-               const uint8_t egprs_ms_class, const uint16_t delay_csec,
-               const uint8_t *data, const uint16_t len);

        int append_data(uint16_t pdu_delay_csec,
                        const uint8_t *data, uint16_t len);
@@ -151,7 +147,16 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
+struct gprs_rlcmac_bts;
+
 struct gprs_rlcmac_dl_tbf *as_dl_tbf(struct gprs_rlcmac_tbf *tbf);
+/* dispatch Unitdata.DL messages */
+int dl_tbf_handle(struct gprs_rlcmac_bts *bts,
+                 const uint32_t tlli, const uint32_t old_tlli,
+                 const char *imsi, const uint8_t ms_class,
+                 const uint8_t egprs_ms_class, const uint16_t delay_csec,
+                 const uint8_t *data, const uint16_t len);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/tests/rlcmac/RLCMACTest.cpp b/tests/rlcmac/RLCMACTest.cpp
index 140b2f2..c6ad192 100644
--- a/tests/rlcmac/RLCMACTest.cpp
+++ b/tests/rlcmac/RLCMACTest.cpp
@@ -259,8 +259,8 @@
         OSMO_ASSERT(data.Count_MS_RA_capability_value == 1);

         /* Make sure GPRS / EGPRS multislot class is parsed correctly */
-        printf("GPRS multislot class = %u\n", 
Decoding::get_ms_class_by_capability(&data));
-        printf("EGPRS multislot class = %u\n", 
Decoding::get_egprs_ms_class_by_capability(&data));
+        printf("GPRS multislot class = %u\n", 
get_ms_class_by_capability(&data));
+        printf("EGPRS multislot class = %u\n", 
get_egprs_ms_class_by_capability(&data));

         /* Test encoding of decoded MS RA Capability */
         printf("=== Test encoding of MS RA Capability ===\n");
@@ -466,8 +466,8 @@
        OSMO_ASSERT(data.Count_MS_RA_capability_value == 3);

        /* Make sure GPRS / EGPRS multislot class is parsed correctly */
-       printf("GPRS multislot class = %u\n", 
Decoding::get_ms_class_by_capability(&data));
-       printf("EGPRS multislot class = %u\n", 
Decoding::get_egprs_ms_class_by_capability(&data));
+       printf("GPRS multislot class = %u\n", 
get_ms_class_by_capability(&data));
+       printf("EGPRS multislot class = %u\n", 
get_egprs_ms_class_by_capability(&data));

        bitvec_free(bv_dec);
 }
diff --git a/tests/tbf/TbfTest.cpp b/tests/tbf/TbfTest.cpp
index ef26862..fbcb503 100644
--- a/tests/tbf/TbfTest.cpp
+++ b/tests/tbf/TbfTest.cpp
@@ -500,7 +500,7 @@

                snprintf(imsi, sizeof(imsi), "001001%09d", i);

-               rc = gprs_rlcmac_dl_tbf::handle(bts, tlli, 0, imsi, ms_class, 0,
+               rc = dl_tbf_handle(bts, tlli, 0, imsi, ms_class, 0,
                        delay_csec, buf, sizeof(buf));

                if (rc < 0)
@@ -545,7 +545,7 @@

        /* Handle LLC frame 1 */
        memset(buf, 1, sizeof(buf));
-       rc = gprs_rlcmac_dl_tbf::handle(bts, tlli, 0, imsi, ms_class, 0,
+       rc = dl_tbf_handle(bts, tlli, 0, imsi, ms_class, 0,
                delay_csec, buf, sizeof(buf));
        OSMO_ASSERT(rc >= 0);

@@ -556,7 +556,7 @@

        /* Handle LLC frame 2 */
        memset(buf, 2, sizeof(buf));
-       rc = gprs_rlcmac_dl_tbf::handle(bts, tlli, 0, imsi, ms_class, 0,
+       rc = dl_tbf_handle(bts, tlli, 0, imsi, ms_class, 0,
                delay_csec, buf, sizeof(buf));
        OSMO_ASSERT(rc >= 0);

@@ -565,7 +565,7 @@

        /* Handle LLC frame 3 */
        memset(buf, 3, sizeof(buf));
-       rc = gprs_rlcmac_dl_tbf::handle(bts, tlli, 0, imsi, ms_class, 0,
+       rc = dl_tbf_handle(bts, tlli, 0, imsi, ms_class, 0,
                delay_csec, buf, sizeof(buf));
        OSMO_ASSERT(rc >= 0);

@@ -1651,7 +1651,7 @@

        ms = bts_ms_store(bts)->get_ms(tlli, 0, imsi);

-       gprs_rlcmac_dl_tbf::handle(bts, tlli, 0, imsi, 0, 0,
+       dl_tbf_handle(bts, tlli, 0, imsi, 0, 0,
                1000, data, data_size);

        ms = bts_ms_by_imsi(bts, imsi);
@@ -2206,7 +2206,7 @@
        gprs_bssgp_init(bts, 3234, 3234, 1, 1, false, 0, 0, 0);

        /* Does not support EGPRS */
-       rc = gprs_rlcmac_dl_tbf::handle(bts, tlli, 0, imsi, ms_class, 0,
+       rc = dl_tbf_handle(bts, tlli, 0, imsi, ms_class, 0,
                delay_csec, buf, sizeof(buf));

        OSMO_ASSERT(rc == 0);

--
To view, visit https://gerrit.osmocom.org/c/osmo-pcu/+/22295
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Change-Id: Ic771a89fd78b5e66151a5384f0ff6a8895589466
Gerrit-Change-Number: 22295
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pes...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: osmith <osm...@sysmocom.de>
Gerrit-Reviewer: pespin <pes...@sysmocom.de>
Gerrit-MessageType: merged

Reply via email to