layer2 program: Use new RSL utility routines, split code in more files
authorHarald Welte <laforge@gnumonks.org>
Tue, 2 Mar 2010 22:02:16 +0000 (23:02 +0100)
committerHarald Welte <laforge@gnumonks.org>
Tue, 2 Mar 2010 22:02:16 +0000 (23:02 +0100)
src/host/layer2/include/osmocom/Makefile.am
src/host/layer2/include/osmocom/layer3.h [new file with mode: 0644]
src/host/layer2/include/osmocom/rslms.h [new file with mode: 0644]
src/host/layer2/src/Makefile.am
src/host/layer2/src/lapdm.c
src/host/layer2/src/osmocom_rslms.c

index 37f37bf..989b53a 100644 (file)
@@ -1,3 +1,3 @@
 # headers from OpenBSC
 noinst_HEADERS = debug.h
-noinst_HEADERS += osmocom_layer2.h osmocom_data.h lapdm.h
+noinst_HEADERS += osmocom_layer2.h osmocom_data.h lapdm.h rslms.h layer3.h
diff --git a/src/host/layer2/include/osmocom/layer3.h b/src/host/layer2/include/osmocom/layer3.h
new file mode 100644 (file)
index 0000000..1b4af07
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef _OSMOCOM_L3_H
+#define _OSMOCOM_L3_H
+
+#include <osmocore/msgb.h>
+#include <osmocom/osmocom_data.h>
+
+int gsm48_rx_ccch(struct msgb *msg, struct osmocom_ms *ms);
+int gsm48_rx_dcch(struct msgb *msg, struct osmocom_ms *ms);
+
+#endif
diff --git a/src/host/layer2/include/osmocom/rslms.h b/src/host/layer2/include/osmocom/rslms.h
new file mode 100644 (file)
index 0000000..7327c11
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef _OSMOCOM_RSLMS_H
+#define _OSMOCOM_RSLMS_H
+
+#include <osmocore/msgb.h>
+#include <osmocom/osmocom_data.h>
+
+/* From L3 into RSLMS (direction -> L2) */
+
+/* Send a 'simple' RLL request to L2 */
+int rslms_tx_rll_req(struct osmocom_ms *ms, uint8_t msg_type,
+                    uint8_t chan_nr, uint8_t link_id);
+
+/* Send a RLL request (including L3 info) to L2 */
+int rslms_tx_rll_req_l3(struct osmocom_ms *ms, uint8_t msg_type,
+                       uint8_t chan_nr, uint8_t link_id, struct msgb *msg);
+
+
+/* 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);
+
+#endif /* _OSMOCOM_RSLMS_H */
index 0f1bf55..a7d2db0 100644 (file)
@@ -5,5 +5,5 @@ noinst_LIBRARIES = libosmocom.a
 libosmocom_a_SOURCES = libosmocom/debug.c 
 
 sbin_PROGRAMS = layer2
-layer2_SOURCES = layer2_main.c osmocom_layer2.c gsmtap_util.c lapdm.c osmocom_rslms.c
+layer2_SOURCES = layer2_main.c osmocom_layer2.c gsmtap_util.c lapdm.c osmocom_rslms.c layer3.c
 layer2_LDADD = libosmocom.a $(LIBOSMOCORE_LIBS)
index 9ca26ff..d525d22 100644 (file)
@@ -176,24 +176,8 @@ static inline unsigned char *msgb_pull_l2h(struct msgb *msg)
 static int send_rslms_rll_l3(uint8_t msg_type, struct lapdm_msg_ctx *mctx,
                             struct msgb *msg)
 {
-       uint8_t l3_len = msg->tail - (uint8_t *)msgb_l3(msg);
-       struct abis_rsl_rll_hdr *rh;
-
-       /* construct a RSLms RLL message (DATA INDICATION, UNIT DATA
-        * INDICATION) and send it off via RSLms */
-
-       /* Push the L3 IE tag and lengh */
-       msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len);
-
-       /* Then push the RSL header */
-       rh = (struct abis_rsl_rll_hdr *) msgb_push(msg, sizeof(*rh));
-       rsl_init_rll_hdr(rh, msg_type);
-       rh->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
-       rh->chan_nr = mctx->chan_nr;
-       rh->link_id = mctx->link_id;
-
-       /* set the l2 header pointer */
-       msg->l2h = (uint8_t *)rh;
+       /* Add the L3 header */
+       rsl_rll_push_l3(msg, msg_type, mctx->chan_nr, mctx->link_id);
 
        /* send off the RSLms message to L3 */
        return rslms_sendmsg(msg, mctx->dl->entity->ms);
