Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/4161

to look at the new patch set (#3).

Remove build dependency on legacy OpenBSC

* copy-paste gsm_data_shared.* from OpenBSC master
* remove corresponding configure check and option
* remove .deb dependency

Actual refactoring with removal of unnecessary structures/parts, moving
common OpenBSC/OsmoBSC parts into libraries etc. are left for further
patches.

Current patch will make coexistence with *BSC easier and will simplify
our build infrastructure.

Change-Id: I9f004fb5c4c1db29d4792dfd281d388c7063da13
Related: OS#1923
---
M configure.ac
M debian/control
M debian/rules
M include/Makefile.am
D include/openbsc/gsm_data.h
M include/osmo-bts/Makefile.am
M include/osmo-bts/gsm_data.h
A include/osmo-bts/gsm_data_shared.h
M src/common/Makefile.am
M src/common/gsm_data_shared.c
M src/osmo-bts-litecell15/Makefile.am
M src/osmo-bts-octphy/Makefile.am
M src/osmo-bts-sysmo/Makefile.am
M src/osmo-bts-trx/Makefile.am
M src/osmo-bts-virtual/Makefile.am
M tests/agch/Makefile.am
M tests/cipher/Makefile.am
M tests/handover/Makefile.am
M tests/meas/Makefile.am
M tests/misc/Makefile.am
M tests/paging/Makefile.am
M tests/sysmobts/Makefile.am
M tests/tx_power/Makefile.am
23 files changed, 1,870 insertions(+), 39 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/61/4161/3

diff --git a/configure.ac b/configure.ac
index bc36456..a41f7ec 100644
--- a/configure.ac
+++ b/configure.ac
@@ -147,25 +147,9 @@
        CPPFLAGS=$oldCPPFLAGS
 fi
 
-# We share gsm_data.h with OpenBSC and need to be pointed to the source
-# directory of OpenBSC for now.
-AC_ARG_WITH([openbsc],
-       [AS_HELP_STRING([--with-openbsc=INCLUDE_DIR],
-               [OpenBSC include directory for openbsc/gsm_data_shared.h])],
-       [openbsc_incdir="$withval"],
-       [openbsc_incdir="`cd $srcdir; pwd`/../openbsc/openbsc/include"])
-AC_SUBST([OPENBSC_INCDIR], $openbsc_incdir)
-
-oldCPPFLAGS=$CPPFLAGS
-CPPFLAGS="$CPPFLAGS -I$OPENBSC_INCDIR -I$srcdir/include $LIBOSMOCORE_CFLAGS"
-AC_CHECK_HEADER([openbsc/gsm_data_shared.h],[],
-       [AC_MSG_ERROR([openbsc/gsm_data_shared.h can not be found in 
$openbsc_incdir])],
-       [#include <osmo-bts/tx_power.h>])
-CPPFLAGS=$oldCPPFLAGS
-
 # Check for the sbts2050_header.h that was added after the 3.6 release
 oldCPPFLAGS=$CPPFLAGS
-CPPFLAGS="$CPPFLAGS -I$OPENBSC_INCDIR $LIBOSMOCORE_CFLAGS"
+CPPFLAGS="$CPPFLAGS $LIBOSMOCORE_CFLAGS"
 AC_CHECK_HEADER([sysmocom/femtobts/sbts2050_header.h],
                [sysmo_uc_header="yes"],[])
 CPPFLAGS=$oldCPPFLAGS
diff --git a/debian/control b/debian/control
index e1a58b2..074f687 100644
--- a/debian/control
+++ b/debian/control
@@ -9,7 +9,6 @@
                autotools-dev,
                pkg-config,
                libosmocore-dev,
-               openbsc-dev,
                libosmo-abis-dev,
                libosmo-netif-dev,
                libgps-dev,
diff --git a/debian/rules b/debian/rules
index 12b3334..80ba0b2 100755
--- a/debian/rules
+++ b/debian/rules
@@ -19,7 +19,7 @@
        dh_autoreconf
 
 override_dh_auto_configure:
-       dh_auto_configure --  --enable-trx 
--with-openbsc=/usr/src/osmocom/openbsc/openbsc/include/
+       dh_auto_configure --  --enable-trx
 
 override_dh_clean:
        dh_clean
diff --git a/include/Makefile.am b/include/Makefile.am
index e35e696..7585a65 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,3 +1 @@
 SUBDIRS = osmo-bts
-
-noinst_HEADERS = openbsc/gsm_data.h
diff --git a/include/openbsc/gsm_data.h b/include/openbsc/gsm_data.h
deleted file mode 120000
index f0d49f2..0000000
--- a/include/openbsc/gsm_data.h
+++ /dev/null
@@ -1 +0,0 @@
-../osmo-bts/gsm_data.h
\ No newline at end of file
diff --git a/include/osmo-bts/Makefile.am b/include/osmo-bts/Makefile.am
index ef4165f..a15ce3d 100644
--- a/include/osmo-bts/Makefile.am
+++ b/include/osmo-bts/Makefile.am
@@ -1,4 +1,4 @@
-noinst_HEADERS = abis.h bts.h bts_model.h gsm_data.h logging.h measurement.h \
+noinst_HEADERS = abis.h bts.h bts_model.h gsm_data.h gsm_data_shared.h 
logging.h measurement.h \
                 oml.h paging.h rsl.h signal.h vty.h amr.h pcu_if.h 
pcuif_proto.h \
                 handover.h msg_utils.h tx_power.h control_if.h cbch.h l1sap.h \
                 power_control.h scheduler.h scheduler_backend.h phy_link.h \
diff --git a/include/osmo-bts/gsm_data.h b/include/osmo-bts/gsm_data.h
index aeac4b2..dcffcf6 100644
--- a/include/osmo-bts/gsm_data.h
+++ b/include/osmo-bts/gsm_data.h
@@ -133,7 +133,7 @@
 
 #define bts_role_bts(x)        ((struct gsm_bts_role_bts *)(x)->role)
 
-#include "openbsc/gsm_data_shared.h"
+#include <osmo-bts/gsm_data_shared.h>
 
 void lchan_set_state(struct gsm_lchan *lchan, enum gsm_lchan_state state);
 int conf_lchans_as_pchan(struct gsm_bts_trx_ts *ts,
diff --git a/include/osmo-bts/gsm_data_shared.h 
b/include/osmo-bts/gsm_data_shared.h
new file mode 100644
index 0000000..c19b125
--- /dev/null
+++ b/include/osmo-bts/gsm_data_shared.h
@@ -0,0 +1,999 @@
+#ifndef _GSM_DATA_SHAREDH
+#define _GSM_DATA_SHAREDH
+
+#include <regex.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <osmocom/core/timer.h>
+#include <osmocom/core/bitvec.h>
+#include <osmocom/core/statistics.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/gsm/tlv.h>
+#include <osmocom/gsm/rxlev_stat.h>
+#include <osmocom/gsm/sysinfo.h>
+#include <osmocom/gsm/meas_rep.h>
+#include <osmocom/gsm/protocol/gsm_04_08.h>
+#include <osmocom/gsm/protocol/gsm_08_58.h>
+#include <osmocom/gsm/protocol/gsm_12_21.h>
+
+#include <osmocom/abis/e1_input.h>
+
+#ifndef ROLE_BSC
+#include <osmocom/gsm/lapdm.h>
+#endif
+
+/* 16 is the max. number of SI2quater messages according to 3GPP TS 44.018 
Table 10.5.2.33b.1:
+   4-bit index is used (2#1111 = 10#15) */
+#define SI2Q_MAX_NUM 16
+/* length in bits (for single SI2quater message) */
+#define SI2Q_MAX_LEN 160
+#define SI2Q_MIN_LEN 18
+
+struct osmo_bsc_data;
+
+struct osmo_bsc_sccp_con;
+struct gsm_sms_queue;
+
+/* RRLP mode of operation */
+enum rrlp_mode {
+       RRLP_MODE_NONE,
+       RRLP_MODE_MS_BASED,
+       RRLP_MODE_MS_PREF,
+       RRLP_MODE_ASS_PREF,
+};
+
+/* Channel Request reason */
+enum gsm_chreq_reason_t {
+       GSM_CHREQ_REASON_EMERG,
+       GSM_CHREQ_REASON_PAG,
+       GSM_CHREQ_REASON_CALL,
+       GSM_CHREQ_REASON_LOCATION_UPD,
+       GSM_CHREQ_REASON_OTHER,
+       GSM_CHREQ_REASON_PDCH,
+};
+
+/* lchans 0..3 are SDCCH in combined channel configuration,
+   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
+#define HARDCODED_BSIC 0x3f    /* NCC = 7 / BCC = 7 */
+
+/* for multi-drop config */
+#define HARDCODED_BTS0_TS      1
+#define HARDCODED_BTS1_TS      6
+#define HARDCODED_BTS2_TS      11
+
+#define MAX_VERSION_LENGTH 64
+
+#define MAX_BTS_FEATURES 128
+
+enum gsm_hooks {
+       GSM_HOOK_NM_SWLOAD,
+       GSM_HOOK_RR_PAGING,
+       GSM_HOOK_RR_SECURITY,
+};
+
+enum gsm_paging_event {
+       GSM_PAGING_SUCCEEDED,
+       GSM_PAGING_EXPIRED,
+       GSM_PAGING_OOM,
+       GSM_PAGING_BUSY,
+};
+
+enum bts_gprs_mode {
+       BTS_GPRS_NONE = 0,
+       BTS_GPRS_GPRS = 1,
+       BTS_GPRS_EGPRS = 2,
+};
+
+struct gsm_lchan;
+struct gsm_subscriber;
+struct gsm_mncc;
+struct osmo_rtp_socket;
+struct rtp_socket;
+struct bsc_api;
+
+/* Network Management State */
+struct gsm_nm_state {
+       uint8_t operational;
+       uint8_t administrative;
+       uint8_t availability;
+};
+
+struct gsm_abis_mo {
+       uint8_t obj_class;
+       uint8_t procedure_pending;
+       struct abis_om_obj_inst obj_inst;
+       const char *name;
+       struct gsm_nm_state nm_state;
+       struct tlv_parsed *nm_attr;
+       struct gsm_bts *bts;
+};
+
+/* Ericsson OM2000 Managed Object */
+struct abis_om2k_mo {
+       uint8_t class;
+       uint8_t bts;
+       uint8_t assoc_so;
+       uint8_t inst;
+} __attribute__ ((packed));
+
+struct om2k_mo {
+       struct abis_om2k_mo addr;
+       struct osmo_fsm_inst *fsm;
+};
+
+#define MAX_A5_KEY_LEN (128/8)
+#define A38_XOR_MIN_KEY_LEN    12
+#define A38_XOR_MAX_KEY_LEN    16
+#define A38_COMP128_KEY_LEN    16
+#define RSL_ENC_ALG_A5(x)      (x+1)
+#define MAX_EARFCN_LIST 32
+
+/* is the data link established? who established it? */
+#define LCHAN_SAPI_UNUSED      0
+#define LCHAN_SAPI_MS          1
+#define LCHAN_SAPI_NET         2
+#define LCHAN_SAPI_REL         3
+
+/* state of a logical channel */
+enum gsm_lchan_state {
+       LCHAN_S_NONE,           /* channel is not active */
+       LCHAN_S_ACT_REQ,        /* channel activation requested */
+       LCHAN_S_ACTIVE,         /* channel is active and operational */
+       LCHAN_S_REL_REQ,        /* channel release has been requested */
+       LCHAN_S_REL_ERR,        /* channel is in an error state */
+       LCHAN_S_BROKEN,         /* channel is somehow unusable */
+       LCHAN_S_INACTIVE,       /* channel is set inactive */
+};
+
+/* BTS ONLY */
+#define MAX_NUM_UL_MEAS        104
+#define LC_UL_M_F_L1_VALID     (1 << 0)
+#define LC_UL_M_F_RES_VALID    (1 << 1)
+
+struct bts_ul_meas {
+       /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
+       uint16_t ber10k;
+       /* timing advance offset (in quarter bits) */
+       int16_t ta_offs_qbits;
+       /* C/I ratio in dB */
+       float c_i;
+       /* flags */
+       uint8_t is_sub:1;
+       /* RSSI in dBm * -1 */
+       uint8_t inv_rssi;
+};
+
+struct bts_codec_conf {
+       uint8_t hr;
+       uint8_t efr;
+       uint8_t amr;
+};
+
+struct amr_mode {
+       uint8_t mode;
+       uint8_t threshold;
+       uint8_t hysteresis;
+};
+
+struct amr_multirate_conf {
+       uint8_t gsm48_ie[2];
+       struct amr_mode ms_mode[4];
+       struct amr_mode bts_mode[4];
+       uint8_t num_modes;
+};
+/* /BTS ONLY */
+
+enum lchan_csd_mode {
+       LCHAN_CSD_M_NT,
+       LCHAN_CSD_M_T_1200_75,
+       LCHAN_CSD_M_T_600,
+       LCHAN_CSD_M_T_1200,
+       LCHAN_CSD_M_T_2400,
+       LCHAN_CSD_M_T_9600,
+       LCHAN_CSD_M_T_14400,
+       LCHAN_CSD_M_T_29000,
+       LCHAN_CSD_M_T_32000,
+};
+
+/* State of the SAPIs in the lchan */
+enum lchan_sapi_state {
+       LCHAN_SAPI_S_NONE,
+       LCHAN_SAPI_S_REQ,
+       LCHAN_SAPI_S_ASSIGNED,
+       LCHAN_SAPI_S_REL,
+       LCHAN_SAPI_S_ERROR,
+};
+
+struct gsm_lchan {
+       /* The TS that we're part of */
+       struct gsm_bts_trx_ts *ts;
+       /* The logical subslot number in the TS */
+       uint8_t nr;
+       /* The logical channel type */
+       enum gsm_chan_t type;
+       /* RSL channel mode */
+       enum rsl_cmod_spd rsl_cmode;
+       /* If TCH, traffic channel mode */
+       enum gsm48_chan_mode tch_mode;
+       enum lchan_csd_mode csd_mode;
+       /* State */
+       enum gsm_lchan_state state;
+       const char *broken_reason;
+       /* Power levels for MS and BTS */
+       uint8_t bs_power;
+       uint8_t ms_power;
+       /* Encryption information */
+       struct {
+               uint8_t alg_id;
+               uint8_t key_len;
+               uint8_t key[MAX_A5_KEY_LEN];
+       } encr;
+
+       /* AMR bits */
+       uint8_t mr_ms_lv[7];
+       uint8_t mr_bts_lv[7];
+
+       /* Established data link layer services */
+       uint8_t sapis[8];
+       int sacch_deact;
+
+       struct {
+               uint32_t bound_ip;
+               uint32_t connect_ip;
+               uint16_t bound_port;
+               uint16_t connect_port;
+               uint16_t conn_id;
+               uint8_t rtp_payload;
+               uint8_t rtp_payload2;
+               uint8_t speech_mode;
+#ifdef ROLE_BSC
+               struct rtp_socket *rtp_socket;
+#else
+               struct osmo_rtp_socket *rtp_socket;
+#endif
+       } abis_ip;
+
+       uint8_t rqd_ta;
+
+       char *name;
+
+#ifdef ROLE_BSC
+       struct osmo_timer_list T3101;
+       struct osmo_timer_list T3109;
+       struct osmo_timer_list T3111;
+       struct osmo_timer_list error_timer;
+       struct osmo_timer_list act_timer;
+       struct osmo_timer_list rel_work;
+       uint8_t error_cause;
+
+       /* table of neighbor cell measurements */
+       struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
+
+       /* cache of last measurement reports on this lchan */
+       struct gsm_meas_rep meas_rep[6];
+       int meas_rep_idx;
+
+       /* GSM Random Access data */
+       struct gsm48_req_ref *rqd_ref;
+
+       struct gsm_subscriber_connection *conn;
+
+       struct {
+               /* channel activation type and handover ref */
+               uint8_t act_type;
+               uint8_t ho_ref;
+               struct gsm48_req_ref *rqd_ref;
+               uint8_t rqd_ta;
+       } dyn;
+#else
+       /* Number of different GsmL1_Sapi_t used in osmo_bts_sysmo is 23.
+        * Currently we don't share these headers so this is a magic number. */
+       struct llist_head sapi_cmds;
+       uint8_t sapis_dl[23];
+       uint8_t sapis_ul[23];
+       struct lapdm_channel lapdm_ch;
+       struct llist_head dl_tch_queue;
+       struct {
+               /* bitmask of all SI that are present/valid in si_buf */
+               uint32_t valid;
+               uint32_t last;
+               /* buffers where we put the pre-computed SI:
+                  SI2Q_MAX_NUM is the max number of SI2quater messages (see 
3GPP TS 44.018) */
+               sysinfo_buf_t buf[_MAX_SYSINFO_TYPE][SI2Q_MAX_NUM];
+       } si;
+       struct {
+               uint8_t flags;
+               /* RSL measurment result number, 0 at lchan_act */
+               uint8_t res_nr;
+               /* current Tx power level of the BTS */
+               uint8_t bts_tx_pwr;
+               /* number of measurements stored in array below */
+               uint8_t num_ul_meas;
+               struct bts_ul_meas uplink[MAX_NUM_UL_MEAS];
+               /* last L1 header from the MS */
+               uint8_t l1_info[2];
+               struct gsm_meas_rep_unidir ul_res;
+       } meas;
+       struct {
+               struct amr_multirate_conf amr_mr;
+               struct {
+                       struct osmo_fsm_inst *dl_amr_fsm;
+                       /* TCH cache */
+                       uint8_t cache[20];
+                       /* FACCH cache */
+                       uint8_t facch[GSM_MACBLOCK_LEN];
+                       uint8_t len;
+                       uint32_t fn;
+                       bool is_update;
+                       /* set for each SID frame to detect talkspurt for codecs
+                          without explicit ONSET event */
+                       bool ul_sid;
+                       /* indicates if DTXd was active during DL measurement
+                          period */
+                       bool dl_active;
+               } dtx;
+               uint8_t last_cmr;
+               uint32_t last_fn;
+       } tch;
+
+       /* 3GPP TS 48.058 § 9.3.37: [0; 255] ok, -1 means invalid*/
+       int16_t ms_t_offs;
+       /* 3GPP TS 45.010 § 1.2 round trip propagation delay (in symbols) or -1 
*/
+       int16_t p_offs;
+
+       /* BTS-side ciphering state (rx only, bi-directional, ...) */
+       uint8_t ciph_state;
+       uint8_t ciph_ns;
+       uint8_t loopback;
+       struct {
+               uint8_t active;
+               uint8_t ref;
+               /* T3105: PHYS INF retransmission */
+               struct osmo_timer_list t3105;
+               /* counts up to Ny1 */
+               unsigned int phys_info_count;
+       } ho;
+       /* S counter for link loss */
+       int s;
+       /* Kind of the release/activation. E.g. RSL or PCU */
+       int rel_act_kind;
+       /* RTP header Marker bit to indicate beginning of speech after pause  */
+       bool rtp_tx_marker;
+       /* power handling */
+       struct {
+               uint8_t current;
+               uint8_t fixed;
+       } ms_power_ctrl;
+
+       struct msgb *pending_rel_ind_msg;
+#endif
+};
+
+enum {
+       TS_F_PDCH_ACTIVE =              0x1000,
+       TS_F_PDCH_ACT_PENDING =         0x2000,
+       TS_F_PDCH_DEACT_PENDING =       0x4000,
+       TS_F_PDCH_PENDING_MASK =        0x6000 /*<
+                       TS_F_PDCH_ACT_PENDING | TS_F_PDCH_DEACT_PENDING */
+} gsm_bts_trx_ts_flags;
+
+/* One Timeslot in a TRX */
+struct gsm_bts_trx_ts {
+       struct gsm_bts_trx *trx;
+       /* number of this timeslot at the TRX */
+       uint8_t nr;
+
+       enum gsm_phys_chan_config pchan;
+
+       struct {
+               enum gsm_phys_chan_config pchan_is;
+               enum gsm_phys_chan_config pchan_want;
+               struct msgb *pending_chan_activ;
+       } dyn;
+
+       unsigned int flags;
+       struct gsm_abis_mo mo;
+       struct tlv_parsed nm_attr;
+       uint8_t nm_chan_comb;
+       int tsc;                /* -1 == use BTS TSC */
+
+       struct {
+               /* Parameters below are configured by VTY */
+               int enabled;
+               uint8_t maio;
+               uint8_t hsn;
+               struct bitvec arfcns;
+               uint8_t arfcns_data[1024/8];
+               /* This is the pre-computed MA for channel assignments */
+               struct bitvec ma;
+               uint8_t ma_len; /* part of ma_data that is used */
+               uint8_t ma_data[8];     /* 10.5.2.21: max 8 bytes value part */
+       } hopping;
+
+       /* To which E1 subslot are we connected */
+       struct gsm_e1_subslot e1_link;
+
+       union {
+               struct {
+                       struct om2k_mo om2k_mo;
+               } rbs2000;
+       };
+
+       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;
+
+       /* 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 */
+
+#ifndef ROLE_BSC
+       struct trx_power_params power_params;
+       int ms_power_control;
+
+       struct {
+               void *l1h;
+       } role_bts;
+#endif
+
+       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_BTS_SI2Q(bts, i)   (struct gsm48_system_information_type_2quater 
*)((bts)->si_buf[SYSINFO_TYPE_2quater][i])
+#define GSM_BTS_HAS_SI(bts, i) ((bts)->si_valid & (1 << i))
+#define GSM_BTS_SI(bts, i)     (void *)((bts)->si_buf[i][0])
+#define GSM_LCHAN_SI(lchan, i) (void *)((lchan)->si.buf[i][0])
+
+enum gsm_bts_type {
+       GSM_BTS_TYPE_UNKNOWN,
+       GSM_BTS_TYPE_BS11,
+       GSM_BTS_TYPE_NANOBTS,
+       GSM_BTS_TYPE_RBS2000,
+       GSM_BTS_TYPE_NOKIA_SITE,
+       GSM_BTS_TYPE_OSMOBTS,
+       _NUM_GSM_BTS_TYPE
+};
+
+enum gsm_bts_type_variant {
+       BTS_UNKNOWN,
+       BTS_OSMO_LITECELL15,
+       BTS_OSMO_OCTPHY,
+       BTS_OSMO_SYSMO,
+       BTS_OSMO_TRX,
+       _NUM_BTS_VARIANT
+};
+
+/* Used by OML layer for BTS Attribute reporting */
+enum bts_attribute {
+       BTS_TYPE_VARIANT,
+       BTS_SUB_MODEL,
+       TRX_PHY_VERSION,
+};
+
+struct vty;
+
+struct gsm_bts_model {
+       struct llist_head list;
+
+       enum gsm_bts_type type;
+       enum gsm_bts_type_variant variant;
+       const char *name;
+
+       bool started;
+       int (*start)(struct gsm_network *net);
+       int (*oml_rcvmsg)(struct msgb *msg);
+
+       void (*e1line_bind_ops)(struct e1inp_line *line);
+
+       void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
+       void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
+       void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
+
+       struct tlv_definition nm_att_tlvdef;
+
+       /* features of a given BTS model set via gsm_bts_model_register() 
locally */
+       struct bitvec features;
+       uint8_t _features_data[MAX_BTS_FEATURES/8];
+};
+
+/* N. B: always add new features to the end of the list (right before 
_NUM_BTS_FEAT) to avoid breaking compatibility
+   with BTS compiled against earlier version of this header */
+enum gsm_bts_features {
+       BTS_FEAT_HSCSD,
+       BTS_FEAT_GPRS,
+       BTS_FEAT_EGPRS,
+       BTS_FEAT_ECSD,
+       BTS_FEAT_HOPPING,
+       BTS_FEAT_MULTI_TSC,
+       BTS_FEAT_OML_ALERTS,
+       BTS_FEAT_AGCH_PCH_PROP,
+       BTS_FEAT_CBCH,
+       _NUM_BTS_FEAT
+};
+
+extern const struct value_string gsm_bts_features_descs[];
+
+/*
+ * This keeps track of the paging status of one BTS. It
+ * includes a number of pending requests, a back pointer
+ * to the gsm_bts, a timer and some more state.
+ */
+struct gsm_bts_paging_state {
+       /* pending requests */
+       struct llist_head pending_requests;
+       struct gsm_bts *bts;
+
+       struct osmo_timer_list work_timer;
+       struct osmo_timer_list credit_timer;
+
+       /* free chans needed */
+       int free_chans_need;
+
+       /* load */
+       uint16_t available_slots;
+};
+
+struct gsm_envabtse {
+       struct gsm_abis_mo mo;
+};
+
+struct gsm_bts_gprs_nsvc {
+       struct gsm_bts *bts;
+       /* data read via VTY config file, to configure the BTS
+        * via OML from BSC */
+       int id;
+       uint16_t nsvci;
+       uint16_t local_port;    /* on the BTS */
+       uint16_t remote_port;   /* on the SGSN */
+       uint32_t remote_ip;     /* on the SGSN */
+
+       struct gsm_abis_mo mo;
+};
+
+enum gprs_rlc_par {
+       RLC_T3142,
+       RLC_T3169,
+       RLC_T3191,
+       RLC_T3193,
+       RLC_T3195,
+       RLC_N3101,
+       RLC_N3103,
+       RLC_N3105,
+       CV_COUNTDOWN,
+       T_DL_TBF_EXT,   /* ms */
+       T_UL_TBF_EXT,   /* ms */
+       _NUM_RLC_PAR
+};
+
+enum gprs_cs {
+       GPRS_CS1,
+       GPRS_CS2,
+       GPRS_CS3,
+       GPRS_CS4,
+       GPRS_MCS1,
+       GPRS_MCS2,
+       GPRS_MCS3,
+       GPRS_MCS4,
+       GPRS_MCS5,
+       GPRS_MCS6,
+       GPRS_MCS7,
+       GPRS_MCS8,
+       GPRS_MCS9,
+       _NUM_GRPS_CS
+};
+
+struct gprs_rlc_cfg {
+       uint16_t parameter[_NUM_RLC_PAR];
+       struct {
+               uint16_t repeat_time; /* ms */
+               uint8_t repeat_count;
+       } paging;
+       uint32_t cs_mask; /* bitmask of gprs_cs */
+       uint8_t initial_cs;
+       uint8_t initial_mcs;
+};
+
+
+enum neigh_list_manual_mode {
+       NL_MODE_AUTOMATIC = 0,
+       NL_MODE_MANUAL = 1,
+       NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists 
*/
+};
+
+enum bts_loc_fix {
+       BTS_LOC_FIX_INVALID = 0,
+       BTS_LOC_FIX_2D = 1,
+       BTS_LOC_FIX_3D = 2,
+};
+
+extern const struct value_string bts_loc_fix_names[];
+
+struct bts_location {
+       struct llist_head list;
+       time_t tstamp;
+       enum bts_loc_fix valid;
+       double lat;
+       double lon;
+       double height;
+};
+
+/* One BTS */
+struct gsm_bts {
+       /* list header in net->bts_list */
+       struct llist_head list;
+
+       /* Geographical location of the BTS */
+       struct llist_head loc_list;
+
+       /* number of ths BTS in network */
+       uint8_t nr;
+       /* human readable name / description */
+       char *description;
+       /* Cell Identity */
+       uint16_t cell_identity;
+       /* location area code of this BTS */
+       uint16_t location_area_code;
+       /* Base Station Identification Code (BSIC), lower 3 bits is BCC,
+        * which is used as TSC for the CCCH */
+       uint8_t bsic;
+       /* type of BTS */
+       enum gsm_bts_type type;
+       enum gsm_bts_type_variant variant;
+       struct gsm_bts_model *model;
+       enum gsm_band band;
+       char version[MAX_VERSION_LENGTH];
+       char sub_model[MAX_VERSION_LENGTH];
+
+       /* features of a given BTS set/reported via OML */
+       struct bitvec features;
+       uint8_t _features_data[MAX_BTS_FEATURES/8];
+
+       /* Connected PCU version (if any) */
+       char pcu_version[MAX_VERSION_LENGTH];
+
+       /* maximum Tx power that the MS is permitted to use in this cell */
+       int ms_max_power;
+
+       /* how do we talk OML with this TRX? */
+       struct gsm_e1_subslot oml_e1_link;
+       uint8_t oml_tei;
+       struct e1inp_sign_link *oml_link;
+       /* when OML link was established */
+       time_t uptime;
+
+       /* Abis network management O&M handle */
+       struct abis_nm_h *nmh;
+
+       struct gsm_abis_mo mo;
+
+       /* number of this BTS on given E1 link */
+       uint8_t bts_nr;
+
+       /* DTX features of this BTS */
+       enum gsm48_dtx_mode dtxu;
+       bool dtxd;
+
+       /* paging state and control */
+       struct gsm_bts_paging_state paging;
+
+       /* CCCH is on C0 */
+       struct gsm_bts_trx *c0;
+
+       struct {
+               struct gsm_abis_mo mo;
+       } site_mgr;
+
+       /* bitmask of all SI that are present/valid in si_buf */
+       uint32_t si_valid;
+       /* 3GPP TS 44.018 Table 10.5.2.33b.1 INDEX and COUNT for SI2quater */
+       uint8_t si2q_index; /* distinguish individual SI2quater messages */
+       uint8_t si2q_count; /* si2q_index for the last (highest indexed) 
individual SI2quater message */
+       /* buffers where we put the pre-computed SI */
+       sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE][SI2Q_MAX_NUM];
+       /* offsets used while generating SI2quater */
+       size_t e_offset;
+       size_t u_offset;
+
+       /* ip.accesss Unit ID's have Site/BTS/TRX layout */
+       union {
+               struct {
+                       uint16_t site_id;
+                       uint16_t bts_id;
+                       uint32_t flags;
+                       uint32_t rsl_ip;
+               } ip_access;
+               struct {
+                       struct {
+                               struct gsm_abis_mo mo;
+                       } cclk;
+                       struct {
+                               struct gsm_abis_mo mo;
+                       } rack;
+                       struct gsm_envabtse envabtse[4];
+               } bs11;
+               struct {
+                       struct {
+                               struct om2k_mo om2k_mo;
+                               struct gsm_abis_mo mo;
+                               struct llist_head conn_groups;
+                       } cf;
+                       struct {
+                               struct om2k_mo om2k_mo;
+                               struct gsm_abis_mo mo;
+                               struct llist_head conn_groups;
+                       } is;
+                       struct {
+                               struct om2k_mo om2k_mo;
+                               struct gsm_abis_mo mo;
+                               struct llist_head conn_groups;
+                       } con;
+                       struct {
+                               struct om2k_mo om2k_mo;
+                               struct gsm_abis_mo mo;
+                       } dp;
+                       struct {
+                               struct om2k_mo om2k_mo;
+                               struct gsm_abis_mo mo;
+                       } tf;
+                       uint32_t use_superchannel:1;
+               } rbs2000;
+               struct {
+                       uint8_t bts_type;
+                       unsigned int configured:1,
+                               skip_reset:1,
+                               no_loc_rel_cnf:1,
+                               bts_reset_timer_cnf,
+                               did_reset:1,
+                               wait_reset:1;
+                       struct osmo_timer_list reset_timer;
+               } nokia;
+       };
+
+       /* Not entirely sure how ip.access specific this is */
+       struct {
+               uint8_t supports_egprs_11bit_rach;
+               enum bts_gprs_mode mode;
+               struct {
+                       struct gsm_abis_mo mo;
+                       uint16_t nsei;
+                       uint8_t timer[7];
+               } nse;
+               struct {
+                       struct gsm_abis_mo mo;
+                       uint16_t bvci;
+                       uint8_t timer[11];
+                       struct gprs_rlc_cfg rlc_cfg;
+               } cell;
+               struct gsm_bts_gprs_nsvc nsvc[2];
+               uint8_t rac;
+               uint8_t net_ctrl_ord;
+               bool ctrl_ack_type_use_block;
+       } gprs;
+
+       /* RACH NM values */
+       int rach_b_thresh;
+       int rach_ldavg_slots;
+
+       /* transceivers */
+       int num_trx;
+       struct llist_head trx_list;
+
+       /* SI related items */
+       int force_combined_si;
+       int bcch_change_mark;
+
+#ifdef ROLE_BSC
+       /* Abis NM queue */
+       struct llist_head abis_queue;
+       int abis_nm_pend;
+
+       struct gsm_network *network;
+
+       /* should the channel allocator allocate channels from high TRX to TRX0,
+        * rather than starting from TRX0 and go upwards? */
+       int chan_alloc_reverse;
+
+       enum neigh_list_manual_mode neigh_list_manual_mode;
+       /* parameters from which we build SYSTEM INFORMATION */
+       struct {
+               struct gsm48_rach_control rach_control;
+               uint8_t ncc_permitted;
+               struct gsm48_cell_sel_par cell_sel_par;
+               struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet 
*/
+               struct gsm48_cell_options cell_options;
+               struct gsm48_control_channel_descr chan_desc;
+               struct bitvec neigh_list;
+               struct bitvec cell_alloc;
+               struct bitvec si5_neigh_list;
+               struct osmo_earfcn_si2q si2quater_neigh_list;
+               size_t uarfcn_length; /* index for uarfcn and scramble lists */
+               struct {
+                       /* bitmask large enough for all possible ARFCN's */
+                       uint8_t neigh_list[1024/8];
+                       uint8_t cell_alloc[1024/8];
+                       /* If the user wants a different neighbor list in SI5 
than in SI2 */
+                       uint8_t si5_neigh_list[1024/8];
+                       uint8_t meas_bw_list[MAX_EARFCN_LIST];
+                       uint16_t earfcn_list[MAX_EARFCN_LIST];
+                       uint16_t uarfcn_list[MAX_EARFCN_LIST];
+                       uint16_t scramble_list[MAX_EARFCN_LIST];
+               } data;
+       } si_common;
+       bool early_classmark_allowed;
+       /* for testing only: Have an infinitely long radio link timeout */
+       bool infinite_radio_link_timeout;
+
+       /* do we use static (user-defined) system information messages? 
(bitmask) */
+       uint32_t si_mode_static;
+
+       /* exclude the BTS from the global RF Lock handling */
+       int excl_from_rf_lock;
+
+       /* supported codecs beside FR */
+       struct bts_codec_conf codec;
+
+       /* BTS dependencies bit field */
+       uint32_t depends_on[256/(8*4)];
+
+       /* full and half rate multirate config */
+       struct amr_multirate_conf mr_full;
+       struct amr_multirate_conf mr_half;
+
+       /* PCU socket state */
+       char *pcu_sock_path;
+       struct pcu_sock_state *pcu_state;
+
+#endif /* ROLE_BSC */
+       void *role;
+};
+
+
+struct gsm_bts *gsm_bts_alloc(void *talloc_ctx, uint8_t bts_num);
+struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
+
+struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
+struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
+
+enum gsm_bts_type str2btstype(const char *arg);
+const char *btstype2str(enum gsm_bts_type type);
+
+enum bts_attribute str2btsattr(const char *s);
+const char *btsatttr2str(enum bts_attribute v);
+
+enum gsm_bts_type_variant str2btsvariant(const char *arg);
+const char *btsvariant2str(enum gsm_bts_type_variant v);
+
+extern const struct value_string gsm_chreq_descs[];
+const struct value_string gsm_pchant_names[13];
+const struct value_string gsm_pchant_descs[13];
+const char *gsm_pchan_name(enum gsm_phys_chan_config c);
+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);
+const char *gsm_lchans_name(enum gsm_lchan_state s);
+
+static inline char *gsm_lchan_name(const struct gsm_lchan *lchan)
+{
+       return lchan->name;
+}
+
+static inline int gsm_bts_set_feature(struct gsm_bts *bts, enum 
gsm_bts_features feat)
+{
+       OSMO_ASSERT(_NUM_BTS_FEAT < MAX_BTS_FEATURES);
+       return bitvec_set_bit_pos(&bts->features, feat, 1);
+}
+
+static inline bool gsm_bts_has_feature(const struct gsm_bts *bts, enum 
gsm_bts_features feat)
+{
+       OSMO_ASSERT(_NUM_BTS_FEAT < MAX_BTS_FEATURES);
+       return bitvec_get_bit_pos(&bts->features, feat);
+}
+
+void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
+
+struct gsm_abis_mo *
+gsm_objclass2mo(struct gsm_bts *bts, uint8_t obj_class,
+           const struct abis_om_obj_inst *obj_inst);
+
+struct gsm_nm_state *
+gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
+                const struct abis_om_obj_inst *obj_inst);
+void *
+gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
+            const struct abis_om_obj_inst *obj_inst);
+
+/* reset the state of all MO in the BTS */
+void gsm_bts_mo_reset(struct gsm_bts *bts);
+
+uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
+                         uint8_t ts_nr, uint8_t lchan_nr);
+uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
+uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
+                                  enum gsm_phys_chan_config as_pchan);
+
+/* return the gsm_lchan for the CBCH (if it exists at all) */
+struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts);
+
+/*
+ * help with parsing regexps
+ */
+int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
+               int argc, const char **argv) __attribute__ 
((warn_unused_result));
+
+static inline uint8_t gsm_ts_tsc(const struct gsm_bts_trx_ts *ts)
+{
+       if (ts->tsc != -1)
+               return ts->tsc;
+       else
+               return ts->trx->bts->bsic & 7;
+}
+
+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 ts_subslots(struct gsm_bts_trx_ts *ts);
+bool ts_is_tch(struct gsm_bts_trx_ts *ts);
+
+#endif
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index d104c48..67f3e80 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include
 AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOTRAU_CFLAGS) 
