aboutsummaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2016-06-17 13:10:38 +0200
committerHarald Welte <laforge@gnumonks.org>2016-06-18 11:35:12 +0000
commit61372a20de695a151611753689ee9a3018b101f6 (patch)
tree7b1b1e69c4c79262eb03806da79457d59cf98020 /src/common
parentc3fb0dcc8cd01a84942d06267003478b972feadb (diff)
Move copy-pasted code into common part
Diffstat (limited to 'src/common')
-rw-r--r--src/common/Makefile.am1
-rw-r--r--src/common/amr.c9
-rw-r--r--src/common/l1sap.c20
-rw-r--r--src/common/msg_utils.c43
4 files changed, 72 insertions, 1 deletions
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index 8df65138..fbb65729 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -6,7 +6,6 @@ noinst_LIBRARIES = libbts.a libl1sched.a
libbts_a_SOURCES = gsm_data_shared.c sysinfo.c logging.c abis.c oml.c bts.c \
rsl.c vty.c paging.c measurement.c amr.c lchan.c \
load_indication.c pcu_sock.c handover.c msg_utils.c \
- load_indication.c pcu_sock.c handover.c msg_utils.c \
tx_power.c bts_ctrl_commands.c bts_ctrl_lookup.c \
l1sap.c cbch.c power_control.c main.c phy_link.c
diff --git a/src/common/amr.c b/src/common/amr.c
index 80c5fb62..56ed4302 100644
--- a/src/common/amr.c
+++ b/src/common/amr.c
@@ -22,6 +22,15 @@ void amr_log_mr_conf(int ss, int logl, const char *pfx,
LOGPC(ss, logl, "\n");
}
+int get_amr_mode_idx(const struct amr_multirate_conf *amr_mrc, uint8_t cmi)
+{
+ unsigned int i;
+ for (i = 0; i < amr_mrc->num_modes; i++) {
+ if (amr_mrc->bts_mode[i].mode == cmi)
+ return i;
+ }
+ return -EINVAL;
+}
/* parse a GSM 04.08 MultiRate Config IE (10.5.2.21aa) in a more
* comfortable internal data structure */
diff --git a/src/common/l1sap.c b/src/common/l1sap.c
index 0af73436..0a6bc49d 100644
--- a/src/common/l1sap.c
+++ b/src/common/l1sap.c
@@ -104,6 +104,26 @@ struct msgb *l1sap_msgb_alloc(unsigned int l2_len)
return msg;
}
+int add_l1sap_header(struct gsm_bts_trx *trx, struct msgb *rmsg,
+ struct gsm_lchan *lchan, uint8_t chan_nr, uint32_t fn)
+{
+ struct osmo_phsap_prim *l1sap;
+
+ LOGP(DL1C, LOGL_DEBUG, "%s Rx -> RTP: %s\n",
+ gsm_lchan_name(lchan), osmo_hexdump(rmsg->data, rmsg->len));
+
+ rmsg->l2h = rmsg->data;
+ msgb_push(rmsg, sizeof(*l1sap));
+ rmsg->l1h = rmsg->data;
+ l1sap = msgb_l1sap_prim(rmsg);
+ osmo_prim_init(&l1sap->oph, SAP_GSM_PH, PRIM_TCH, PRIM_OP_INDICATION,
+ rmsg);
+ l1sap->u.tch.chan_nr = chan_nr;
+ l1sap->u.tch.fn = fn;
+
+ return l1sap_up(trx, l1sap);
+}
+
static int l1sap_tx_ciph_req(struct gsm_bts_trx *trx, uint8_t chan_nr,
uint8_t downlink, uint8_t uplink)
{
diff --git a/src/common/msg_utils.c b/src/common/msg_utils.c
index 841ffe61..6f42f73b 100644
--- a/src/common/msg_utils.c
+++ b/src/common/msg_utils.c
@@ -86,6 +86,49 @@ static int check_manuf(struct msgb *msg, struct abis_om_hdr *omh, size_t msg_siz
return type;
}
+/* store the last SID frame in lchan context */
+void save_last_sid(struct gsm_lchan *lchan, uint8_t *l1_payload, size_t length,
+ uint32_t fn, bool update)
+{
+ size_t copy_len = OSMO_MIN(length + 1,
+ ARRAY_SIZE(lchan->tch.last_sid.buf));
+
+ lchan->tch.last_sid.len = copy_len;
+ lchan->tch.last_sid.fn = fn;
+ lchan->tch.last_sid.is_update = update;
+
+ memcpy(lchan->tch.last_sid.buf, l1_payload, copy_len);
+}
+
+static inline bool fn_chk(uint8_t *t, uint32_t fn)
+{
+ uint8_t i;
+ for (i = 0; i < ARRAY_SIZE(t); i++)
+ if (fn % 104 == t[i])
+ return false;
+ return true;
+}
+
+/*! \brief Check if TX scheduling is optional for a given FN in case of DTX
+ * \param[in] lchan Logical channel on which we check scheduling
+ * \param[in] fn Frame Number for which we check scheduling
+ * \returns true if transmission can be omitted, false otherwise
+ */
+bool dtx_sched_optional(struct gsm_lchan *lchan, uint32_t fn)
+{
+ /* According to 3GPP TS 45.008 ยง 8.3: */
+ uint8_t f[] = { 52, 53, 54, 55, 56, 57, 58, 59 },
+ h0[] = { 0, 2, 4, 6, 52, 54, 56, 58 },
+ h1[] = { 14, 16, 18, 20, 66, 68, 70, 72 };
+ if (lchan->tch_mode == GSM48_CMODE_SPEECH_V1) {
+ if (lchan->type == GSM_LCHAN_TCH_F)
+ return fn_chk(f, fn);
+ else
+ return fn_chk(lchan->nr ? h1 : h0, fn);
+ }
+ return false;
+}
+
/**
* Return 0 in case the IPA structure is okay and in this
* case the l2h will be set to the beginning of the data.