summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2018-10-03 06:34:05 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2018-11-21 11:03:10 +0700
commit33afaa9c6f8360b843ac4de0567f7662cd89d5c3 (patch)
treebad1309d2d4bdfd1029be0bfaf8adc4401cda155 /src
parentc8de8cb1e126a18c0269571fba38310589dd9273 (diff)
layer23/common: introduce L23SAP API for L1CTL
Having a separate abstraction layer between both L1CTL interface and the upper layers would allow to keep the L1CTL implementation clean from GSMTAP / LAPDm / measurement specific stuff. Change-Id: I22d7932ddc03c692f2616726ced53b6e8eef822d
Diffstat (limited to 'src')
-rw-r--r--src/host/layer23/include/osmocom/bb/common/Makefile.am2
-rw-r--r--src/host/layer23/include/osmocom/bb/common/l23sap.h15
-rw-r--r--src/host/layer23/include/osmocom/bb/common/logging.h1
-rw-r--r--src/host/layer23/src/common/Makefile.am2
-rw-r--r--src/host/layer23/src/common/l1ctl.c61
-rw-r--r--src/host/layer23/src/common/l23sap.c98
-rw-r--r--src/host/layer23/src/common/logging.c6
7 files changed, 134 insertions, 51 deletions
diff --git a/src/host/layer23/include/osmocom/bb/common/Makefile.am b/src/host/layer23/include/osmocom/bb/common/Makefile.am
index cd3437e3..5a137dfb 100644
--- a/src/host/layer23/include/osmocom/bb/common/Makefile.am
+++ b/src/host/layer23/include/osmocom/bb/common/Makefile.am
@@ -1,2 +1,2 @@
noinst_HEADERS = l1ctl.h l1l2_interface.h l23_app.h logging.h \
- networks.h gps.h sysinfo.h osmocom_data.h utils.h
+ networks.h gps.h sysinfo.h osmocom_data.h utils.h l23sap.h
diff --git a/src/host/layer23/include/osmocom/bb/common/l23sap.h b/src/host/layer23/include/osmocom/bb/common/l23sap.h
new file mode 100644
index 00000000..814fb7de
--- /dev/null
+++ b/src/host/layer23/include/osmocom/bb/common/l23sap.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <osmocom/core/msgb.h>
+#include <osmocom/bb/common/osmocom_data.h>
+
+/* Logical channel link ID */
+#define LID_SACCH 0x40
+#define LID_DEDIC 0x00
+
+#define CHAN_IS_SACCH(link_id) \
+ ((link_id & 0xc0) == LID_SACCH)
+
+int l23sap_data_ind(struct osmocom_ms *ms, struct msgb *msg);
+int l23sap_data_conf(struct osmocom_ms *ms, struct msgb *msg);
+int l23sap_rach_conf(struct osmocom_ms *ms, struct msgb *msg);
diff --git a/src/host/layer23/include/osmocom/bb/common/logging.h b/src/host/layer23/include/osmocom/bb/common/logging.h
index bf6e6aa0..10b2f7f9 100644
--- a/src/host/layer23/include/osmocom/bb/common/logging.h
+++ b/src/host/layer23/include/osmocom/bb/common/logging.h
@@ -25,6 +25,7 @@ enum {
DMOB,
DPRIM,
DLUA,
+ DL23SAP,
};
extern const struct log_info log_info;
diff --git a/src/host/layer23/src/common/Makefile.am b/src/host/layer23/src/common/Makefile.am
index b76094c6..e1b7b448 100644
--- a/src/host/layer23/src/common/Makefile.am
+++ b/src/host/layer23/src/common/Makefile.am
@@ -3,4 +3,4 @@ AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBGPS_CFLAGS)
noinst_LIBRARIES = liblayer23.a
liblayer23_a_SOURCES = l1ctl.c l1l2_interface.c sap_interface.c \
- logging.c networks.c sim.c sysinfo.c gps.c l1ctl_lapdm_glue.c utils.c
+ logging.c networks.c sim.c sysinfo.c gps.c l1ctl_lapdm_glue.c utils.c l23sap.c
diff --git a/src/host/layer23/src/common/l1ctl.c b/src/host/layer23/src/common/l1ctl.c
index 5d6d9c0c..df12105e 100644
--- a/src/host/layer23/src/common/l1ctl.c
+++ b/src/host/layer23/src/common/l1ctl.c
@@ -43,9 +43,9 @@
#include <osmocom/gsm/rsl.h>
#include <osmocom/bb/common/l1ctl.h>
+#include <osmocom/bb/common/l23sap.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/l1l2_interface.h>
-#include <osmocom/gsm/lapdm.h>
#include <osmocom/bb/common/logging.h>
extern struct gsmtap_inst *gsmtap_inst;
@@ -114,34 +114,21 @@ static int rx_l1_fbsb_conf(struct osmocom_ms *ms, struct msgb *msg)
static int rx_l1_rach_conf(struct osmocom_ms *ms, struct msgb *msg)
{
- struct lapdm_entity *le = &ms->lapdm_channel.lapdm_dcch;
- struct osmo_phsap_prim pp;
- struct l1ctl_info_dl *dl;
-
- if (msgb_l1len(msg) < sizeof(*dl)) {
+ if (msgb_l1len(msg) < sizeof(struct l1ctl_info_dl)) {
LOGP(DL1C, LOGL_ERROR, "RACH CONF MSG too short "
"(len=%u), missing DL info header\n", msgb_l1len(msg));
msgb_free(msg);
return -1;
}
- dl = (struct l1ctl_info_dl *) msg->l1h;
- msg->l2h = msg->l3h = dl->payload;
-
- osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_RACH,
- PRIM_OP_CONFIRM, msg);
- pp.u.rach_ind.fn = ntohl(dl->frame_nr);
-
- return lapdm_phsap_up(&pp.oph, le);
+ return l23sap_rach_conf(ms, msg);
}
/* Receive L1CTL_DATA_IND (Data Indication from L1) */
-static int rx_ph_data_ind(struct osmocom_ms *ms, struct msgb *msg)
+static int rx_data_ind(struct osmocom_ms *ms, struct msgb *msg)
{
- struct osmo_phsap_prim pp;
struct l1ctl_info_dl *dl;
struct l1ctl_data_ind *ccch;
- struct lapdm_entity *le;
struct rx_meas_stat *meas = &ms->meas;
uint8_t chan_type, chan_ts, chan_ss;
uint8_t gsmtap_chan_type;
@@ -235,46 +222,22 @@ static int rx_ph_data_ind(struct osmocom_ms *ms, struct msgb *msg)
gsmtap_chan_type, chan_ss, tm.fn, dl->rx_level-110,
dl->snr, ccch->data, sizeof(ccch->data));
- /* determine LAPDm entity based on SACCH or not */
- if (dl->link_id & 0x40)
- le = &ms->lapdm_channel.lapdm_acch;
- else
- le = &ms->lapdm_channel.lapdm_dcch;
-
- osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_DATA,
- PRIM_OP_INDICATION, msg);
- pp.u.data.chan_nr = dl->chan_nr;
- pp.u.data.link_id = dl->link_id;
-
- /* send it up into LAPDm */
- return lapdm_phsap_up(&pp.oph, le);
+ /* Send it up towards LAPDm via L23SAP */
+ return l23sap_data_ind(ms, msg);
}
/* Receive L1CTL_DATA_CONF (Data Confirm from L1) */
-static int rx_ph_data_conf(struct osmocom_ms *ms, struct msgb *msg)
+static int rx_data_conf(struct osmocom_ms *ms, struct msgb *msg)
{
- struct osmo_phsap_prim pp;
- struct l1ctl_info_dl *dl = (struct l1ctl_info_dl *) msg->l1h;
- struct lapdm_entity *le;
-
- if (msgb_l1len(msg) < sizeof(*dl)) {
+ if (msgb_l1len(msg) < sizeof(struct l1ctl_info_dl)) {
LOGP(DL1C, LOGL_ERROR, "DATA CONF MSG too short (len=%u), "
"missing UL info header\n", msgb_l1len(msg));
msgb_free(msg);
return -1;
}
- osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_RTS,
- PRIM_OP_INDICATION, msg);
-
- /* determine LAPDm entity based on SACCH or not */
- if (dl->link_id & 0x40)
- le = &ms->lapdm_channel.lapdm_acch;
- else
- le = &ms->lapdm_channel.lapdm_dcch;
-
- /* send it up into LAPDm */
- return lapdm_phsap_up(&pp.oph, le);
+ /* Send it up towards LAPDm via L23SAP */
+ return l23sap_data_conf(ms, msg);
}
/* Transmit L1CTL_DATA_REQ */
@@ -912,10 +875,10 @@ int l1ctl_recv(struct osmocom_ms *ms, struct msgb *msg)
msgb_free(msg);
break;
case L1CTL_DATA_IND:
- rc = rx_ph_data_ind(ms, msg);
+ rc = rx_data_ind(ms, msg);
break;
case L1CTL_DATA_CONF:
- rc = rx_ph_data_conf(ms, msg);
+ rc = rx_data_conf(ms, msg);
break;
case L1CTL_RESET_IND:
case L1CTL_RESET_CONF:
diff --git a/src/host/layer23/src/common/l23sap.c b/src/host/layer23/src/common/l23sap.c
new file mode 100644
index 00000000..b07265ac
--- /dev/null
+++ b/src/host/layer23/src/common/l23sap.c
@@ -0,0 +1,98 @@
+/*
+ * L23SAP (L2&3 Service Access Point), an interface between
+ * L1 implementation and the upper layers (i.e. L2&3).
+ *
+ * (C) 2011 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2018 by Vadim Yanitskiy <axilirator@gmail.com>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <errno.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <arpa/inet.h>
+#include <l1ctl_proto.h>
+
+#include <osmocom/core/logging.h>
+#include <osmocom/core/prim.h>
+#include <osmocom/core/msgb.h>
+#include <osmocom/gsm/lapdm.h>
+
+#include <osmocom/bb/common/osmocom_data.h>
+#include <osmocom/bb/common/logging.h>
+#include <osmocom/bb/common/l23sap.h>
+
+int l23sap_data_ind(struct osmocom_ms *ms, struct msgb *msg)
+{
+ struct l1ctl_info_dl *dl = (struct l1ctl_info_dl *) msg->l1h;
+ struct osmo_phsap_prim pp;
+ struct lapdm_entity *le;
+
+ /* Init a new DATA IND primitive */
+ osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_DATA,
+ PRIM_OP_INDICATION, msg);
+ pp.u.data.chan_nr = dl->chan_nr;
+ pp.u.data.link_id = dl->link_id;
+
+ /* Determine LAPDm entity based on SACCH or not */
+ if (CHAN_IS_SACCH(dl->link_id))
+ le = &ms->lapdm_channel.lapdm_acch;
+ else
+ le = &ms->lapdm_channel.lapdm_dcch;
+
+ /* Send it up into LAPDm */
+ return lapdm_phsap_up(&pp.oph, le);
+}
+
+int l23sap_data_conf(struct osmocom_ms *ms, struct msgb *msg)
+{
+ struct l1ctl_info_dl *dl = (struct l1ctl_info_dl *) msg->l1h;
+ struct osmo_phsap_prim pp;
+ struct lapdm_entity *le;
+
+ osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_RTS,
+ PRIM_OP_INDICATION, msg);
+
+ /* Determine LAPDm entity based on SACCH or not */
+ if (CHAN_IS_SACCH(dl->link_id))
+ le = &ms->lapdm_channel.lapdm_acch;
+ else
+ le = &ms->lapdm_channel.lapdm_dcch;
+
+ /* Send it up into LAPDm */
+ return lapdm_phsap_up(&pp.oph, le);
+}
+
+int l23sap_rach_conf(struct osmocom_ms *ms, struct msgb *msg)
+{
+ struct l1ctl_info_dl *dl = (struct l1ctl_info_dl *) msg->l1h;
+ struct osmo_phsap_prim pp;
+
+ osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_RACH,
+ PRIM_OP_CONFIRM, msg);
+ pp.u.rach_ind.fn = ntohl(dl->frame_nr);
+
+ /* TODO: do we really need this? */
+ msg->l2h = msg->l3h = dl->payload;
+
+ /* Send it up into LAPDm */
+ return lapdm_phsap_up(&pp.oph,
+ &ms->lapdm_channel.lapdm_dcch);
+}
diff --git a/src/host/layer23/src/common/logging.c b/src/host/layer23/src/common/logging.c
index ed799913..2f43fff4 100644
--- a/src/host/layer23/src/common/logging.c
+++ b/src/host/layer23/src/common/logging.c
@@ -145,6 +145,12 @@ static const struct log_info_cat default_categories[] = {
.color = "\033[1;32m",
.enabled = 1, .loglevel = LOGL_DEBUG,
},
+ [DL23SAP] = {
+ .name = "DL23SAP",
+ .description = "L2&3 SAP (Service Access Point)",
+ .color = "\033[1;36m",
+ .enabled = 1, .loglevel = LOGL_DEBUG,
+ },
};
const struct log_info log_info = {