$(LIBOSMOCODEC_CFLAGS)
 LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOTRAU_LIBS) $(LIBOSMOCODEC_LIBS)
 
diff --git a/src/common/gsm_data_shared.c b/src/common/gsm_data_shared.c
index 706892d..c2d196b 100644
--- a/src/common/gsm_data_shared.c
+++ b/src/common/gsm_data_shared.c
@@ -1 +1,853 @@
-#include "../../../openbsc/openbsc/src/libcommon/gsm_data_shared.c"
+/* (C) 2008-2010 by Harald Welte <[email protected]>
+ *
+ * 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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <ctype.h>
+
+#include <netinet/in.h>
+
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/talloc.h>
+#include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/gsm/abis_nm.h>
+#include <osmocom/core/statistics.h>
+
+#include <osmo-bts/gsm_data.h>
+
+void gsm_abis_mo_reset(struct gsm_abis_mo *mo)
+{
+       mo->nm_state.operational = NM_OPSTATE_NULL;
+       mo->nm_state.availability = NM_AVSTATE_POWER_OFF;
+}
+
+static void gsm_mo_init(struct gsm_abis_mo *mo, struct gsm_bts *bts,
+                       uint8_t obj_class, uint8_t p1, uint8_t p2, uint8_t p3)
+{
+       mo->bts = bts;
+       mo->obj_class = obj_class;
+       mo->obj_inst.bts_nr = p1;
+       mo->obj_inst.trx_nr = p2;
+       mo->obj_inst.ts_nr = p3;
+       gsm_abis_mo_reset(mo);
+}
+
+const struct value_string bts_attribute_names[] = {
+       OSMO_VALUE_STRING(BTS_TYPE_VARIANT),
+       OSMO_VALUE_STRING(BTS_SUB_MODEL),
+       OSMO_VALUE_STRING(TRX_PHY_VERSION),
+       { 0, NULL }
+};
+
+enum bts_attribute str2btsattr(const char *s)
+{
+       return get_string_value(bts_attribute_names, s);
+}
+
+const char *btsatttr2str(enum bts_attribute v)
+{
+       return get_value_string(bts_attribute_names, v);
+}
+
+const struct value_string osmo_bts_variant_names[_NUM_BTS_VARIANT + 1] = {
+       { BTS_UNKNOWN,          "unknown" },
+       { BTS_OSMO_LITECELL15,  "osmo-bts-lc15" },
+       { BTS_OSMO_OCTPHY,      "osmo-bts-octphy" },
+       { BTS_OSMO_SYSMO,       "osmo-bts-sysmo" },
+       { BTS_OSMO_TRX,         "omso-bts-trx" },
+       { 0, NULL }
+};
+
+enum gsm_bts_type_variant str2btsvariant(const char *arg)
+{
+       return get_string_value(osmo_bts_variant_names, arg);
+}
+
+const char *btsvariant2str(enum gsm_bts_type_variant v)
+{
+       return get_value_string(osmo_bts_variant_names, v);
+}
+
+const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE + 1] = {
+       { GSM_BTS_TYPE_UNKNOWN,         "unknown" },
+       { GSM_BTS_TYPE_BS11,            "bs11" },
+       { GSM_BTS_TYPE_NANOBTS,         "nanobts" },
+       { GSM_BTS_TYPE_RBS2000,         "rbs2000" },
+       { GSM_BTS_TYPE_NOKIA_SITE,      "nokia_site" },
+       { GSM_BTS_TYPE_OSMOBTS,         "sysmobts" },
+       { 0, NULL }
+};
+
+enum gsm_bts_type str2btstype(const char *arg)
+{
+       return get_string_value(bts_type_names, arg);
+}
+
+const char *btstype2str(enum gsm_bts_type type)
+{
+       return get_value_string(bts_type_names, type);
+}
+
+const struct value_string gsm_bts_features_descs[] = {
+       { BTS_FEAT_HSCSD,               "HSCSD" },
+       { BTS_FEAT_GPRS,                "GPRS" },
+       { BTS_FEAT_EGPRS,               "EGPRS" },
+       { BTS_FEAT_ECSD,                "ECSD" },
+       { BTS_FEAT_HOPPING,             "Frequency Hopping" },
+       { BTS_FEAT_MULTI_TSC,           "Multi-TSC" },
+       { BTS_FEAT_OML_ALERTS,          "OML Alerts" },
+       { BTS_FEAT_AGCH_PCH_PROP,       "AGCH/PCH proportional allocation" },
+       { BTS_FEAT_CBCH,                "CBCH" },
+       { 0, NULL }
+};
+
+const struct value_string gsm_chreq_descs[] = {
+       { GSM_CHREQ_REASON_EMERG,       "emergency call" },
+       { GSM_CHREQ_REASON_PAG,         "answer to paging" },
+       { GSM_CHREQ_REASON_CALL,        "call re-establishment" },
+       { GSM_CHREQ_REASON_LOCATION_UPD,"Location updating" },
+       { GSM_CHREQ_REASON_PDCH,        "one phase packet access" },
+       { GSM_CHREQ_REASON_OTHER,       "other" },
+       { 0,                            NULL }
+};
+
+const struct value_string gsm_pchant_names[13] = {
+       { GSM_PCHAN_NONE,       "NONE" },
+       { GSM_PCHAN_CCCH,       "CCCH" },
+       { GSM_PCHAN_CCCH_SDCCH4,"CCCH+SDCCH4" },
+       { GSM_PCHAN_TCH_F,      "TCH/F" },
+       { GSM_PCHAN_TCH_H,      "TCH/H" },
+       { GSM_PCHAN_SDCCH8_SACCH8C, "SDCCH8" },
+       { GSM_PCHAN_PDCH,       "PDCH" },
+       { GSM_PCHAN_TCH_F_PDCH, "TCH/F_PDCH" },
+       { GSM_PCHAN_UNKNOWN,    "UNKNOWN" },
+       { GSM_PCHAN_CCCH_SDCCH4_CBCH, "CCCH+SDCCH4+CBCH" },
+       { GSM_PCHAN_SDCCH8_SACCH8C_CBCH, "SDCCH8+CBCH" },
+       { GSM_PCHAN_TCH_F_TCH_H_PDCH, "TCH/F_TCH/H_PDCH" },
+       { 0,                    NULL }
+};
+
+const struct value_string gsm_pchant_descs[13] = {
+       { GSM_PCHAN_NONE,       "Physical Channel not configured" },
+       { GSM_PCHAN_CCCH,       "FCCH + SCH + BCCH + CCCH (Comb. IV)" },
+       { GSM_PCHAN_CCCH_SDCCH4,
+               "FCCH + SCH + BCCH + CCCH + 4 SDCCH + 2 SACCH (Comb. V)" },
+       { GSM_PCHAN_TCH_F,      "TCH/F + FACCH/F + SACCH (Comb. I)" },
+       { GSM_PCHAN_TCH_H,      "2 TCH/H + 2 FACCH/H + 2 SACCH (Comb. II)" },
+       { GSM_PCHAN_SDCCH8_SACCH8C, "8 SDCCH + 4 SACCH (Comb. VII)" },
+       { GSM_PCHAN_PDCH,       "Packet Data Channel for GPRS/EDGE" },
+       { GSM_PCHAN_TCH_F_PDCH, "Dynamic TCH/F or GPRS PDCH" },
+       { GSM_PCHAN_UNKNOWN,    "Unknown / Unsupported channel combination" },
+       { GSM_PCHAN_CCCH_SDCCH4_CBCH, "FCCH + SCH + BCCH + CCCH + CBCH + 3 
SDCCH + 2 SACCH (Comb. V)" },
+       { GSM_PCHAN_SDCCH8_SACCH8C_CBCH, "7 SDCCH + 4 SACCH + CBCH (Comb. VII)" 
},
+       { GSM_PCHAN_TCH_F_TCH_H_PDCH, "Dynamic TCH/F or TCH/H or GPRS PDCH" },
+       { 0,                    NULL }
+};
+
+const char *gsm_pchan_name(enum gsm_phys_chan_config c)
+{
+       return get_value_string(gsm_pchant_names, c);
+}
+
+enum gsm_phys_chan_config gsm_pchan_parse(const char *name)
+{
+       return get_string_value(gsm_pchant_names, name);
+}
+
+/* TODO: move to libosmocore, next to gsm_chan_t_names? */
+const char *gsm_lchant_name(enum gsm_chan_t c)
+{
+       return get_value_string(gsm_chan_t_names, c);
+}
+
+static const struct value_string lchan_s_names[] = {
+       { LCHAN_S_NONE,         "NONE" },
+       { LCHAN_S_ACT_REQ,      "ACTIVATION REQUESTED" },
+       { LCHAN_S_ACTIVE,       "ACTIVE" },
+       { LCHAN_S_INACTIVE,     "INACTIVE" },
+       { LCHAN_S_REL_REQ,      "RELEASE REQUESTED" },
+       { LCHAN_S_REL_ERR,      "RELEASE DUE ERROR" },
+       { LCHAN_S_BROKEN,       "BROKEN UNUSABLE" },
+       { 0,                    NULL }
+};
+
+const char *gsm_lchans_name(enum gsm_lchan_state s)
+{
+       return get_value_string(lchan_s_names, s);
+}
+
+static const struct value_string chreq_names[] = {
+       { GSM_CHREQ_REASON_EMERG,       "EMERGENCY" },
+       { GSM_CHREQ_REASON_PAG,         "PAGING" },
+       { GSM_CHREQ_REASON_CALL,        "CALL" },
+       { GSM_CHREQ_REASON_LOCATION_UPD,"LOCATION_UPDATE" },
+       { GSM_CHREQ_REASON_OTHER,       "OTHER" },
+       { 0,                            NULL }
+};
+
+const char *gsm_chreq_name(enum gsm_chreq_reason_t c)
+{
+       return get_value_string(chreq_names, c);
+}
+
+struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num)
+{
+       struct gsm_bts *bts;
+
+       if (num >= net->num_bts)
+               return NULL;
+
+       llist_for_each_entry(bts, &net->bts_list, list) {
+               if (bts->nr == num)
+                       return bts;
+       }
+
+       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 = GSM_PCHAN_NONE;
+               ts->dyn.pchan_is = GSM_PCHAN_NONE;
+               ts->dyn.pchan_want = GSM_PCHAN_NONE;
+               ts->tsc = -1;
+
+               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);
+#ifndef ROLE_BSC
+                       INIT_LLIST_HEAD(&lchan->sapi_cmds);
+#endif
+               }
+       }
+
+       if (trx->nr != 0)
+               trx->nominal_power = bts->c0->nominal_power;
+
+       llist_add_tail(&trx->list, &bts->trx_list);
+
+       return trx;
+}
+
+
+static const uint8_t bts_nse_timer_default[] = { 3, 3, 3, 3, 30, 3, 10 };
+static const uint8_t bts_cell_timer_default[] =
+                               { 3, 3, 3, 3, 3, 10, 3, 10, 3, 10, 3 };
+static const struct gprs_rlc_cfg rlc_cfg_default = {
+       .parameter = {
+               [RLC_T3142] = 20,
+               [RLC_T3169] = 5,
+               [RLC_T3191] = 5,
+               [RLC_T3193] = 160, /* 10ms */
+               [RLC_T3195] = 5,
+               [RLC_N3101] = 10,
+               [RLC_N3103] = 4,
+               [RLC_N3105] = 8,
+               [CV_COUNTDOWN] = 15,
+               [T_DL_TBF_EXT] = 250 * 10, /* ms */
+               [T_UL_TBF_EXT] = 250 * 10, /* ms */
+       },
+       .paging = {
+               .repeat_time = 5 * 50, /* ms */
+               .repeat_count = 3,
+       },
+       .cs_mask = 0x1fff,
+       .initial_cs = 2,
+       .initial_mcs = 6,
+};
+
+struct gsm_bts *gsm_bts_alloc(void *ctx, uint8_t bts_num)
+{
+       struct gsm_bts *bts = talloc_zero(ctx, struct gsm_bts);
+       int i;
+
+       if (!bts)
+               return NULL;
+
+       bts->nr = bts_num;
+       bts->num_trx = 0;
+       INIT_LLIST_HEAD(&bts->trx_list);
+       bts->ms_max_power = 15; /* dBm */
+
+       gsm_mo_init(&bts->mo, bts, NM_OC_BTS,
+                       bts->nr, 0xff, 0xff);
+       gsm_mo_init(&bts->site_mgr.mo, bts, NM_OC_SITE_MANAGER,
+                       0xff, 0xff, 0xff);
+
+       for (i = 0; i < ARRAY_SIZE(bts->gprs.nsvc); i++) {
+               bts->gprs.nsvc[i].bts = bts;
+               bts->gprs.nsvc[i].id = i;
+               gsm_mo_init(&bts->gprs.nsvc[i].mo, bts, NM_OC_GPRS_NSVC,
+                               bts->nr, i, 0xff);
+       }
+       memcpy(&bts->gprs.nse.timer, bts_nse_timer_default,
+               sizeof(bts->gprs.nse.timer));
+       gsm_mo_init(&bts->gprs.nse.mo, bts, NM_OC_GPRS_NSE,
+                       bts->nr, 0xff, 0xff);
+       memcpy(&bts->gprs.cell.timer, bts_cell_timer_default,
+               sizeof(bts->gprs.cell.timer));
+       gsm_mo_init(&bts->gprs.cell.mo, bts, NM_OC_GPRS_CELL,
+                       bts->nr, 0xff, 0xff);
+       memcpy(&bts->gprs.cell.rlc_cfg, &rlc_cfg_default,
+               sizeof(bts->gprs.cell.rlc_cfg));
+
+       /* create our primary TRX */
+       bts->c0 = gsm_bts_trx_alloc(bts);
+       if (!bts->c0) {
+               talloc_free(bts);
+               return NULL;
+       }
+       bts->c0->ts[0].pchan = GSM_PCHAN_CCCH_SDCCH4;
+
+       bts->rach_b_thresh = -1;
+       bts->rach_ldavg_slots = -1;
+       bts->paging.free_chans_need = -1;
+       bts->features.data = &bts->_features_data[0];
+       bts->features.data_len = sizeof(bts->_features_data);
+
+       /* si handling */
+       bts->bcch_change_mark = 1;
+
+       return bts;
+}
+
+/* reset the state of all MO in the BTS */
+void gsm_bts_mo_reset(struct gsm_bts *bts)
+{
+       struct gsm_bts_trx *trx;
+       unsigned int i;
+
+       gsm_abis_mo_reset(&bts->mo);
+       gsm_abis_mo_reset(&bts->site_mgr.mo);
+       for (i = 0; i < ARRAY_SIZE(bts->gprs.nsvc); i++)
+               gsm_abis_mo_reset(&bts->gprs.nsvc[i].mo);
+       gsm_abis_mo_reset(&bts->gprs.nse.mo);
+       gsm_abis_mo_reset(&bts->gprs.cell.mo);
+
+       llist_for_each_entry(trx, &bts->trx_list, list) {
+               gsm_abis_mo_reset(&trx->mo);
+               gsm_abis_mo_reset(&trx->bb_transc.mo);
+
+               for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
+                       struct gsm_bts_trx_ts *ts = &trx->ts[i];
+                       gsm_abis_mo_reset(&ts->mo);
+               }
+       }
+}
+
+struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num)
+{
+       struct gsm_bts_trx *trx;
+
+       if (num >= bts->num_trx)
+               return NULL;
+
+       llist_for_each_entry(trx, &bts->trx_list, list) {
+               if (trx->nr == num)
+                       return trx;
+       }
+
+       return NULL;
+}
+
+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)",
+                ts->trx->bts->nr, ts->trx->nr, ts->nr);
+
+       return ts2str;
+}
+
+/*! Log timeslot number with full pchan information */
+char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts)
+{
+       switch (ts->pchan) {
+       case GSM_PCHAN_TCH_F_TCH_H_PDCH:
+               if (ts->dyn.pchan_is == ts->dyn.pchan_want)
+                       snprintf(ts2str, sizeof(ts2str),
+                                "(bts=%d,trx=%d,ts=%d,pchan=%s as %s)",
+                                ts->trx->bts->nr, ts->trx->nr, ts->nr,
+                                gsm_pchan_name(ts->pchan),
+                                gsm_pchan_name(ts->dyn.pchan_is));
+               else
+                       snprintf(ts2str, sizeof(ts2str),
+                                "(bts=%d,trx=%d,ts=%d,pchan=%s"
+                                " switching %s -> %s)",
+                                ts->trx->bts->nr, ts->trx->nr, ts->nr,
+                                gsm_pchan_name(ts->pchan),
+                                gsm_pchan_name(ts->dyn.pchan_is),
+                                gsm_pchan_name(ts->dyn.pchan_want));
+               break;
+       case GSM_PCHAN_TCH_F_PDCH:
+               if ((ts->flags & TS_F_PDCH_PENDING_MASK) == 0)
+                       snprintf(ts2str, sizeof(ts2str),
+                                "(bts=%d,trx=%d,ts=%d,pchan=%s as %s)",
+                                ts->trx->bts->nr, ts->trx->nr, ts->nr,
+                                gsm_pchan_name(ts->pchan),
+                                (ts->flags & TS_F_PDCH_ACTIVE)? "PDCH"
+                                                              : "TCH/F");
+               else
+                       snprintf(ts2str, sizeof(ts2str),
+                                "(bts=%d,trx=%d,ts=%d,pchan=%s"
+                                " switching %s -> %s)",
+                                ts->trx->bts->nr, ts->trx->nr, ts->nr,
+                                gsm_pchan_name(ts->pchan),
+                                (ts->flags & TS_F_PDCH_ACTIVE)? "PDCH"
+                                                              : "TCH/F",
+                                (ts->flags & TS_F_PDCH_ACT_PENDING)? "PDCH"
+                                                                   : "TCH/F");
+               break;
+       default:
+               snprintf(ts2str, sizeof(ts2str), 
"(bts=%d,trx=%d,ts=%d,pchan=%s)",
+                        ts->trx->bts->nr, ts->trx->nr, ts->nr,
+                        gsm_pchan_name(ts->pchan));
+               break;
+       }
+
+       return ts2str;
+}
+
+char *gsm_lchan_name_compute(const struct gsm_lchan *lchan)
+{
+       struct gsm_bts_trx_ts *ts = lchan->ts;
+
+       snprintf(ts2str, sizeof(ts2str), "(bts=%d,trx=%d,ts=%d,ss=%d)",
+                ts->trx->bts->nr, ts->trx->nr, ts->nr, lchan->nr);
+
+       return ts2str;
+}
+
+/* obtain the MO structure for a given object instance */
+struct gsm_abis_mo *
+gsm_objclass2mo(struct gsm_bts *bts, uint8_t obj_class,
+           const struct abis_om_obj_inst *obj_inst)
+{
+       struct gsm_bts_trx *trx;
+       struct gsm_abis_mo *mo = NULL;
+
+       switch (obj_class) {
+       case NM_OC_BTS:
+               mo = &bts->mo;
+               break;
+       case NM_OC_RADIO_CARRIER:
+               if (obj_inst->trx_nr >= bts->num_trx) {
+                       return NULL;
+               }
+               trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
+               mo = &trx->mo;
+               break;
+       case NM_OC_BASEB_TRANSC:
+               if (obj_inst->trx_nr >= bts->num_trx) {
+                       return NULL;
+               }
+               trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
+               mo = &trx->bb_transc.mo;
+               break;
+       case NM_OC_CHANNEL:
+               if (obj_inst->trx_nr >= bts->num_trx) {
+                       return NULL;
+               }
+               trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
+               if (obj_inst->ts_nr >= TRX_NR_TS)
+                       return NULL;
+               mo = &trx->ts[obj_inst->ts_nr].mo;
+               break;
+       case NM_OC_SITE_MANAGER:
+               mo = &bts->site_mgr.mo;
+               break;
+       case NM_OC_BS11:
+               switch (obj_inst->bts_nr) {
+               case BS11_OBJ_CCLK:
+                       mo = &bts->bs11.cclk.mo;
+                       break;
+               case BS11_OBJ_BBSIG:
+                       if (obj_inst->ts_nr > bts->num_trx)
+                               return NULL;
+                       trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
+                       mo = &trx->bs11.bbsig.mo;
+                       break;
+               case BS11_OBJ_PA:
+                       if (obj_inst->ts_nr > bts->num_trx)
+                               return NULL;
+                       trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
+                       mo = &trx->bs11.pa.mo;
+                       break;
+               default:
+                       return NULL;
+               }
+               break;
+       case NM_OC_BS11_RACK:
+               mo = &bts->bs11.rack.mo;
+               break;
+       case NM_OC_BS11_ENVABTSE:
+               if (obj_inst->trx_nr >= ARRAY_SIZE(bts->bs11.envabtse))
+                       return NULL;
+               mo = &bts->bs11.envabtse[obj_inst->trx_nr].mo;
+               break;
+       case NM_OC_GPRS_NSE:
+               mo = &bts->gprs.nse.mo;
+               break;
+       case NM_OC_GPRS_CELL:
+               mo = &bts->gprs.cell.mo;
+               break;
+       case NM_OC_GPRS_NSVC:
+               if (obj_inst->trx_nr >= ARRAY_SIZE(bts->gprs.nsvc))
+                       return NULL;
+               mo = &bts->gprs.nsvc[obj_inst->trx_nr].mo;
+               break;
+       }
+       return mo;
+}
+
+/* obtain the gsm_nm_state data structure for a given object instance */
+struct gsm_nm_state *
+gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
+                const struct abis_om_obj_inst *obj_inst)
+{
+       struct gsm_abis_mo *mo;
+
+       mo = gsm_objclass2mo(bts, obj_class, obj_inst);
+       if (!mo)
+               return NULL;
+
+       return &mo->nm_state;
+}
+
+/* obtain the in-memory data structure of a given object instance */
+void *
+gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
+            const struct abis_om_obj_inst *obj_inst)
+{
+       struct gsm_bts_trx *trx;
+       void *obj = NULL;
+
+       switch (obj_class) {
+       case NM_OC_BTS:
+               obj = bts;
+               break;
+       case NM_OC_RADIO_CARRIER:
+               if (obj_inst->trx_nr >= bts->num_trx) {
+                       return NULL;
+               }
+               trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
+               obj = trx;
+               break;
+       case NM_OC_BASEB_TRANSC:
+               if (obj_inst->trx_nr >= bts->num_trx) {
+                       return NULL;
+               }
+               trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
+               obj = &trx->bb_transc;
+               break;
+       case NM_OC_CHANNEL:
+               if (obj_inst->trx_nr >= bts->num_trx) {
+                       return NULL;
+               }
+               trx = gsm_bts_trx_num(bts, obj_inst->trx_nr);
+               if (obj_inst->ts_nr >= TRX_NR_TS)
+                       return NULL;
+               obj = &trx->ts[obj_inst->ts_nr];
+               break;
+       case NM_OC_SITE_MANAGER:
+               obj = &bts->site_mgr;
+               break;
+       case NM_OC_GPRS_NSE:
+               obj = &bts->gprs.nse;
+               break;
+       case NM_OC_GPRS_CELL:
+               obj = &bts->gprs.cell;
+               break;
+       case NM_OC_GPRS_NSVC:
+               if (obj_inst->trx_nr >= ARRAY_SIZE(bts->gprs.nsvc))
+                       return NULL;
+               obj = &bts->gprs.nsvc[obj_inst->trx_nr];
+               break;
+       }
+       return obj;
+}
+
+/* See Table 10.5.25 of GSM04.08 */
+uint8_t gsm_pchan2chan_nr(enum gsm_phys_chan_config pchan,
+                         uint8_t ts_nr, uint8_t lchan_nr)
+{
+       uint8_t cbits, chan_nr;
+
+       switch (pchan) {
+       case GSM_PCHAN_TCH_F:
+       case GSM_PCHAN_TCH_F_PDCH:
+               OSMO_ASSERT(lchan_nr == 0);
+               cbits = 0x01;
+               break;
+       case GSM_PCHAN_PDCH:
+               OSMO_ASSERT(lchan_nr == 0);
+               cbits = RSL_CHAN_OSMO_PDCH >> 3;
+               break;
+       case GSM_PCHAN_TCH_H:
+               OSMO_ASSERT(lchan_nr < 2);
+               cbits = 0x02;
+               cbits += lchan_nr;
+               break;
+       case GSM_PCHAN_CCCH_SDCCH4:
+       case GSM_PCHAN_CCCH_SDCCH4_CBCH:
+               /*
+                * As a special hack for BCCH, lchan_nr == 4 may be passed
+                * here. This should never be sent in an RSL message.
+                * See osmo-bts-xxx/oml.c:opstart_compl().
+                */
+               if (lchan_nr == CCCH_LCHAN)
+                       chan_nr = 0;
+               else
+                       OSMO_ASSERT(lchan_nr < 4);
+               cbits = 0x04;
+               cbits += lchan_nr;
+               break;
+       case GSM_PCHAN_SDCCH8_SACCH8C:
+       case GSM_PCHAN_SDCCH8_SACCH8C_CBCH:
+               OSMO_ASSERT(lchan_nr < 8);
+               cbits = 0x08;
+               cbits += lchan_nr;
+               break;
+       default:
+       case GSM_PCHAN_CCCH:
+#ifdef ROLE_BSC
+               OSMO_ASSERT(lchan_nr == 0);
+#else
+               /*
+                * FIXME: On octphy and litecell, we hit above assertion (see
+                * Max's comment at https://gerrit.osmocom.org/589 ); disabled
+                * for BTS until this is clarified; remove the #ifdef when it
+                * is fixed.
+                */
+#warning "fix caller that passes lchan_nr != 0"
+#endif
+               cbits = 0x10;
+               break;
+       }
+
+       chan_nr = (cbits << 3) | (ts_nr & 0x7);
+
+       return chan_nr;
+}
+
+uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan)
+{
+       enum gsm_phys_chan_config pchan = lchan->ts->pchan;
+       if (pchan == GSM_PCHAN_TCH_F_TCH_H_PDCH)
+               return gsm_lchan_as_pchan2chan_nr(lchan,
+                                                 lchan->ts->dyn.pchan_is);
+       return gsm_pchan2chan_nr(lchan->ts->pchan, lchan->ts->nr, lchan->nr);
+}
+
+uint8_t gsm_lchan_as_pchan2chan_nr(const struct gsm_lchan *lchan,
+                                  enum gsm_phys_chan_config as_pchan)
+{
+       if (lchan->ts->pchan == GSM_PCHAN_TCH_F_TCH_H_PDCH
+           && as_pchan == GSM_PCHAN_PDCH)
+               return RSL_CHAN_OSMO_PDCH | (lchan->ts->nr & ~RSL_CHAN_NR_MASK);
+       return gsm_pchan2chan_nr(as_pchan, lchan->ts->nr, lchan->nr);
+}
+
+/* return the gsm_lchan for the CBCH (if it exists at all) */
+struct gsm_lchan *gsm_bts_get_cbch(struct gsm_bts *bts)
+{
+       struct gsm_lchan *lchan = NULL;
+       struct gsm_bts_trx *trx = bts->c0;
+
+       if (trx->ts[0].pchan == GSM_PCHAN_CCCH_SDCCH4_CBCH)
+               lchan = &trx->ts[0].lchan[2];
+       else {
+               int i;
+               for (i = 0; i < 8; i++) {
+                       if (trx->ts[i].pchan == GSM_PCHAN_SDCCH8_SACCH8C_CBCH) {
+                               lchan = &trx->ts[i].lchan[2];
+                               break;
+                       }
+               }
+       }
+
+       return lchan;
+}
+
+/* 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 = true;
+
+       if (rc)
+               *rc = -EINVAL;
+
+       if (cbits == 0x01) {
+               lch_idx = 0;    /* TCH/F */     
+               if (ts->pchan != GSM_PCHAN_TCH_F &&
+                   ts->pchan != GSM_PCHAN_PDCH &&
+                   ts->pchan != GSM_PCHAN_TCH_F_PDCH
+                   && !(ts->pchan == GSM_PCHAN_TCH_F_TCH_H_PDCH
+                        && (ts->dyn.pchan_is == GSM_PCHAN_TCH_F
+                            || ts->dyn.pchan_want == GSM_PCHAN_TCH_F)))
+                       ok = false;
+       } else if ((cbits & 0x1e) == 0x02) {
+               lch_idx = cbits & 0x1;  /* TCH/H */
+               if (ts->pchan != GSM_PCHAN_TCH_H
+                   && !(ts->pchan == GSM_PCHAN_TCH_F_TCH_H_PDCH
+                        && (ts->dyn.pchan_is == GSM_PCHAN_TCH_H
+                            || ts->dyn.pchan_want == GSM_PCHAN_TCH_H)))
+                       ok = false;
+       } else if ((cbits & 0x1c) == 0x04) {
+               lch_idx = cbits & 0x3;  /* SDCCH/4 */
+               if (ts->pchan != GSM_PCHAN_CCCH_SDCCH4 &&
+                   ts->pchan != GSM_PCHAN_CCCH_SDCCH4_CBCH)
+                       ok = false;
+       } else if ((cbits & 0x18) == 0x08) {
+               lch_idx = cbits & 0x7;  /* SDCCH/8 */
+               if (ts->pchan != GSM_PCHAN_SDCCH8_SACCH8C &&
+                   ts->pchan != GSM_PCHAN_SDCCH8_SACCH8C_CBCH)
+                       ok = false;
+       } else if (cbits == 0x10 || cbits == 0x11 || cbits == 0x12) {
+               lch_idx = 0;
+               if (ts->pchan != GSM_PCHAN_CCCH &&
+                   ts->pchan != GSM_PCHAN_CCCH_SDCCH4 &&
+                   ts->pchan != GSM_PCHAN_CCCH_SDCCH4_CBCH)
+                       ok = false;
+               /* FIXME: we should not return first sdcch4 !!! */
+       } else if ((chan_nr & RSL_CHAN_NR_MASK) == RSL_CHAN_OSMO_PDCH) {
+               lch_idx = 0;
+               if (ts->pchan != GSM_PCHAN_TCH_F_TCH_H_PDCH)
+                       ok = false;
+       } 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,
+       [GSM_PCHAN_PDCH] = 0,
+       [GSM_PCHAN_CCCH_SDCCH4] = 4,
+       [GSM_PCHAN_TCH_F] = 1,
+       [GSM_PCHAN_TCH_H] = 2,
+       [GSM_PCHAN_SDCCH8_SACCH8C] = 8,
+       [GSM_PCHAN_CCCH_SDCCH4_CBCH] = 4,
+       [GSM_PCHAN_SDCCH8_SACCH8C_CBCH] = 8,
+       /*
+        * GSM_PCHAN_TCH_F_PDCH and GSM_PCHAN_TCH_F_TCH_H_PDCH should not be
+        * part of this, those TS are handled according to their dynamic state.
+        */
+};
+
+/*! Return the actual pchan type, also heeding dynamic TS. */
+enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts)
+{
+       switch (ts->pchan) {
+       case GSM_PCHAN_TCH_F_TCH_H_PDCH:
+               return ts->dyn.pchan_is;
+       case GSM_PCHAN_TCH_F_PDCH:
+               if (ts->flags & TS_F_PDCH_ACTIVE)
+                       return GSM_PCHAN_PDCH;
+               else
+                       return GSM_PCHAN_TCH_F;
+       default:
+               return ts->pchan;
+       }
+}
+
+/*! According to ts->pchan and possibly ts->dyn_pchan, return the number of
+ * logical channels available in the timeslot. */
+uint8_t ts_subslots(struct gsm_bts_trx_ts *ts)
+{
+       return subslots_per_pchan[ts_pchan(ts)];
+}
+
+static bool pchan_is_tch(enum gsm_phys_chan_config pchan)
+{
+       switch (pchan) {
+       case GSM_PCHAN_TCH_F:
+       case GSM_PCHAN_TCH_H:
+               return true;
+       default:
+               return false;
+       }
+}
+
+bool ts_is_tch(struct gsm_bts_trx_ts *ts)
+{
+       return pchan_is_tch(ts_pchan(ts));
+}
diff --git a/src/osmo-bts-litecell15/Makefile.am 
b/src/osmo-bts-litecell15/Makefile.am
index 78a770a..fdb794d 100644
--- a/src/osmo-bts-litecell15/Makefile.am
+++ b/src/osmo-bts-litecell15/Makefile.am
@@ -1,6 +1,6 @@
 AUTOMAKE_OPTIONS = subdir-objects 
 
-AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR) 
-I$(LITECELL15_INCDIR)
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(LITECELL15_INCDIR)
 AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOCODEC_CFLAGS) 
$(LIBOSMOGSM_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS) 
$(LIBOSMOABIS_CFLAGS) $(LIBOSMOCTRL_CFLAGS) $(LIBOSMOABIS_CFLAGS) 
$(LIBGPS_CFLAGS) $(ORTP_CFLAGS) $(LIBSYSTEMD_CFLAGS)
 COMMON_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOCODEC_LIBS) $(LIBOSMOGSM_LIBS) 
$(LIBOSMOVTY_LIBS) $(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS) $(LIBOSMOCTRL_LIBS) 
$(ORTP_LIBS)
 
diff --git a/src/osmo-bts-octphy/Makefile.am b/src/osmo-bts-octphy/Makefile.am
index ac6a83e..9ca9e44 100644
--- a/src/osmo-bts-octphy/Makefile.am
+++ b/src/osmo-bts-octphy/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR) 
-I$(OCTSDR2G_INCDIR)
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OCTSDR2G_INCDIR)
 AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOCODEC_CFLAGS) 
$(LIBOSMOGSM_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS) 
$(LIBOSMOABIS_CFLAGS) $(LIBOSMOCTRL_CFLAGS) $(ORTP_CFLAGS)
 COMMON_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOCODEC_LIBS) $(LIBOSMOGSM_LIBS) 
