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
diff --git a/src/pcu_vty_functions.cpp b/src/pcu_vty_functions.cpp
index 416c006..6100b13 100644
--- a/src/pcu_vty_functions.cpp
+++ b/src/pcu_vty_functions.cpp
@@ -61,7 +61,7 @@
 		tbf->first_ts,
 		tbf->first_common_ts, tbf->control_ts,
 		tbf->ms_class(),
-		tbf->ms() ? tbf->ms()->egprs_ms_class() : -1,
+		tbf->ms() ? ms_egprs_ms_class(tbf->ms()) : -1,
 		VTY_NEWLINE);
 	vty_out(vty, " TS_alloc=");
 	for (int i = 0; i < 8; i++) {
@@ -79,7 +79,7 @@
 			ul_tbf->window_size(), win->v_q(), win->v_r());
 		vty_out(vty, "%s", VTY_NEWLINE);
 		vty_out(vty, " TBF Statistics:%s", VTY_NEWLINE);
-		if (GPRS == tbf->ms()->mode()) {
+		if (GPRS == ms_mode(tbf->ms())) {
 			vty_out_rate_ctr_group(vty, " ", ul_tbf->m_ul_gprs_ctrs);
 		} else {
 			vty_out_rate_ctr_group(vty, " ", ul_tbf->m_ul_egprs_ctrs);
@@ -92,7 +92,7 @@
 			win->window_stalled() ? " STALLED" : "");
 		vty_out(vty, "%s", VTY_NEWLINE);
 		vty_out_rate_ctr_group(vty, " ", tbf->m_ctrs);
-		if (GPRS == tbf->ms()->mode()) {
+		if (GPRS == ms_mode(tbf->ms())) {
 			vty_out_rate_ctr_group(vty, " ", dl_tbf->m_dl_gprs_ctrs);
 		} else {
 			vty_out_rate_ctr_group(vty, " ", dl_tbf->m_dl_egprs_ctrs);
@@ -124,81 +124,83 @@
 static int show_ms(struct vty *vty, GprsMs *ms)
 {
 	unsigned i;
-	LListHead<gprs_rlcmac_tbf> *i_tbf;
+	struct llist_item *i_tbf;
 	uint8_t slots;
 
-	vty_out(vty, "MS TLLI=%08x, IMSI=%s%s", ms->tlli(), ms->imsi(), VTY_NEWLINE);
-	vty_out(vty, "  Timing advance (TA):    %d%s", ms->ta(), VTY_NEWLINE);
-	vty_out(vty, "  Coding scheme uplink:   %s%s", mcs_name(ms->current_cs_ul()),
+	vty_out(vty, "MS TLLI=%08x, IMSI=%s%s", ms_tlli(ms), ms_imsi(ms), VTY_NEWLINE);
+	vty_out(vty, "  Timing advance (TA):    %d%s", ms_ta(ms), VTY_NEWLINE);
+	vty_out(vty, "  Coding scheme uplink:   %s%s", mcs_name(ms_current_cs_ul(ms)),
 		VTY_NEWLINE);
-	vty_out(vty, "  Coding scheme downlink: %s%s", mcs_name(ms->current_cs_dl()),
+	vty_out(vty, "  Coding scheme downlink: %s%s", mcs_name(ms_current_cs_dl(ms)),
 		VTY_NEWLINE);
-	vty_out(vty, "  Mode:                   %s%s", mode_name(ms->mode()), VTY_NEWLINE);
-	vty_out(vty, "  MS class:               %d%s", ms->ms_class(), VTY_NEWLINE);
-	vty_out(vty, "  EGPRS MS class:         %d%s", ms->egprs_ms_class(), VTY_NEWLINE);
+	vty_out(vty, "  Mode:                   %s%s", mode_name(ms_mode(ms)), VTY_NEWLINE);
+	vty_out(vty, "  MS class:               %d%s", ms_ms_class(ms), VTY_NEWLINE);
+	vty_out(vty, "  EGPRS MS class:         %d%s", ms_egprs_ms_class(ms), VTY_NEWLINE);
 	vty_out(vty, "  PACCH:                  ");
-	slots = ms->current_pacch_slots();
+	slots = ms_current_pacch_slots(ms);
 	for (int i = 0; i < 8; i++)
 		if (slots & (1 << i))
 			vty_out(vty, "%d ", i);
 	vty_out(vty, "%s", VTY_NEWLINE);
-	vty_out(vty, "  LLC queue length:       %zd%s", ms->llc_queue()->size(),
+	vty_out(vty, "  LLC queue length:       %zd%s", llc_queue_size(ms_llc_queue(ms)),
 		VTY_NEWLINE);
-	vty_out(vty, "  LLC queue octets:       %zd%s", ms->llc_queue()->octets(),
+	vty_out(vty, "  LLC queue octets:       %zd%s", llc_queue_octets(ms_llc_queue(ms)),
 		VTY_NEWLINE);
-	if (ms->l1_meas()->have_rssi)
+	if (ms->l1_meas.have_rssi)
 		vty_out(vty, "  RSSI:                   %d dBm%s",
-			ms->l1_meas()->rssi, VTY_NEWLINE);
-	if (ms->l1_meas()->have_ber)
+			ms->l1_meas.rssi, VTY_NEWLINE);
+	if (ms->l1_meas.have_ber)
 		vty_out(vty, "  Bit error rate:         %d %%%s",
-			ms->l1_meas()->ber, VTY_NEWLINE);
-	if (ms->l1_meas()->have_link_qual)
+			ms->l1_meas.ber, VTY_NEWLINE);
+	if (ms->l1_meas.have_link_qual)
 		vty_out(vty, "  Link quality:           %d dB%s",
-			ms->l1_meas()->link_qual, VTY_NEWLINE);
-	if (ms->l1_meas()->have_bto)
+			ms->l1_meas.link_qual, VTY_NEWLINE);
+	if (ms->l1_meas.have_bto)
 		vty_out(vty, "  Burst timing offset:    %d/4 bit%s",
-			ms->l1_meas()->bto, VTY_NEWLINE);
-	if (ms->l1_meas()->have_ms_rx_qual)
+			ms->l1_meas.bto, VTY_NEWLINE);
+	if (ms->l1_meas.have_ms_rx_qual)
 		vty_out(vty, "  Downlink NACK rate:     %d %%%s",
-			ms->nack_rate_dl(), VTY_NEWLINE);
-	if (ms->l1_meas()->have_ms_rx_qual)
+			ms_nack_rate_dl(ms), VTY_NEWLINE);
+	if (ms->l1_meas.have_ms_rx_qual)
 		vty_out(vty, "  MS RX quality:          %d %%%s",
-			ms->l1_meas()->ms_rx_qual, VTY_NEWLINE);
-	if (ms->l1_meas()->have_ms_c_value)
+			ms->l1_meas.ms_rx_qual, VTY_NEWLINE);
+	if (ms->l1_meas.have_ms_c_value)
 		vty_out(vty, "  MS C value:             %d dB%s",
-			ms->l1_meas()->ms_c_value, VTY_NEWLINE);
-	if (ms->l1_meas()->have_ms_sign_var)
+			ms->l1_meas.ms_c_value, VTY_NEWLINE);
+	if (ms->l1_meas.have_ms_sign_var)
 		vty_out(vty, "  MS SIGN variance:       %d dB%s",
-			ms->l1_meas()->ms_sign_var, VTY_NEWLINE);
-	for (i = 0; i < ARRAY_SIZE(ms->l1_meas()->ts); ++i) {
-		if (ms->l1_meas()->ts[i].have_ms_i_level)
+			ms->l1_meas.ms_sign_var, VTY_NEWLINE);
+	for (i = 0; i < ARRAY_SIZE(ms->l1_meas.ts); ++i) {
+		if (ms->l1_meas.ts[i].have_ms_i_level)
 			vty_out(vty, "  MS I level (slot %d):    %d dB%s",
-				i, ms->l1_meas()->ts[i].ms_i_level, VTY_NEWLINE);
+				i, ms->l1_meas.ts[i].ms_i_level, VTY_NEWLINE);
 	}
