Change in osmo-bsc[master]: Move struct gsm_bts_trx: gsm-data.* => bts_trx.*

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Thu Jul 16 13:27:45 UTC 2020


pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bsc/+/19298 )


Change subject: Move struct gsm_bts_trx: gsm-data.* => bts_trx.*
......................................................................

Move struct gsm_bts_trx: gsm-data.* => bts_trx.*

See rant fro similar recent commit moving stuff to bts.*.

Change-Id: I11758ca3d255d849d77bd068f24bb68bde1f89a5
---
M include/osmocom/bsc/Makefile.am
M include/osmocom/bsc/bts.h
A include/osmocom/bsc/bts_trx.h
M include/osmocom/bsc/gsm_data.h
M src/ipaccess/Makefile.am
M src/ipaccess/network_listen.c
M src/osmo-bsc/Makefile.am
M src/osmo-bsc/abis_nm.c
M src/osmo-bsc/bsc_subscr_conn_fsm.c
A src/osmo-bsc/bts_trx.c
M src/osmo-bsc/gsm_data.c
M src/utils/Makefile.am
M tests/abis/Makefile.am
M tests/bsc/Makefile.am
M tests/gsm0408/Makefile.am
M tests/handover/Makefile.am
M tests/nanobts_omlattr/Makefile.am
17 files changed, 398 insertions(+), 331 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/98/19298/1

diff --git a/include/osmocom/bsc/Makefile.am b/include/osmocom/bsc/Makefile.am
index 4d2df20..c2a82ce 100644
--- a/include/osmocom/bsc/Makefile.am
+++ b/include/osmocom/bsc/Makefile.am
@@ -11,6 +11,7 @@
 	bsc_subscr_conn_fsm.h \
 	bss.h \
 	bts.h \
+	bts_trx.h \
 	bts_ipaccess_nanobts_omlattr.h \
 	chan_alloc.h \
 	codec_pref.h \
diff --git a/include/osmocom/bsc/bts.h b/include/osmocom/bsc/bts.h
index b38c11a..9b89f4f 100644
--- a/include/osmocom/bsc/bts.h
+++ b/include/osmocom/bsc/bts.h
@@ -13,6 +13,7 @@
 #include <osmocom/abis/e1_input.h>
 
 #include "osmocom/bsc/gsm_data.h"
+#include "osmocom/bsc/bts_trx.h"
 
 enum bts_counter_id {
 	BTS_CTR_CHREQ_TOTAL,
diff --git a/include/osmocom/bsc/bts_trx.h b/include/osmocom/bsc/bts_trx.h
new file mode 100644
index 0000000..7e64439
--- /dev/null
+++ b/include/osmocom/bsc/bts_trx.h
@@ -0,0 +1,92 @@
+#pragma once
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <stdbool.h>
+
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/msgb.h>
+#include <osmocom/core/timer.h>
+#include <osmocom/core/bitvec.h>
+#include <osmocom/gsm/tlv.h>
+
+#include <osmocom/abis/e1_input.h>
+
+#include "osmocom/bsc/gsm_data.h"
+
+struct gsm_bts;
+
+#define TRX_NR_TS	8
+
+/* One TRX in a BTS */
+struct gsm_bts_trx {
+	/* list header in bts->trx_list */
+	struct llist_head list;
+
+	struct gsm_bts *bts;
+	/* number of this TRX in the BTS */
+	uint8_t nr;
+	/* human readable name / description */
+	char *description;
+	/* how do we talk RSL with this TRX? */
+	struct gsm_e1_subslot rsl_e1_link;
+	uint8_t rsl_tei;
+	struct e1inp_sign_link *rsl_link;
+
+	/* Timeout for initiating the RSL connection. */
+	struct osmo_timer_list rsl_connect_timeout;
+
+	/* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
+	struct e1inp_sign_link *oml_link;
+
+	struct gsm_abis_mo mo;
+	struct tlv_parsed nm_attr;
+	struct {
+		struct gsm_abis_mo mo;
+	} bb_transc;
+
+	uint16_t arfcn;
+	int nominal_power;		/* in dBm */
+	unsigned int max_power_red;	/* in actual dB */
+
+	union {
+		struct {
+			struct {
+				struct gsm_abis_mo mo;
+			} bbsig;
+			struct {
+				struct gsm_abis_mo mo;
+			} pa;
+		} bs11;
+		struct {
+			unsigned int test_state;
+			uint8_t test_nr;
+			struct rxlev_stats rxlev_stat;
+		} ipaccess;
+		struct {
+			struct {
+				struct om2k_mo om2k_mo;
+			} trxc;
+			struct {
+				struct om2k_mo om2k_mo;
+			} rx;
+			struct {
+				struct om2k_mo om2k_mo;
+			} tx;
+		} rbs2000;
+	};
+	struct gsm_bts_trx_ts ts[TRX_NR_TS];
+};
+
+struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
+char *gsm_trx_name(const struct gsm_bts_trx *trx);
+
+struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
+				   int *rc);
+
+void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason);
+bool trx_is_usable(const struct gsm_bts_trx *trx);
+
+void gsm_trx_all_ts_dispatch(struct gsm_bts_trx *trx, uint32_t ts_ev, void *data);
+int trx_count_free_ts(struct gsm_bts_trx *trx, enum gsm_phys_chan_config pchan);
+bool trx_has_valid_pchan_config(const struct gsm_bts_trx *trx);
diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index f90bfa7..e85be70 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -40,6 +40,7 @@
 struct gsm0808_cell_id;
 struct osmo_mgcpc_ep;
 struct gsm_bts;