@@ -201,18 +185,9 @@ static int send_rslms_rll_l3(uint8_t msg_type, struct lapdm_msg_ctx *mctx,
 
 static int send_rslms_rll_simple(uint8_t msg_type, struct lapdm_msg_ctx *mctx)
 {
-       struct abis_rsl_rll_hdr *rh;
-       struct msgb *msg = msgb_alloc(sizeof(*rh), "rslms_rll_simple");
-
-       /* put the RSL header */
-       rh = (struct abis_rsl_rll_hdr *) msgb_put(msg, sizeof(*rh));
-       rsl_init_rll_hdr(rh, msg_type);
-       rh->c.msg_discr |= ABIS_RSL_MDISC_TRANSP;
-       rh->chan_nr = mctx->chan_nr;
-       rh->link_id = mctx->link_id;
-
-       /* set the l2 header pointer */
-       msg->l2h = (uint8_t *)rh;
+       struct msgb *msg;
+
+       msg = rsl_rll_simple(msg_type, mctx->chan_nr, mctx->link_id);
 
        /* send off the RSLms message to L3 */
        return rslms_sendmsg(msg, mctx->dl->entity->ms);
index f34c64d..4a51408 100644 (file)
@@ -7,7 +7,10 @@
 #include <osmocore/rsl.h>
 #include <osmocore/tlv.h>
 #include <osmocore/protocol/gsm_04_08.h>
+
 #include <osmocom/lapdm.h>
+#include <osmocom/rslms.h>
+#include <osmocom/layer3.h>
 #include <osmocom/osmocom_data.h>
 #include <osmocom/osmocom_layer2.h>
 
@@ -35,58 +38,24 @@ int rsl_dec_chan_nr(uint8_t chan_nr, uint8_t *type, uint8_t *subch, uint8_t *tim
        return 0;
 }
 
-
-static int gsm48_rx_imm_ass(struct msgb *msg, struct osmocom_ms *ms)
+/* Send a 'simple' RLL request to L2 */
+int rslms_tx_rll_req(struct osmocom_ms *ms, uint8_t msg_type,
+                    uint8_t chan_nr, uint8_t link_id)
 {
-       struct gsm48_imm_ass *ia = msgb_l3(msg);
-       uint8_t ch_type, ch_subch, ch_ts;
-       uint16_t arfcn;
-
-       rsl_dec_chan_nr(ia->chan_desc.chan_nr, &ch_type, &ch_subch, &ch_ts);
-       arfcn = ia->chan_desc.h0.arfcn_low | (ia->chan_desc.h0.arfcn_high << 8);
+       struct msgb *msg;
 
-       printf("GSM48 IMM ASS (ra=0x%02x, chan_nr=0x%02x, ARFCN=%u, TS=%u, SS=%u, TSC=%u) ",
-               ia->req_ref.ra, ia->chan_desc.chan_nr, arfcn, ch_ts, ch_subch,
-               ia->chan_desc.h0.tsc);
+       msg = rsl_rll_simple(msg_type, chan_nr, link_id);
 
-       /* FIXME: compare RA and GSM time with when we sent RACH req */
-
-       /* check if we can support this type of channel at the moment */
-       if (ch_type != RSL_CHAN_SDCCH4_ACCH || ch_ts != 0 ||
-           ia->chan_desc.h0.h == 1) {
-               printf("UNSUPPORTED!\n");
-               return 0;
-       }
-
-       /* FIXME: request L1 to go to dedicated mode on assigned channel */
-       return tx_ph_dm_est_req(ms, arfcn, ia->chan_desc.chan_nr);
-
-       return 0;
+       return rslms_recvmsg(msg, ms);
 }
 
-static int gsm48_rx_ccch(struct msgb *msg, struct osmocom_ms *ms)
+/* Send a RLL request (including L3 info) to L2 */
+int rslms_tx_rll_req_l3(struct osmocom_ms *ms, uint8_t msg_type,
+                       uint8_t chan_nr, uint8_t link_id, struct msgb *msg)
 {
-       struct gsm48_system_information_type_header *sih = msgb_l3(msg);
-       int rc = 0;
+       rsl_rll_push_l3(msg, msg_type, chan_nr, link_id);
 
-       if (sih->rr_protocol_discriminator != GSM48_PDISC_RR)
-               printf("PCH pdisc != RR\n");
-       
-       switch (sih->system_information) {
-       case GSM48_MT_RR_PAG_REQ_1:
-       case GSM48_MT_RR_PAG_REQ_2:
-       case GSM48_MT_RR_PAG_REQ_3:
-               /* FIXME: implement decoding of paging request */
-               break;
-       case GSM48_MT_RR_IMM_ASS:
-               rc = gsm48_rx_imm_ass(msg, ms);
-               break;
-       default:
-               printf("unknown PCH/AGCH type 0x%02x\n", sih->system_information);
-               rc = -EINVAL;
-       }
-
-       return rc;
+       return rslms_recvmsg(msg, ms);
 }
 
 static int rach_count = 0;