$(LIBOSMOVTY_LIBS) $(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS) $(LIBOSMOCTRL_LIBS) 
$(ORTP_LIBS)
 
diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am
index 7b27e70..c48b77c 100644
--- a/src/osmo-bts-sysmo/Makefile.am
+++ b/src/osmo-bts-sysmo/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include
 AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOCODEC_CFLAGS) 
$(LIBOSMOGSM_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS) 
$(LIBOSMOABIS_CFLAGS) $(LIBOSMOCTRL_CFLAGS) $(LIBOSMOABIS_CFLAGS) 
$(LIBGPS_CFLAGS) $(ORTP_CFLAGS)
 COMMON_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOCODEC_LIBS) $(LIBOSMOGSM_LIBS) 
$(LIBOSMOVTY_LIBS) $(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS) $(LIBOSMOCTRL_LIBS) 
$(ORTP_LIBS)
 
diff --git a/src/osmo-bts-trx/Makefile.am b/src/osmo-bts-trx/Makefile.am
index 0a97251..5fe7705 100644
--- a/src/osmo-bts-trx/Makefile.am
+++ b/src/osmo-bts-trx/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include
 AM_CFLAGS = -Wall -fno-strict-aliasing $(LIBOSMOCORE_CFLAGS) 
$(LIBOSMOGSM_CFLAGS) $(LIBOSMOCODEC_CFLAGS) $(LIBOSMOCODING_CFLAGS) 
$(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS) $(LIBOSMOABIS_CFLAGS) 
$(LIBOSMOCTRL_CFLAGS) $(ORTP_CFLAGS)
 LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCODEC_LIBS) 