+struct gsm_bts_trx;
 
 /** annotations for msgb ownership */
 #define __uses
@@ -330,7 +331,6 @@
    use 4 as magic number for BCCH hack - see osmo-bts-../oml.c:opstart_compl() */
 #define CCCH_LCHAN 4
 
-#define TRX_NR_TS	8
 #define TS_MAX_LCHAN	8
 
 #define HARDCODED_ARFCN 123
@@ -713,66 +713,6 @@
 	struct gsm_lchan lchan[TS_MAX_LCHAN];
 };
 
-/* One TRX in a BTS */
-struct gsm_bts_trx {
-	/* list header in bts->trx_list */
-	struct llist_head list;
-
-	struct gsm_bts *bts;
-	/* number of this TRX in the BTS */
-	uint8_t nr;
-	/* human readable name / description */
-	char *description;
-	/* how do we talk RSL with this TRX? */
-	struct gsm_e1_subslot rsl_e1_link;
-	uint8_t rsl_tei;
-	struct e1inp_sign_link *rsl_link;
-
-	/* Timeout for initiating the RSL connection. */
-	struct osmo_timer_list rsl_connect_timeout;
-
-	/* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
-	struct e1inp_sign_link *oml_link;
-
-	struct gsm_abis_mo mo;
-	struct tlv_parsed nm_attr;
-	struct {
-		struct gsm_abis_mo mo;
-	} bb_transc;
-
-	uint16_t arfcn;
-	int nominal_power;		/* in dBm */
-	unsigned int max_power_red;	/* in actual dB */
-
-	union {
-		struct {
-			struct {
-				struct gsm_abis_mo mo;
-			} bbsig;
-			struct {
-				struct gsm_abis_mo mo;
-			} pa;
-		} bs11;
-		struct {
-			unsigned int test_state;
-			uint8_t test_nr;
-			struct rxlev_stats rxlev_stat;
-		} ipaccess;
-		struct {
-			struct {
-				struct om2k_mo om2k_mo;
-			} trxc;
-			struct {
-				struct om2k_mo om2k_mo;
-			} rx;
-			struct {
-				struct om2k_mo om2k_mo;
-			} tx;
-		} rbs2000;
-	};
-	struct gsm_bts_trx_ts ts[TRX_NR_TS];
-};
-
 #define GSM_LCHAN_SI(lchan, i) (void *)((lchan)->si.buf[i][0])
 
 /*
@@ -962,8 +902,6 @@
 				   const struct gsm0808_cell_id *cell_id,
 				   int match_idx);
 
-struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
-
 extern const struct value_string gsm_chreq_descs[];
 extern const struct value_string gsm_pchant_names[];
 extern const struct value_string gsm_pchant_descs[];
@@ -974,7 +912,6 @@
 enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
 const char *gsm_lchant_name(enum gsm_chan_t c);
 const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
-char *gsm_trx_name(const struct gsm_bts_trx *trx);
 char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
 char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
 char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
@@ -1007,9 +944,6 @@
 
 uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts);
 
-struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
-				   int *rc);
-
 enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
 uint8_t pchan_subslots(enum gsm_phys_chan_config pchan);
 bool ts_is_tch(struct gsm_bts_trx_ts *ts);
@@ -1255,7 +1189,6 @@
 void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
 		   uint8_t e1_ts, uint8_t e1_ts_ss);
 
-void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason);
 int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
 int gsm_bts_set_system_infos(struct gsm_bts *bts);
 
@@ -1265,17 +1198,11 @@
 /* control interface handling */
 int bsc_base_ctrl_cmds_install(void);
 
-bool trx_is_usable(const struct gsm_bts_trx *trx);
 bool ts_is_usable(const struct gsm_bts_trx_ts *ts);
 
 int gsm_lchan_type_by_pchan(enum gsm_phys_chan_config pchan);
 enum gsm_phys_chan_config gsm_pchan_by_lchan_type(enum gsm_chan_t type);
 
-void gsm_trx_all_ts_dispatch(struct gsm_bts_trx *trx, uint32_t ts_ev, void *data);
-int trx_count_free_ts(struct gsm_bts_trx *trx, enum gsm_phys_chan_config pchan);
-
-bool trx_has_valid_pchan_config(const struct gsm_bts_trx *trx);
-
 enum gsm48_rr_cause bsc_gsm48_rr_cause_from_gsm0808_cause(enum gsm0808_cause c);
 enum gsm48_rr_cause bsc_gsm48_rr_cause_from_rsl_cause(uint8_t c);
 
diff --git a/src/ipaccess/Makefile.am b/src/ipaccess/Makefile.am
index 273530c..a1812a9 100644
--- a/src/ipaccess/Makefile.am
+++ b/src/ipaccess/Makefile.am
@@ -47,6 +47,7 @@
 # FIXME: resolve the bogus dependencies patched around here:
 ipaccess_config_LDADD = \
 	$(top_builddir)/src/osmo-bsc/bts.o \
