summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte2010-04-05 13:26:09 +0200
committerHarald Welte2010-04-05 15:30:00 +0200
commitdb60b706ccef02a9b1ef28facc6b3d6f94da9e36 (patch)
tree8fd0439abac4242580f99792e04cf39f837c0896
parentWork on Radio Ressource: RSL-SAP interface on L3 side. (diff)
downloadosmocom-db60b706ccef02a9b1ef28facc6b3d6f94da9e36.tar.gz
osmocom-db60b706ccef02a9b1ef28facc6b3d6f94da9e36.tar.xz
osmocom-db60b706ccef02a9b1ef28facc6b3d6f94da9e36.zip
layer23: split into liblayer23 and 'apps'
similar to the concept of having 'apps' in the firmware build process, I'm now building the common code as liblayer23 and we have three apps that use this library: layer23 - the old layer23 program bcch_scan - a passive bcch scanner under development echo_test - a test program sending large msgb's containing zero bytes
-rw-r--r--src/host/layer23/include/osmocom/l23_app.h8
-rw-r--r--src/host/layer23/include/osmocom/lapdm.h5
-rw-r--r--src/host/layer23/include/osmocom/layer3.h3
-rw-r--r--src/host/layer23/include/osmocom/osmocom_data.h12
-rw-r--r--src/host/layer23/include/osmocom/rslms.h2
-rw-r--r--src/host/layer23/src/Makefile.am19
-rw-r--r--src/host/layer23/src/app_bcch_scan.c39
-rw-r--r--src/host/layer23/src/app_echo_test.c56
-rw-r--r--src/host/layer23/src/app_phone.c38
-rw-r--r--src/host/layer23/src/l1ctl.c8
-rw-r--r--src/host/layer23/src/lapdm.c21
-rw-r--r--src/host/layer23/src/main.c32
-rw-r--r--src/host/layer23/src/rslms.c7
13 files changed, 210 insertions, 40 deletions
diff --git a/src/host/layer23/include/osmocom/l23_app.h b/src/host/layer23/include/osmocom/l23_app.h
new file mode 100644
index 0000000..6c246b3
--- /dev/null
+++ b/src/host/layer23/include/osmocom/l23_app.h
@@ -0,0 +1,8 @@
+#ifndef _L23_APP_H
+#define _L23_APP_H
+
+/* initialization, called once when starting the app, before entering
+ * select loop */
+int l23_app_init(struct osmocom_ms *ms);
+
+#endif /* _L23_APP_H */
diff --git a/src/host/layer23/include/osmocom/lapdm.h b/src/host/layer23/include/osmocom/lapdm.h
index f3967a9..12697c2 100644
--- a/src/host/layer23/include/osmocom/lapdm.h
+++ b/src/host/layer23/include/osmocom/lapdm.h
@@ -57,4 +57,9 @@ int rslms_recvmsg(struct msgb *msg, struct osmocom_ms *ms);
/* sending messages up from L2 to L3 */
int rslms_sendmsg(struct msgb *msg, struct osmocom_ms *ms);
+typedef int (*osmol2_cb_t)(struct msgb *msg, struct osmocom_ms *ms);
+
+/* register message handler for messages that are sent from L2->L3 */
+int osmol2_register_handler(struct osmocom_ms *ms, osmol2_cb_t cb);
+
#endif /* _OSMOCOM_LAPDM_H */
diff --git a/src/host/layer23/include/osmocom/layer3.h b/src/host/layer23/include/osmocom/layer3.h
index 415b909..bf68102 100644
--- a/src/host/layer23/include/osmocom/layer3.h
+++ b/src/host/layer23/include/osmocom/layer3.h
@@ -8,4 +8,7 @@ int gsm48_rx_ccch(struct msgb *msg, struct osmocom_ms *ms);
int gsm48_rx_dcch(struct msgb *msg, struct osmocom_ms *ms);
int gsm48_rx_bcch(struct msgb *msg, struct osmocom_ms *ms);
+/* Initialize layer3 for the MS, hook it to L2 */
+int layer3_init(struct osmocom_ms *ms);
+
#endif
diff --git a/src/host/layer23/include/osmocom/osmocom_data.h b/src/host/layer23/include/osmocom/osmocom_data.h
index 79a01d5..e46967c 100644
--- a/src/host/layer23/include/osmocom/osmocom_data.h
+++ b/src/host/layer23/include/osmocom/osmocom_data.h
@@ -7,14 +7,22 @@
#include <osmocom/lapdm.h>
+struct osmocom_ms;
+
+/* A layer2 entity */
+struct osmol2_entity {
+ struct lapdm_entity lapdm_dcch;
+ struct lapdm_entity lapdm_acch;
+ osmol2_cb_t msg_handler;
+};
+
/* One Mobilestation for osmocom */
struct osmocom_ms {
struct write_queue wq;
enum gsm_band band;
int arfcn;
- struct lapdm_entity lapdm_dcch;
- struct lapdm_entity lapdm_acch;
+ struct osmol2_entity l2_entity;
};
#endif
diff --git a/src/host/layer23/include/osmocom/rslms.h b/src/host/layer23/include/osmocom/rslms.h
index 7327c11..8f17b81 100644
--- a/src/host/layer23/include/osmocom/rslms.h
+++ b/src/host/layer23/include/osmocom/rslms.h
@@ -18,6 +18,6 @@ int rslms_tx_rll_req_l3(struct osmocom_ms *ms, uint8_t msg_type,
/* From L2 into RSLMS (direction -> L3) */
/* input function that L2 calls when sending messages up to L3 */
-int rslms_sendmsg(struct msgb *msg, struct osmocom_ms *ms);
+//int rslms_sendmsg(struct msgb *msg, struct osmocom_ms *ms);
#endif /* _OSMOCOM_RSLMS_H */
diff --git a/src/host/layer23/src/Makefile.am b/src/host/layer23/src/Makefile.am
index ae867fa..0840ef0 100644
--- a/src/host/layer23/src/Makefile.am
+++ b/src/host/layer23/src/Makefile.am
@@ -1,7 +1,18 @@
INCLUDES = $(all_includes) -I$(top_srcdir)/include
AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS)
+AM_LDFLAGS = $(LIBOSMOCORE_LIBS)
-sbin_PROGRAMS = layer23
-layer23_SOURCES = main.c l1ctl.c gsmtap_util.c lapdm.c rslms.c \
- layer3.c logging.c
-layer23_LDADD = $(LIBOSMOCORE_LIBS)
+noinst_LIBRARIES = liblayer23.a
+liblayer23_a_SOURCES = l1ctl.c gsmtap_util.c lapdm.c rslms.c \
+ layer3.c logging.c
+
+bin_PROGRAMS = bcch_scan layer23 echo_test
+
+bcch_scan_SOURCES = main.c app_bcch_scan.c
+bcch_scan_LDADD = liblayer23.a
+
+layer23_SOURCES = main.c app_phone.c
+layer23_LDADD = liblayer23.a
+
+echo_test_SOURCES = main.c app_echo_test.c
+echo_test_LDADD = liblayer23.a
diff --git a/src/host/layer23/src/app_bcch_scan.c b/src/host/layer23/src/app_bcch_scan.c
new file mode 100644
index 0000000..c89ce06
--- /dev/null
+++ b/src/host/layer23/src/app_bcch_scan.c
@@ -0,0 +1,39 @@
+/* "Application" code of the layer2/3 stack */
+
+/* (C) 2010 by Holger Hans Peter Freyther
+ * (C) 2010 by Harald Welte <laforge@gnumonks.org>
+ *
+ * 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 <osmocom/osmocom_data.h>
+#include <osmocom/l1ctl.h>
+#include <osmocom/layer3.h>
+#include <osmocom/lapdm.h>
+#include <osmocom/gsmtap_util.h>
+#include <osmocom/logging.h>
+
+#include <osmocore/msgb.h>
+#include <osmocore/talloc.h>
+#include <osmocore/select.h>
+
+int l23_app_init(struct osmocom_ms *ms)
+{
+ /* don't do layer3_init() as we don't want an actualy L3 */
+ return 0;
+}
diff --git a/src/host/layer23/src/app_echo_test.c b/src/host/layer23/src/app_echo_test.c
new file mode 100644
index 0000000..285b80a
--- /dev/null
+++ b/src/host/layer23/src/app_echo_test.c
@@ -0,0 +1,56 @@
+/* TEST code, regularly transmit ECHO REQ packet to L1 */
+
+/* (C) 2010 by Holger Hans Peter Freyther
+ * (C) 2010 by Harald Welte <laforge@gnumonks.org>
+ *
+ * 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 <osmocom/osmocom_data.h>
+#include <osmocom/l1ctl.h>
+#include <osmocom/layer3.h>
+#include <osmocom/lapdm.h>
+#include <osmocom/gsmtap_util.h>
+#include <osmocom/logging.h>
+
+#include <osmocore/msgb.h>
+#include <osmocore/talloc.h>
+#include <osmocore/select.h>
+
+
+static struct {
+ struct timer_list timer;
+} test_data;
+
+static void test_tmr_cb(void *data)
+{
+ struct osmocom_ms *ms = data;
+
+ l1ctl_tx_echo_req(ms, 62);
+ bsc_schedule_timer(&test_data.timer, 1, 0);
+}
+
+int l23_app_init(struct osmocom_ms *ms)
+{
+ test_data.timer.cb = &test_tmr_cb;
+ test_data.timer.data = ms;
+
+ bsc_schedule_timer(&test_data.timer, 1, 0);
+
+ return 0;
+}
diff --git a/src/host/layer23/src/app_phone.c b/src/host/layer23/src/app_phone.c
new file mode 100644
index 0000000..1f280a8
--- /dev/null
+++ b/src/host/layer23/src/app_phone.c
@@ -0,0 +1,38 @@
+/* "Application" code of the layer2/3 stack */
+
+/* (C) 2010 by Holger Hans Peter Freyther
+ * (C) 2010 by Harald Welte <laforge@gnumonks.org>
+ *
+ * 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 <osmocom/osmocom_data.h>
+#include <osmocom/l1ctl.h>
+#include <osmocom/layer3.h>
+#include <osmocom/lapdm.h>
+#include <osmocom/gsmtap_util.h>
+#include <osmocom/logging.h>
+
+#include <osmocore/msgb.h>
+#include <osmocore/talloc.h>
+#include <osmocore/select.h>
+
+int l23_app_init(struct osmocom_ms *ms)
+{
+ return layer3_init(ms);
+}
diff --git a/src/host/layer23/src/l1ctl.c b/src/host/layer23/src/l1ctl.c
index ada7ec8..82c9dc5 100644
--- a/src/host/layer23/src/l1ctl.c
+++ b/src/host/layer23/src/l1ctl.c
@@ -152,9 +152,9 @@ static int rx_ph_data_ind(struct osmocom_ms *ms, struct msgb *msg)
/* determine LAPDm entity based on SACCH or not */
if (dl->link_id & 0x40)
- le = &ms->lapdm_acch;
+ le = &ms->l2_entity.lapdm_acch;
else
- le = &ms->lapdm_dcch;
+ le = &ms->l2_entity.lapdm_dcch;
/* make local stack copy of l1ctl_info_dl, as LAPDm will
* overwrite skb hdr */
memcpy(&dl_cpy, dl, sizeof(dl_cpy));
@@ -312,8 +312,8 @@ int l1ctl_tx_pm_req_range(struct osmocom_ms *ms, uint16_t arfcn_from,
static int rx_l1_reset(struct osmocom_ms *ms)
{
printf("Layer1 Reset.\n");
- //return l1ctl_tx_pm_req_range(ms, 0, 124);
- return l1ctl_tx_ccch_req(ms);
+ return l1ctl_tx_pm_req_range(ms, 0, 124);
+ //return l1ctl_tx_ccch_req(ms);
}
/* Receive L1CTL_PM_RESP */
diff --git a/src/host/layer23/src/lapdm.c b/src/host/layer23/src/lapdm.c
index ede9d7d..d507da8 100644
--- a/src/host/layer23/src/lapdm.c
+++ b/src/host/layer23/src/lapdm.c
@@ -794,9 +794,9 @@ static int rslms_rx_rll(struct msgb *msg, struct osmocom_ms *ms)
struct lapdm_datalink *dl;
if (rllh->link_id & 0x40)
- le = &ms->lapdm_acch;
+ le = &ms->l2_entity.lapdm_acch;
else
- le = &ms->lapdm_dcch;
+ le = &ms->l2_entity.lapdm_dcch;
dl = datalink_for_sapi(le, sapi);
switch (rllh->c.msg_type) {
@@ -844,3 +844,20 @@ int rslms_recvmsg(struct msgb *msg, struct osmocom_ms *ms)
return rc;
}
+/* input function that L2 calls when sending messages up to L3 */
+int rslms_sendmsg(struct msgb *msg, struct osmocom_ms *ms)
+{
+ if (!ms->l2_entity.msg_handler)
+ return -EIO;
+
+ /* call the layer2 message handler that is registered */
+ return ms->l2_entity.msg_handler(msg, ms);
+}
+
+/* register message handler for messages that are sent from L2->L3 */
+int osmol2_register_handler(struct osmocom_ms *ms, osmol2_cb_t cb)
+{
+ ms->l2_entity.msg_handler = cb;
+
+ return 0;
+}
diff --git a/src/host/layer23/src/main.c b/src/host/layer23/src/main.c
index 8e76e8b..7709e9e 100644
--- a/src/host/layer23/src/main.c
+++ b/src/host/layer23/src/main.c
@@ -23,9 +23,11 @@
#include <osmocom/osmocom_data.h>
#include <osmocom/l1ctl.h>
+#include <osmocom/layer3.h>
#include <osmocom/lapdm.h>
#include <osmocom/gsmtap_util.h>
#include <osmocom/logging.h>
+#include <osmocom/l23_app.h>
#include <osmocore/msgb.h>
#include <osmocore/talloc.h>
@@ -189,28 +191,6 @@ static void handle_options(int argc, char **argv)
}
}
-/* TEST code, regularly transmit ECHO REQ packet to L1 */
-
-static struct {
- struct timer_list timer;
-} test_data;
-
-static void test_tmr_cb(void *data)
-{
- struct osmocom_ms *ms = data;
-
- l1ctl_tx_echo_req(ms, 62);
- bsc_schedule_timer(&test_data.timer, 1, 0);
-}
-
-void test_start(struct osmocom_ms *ms)
-{
- test_data.timer.cb = &test_tmr_cb;
- test_data.timer.data = ms;
-
- bsc_schedule_timer(&test_data.timer, 1, 0);
-}
-
int main(int argc, char **argv)
{
int rc;
@@ -256,8 +236,10 @@ int main(int argc, char **argv)
ms->wq.read_cb = layer2_read;
ms->wq.write_cb = layer2_write;
- lapdm_init(&ms->lapdm_dcch, ms);
- lapdm_init(&ms->lapdm_acch, ms);
+ lapdm_init(&ms->l2_entity.lapdm_dcch, ms);
+ lapdm_init(&ms->l2_entity.lapdm_acch, ms);
+
+ l23_app_init(ms);
if (bsc_register_fd(&ms->wq.bfd) != 0) {
fprintf(stderr, "Failed to register fd.\n");
@@ -272,8 +254,6 @@ int main(int argc, char **argv)
}
}
- //test_start(ms);
-
while (1) {
bsc_select_main(0);
}
diff --git a/src/host/layer23/src/rslms.c b/src/host/layer23/src/rslms.c
index 5b1cc06..63afa77 100644
--- a/src/host/layer23/src/rslms.c
+++ b/src/host/layer23/src/rslms.c
@@ -126,7 +126,7 @@ static int rslms_rx_rll(struct msgb *msg, struct osmocom_ms *ms)
}
/* input function that L2 calls when sending messages up to L3 */
-int rslms_sendmsg(struct msgb *msg, struct osmocom_ms *ms)
+static int layer3_from_layer2(struct msgb *msg, struct osmocom_ms *ms)
{
struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
int rc = 0;
@@ -145,3 +145,8 @@ int rslms_sendmsg(struct msgb *msg, struct osmocom_ms *ms)
return rc;
}
+
+int layer3_init(struct osmocom_ms *ms)
+{
+ return osmol2_register_handler(ms, &layer3_from_layer2);
+}