Change in osmocom-bb[master]: layer23/common: introduce L23SAP API for L1CTL

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/.

Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Sat Oct 6 09:44:58 UTC 2018


Vadim Yanitskiy has uploaded this change for review. ( https://gerrit.osmocom.org/11246


Change subject: layer23/common: introduce L23SAP API for L1CTL
......................................................................

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
---
M src/host/layer23/include/osmocom/bb/common/Makefile.am
A src/host/layer23/include/osmocom/bb/common/l23sap.h
M src/host/layer23/include/osmocom/bb/common/logging.h
M src/host/layer23/src/common/Makefile.am
M src/host/layer23/src/common/l1ctl.c
A src/host/layer23/src/common/l23sap.c
M src/host/layer23/src/common/logging.c
7 files changed, 134 insertions(+), 51 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/46/11246/1

diff --git a/src/host/layer23/include/osmocom/bb/common/Makefile.am b/src/host/layer23/include/osmocom/bb/common/Makefile.am
index cd3437e..5a137df 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 0000000..814fb7d
--- /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 bf6e6aa..10b2f7f 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 @@
 	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 b76094c..e1b7b44 100644
--- a/src/host/layer23/src/common/Makefile.am
+++ b/src/host/layer23/src/common/Makefile.am
@@ -3,4 +3,4 @@
 
 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 6f4a6d8..8a45ebe 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;
@@ -117,34 +117,21 @@
 
 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;
@@ -238,46 +225,22 @@
 		    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 */
@@ -919,10 +882,10 @@
 		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 0000000..b07265a
--- /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 at gnumonks.org>
+ * (C) 2018 by Vadim Yanitskiy <axilirator at 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 ed79991..2f43fff 100644
--- a/src/host/layer23/src/common/logging.c
+++ b/src/host/layer23/src/common/logging.c
@@ -145,6 +145,12 @@
 		.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 = {

-- 
To view, visit https://gerrit.osmocom.org/11246
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I22d7932ddc03c692f2616726ced53b6e8eef822d
Gerrit-Change-Number: 11246
Gerrit-PatchSet: 1
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181006/98e757f7/attachment.htm>


More information about the gerrit-log mailing list