+	$(top_builddir)/src/osmo-bsc/bts_trx.o \
 	$(top_builddir)/src/osmo-bsc/abis_nm.o \
 	$(top_builddir)/src/osmo-bsc/bts_ipaccess_nanobts.o \
 	$(top_builddir)/src/osmo-bsc/bts_ipaccess_nanobts_omlattr.o \
@@ -61,7 +62,9 @@
 	$(NULL)
 
 ipaccess_proxy_LDADD = \
+	$(top_builddir)/src/osmo-bsc/abis_nm.o \
 	$(top_builddir)/src/osmo-bsc/bts.o \
+	$(top_builddir)/src/osmo-bsc/bts_trx.o \
 	$(top_builddir)/src/osmo-bsc/gsm_data.o \
 	$(OSMO_LIBS) \
 	$(NULL)
diff --git a/src/ipaccess/network_listen.c b/src/ipaccess/network_listen.c
index bbaf798..e9f5c93 100644
--- a/src/ipaccess/network_listen.c
+++ b/src/ipaccess/network_listen.c
@@ -34,6 +34,7 @@
 #include <osmocom/gsm/gsm48_ie.h>
 
 #include <osmocom/bsc/gsm_data.h>
+#include <osmocom/bsc/bts_trx.h>
 #include <osmocom/bsc/abis_nm.h>
 #include <osmocom/bsc/signal.h>
 #include <osmocom/bsc/debug.h>
diff --git a/src/osmo-bsc/Makefile.am b/src/osmo-bsc/Makefile.am
index f66421a..231707c 100644
--- a/src/osmo-bsc/Makefile.am
+++ b/src/osmo-bsc/Makefile.am
@@ -44,6 +44,7 @@
 	bsc_subscriber.c \
 	bsc_vty.c \
 	bts.c \
+	bts_trx.c \
 	bts_ericsson_rbs2000.c \
 	bts_init.c \
 	bts_ipaccess_nanobts.c \
diff --git a/src/osmo-bsc/abis_nm.c b/src/osmo-bsc/abis_nm.c
index 19eed8c..d88ce24 100644
--- a/src/osmo-bsc/abis_nm.c
+++ b/src/osmo-bsc/abis_nm.c
@@ -3020,26 +3020,6 @@
 	memcpy(&_buf->rac, &ci, sizeof(ci));
 }
 