$(LIBOSMOCODING_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMOTRAU_LIBS) 
$(LIBOSMOABIS_LIBS) $(LIBOSMOCTRL_LIBS) $(ORTP_LIBS) -ldl
 
diff --git a/src/osmo-bts-virtual/Makefile.am b/src/osmo-bts-virtual/Makefile.am
index d1f05af..6038426 100644
--- a/src/osmo-bts-virtual/Makefile.am
+++ b/src/osmo-bts-virtual/Makefile.am
@@ -1,5 +1,5 @@
 AM_CFLAGS = -Wall -fno-strict-aliasing $(LIBOSMOCORE_CFLAGS) 
$(LIBOSMOGSM_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS) 
$(LIBOSMOABIS_CFLAGS) $(LIBOSMOCTRL_CFLAGS) $(LIBOSMOABIS_CFLAGS) 
$(LIBGPS_CFLAGS) $(ORTP_CFLAGS)
-AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR) 
-Iinclude
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -Iinclude
 COMMON_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) 
$(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS) $(LIBOSMOCTRL_LIBS) $(ORTP_LIBS) -ldl
 
 noinst_HEADERS = l1_if.h osmo_mcast_sock.h virtual_um.h
diff --git a/tests/agch/Makefile.am b/tests/agch/Makefile.am
index 46b55e9..1357ea2 100644
--- a/tests/agch/Makefile.am
+++ b/tests/agch/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include
 AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) 