-	vty_out(vty, "  RLC/MAC DL Control Msg: %d%s", ms->dl_ctrl_msg(),
+	vty_out(vty, "  RLC/MAC DL Control Msg: %d%s", ms_dl_ctrl_msg(ms),
 		VTY_NEWLINE);
-	if (ms->ul_tbf())
+	if (ms_ul_tbf(ms))
 		vty_out(vty, "  Uplink TBF:             TFI=%d, state=%s%s",
-			ms->ul_tbf()->tfi(),
-			ms->ul_tbf()->state_name(),
+			ms_ul_tbf(ms)->tfi(),
+			ms_ul_tbf(ms)->state_name(),
 			VTY_NEWLINE);
-	if (ms->dl_tbf()) {
+	if (ms_dl_tbf(ms)) {
 		vty_out(vty, "  Downlink TBF:           TFI=%d, state=%s%s",
-			ms->dl_tbf()->tfi(),
-			ms->dl_tbf()->state_name(),
+			ms_dl_tbf(ms)->tfi(),
+			ms_dl_tbf(ms)->state_name(),
 			VTY_NEWLINE);
 		vty_out(vty, "  Current DL Throughput:  %d Kbps %s",
-			ms->dl_tbf()->m_bw.dl_throughput,
+			ms_dl_tbf(ms)->m_bw.dl_throughput,
 			VTY_NEWLINE);
 	}
 
-	llist_for_each(i_tbf, &ms->old_tbfs())
+	llist_for_each_entry(i_tbf, &ms->old_tbfs, list) {
+		struct gprs_rlcmac_tbf *tbf = (struct gprs_rlcmac_tbf *)i_tbf->entry;
 		vty_out(vty, "  Old %-19s TFI=%d, state=%s%s",
-			i_tbf->entry()->direction == GPRS_RLCMAC_UL_TBF ?
+			tbf_direction(tbf) == GPRS_RLCMAC_UL_TBF ?
 			"Uplink TBF:" : "Downlink TBF:",
-			i_tbf->entry()->tfi(),
-			i_tbf->entry()->state_name(),
+			tbf->tfi(),
+			tbf->state_name(),
 			VTY_NEWLINE);
+	}
 
 	return CMD_SUCCESS;
 }
@@ -206,10 +208,10 @@
 int pcu_vty_show_ms_all(struct vty *vty, struct gprs_rlcmac_bts *bts_data)
 {
 	BTS *bts = bts_data->bts;
-	LListHead<GprsMs> *ms_iter;
+	GprsMs *ms_iter;
 
-	llist_for_each(ms_iter, &bts->ms_store().ms_list())
-		show_ms(vty, ms_iter->entry());
+	llist_for_each_entry(ms_iter, bts->ms_store().ms_list(), list)
+		show_ms(vty, ms_iter);
 
 	return CMD_SUCCESS;
 }