-void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason)
-{
-	uint8_t new_state = locked ? NM_STATE_LOCKED : NM_STATE_UNLOCKED;
-
-
-	if (!trx->bts || !trx->bts->oml_link) {
-		/* Set initial state which will be sent when BTS connects. */
-		trx->mo.nm_state.administrative = new_state;
-		return;
-	}
-
-	LOG_TRX(trx, DNM, LOGL_NOTICE, "Requesting administrative state change %s -> %s [%s]\n",
-	     get_value_string(abis_nm_adm_state_names, trx->mo.nm_state.administrative),
-	     get_value_string(abis_nm_adm_state_names, new_state), reason);
-
-	abis_nm_chg_adm_state(trx->bts, NM_OC_RADIO_CARRIER,
-			      trx->bts->bts_nr, trx->nr, 0xff,
-			      new_state);
-}
-
 static const struct value_string ipacc_testres_names[] = {
 	{ NM_IPACC_TESTRES_SUCCESS,	"SUCCESS" },
 	{ NM_IPACC_TESTRES_TIMEOUT,	"TIMEOUT" },
diff --git a/src/osmo-bsc/bsc_subscr_conn_fsm.c b/src/osmo-bsc/bsc_subscr_conn_fsm.c
index 72f2474..9b1fb3f 100644
--- a/src/osmo-bsc/bsc_subscr_conn_fsm.c
+++ b/src/osmo-bsc/bsc_subscr_conn_fsm.c
@@ -28,6 +28,7 @@
 #include <osmocom/bsc/a_reset.h>
 #include <osmocom/bsc/gsm_08_08.h>
 #include <osmocom/bsc/gsm_data.h>
+#include <osmocom/bsc/bts.h>
 #include <osmocom/bsc/handover_fsm.h>
 #include <osmocom/bsc/lchan_fsm.h>
 #include <osmocom/bsc/lchan_rtp_fsm.h>
diff --git a/src/osmo-bsc/bts_trx.c b/src/osmo-bsc/bts_trx.c
new file mode 100644
index 0000000..15d5b59
--- /dev/null
+++ b/src/osmo-bsc/bts_trx.c
@@ -0,0 +1,288 @@
+/* (C) 2008-2018 by Harald Welte <laforge at gnumonks.org>
+ * (C) 2020 by sysmocom s.f.m.c. GmbH <info at sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <osmocom/gsm/abis_nm.h>
+
+#include <osmocom/bsc/gsm_data.h>
+#include <osmocom/bsc/bts.h>
+#include <osmocom/bsc/bts_trx.h>
+#include <osmocom/bsc/timeslot_fsm.h>
+#include <osmocom/bsc/abis_nm.h>
+#include <osmocom/bsc/lchan_fsm.h>
+#include <osmocom/bsc/debug.h>
+
+struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts)
+{
+	struct gsm_bts_trx *trx = talloc_zero(bts, struct gsm_bts_trx);
+	int k;
+
+	if (!trx)
+		return NULL;
+
+	trx->bts = bts;
+	trx->nr = bts->num_trx++;
+	trx->mo.nm_state.administrative = NM_STATE_UNLOCKED;
+
+	gsm_mo_init(&trx->mo, bts, NM_OC_RADIO_CARRIER,
+		    bts->nr, trx->nr, 0xff);
+	gsm_mo_init(&trx->bb_transc.mo, bts, NM_OC_BASEB_TRANSC,
+		    bts->nr, trx->nr, 0xff);
+
+	for (k = 0; k < TRX_NR_TS; k++) {
+		struct gsm_bts_trx_ts *ts = &trx->ts[k];
+		int l;
+
+
+		ts->trx = trx;
+		ts->nr = k;
+		ts->pchan_from_config = ts->pchan_on_init = ts->pchan_is = GSM_PCHAN_NONE;
+		ts->tsc = -1;
+
+		ts_fsm_alloc(ts);
+
+		gsm_mo_init(&ts->mo, bts, NM_OC_CHANNEL,
+			    bts->nr, trx->nr, ts->nr);
+
+		ts->hopping.arfcns.data_len = sizeof(ts->hopping.arfcns_data);
+		ts->hopping.arfcns.data = ts->hopping.arfcns_data;
+		ts->hopping.ma.data_len = sizeof(ts->hopping.ma_data);
+		ts->hopping.ma.data = ts->hopping.ma_data;
+
+		for (l = 0; l < TS_MAX_LCHAN; l++) {
+			struct gsm_lchan *lchan;
+			char *name;
+			lchan = &ts->lchan[l];
+
+			lchan->ts = ts;
+			lchan->nr = l;
+			lchan->type = GSM_LCHAN_NONE;
+
+			name = gsm_lchan_name_compute(lchan);
+			lchan->name = talloc_strdup(trx, name);
+		}
+	}
+
+	if (trx->nr != 0)
+		trx->nominal_power = bts->c0->nominal_power;
+
+	llist_add_tail(&trx->list, &bts->trx_list);
+
+	return trx;
+}
+
+static char ts2str[255];
+
+char *gsm_trx_name(const struct gsm_bts_trx *trx)
+{
+	if (!trx)
+		snprintf(ts2str, sizeof(ts2str), "(trx=NULL)");
+	else
+		snprintf(ts2str, sizeof(ts2str), "(bts=%d,trx=%d)",
+			 trx->bts->nr, trx->nr);
+
+	return ts2str;
+}
+
+/* determine logical channel based on TRX and channel number IE */
+struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
+				   int *rc)
+{
+	uint8_t ts_nr = chan_nr & 0x07;
+	uint8_t cbits = chan_nr >> 3;
+	uint8_t lch_idx;
+	struct gsm_bts_trx_ts *ts = &trx->ts[ts_nr];
+	bool ok;
+
+	if (rc)
+		*rc = -EINVAL;
+
+	if (cbits == 0x01) {
+		lch_idx = 0;	/* TCH/F */
+		ok = ts_is_capable_of_pchan(ts, GSM_PCHAN_TCH_F)
+			|| ts->pchan_on_init == GSM_PCHAN_PDCH; /* PDCH? really? */
+	} else if ((cbits & 0x1e) == 0x02) {
+		lch_idx = cbits & 0x1;	/* TCH/H */
+		ok = ts_is_capable_of_pchan(ts, GSM_PCHAN_TCH_H);
+	} else if ((cbits & 0x1c) == 0x04) {
+		lch_idx = cbits & 0x3;	/* SDCCH/4 */
+		ok = ts_is_capable_of_pchan(ts, GSM_PCHAN_CCCH_SDCCH4);
+	} else if ((cbits & 0x18) == 0x08) {
+		lch_idx = cbits & 0x7;	/* SDCCH/8 */
+		ok = ts_is_capable_of_pchan(ts, GSM_PCHAN_SDCCH8_SACCH8C);
+	} else if (cbits == 0x10 || cbits == 0x11 || cbits == 0x12) {
+		lch_idx = 0; /* CCCH? */
+		ok = ts_is_capable_of_pchan(ts, GSM_PCHAN_CCCH);
+		/* FIXME: we should not return first sdcch4 !!! */
+	} else if ((chan_nr & RSL_CHAN_NR_MASK) == RSL_CHAN_OSMO_PDCH) {
+		lch_idx = 0;
+		ok = (ts->pchan_on_init == GSM_PCHAN_TCH_F_TCH_H_PDCH);
+	} else
+		return NULL;
+
+	if (rc && ok)
+		*rc = 0;
+
+	return &ts->lchan[lch_idx];
+}
+
+void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason)
+{
+	uint8_t new_state = locked ? NM_STATE_LOCKED : NM_STATE_UNLOCKED;
+
+
+	if (!trx->bts || !trx->bts->oml_link) {
+		/* Set initial state which will be sent when BTS connects. */
+		trx->mo.nm_state.administrative = new_state;
+		return;
+	}
+
+	LOG_TRX(trx, DNM, LOGL_NOTICE, "Requesting administrative state change %s -> %s [%s]\n",
+	     get_value_string(abis_nm_adm_state_names, trx->mo.nm_state.administrative),
+	     get_value_string(abis_nm_adm_state_names, new_state), reason);
+
+	abis_nm_chg_adm_state(trx->bts, NM_OC_RADIO_CARRIER,
+			      trx->bts->bts_nr, trx->nr, 0xff,
+			      new_state);
+}
+
+bool trx_is_usable(const struct gsm_bts_trx *trx)
+{
+	/* FIXME: How does this behave for BS-11 ? */
+	if (is_ipaccess_bts(trx->bts)) {
+		if (!nm_is_running(&trx->mo.nm_state) ||
+		    !nm_is_running(&trx->bb_transc.mo.nm_state))
+			return false;
+	} else if (is_ericsson_bts(trx->bts)) {
+		/* The OM2000 -> 12.21 mapping we do doesn't have separate bb_transc MO */
+		if (!nm_is_running(&trx->mo.nm_state))
+			return false;
+	}
+
+	return true;
+}
+
+
+void gsm_trx_all_ts_dispatch(struct gsm_bts_trx *trx, uint32_t ts_ev, void *data)
+{
+	int i;
+	for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
+		struct gsm_bts_trx_ts *ts = &trx->ts[i];
+		osmo_fsm_inst_dispatch(ts->fi, ts_ev, data);
+	}
+}
+
+int trx_count_free_ts(struct gsm_bts_trx *trx, enum gsm_phys_chan_config pchan)
+{
+	struct gsm_bts_trx_ts *ts;
+	struct gsm_lchan *lchan;
+	int j;
+	int count = 0;
+
+	if (!trx_is_usable(trx))
+		return 0;
+
+	for (j = 0; j < ARRAY_SIZE(trx->ts); j++) {
+		ts = &trx->ts[j];
+		if (!ts_is_usable(ts))
+			continue;
+
+		if (ts->pchan_is == GSM_PCHAN_PDCH) {
+			/* Dynamic timeslots in PDCH mode will become TCH if needed. */
+			switch (ts->pchan_on_init) {
+			case GSM_PCHAN_TCH_F_PDCH:
+				if (pchan == GSM_PCHAN_TCH_F)
+					count++;
+				continue;
+
+			case GSM_PCHAN_TCH_F_TCH_H_PDCH:
+				if (pchan == GSM_PCHAN_TCH_F)
+					count++;
+				else if (pchan == GSM_PCHAN_TCH_H)
+					count += 2;
+				continue;
+
+			default:
+				/* Not dynamic, not applicable. */
+				continue;
+			}
+		}
+
+		if (ts->pchan_is != pchan)
+			continue;
+
+		ts_for_each_lchan(lchan, ts) {
+			if (lchan_state_is(lchan, LCHAN_ST_UNUSED))
+				count++;
+		}
+	}
+
+	return count;
+}
+
+bool trx_has_valid_pchan_config(const struct gsm_bts_trx *trx)
+{
+	bool combined = false;
+	bool result = true;
+	unsigned int i;
+
+	/* Iterate over all timeslots */
+	for (i = 0; i < 8; i++) {
+		const struct gsm_bts_trx_ts *ts = &trx->ts[i];
+
+		switch (ts->pchan_from_config) {
+		case GSM_PCHAN_CCCH_SDCCH4_CBCH:
+		case GSM_PCHAN_CCCH_SDCCH4:
+			/* CCCH+SDCCH4 can only be configured on TS0 */
+			if (i > 0) {
+				LOGP(DNM, LOGL_ERROR, "Combined CCCH is not allowed "
+						      "on TS%u > 0\n", i);
+				result = false;
+			}
+			if (i == 0)
+				combined = true;
+			/* fall-through */
+		case GSM_PCHAN_CCCH:
+			/* 3GPP TS 45.002, Table 3, CCCH: TS (0, 2, 4, 6) */
+			if (i % 2 != 0) {
+				LOGP(DNM, LOGL_ERROR, "%s is not allowed on odd TS%u\n",
+				     gsm_pchan_name(ts->pchan_from_config), i);
+				result = false;
+			}
+
+			/* There can be no more CCCHs if TS0/C0 is combined */
+			if (i > 0 && combined) {
+				LOGP(DNM, LOGL_ERROR, "%s is not allowed on TS%u, "
+				     "because TS0 is using combined channel configuration\n",
+				     gsm_pchan_name(ts->pchan_from_config), i);
+				result = false;
+			}
+			break;
+
+		default:
+			/* CCCH on TS0 is mandatory for C0 */
+			if (trx->bts->c0 == trx && i == 0) {
+				LOGP(DNM, LOGL_ERROR, "TS0 on C0 must be CCCH/BCCH\n");
+				result = false;
+			}
+		}
+	}
+
+	return result;
+}
diff --git a/src/osmo-bsc/gsm_data.c b/src/osmo-bsc/gsm_data.c
index 5daee26..c0c8cf6 100644
--- a/src/osmo-bsc/gsm_data.c
+++ b/src/osmo-bsc/gsm_data.c
@@ -290,79 +290,8 @@
 	return NULL;
 }
 
-struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts)
-{
-	struct gsm_bts_trx *trx = talloc_zero(bts, struct gsm_bts_trx);
-	int k;
-
-	if (!trx)
-		return NULL;
-
-	trx->bts = bts;
-	trx->nr = bts->num_trx++;
-	trx->mo.nm_state.administrative = NM_STATE_UNLOCKED;
-
-	gsm_mo_init(&trx->mo, bts, NM_OC_RADIO_CARRIER,
-		    bts->nr, trx->nr, 0xff);
-	gsm_mo_init(&trx->bb_transc.mo, bts, NM_OC_BASEB_TRANSC,
-		    bts->nr, trx->nr, 0xff);
-
-	for (k = 0; k < TRX_NR_TS; k++) {
-		struct gsm_bts_trx_ts *ts = &trx->ts[k];
-		int l;
-
-
-		ts->trx = trx;
-		ts->nr = k;
-		ts->pchan_from_config = ts->pchan_on_init = ts->pchan_is = GSM_PCHAN_NONE;
-		ts->tsc = -1;
-
-		ts_fsm_alloc(ts);
-
-		gsm_mo_init(&ts->mo, bts, NM_OC_CHANNEL,
-			    bts->nr, trx->nr, ts->nr);
-
-		ts->hopping.arfcns.data_len = sizeof(ts->hopping.arfcns_data);
-		ts->hopping.arfcns.data = ts->hopping.arfcns_data;
-		ts->hopping.ma.data_len = sizeof(ts->hopping.ma_data);
-		ts->hopping.ma.data = ts->hopping.ma_data;
-
-		for (l = 0; l < TS_MAX_LCHAN; l++) {
-			struct gsm_lchan *lchan;
-			char *name;
-			lchan = &ts->lchan[l];
-
-			lchan->ts = ts;
-			lchan->nr = l;
-			lchan->type = GSM_LCHAN_NONE;
-
-			name = gsm_lchan_name_compute(lchan);
-			lchan->name = talloc_strdup(trx, name);
-		}
-	}
-
-	if (trx->nr != 0)
-		trx->nominal_power = bts->c0->nominal_power;
-
-	llist_add_tail(&trx->list, &bts->trx_list);
-
-	return trx;
-}
-
 static char ts2str[255];
 