$(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS) $(LIBOSMOCODEC_CFLAGS) $(ORTP_CFLAGS)
 LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) 
$(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS) $(LIBOSMOCODEC_LIBS) $(ORTP_LIBS)
 noinst_PROGRAMS = agch_test
diff --git a/tests/cipher/Makefile.am b/tests/cipher/Makefile.am
index d76dcd5..a671550 100644
--- a/tests/cipher/Makefile.am
+++ b/tests/cipher/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include
 AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) 
$(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS) $(LIBOSMOCODEC_CFLAGS) $(ORTP_CFLAGS)
 LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) 
$(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS) $(LIBOSMOCODEC_LIBS) $(ORTP_LIBS)
 noinst_PROGRAMS = cipher_test
diff --git a/tests/handover/Makefile.am b/tests/handover/Makefile.am
index 597ab2d..8bff297 100644
--- a/tests/handover/Makefile.am
+++ b/tests/handover/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include
 AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) 
$(LIBOSMOCODEC_CFLAGS)$(LIBOSMOTRAU_CFLAGS)
 LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCODEC_LIBS) 
$(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS)
 noinst_PROGRAMS = handover_test
diff --git a/tests/meas/Makefile.am b/tests/meas/Makefile.am
index 8dd0582..895d474 100644
--- a/tests/meas/Makefile.am
+++ b/tests/meas/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include
 AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) 