-char *gsm_trx_name(const struct gsm_bts_trx *trx)
-{
-	if (!trx)
-		snprintf(ts2str, sizeof(ts2str), "(trx=NULL)");
-	else
-		snprintf(ts2str, sizeof(ts2str), "(bts=%d,trx=%d)",
-			 trx->bts->nr, trx->nr);
-
-	return ts2str;
-}
-
-
 char *gsm_ts_name(const struct gsm_bts_trx_ts *ts)
 {
 	snprintf(ts2str, sizeof(ts2str), "(bts=%d,trx=%d,ts=%d)",
@@ -620,48 +549,6 @@
 	return gsm_pchan2chan_nr(lchan->ts->pchan_is, lchan->ts->nr, lchan->nr);
 }
 
-/* determine logical channel based on TRX and channel number IE */
-struct gsm_lchan *rsl_lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
-				   int *rc)
-{
-	uint8_t ts_nr = chan_nr & 0x07;
-	uint8_t cbits = chan_nr >> 3;
-	uint8_t lch_idx;
-	struct gsm_bts_trx_ts *ts = &trx->ts[ts_nr];
-	bool ok;
-
-	if (rc)
-		*rc = -EINVAL;
-
-	if (cbits == 0x01) {
-		lch_idx = 0;	/* TCH/F */
-		ok = ts_is_capable_of_pchan(ts, GSM_PCHAN_TCH_F)
-			|| ts->pchan_on_init == GSM_PCHAN_PDCH; /* PDCH? really? */
-	} else if ((cbits & 0x1e) == 0x02) {
-		lch_idx = cbits & 0x1;	/* TCH/H */
-		ok = ts_is_capable_of_pchan(ts, GSM_PCHAN_TCH_H);
-	} else if ((cbits & 0x1c) == 0x04) {
-		lch_idx = cbits & 0x3;	/* SDCCH/4 */
-		ok = ts_is_capable_of_pchan(ts, GSM_PCHAN_CCCH_SDCCH4);
-	} else if ((cbits & 0x18) == 0x08) {
-		lch_idx = cbits & 0x7;	/* SDCCH/8 */
-		ok = ts_is_capable_of_pchan(ts, GSM_PCHAN_SDCCH8_SACCH8C);
-	} else if (cbits == 0x10 || cbits == 0x11 || cbits == 0x12) {
-		lch_idx = 0; /* CCCH? */
-		ok = ts_is_capable_of_pchan(ts, GSM_PCHAN_CCCH);
-		/* FIXME: we should not return first sdcch4 !!! */
-	} else if ((chan_nr & RSL_CHAN_NR_MASK) == RSL_CHAN_OSMO_PDCH) {
-		lch_idx = 0;
-		ok = (ts->pchan_on_init == GSM_PCHAN_TCH_F_TCH_H_PDCH);
-	} else
-		return NULL;
-
-	if (rc && ok)
-		*rc = 0;
-
-	return &ts->lchan[lch_idx];
-}
-
 static const uint8_t subslots_per_pchan[] = {
 	[GSM_PCHAN_NONE] = 0,
 	[GSM_PCHAN_CCCH] = 0,
@@ -708,31 +595,6 @@
 	return conn->lchan->ts->trx->bts;
 }
 
-bool trx_is_usable(const struct gsm_bts_trx *trx)
-{
-	/* FIXME: How does this behave for BS-11 ? */
-	if (is_ipaccess_bts(trx->bts)) {
-		if (!nm_is_running(&trx->mo.nm_state) ||
-		    !nm_is_running(&trx->bb_transc.mo.nm_state))
-			return false;
-	} else if (is_ericsson_bts(trx->bts)) {
-		/* The OM2000 -> 12.21 mapping we do doesn't have separate bb_transc MO */
-		if (!nm_is_running(&trx->mo.nm_state))
-			return false;
-	}
-
-	return true;
-}
-
-void gsm_trx_all_ts_dispatch(struct gsm_bts_trx *trx, uint32_t ts_ev, void *data)
-{
-	int i;
-	for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
-		struct gsm_bts_trx_ts *ts = &trx->ts[i];
-		osmo_fsm_inst_dispatch(ts->fi, ts_ev, data);
-	}
-}
-
 static void _chan_desc_fill_tail(struct gsm48_chan_desc *cd, const struct gsm_lchan *lchan)
 {
 	if (!lchan->ts->hopping.enabled) {
@@ -950,54 +812,6 @@
 	}
 }
 
-int trx_count_free_ts(struct gsm_bts_trx *trx, enum gsm_phys_chan_config pchan)
-{
-	struct gsm_bts_trx_ts *ts;
-	struct gsm_lchan *lchan;
-	int j;
-	int count = 0;
-
-	if (!trx_is_usable(trx))
-		return 0;
-
-	for (j = 0; j < ARRAY_SIZE(trx->ts); j++) {
-		ts = &trx->ts[j];
-		if (!ts_is_usable(ts))
-			continue;
-
-		if (ts->pchan_is == GSM_PCHAN_PDCH) {
-			/* Dynamic timeslots in PDCH mode will become TCH if needed. */
-			switch (ts->pchan_on_init) {
-			case GSM_PCHAN_TCH_F_PDCH:
-				if (pchan == GSM_PCHAN_TCH_F)
-					count++;
-				continue;
-
-			case GSM_PCHAN_TCH_F_TCH_H_PDCH:
-				if (pchan == GSM_PCHAN_TCH_F)
-					count++;
-				else if (pchan == GSM_PCHAN_TCH_H)
-					count += 2;
-				continue;
-
-			default:
-				/* Not dynamic, not applicable. */
-				continue;
-			}
-		}
-
-		if (ts->pchan_is != pchan)
-			continue;
-
-		ts_for_each_lchan(lchan, ts) {
-			if (lchan_state_is(lchan, LCHAN_ST_UNUSED))
-				count++;
-		}
-	}
-
-	return count;
-}
-
 bool ts_is_usable(const struct gsm_bts_trx_ts *ts)
 {
 	if (!trx_is_usable(ts->trx)) {
@@ -1095,57 +909,6 @@
 	{}
 };
 
-bool trx_has_valid_pchan_config(const struct gsm_bts_trx *trx)
-{
-	bool combined = false;
-	bool result = true;
-	unsigned int i;
-
-	/* Iterate over all timeslots */
-	for (i = 0; i < 8; i++) {
-		const struct gsm_bts_trx_ts *ts = &trx->ts[i];
-
-		switch (ts->pchan_from_config) {
-		case GSM_PCHAN_CCCH_SDCCH4_CBCH:
-		case GSM_PCHAN_CCCH_SDCCH4:
-			/* CCCH+SDCCH4 can only be configured on TS0 */
-			if (i > 0) {
-				LOGP(DNM, LOGL_ERROR, "Combined CCCH is not allowed "
-						      "on TS%u > 0\n", i);
-				result = false;
-			}
-			if (i == 0)
-				combined = true;
-			/* fall-through */
-		case GSM_PCHAN_CCCH:
-			/* 3GPP TS 45.002, Table 3, CCCH: TS (0, 2, 4, 6) */
-			if (i % 2 != 0) {
-				LOGP(DNM, LOGL_ERROR, "%s is not allowed on odd TS%u\n",
-				     gsm_pchan_name(ts->pchan_from_config), i);
-				result = false;
-			}
-
-			/* There can be no more CCCHs if TS0/C0 is combined */
-			if (i > 0 && combined) {
-				LOGP(DNM, LOGL_ERROR, "%s is not allowed on TS%u, "
-				     "because TS0 is using combined channel configuration\n",
-				     gsm_pchan_name(ts->pchan_from_config), i);
-				result = false;
-			}
-			break;
-
-		default:
-			/* CCCH on TS0 is mandatory for C0 */
-			if (trx->bts->c0 == trx && i == 0) {
-				LOGP(DNM, LOGL_ERROR, "TS0 on C0 must be CCCH/BCCH\n");
-				result = false;
-			}
-		}
-	}
-
-	return result;
-}
-
 /* This may be specific to RR Channel Release, and the mappings were chosen by pure naive guessing without a proper
  * specification available. */
 enum gsm48_rr_cause bsc_gsm48_rr_cause_from_gsm0808_cause(enum gsm0808_cause c)
diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am
index 6696679..653ed97 100644
--- a/src/utils/Makefile.am
+++ b/src/utils/Makefile.am
@@ -49,6 +49,7 @@
 bs11_config_LDADD = \
 	$(top_builddir)/src/osmo-bsc/abis_nm.o \
 	$(top_builddir)/src/osmo-bsc/bts.o \
+	$(top_builddir)/src/osmo-bsc/bts_trx.o \
 	$(top_builddir)/src/osmo-bsc/bts_siemens_bs11.o \
 	$(top_builddir)/src/osmo-bsc/e1_config.o \
 	$(top_builddir)/src/osmo-bsc/gsm_data.o \
@@ -118,7 +119,9 @@
 	$(NULL)
 
 meas_json_LDADD = \
+	$(top_builddir)/src/osmo-bsc/abis_nm.o \
 	$(top_builddir)/src/osmo-bsc/bts.o \
+	$(top_builddir)/src/osmo-bsc/bts_trx.o \
 	$(top_builddir)/src/osmo-bsc/gsm_data.o \
 	$(LIBOSMOCORE_LIBS) \
 	$(LIBOSMOGSM_LIBS) \
diff --git a/tests/abis/Makefile.am b/tests/abis/Makefile.am
index a01f56a..5f81ceb 100644
--- a/tests/abis/Makefile.am
+++ b/tests/abis/Makefile.am
@@ -27,6 +27,7 @@
 abis_test_LDADD = \
 	$(top_builddir)/src/osmo-bsc/abis_nm.o \
 	$(top_builddir)/src/osmo-bsc/bts.o \
+	$(top_builddir)/src/osmo-bsc/bts_trx.o \
 	$(top_builddir)/src/osmo-bsc/gsm_data.o \
 	$(top_builddir)/src/osmo-bsc/net_init.o \
 	$(LIBOSMOCORE_LIBS) \
diff --git a/tests/bsc/Makefile.am b/tests/bsc/Makefile.am
index 7ea002e..012bd79 100644
--- a/tests/bsc/Makefile.am
+++ b/tests/bsc/Makefile.am
@@ -38,6 +38,7 @@
 	$(top_builddir)/src/osmo-bsc/osmo_bsc_filter.o \
 	$(top_builddir)/src/osmo-bsc/bsc_subscriber.o \
 	$(top_builddir)/src/osmo-bsc/bts.o \
+	$(top_builddir)/src/osmo-bsc/bts_trx.o \
 	$(top_builddir)/src/osmo-bsc/gsm_data.o \
 	$(top_builddir)/src/osmo-bsc/handover_cfg.o \
 	$(top_builddir)/src/osmo-bsc/handover_logic.o \
diff --git a/tests/gsm0408/Makefile.am b/tests/gsm0408/Makefile.am
index 21b7873..790f3aa 100644
--- a/tests/gsm0408/Makefile.am
+++ b/tests/gsm0408/Makefile.am
@@ -23,9 +23,11 @@
 	$(NULL)
 
 gsm0408_test_LDADD = \
+	$(top_builddir)/src/osmo-bsc/abis_nm.o \
 	$(top_builddir)/src/osmo-bsc/gsm_04_08_rr.o \
 	$(top_builddir)/src/osmo-bsc/arfcn_range_encode.o \
 	$(top_builddir)/src/osmo-bsc/bts.o \
+	$(top_builddir)/src/osmo-bsc/bts_trx.o \
 	$(top_builddir)/src/osmo-bsc/gsm_data.o \
 	$(top_builddir)/src/osmo-bsc/net_init.o \
 	$(top_builddir)/src/osmo-bsc/rest_octets.o \
diff --git a/tests/handover/Makefile.am b/tests/handover/Makefile.am
index 571b7a9..661b3d2 100644
--- a/tests/handover/Makefile.am
+++ b/tests/handover/Makefile.am
@@ -58,6 +58,7 @@
 	$(top_builddir)/src/osmo-bsc/bsc_subscriber.o \
 	$(top_builddir)/src/osmo-bsc/bsc_vty.o \
 	$(top_builddir)/src/osmo-bsc/bts.o \
+	$(top_builddir)/src/osmo-bsc/bts_trx.o \
 	$(top_builddir)/src/osmo-bsc/bts_ipaccess_nanobts.o \
 	$(top_builddir)/src/osmo-bsc/bts_ipaccess_nanobts_omlattr.o \
 	$(top_builddir)/src/osmo-bsc/bts_unknown.o \
diff --git a/tests/nanobts_omlattr/Makefile.am b/tests/nanobts_omlattr/Makefile.am
index 93fdbe8..5a627ff 100644
--- a/tests/nanobts_omlattr/Makefile.am
+++ b/tests/nanobts_omlattr/Makefile.am
@@ -26,6 +26,7 @@
 	$(top_builddir)/src/osmo-bsc/abis_nm.o \
 	$(top_builddir)/src/osmo-bsc/bts_ipaccess_nanobts_omlattr.o \
 	$(top_builddir)/src/osmo-bsc/bts.o \
+	$(top_builddir)/src/osmo-bsc/bts_trx.o \
 	$(top_builddir)/src/osmo-bsc/gsm_data.o \
 	$(LIBOSMOCORE_LIBS) \
 	$(LIBOSMOGSM_LIBS) \

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

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: I11758ca3d255d849d77bd068f24bb68bde1f89a5
Gerrit-Change-Number: 19298
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200716/192c96b0/attachment.htm>


More information about the gerrit-log mailing list