$(LIBOSMOCODEC_CFLAGS)$(LIBOSMOTRAU_CFLAGS)
 LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCODEC_LIBS) 
$(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS)
 noinst_PROGRAMS = meas_test
diff --git a/tests/misc/Makefile.am b/tests/misc/Makefile.am
index d5acb18..6575fe8 100644
--- a/tests/misc/Makefile.am
+++ b/tests/misc/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include
 AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) 
$(LIBOSMOCODEC_CFLAGS)
 LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCODEC_LIBS)
 noinst_PROGRAMS = misc_test
diff --git a/tests/paging/Makefile.am b/tests/paging/Makefile.am
index be9de74..98c6673 100644
--- a/tests/paging/Makefile.am
+++ b/tests/paging/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include
 AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) 
$(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS) $(LIBOSMOCODEC_CFLAGS) $(ORTP_CFLAGS)
 LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) 
$(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS) $(LIBOSMOCODEC_LIBS) $(ORTP_LIBS)
 noinst_PROGRAMS = paging_test
diff --git a/tests/sysmobts/Makefile.am b/tests/sysmobts/Makefile.am
index 2f267f3..654ab5d 100644
--- a/tests/sysmobts/Makefile.am
+++ b/tests/sysmobts/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR) 
-I$(top_srcdir)/src/osmo-bts-sysmo
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include 
-I$(top_srcdir)/src/osmo-bts-sysmo
 AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOCODEC_CFLAGS) 
$(LIBOSMOGSM_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS) $(ORTP_CFLAGS)
 LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOCODEC_LIBS) $(LIBOSMOGSM_LIBS) 
$(LIBOSMOVTY_LIBS) $(LIBOSMOTRAU_LIBS) $(ORTP_LIBS)
 
diff --git a/tests/tx_power/Makefile.am b/tests/tx_power/Makefile.am
index 3d4377a..349958c 100644
--- a/tests/tx_power/Makefile.am
+++ b/tests/tx_power/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include
 AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) 
$(LIBOSMOCODEC_CFLAGS)$(LIBOSMOTRAU_CFLAGS)
 LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCODEC_LIBS) 
$(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS)
 noinst_PROGRAMS = tx_power_test

-- 
To view, visit https://gerrit.osmocom.org/4161
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I9f004fb5c4c1db29d4792dfd281d388c7063da13
Gerrit-PatchSet: 3
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Max <[email protected]>
Gerrit-Reviewer: Jenkins Builder

Reply via email to