layer23: convert to libosmocore logging API
authorHarald Welte <laforge@gnumonks.org>
Sat, 27 Mar 2010 00:56:05 +0000 (08:56 +0800)
committerHarald Welte <laforge@gnumonks.org>
Sat, 27 Mar 2010 00:56:05 +0000 (08:56 +0800)
src/host/layer23/include/osmocom/Makefile.am
src/host/layer23/include/osmocom/logging.h [new file with mode: 0644]
src/host/layer23/src/Makefile.am
src/host/layer23/src/l1ctl.c
src/host/layer23/src/lapdm.c
src/host/layer23/src/layer3.c
src/host/layer23/src/logging.c [new file with mode: 0644]
src/host/layer23/src/main.c
src/host/layer23/src/rslms.c

index 01c0225..86537aa 100644 (file)
@@ -1 +1,2 @@
-noinst_HEADERS = l1ctl.h osmocom_data.h lapdm.h rslms.h layer3.h gsmtap_util.h
+noinst_HEADERS = l1ctl.h osmocom_data.h lapdm.h rslms.h layer3.h \
+                gsmtap_util.h logging.h
diff --git a/src/host/layer23/include/osmocom/logging.h b/src/host/layer23/include/osmocom/logging.h
new file mode 100644 (file)
index 0000000..e1bb583
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef _LOGGING_H
+#define _LOGGING_H
+
+#define DEBUG
+#include <osmocore/logging.h>
+
+enum {
+       DRSL,
+       DRR,
+       DMM,
+       DCC,
+       DSMS,
+       DMEAS,
+       DPAG,
+       DLAPDM,
+       DL1C,
+};
+
+extern const struct log_info log_info;
+
+#endif /* _LOGGING_H */
index 0dd2203..ae867fa 100644 (file)
@@ -2,5 +2,6 @@ INCLUDES = $(all_includes) -I$(top_srcdir)/include
 AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS)
 
 sbin_PROGRAMS = layer23
-layer23_SOURCES = main.c l1ctl.c gsmtap_util.c lapdm.c rslms.c layer3.c
+layer23_SOURCES = main.c l1ctl.c gsmtap_util.c lapdm.c rslms.c \
+                 layer3.c logging.c
 layer23_LDADD = $(LIBOSMOCORE_LIBS)
index eaff7a1..2e6e8e0 100644 (file)
@@ -42,6 +42,7 @@
 #include <osmocom/l1ctl.h>
 #include <osmocom/osmocom_data.h>
 #include <osmocom/lapdm.h>
+#include <osmocom/logging.h>
 #include <osmocom/gsmtap_util.h>
 
 static struct msgb *osmo_l1_alloc(uint8_t msg_type)
@@ -50,7 +51,7 @@ static struct msgb *osmo_l1_alloc(uint8_t msg_type)
        struct msgb *msg = msgb_alloc_headroom(256, 4, "osmo_l1");
 
        if (!msg) {
-               fprintf(stderr, "Failed to allocate memory.\n");
+               LOGP(DL1C, LOGL_ERROR, "Failed to allocate memory.\n");
                return NULL;
        }
 
@@ -75,7 +76,8 @@ static int rx_l1_ccch_resp(struct osmocom_ms *ms, struct msgb *msg)
        struct gsm_time tm;
 
        if (msgb_l3len(msg) < sizeof(*sb)) {
-               fprintf(stderr, "MSG too short for CCCH RESP: %u\n", msgb_l3len(msg));
+               LOGP(DL1C, LOGL_ERROR, "MSG too short for CCCH RESP: %u\n",
+                       msgb_l3len(msg));
                return -1;
        }
 
@@ -83,7 +85,7 @@ static int rx_l1_ccch_resp(struct osmocom_ms *ms, struct msgb *msg)
        sb = (struct l1ctl_sync_new_ccch_resp *) dl->payload;
 
        gsm_fn2gsmtime(&tm, ntohl(dl->frame_nr));
-       printf("SCH: SNR: %u TDMA: (%.4u/%.2u/%.2u) bsic: %d\n",
+       DEBUGP(DL1C, "SCH: SNR: %u TDMA: (%.4u/%.2u/%.2u) bsic: %d\n",
                dl->snr, tm.t1, tm.t2, tm.t3, sb->bsic);
 
        return 0;
@@ -127,7 +129,8 @@ static int rx_ph_data_ind(struct osmocom_ms *ms, struct msgb *msg)
        struct gsm_time tm;
 
        if (msgb_l3len(msg) < sizeof(*ccch)) {
-               fprintf(stderr, "MSG too short Data Ind: %u\n", msgb_l3len(msg));
+               LOGP(DL1C, LOGL_ERROR, "MSG too short Data Ind: %u\n",
+                       msgb_l3len(msg));
                return -1;
        }
 
@@ -137,21 +140,23 @@ static int rx_ph_data_ind(struct osmocom_ms *ms, struct msgb *msg)
 
        gsm_fn2gsmtime(&tm, ntohl(dl->frame_nr));
        rsl_dec_chan_nr(dl->chan_nr, &chan_type, &chan_ss, &chan_ts);
-       printf("%s (%.4u/%.2u/%.2u) %s\n",
+       DEBUGP(DL1C, "%s (%.4u/%.2u/%.2u) %s\n",
                chan_nr2string(dl->chan_nr), tm.t1, tm.t2, tm.t3,
                hexdump(ccch->data, sizeof(ccch->data)));
 
        /* send CCCH data via GSMTAP */
        gsmtap_chan_type = chantype_rsl2gsmtap(chan_type, dl->link_id);
        gsmtap_sendmsg(dl->band_arfcn, chan_ts, gsmtap_chan_type, chan_ss,
-                       tm.fn, dl->rx_level-110, dl->snr, ccch->data, sizeof(ccch->data));
+                       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_acch;
        else
                le = &ms->lapdm_dcch;
-       /* make local stack copy of l1ctl_info_dl, as LAPDm will overwrite skb hdr */
+       /* make local stack copy of l1ctl_info_dl, as LAPDm will
+        * overwrite skb hdr */
        memcpy(&dl_cpy, dl, sizeof(dl_cpy));
 
        /* pull the L1 header from the msgb */
@@ -173,14 +178,16 @@ int tx_ph_data_req(struct osmocom_ms *ms, struct msgb *msg,
        uint8_t chan_type, chan_ts, chan_ss;
        uint8_t gsmtap_chan_type;
 
-       printf("tx_ph_data_req(%s)\n", hexdump(msg->l2h, msgb_l2len(msg)));
+       DEBUGP(DL1C, "(%s)\n", hexdump(msg->l2h, msgb_l2len(msg)));
 
        if (msgb_l2len(msg) > 23) {
-               printf("L1 cannot handle message length > 23 (%u)\n", msgb_l2len(msg));
+               LOGP(DL1C, LOGL_ERROR, "L1 cannot handle message length "
+                       "> 23 (%u)\n", msgb_l2len(msg));
                msgb_free(msg);
                return -EINVAL;
        } else if (msgb_l2len(msg) < 23)
-               printf("L1 message length < 23 (%u) doesn't seem right!\n", msgb_l2len(msg));
+               LOGP(DL1C, LOGL_ERROR, "L1 message length < 23 (%u) "
+                       "doesn't seem right!\n", msgb_l2len(msg));
 
        /* send copy via GSMTAP */
        rsl_dec_chan_nr(chan_nr, &chan_type, &chan_ss, &chan_ts);
@@ -215,7 +222,7 @@ static int rx_l1_reset(struct osmocom_ms *ms)
        if (!msg)
                return -1;
 
-       printf("Layer1 Reset.\n");
+       LOGP(DL1C, LOGL_INFO, "Layer1 Reset.\n");
        req = (struct l1ctl_sync_new_ccch_req *) msgb_put(msg, sizeof(*req));
        req->band_arfcn = osmo_make_band_arfcn(ms);
 
@@ -234,7 +241,7 @@ int tx_ph_rach_req(struct osmocom_ms *ms)
        if (!msg)
                return -1;
 
-       printf("RACH Req.\n");
+       DEBUGP(DL1C, "RACH Req.\n");
        ul = (struct l1ctl_info_ul *) msgb_put(msg, sizeof(*ul));
        req = (struct l1ctl_rach_req *) msgb_put(msg, sizeof(*req));
        req->ra = i++;
@@ -253,7 +260,7 @@ int tx_ph_dm_est_req(struct osmocom_ms *ms, uint16_t band_arfcn, uint8_t chan_nr
        if (!msg)
                return -1;
 
-       printf("Tx Dedic.Mode Est Req (arfcn=%u, chan_nr=0x%02x)\n",
+       DEBUGP(DL1C, "Tx Dedic.Mode Est Req (arfcn=%u, chan_nr=0x%02x)\n",
                band_arfcn, chan_nr);
        ul = (struct l1ctl_info_ul *) msgb_put(msg, sizeof(*ul));
        ul->chan_nr = chan_nr;
@@ -273,7 +280,8 @@ int l1ctl_recv(struct osmocom_ms *ms, struct msgb *msg)
        struct l1ctl_info_dl *dl;
 
        if (msgb_l2len(msg) < sizeof(*dl)) {
-               fprintf(stderr, "Short Layer2 message: %u\n", msgb_l2len(msg));
+               LOGP(DL1C, LOGL_ERROR, "Short Layer2 message: %u\n",
+                       msgb_l2len(msg));
                return -1;
        }
 
index e1f40a4..700b954 100644 (file)
@@ -36,6 +36,7 @@
 #include <osmocom/osmocom_data.h>
 #include <osmocom/l1ctl.h>
 #include <osmocom/lapdm.h>
+#include <osmocom/logging.h>
 
 #include <l1a_l23_interface.h>
 
@@ -179,7 +180,8 @@ static void lapdm_pad_msgb(struct msgb *msg)
        uint8_t *data;
 
        if (pad_len < 0) {
-               printf("cannot pad message that is already too big!\n");
+               LOGP(DLAPDM, LOGL_ERROR,
+                    "cannot pad message that is already too big!\n");
                return;
        }
 
@@ -221,11 +223,13 @@ static int check_length_ind(uint8_t length_ind)
                /* G.4.1 If the EL bit is set to "0", an MDL-ERROR-INDICATION
                 * primitive with cause "frame not implemented" is sent to the
                 * mobile management entity. */
-               printf("we don't support multi-octet length\n");
+               LOGP(DLAPDM, LOGL_ERROR,
+                       "we don't support multi-octet length\n");
                return -EINVAL;
        }
        if (length_ind & 0x02) {
-               printf("we don't support LAPDm fragmentation yet\n");
+               LOGP(DLAPDM, LOGL_ERROR,
+                       "we don't support LAPDm fragmentation yet\n");
                return -EINVAL;
        }
        return 0;
@@ -236,7 +240,7 @@ static void lapdm_t200_cb(void *data)
 {
        struct lapdm_datalink *dl = data;
 
-       printf("lapdm_t200_cb(%p) state=%u\n", dl, dl->state);
+       DEBUGP(DLAPDM, "lapdm_t200_cb(%p) state=%u\n", dl, dl->state);
 
        switch (dl->state) {
        case LAPDm_STATE_SABM_SENT:
@@ -269,7 +273,8 @@ static void lapdm_t200_cb(void *data)
                }
                break;
        default:
-               printf("T200 expired in unexpected dl->state %u\n", dl->state);
+               DEBUGP(DLAPDM, "T200 expired in unexpected dl->state %u\n",
+                       dl->state);
        }
 }
 
@@ -297,7 +302,7 @@ static int lapdm_rx_u(struct msgb *msg, struct lapdm_msg_ctx *mctx)
 
        switch (LAPDm_CTRL_U_BITS(mctx->ctrl)) {
        case LAPDm_U_SABM:
-               printf("SABM ");
+               DEBUGPC(DLAPDM, "SABM ");
                /* Must be Format B */
                rc = check_length_ind(msg->l2h[2]);
                if (rc < 0)
@@ -309,7 +314,8 @@ static int lapdm_rx_u(struct msgb *msg, struct lapdm_msg_ctx *mctx)
                                /* FIXME: re-establishment procedure 5.6 */
                        } else {
                                /* FIXME: check for contention resoultion */
-                               printf("SABM command, multiple frame established state\n");
+                               DEBUGP(DLAPDM, "SABM command, multiple "
+                                       "frame established state\n");
                                return 0;
                        }
                }
@@ -328,7 +334,7 @@ static int lapdm_rx_u(struct msgb *msg, struct lapdm_msg_ctx *mctx)
 #endif
                break;
        case LAPDm_U_DM:
-               printf("DM ");
+               DEBUGPC(DLAPDM, "DM ");
                if (!LAPDm_CTRL_PF_BIT(mctx->ctrl)) {
                        /* 5.4.1.2 DM responses with the F bit set to "0" shall be ignored. */
                        return 0;
@@ -336,18 +342,18 @@ static int lapdm_rx_u(struct msgb *msg, struct lapdm_msg_ctx *mctx)
                switch (dl->state) {
                case LAPDm_STATE_IDLE:
                        /* 5.4.5 all other frame types shall be discarded */
-                       printf("state=IDLE (discarding) ");
+                       DEBUGPC(DLAPDM, "state=IDLE (discarding) ");
                        return 0;
                case LAPDm_STATE_MF_EST:
                        if (LAPDm_CTRL_PF_BIT(mctx->ctrl) == 1)
-                               printf("unsolicited DM resposne ");
+                               DEBUGPC(DLAPDM, "unsolicited DM resposne ");
                        else
-                               printf("unsolicited DM resposne, multiple frame established state ");
+                               DEBUGPC(DLAPDM, "unsolicited DM resposne, multiple frame established state ");
                        return 0;
                case LAPDm_STATE_TIMER_RECOV:
                        /* DM is normal in case PF = 1 */
                        if (LAPDm_CTRL_PF_BIT(mctx->ctrl) == 0) {
-                               printf("unsolicited DM resposne, multiple frame established state ");
+                               DEBUGPC(DLAPDM, "unsolicited DM resposne, multiple frame established state ");
                                return 0;
                        }
                        break;
@@ -357,7 +363,7 @@ static int lapdm_rx_u(struct msgb *msg, struct lapdm_msg_ctx *mctx)
                rc = send_rslms_rll_simple(RSL_MT_REL_IND, mctx);
                break;
        case LAPDm_U_UI:
-               printf("UI ");
+               DEBUGP(DLAPDM, "UI ");
                if (mctx->lapdm_fmt == LAPDm_FMT_B4) {
                        length = N201_B4;
                        msg->l3h = msg->l2h + 2;
@@ -371,7 +377,7 @@ static int lapdm_rx_u(struct msgb *msg, struct lapdm_msg_ctx *mctx)
                /* do some length checks */
                if (length == 0) {
                        /* 5.3.3 UI frames received with the length indicator set to "0" shall be ignored */
-                       printf("length=0 (discarding) ");
+                       DEBUGP(DLAPDM, "length=0 (discarding) ");
                        return 0;
                }
                /* FIXME: G.4.5 check */
@@ -381,21 +387,22 @@ static int lapdm_rx_u(struct msgb *msg, struct lapdm_msg_ctx *mctx)
                        break;
                default:
                        /* 5.3.3 UI frames with invalid SAPI values shall be discarded */
-                       printf("sapi=%u (discarding) ", LAPDm_ADDR_SAPI(mctx->ctrl));
+                       DEBUGP(DLAPDM, "sapi=%u (discarding) ", LAPDm_ADDR_SAPI(mctx->ctrl));
                        return 0;
                }
                msgb_pull_l2h(msg);
                rc = send_rslms_rll_l3(RSL_MT_UNIT_DATA_IND, mctx, msg);
                break;
        case LAPDm_U_DISC:
-               printf("DISC ");
+               DEBUGP(DLAPDM, "DISC ");
                length = msg->l2h[2] >> 2;
                if (length > 0 || msg->l2h[2] & 0x02) {
                        /* G.4.4 If a DISC or DM frame is received with L>0 or
                         * with the M bit set to "1", an MDL-ERROR-INDICATION
                         * primitive with cause "U frame with incorrect
                         * parameters" is sent to the mobile management entity. */
-                       printf("U frame iwth incorrect parameters ");
+                       LOGP(DLAPDM, LOGL_ERROR,
+                               "U frame iwth incorrect parameters ");
                        return -EIO;
                }
                switch (dl->state) {
@@ -408,11 +415,11 @@ static int lapdm_rx_u(struct msgb *msg, struct lapdm_msg_ctx *mctx)
                }
                break;
        case LAPDm_U_UA:
-               printf("UA ");
+               DEBUGP(DLAPDM, "UA ");
                /* FIXME: G.4.5 check */
                if (!LAPDm_CTRL_PF_BIT(mctx->ctrl)) {
                        /* 5.4.1.2 A UA response with the F bit set to "0" shall be ignored. */
-                       printf("F=0 (discarding) ");
+                       DEBUGP(DLAPDM, "F=0 (discarding) ");
                        return 0;
                }
                switch (dl->state) {
@@ -421,7 +428,8 @@ static int lapdm_rx_u(struct msgb *msg, struct lapdm_msg_ctx *mctx)
                case LAPDm_STATE_IDLE:
                        /* 5.4.5 all other frame types shall be discarded */
                default:
-                       printf("unsolicited UA response! (discarding) ");
+                       DEBUGP(DLAPDM,
+                               "unsolicited UA response! (discarding) ");
                        return 0;
                }
                /* reset Timer T200 */
@@ -510,7 +518,8 @@ static int lapdm_rx_i(struct msgb *msg, struct lapdm_msg_ctx *mctx)
                msgb_pull_l2h(msg);
                rc = send_rslms_rll_l3(RSL_MT_DATA_IND, mctx, msg);
        } else {
-               printf("N(s) sequence error: Ns=%u, V_recv=%u ", ns, dl->V_recv);
+               LOGP(DLAPDM, LOGL_INFO, "N(s) sequence error: Ns=%u, "
+                    "V_recv=%u ", ns, dl->V_recv);
                /* FIXME: 5.7.1: N(s) sequence error */
                /* discard data */
                return -EIO;
@@ -568,7 +577,7 @@ static int lapdm_ph_data_ind(struct msgb *msg, struct lapdm_msg_ctx *mctx)
        else if (LAPDm_CTRL_is_I(mctx->ctrl))
                rc = lapdm_rx_i(msg, mctx);
        else {
-               printf("unknown LAPDm format ");
+               LOGP(DLAPDM, LOGL_ERROR, "unknown LAPDm format ");
                rc = -EINVAL;
        }
        return rc;
@@ -582,7 +591,7 @@ int l2_ph_data_ind(struct msgb *msg, struct lapdm_entity *le, struct l1ctl_info_
        struct lapdm_msg_ctx mctx;
        int rc;
 
-       printf("l2_ph_data_ind() ");
+       DEBUGP(DLAPDM, "");
        /* when we reach here, we have a msgb with l2h pointing to the raw
         * 23byte mac block. The l1h has already been purged. */
 
@@ -595,19 +604,19 @@ int l2_ph_data_ind(struct msgb *msg, struct lapdm_entity *le, struct l1ctl_info_
        if (cbits == 0x10 || cbits == 0x12) {
                /* Format Bbis is used on BCCH and CCCH(PCH, NCH and AGCH) */
                mctx.lapdm_fmt = LAPDm_FMT_Bbis;
-               printf("fmt=Bbis ");
+               DEBUGPC(DLAPDM, "fmt=Bbis ");
        } else {
                if (mctx.link_id & 0x40) {
                        /* It was received from network on SACCH, thus
                         * lapdm_fmt must be B4 */
                        mctx.lapdm_fmt = LAPDm_FMT_B4;
-                       printf("fmt=B4 ");
+                       DEBUGPC(DLAPDM, "fmt=B4 ");
                        /* SACCH frames have a two-byte L1 header that OsmocomBB L1 doesn't
                         * strip */
                        msg->l2h += 2;
                } else {
                        mctx.lapdm_fmt = LAPDm_FMT_B;
-                       printf("fmt=B ");
+                       DEBUGPC(DLAPDM, "fmt=B ");
                }
        }
 
@@ -617,7 +626,8 @@ int l2_ph_data_ind(struct msgb *msg, struct lapdm_entity *le, struct l1ctl_info_
        case LAPDm_FMT_B4:
                mctx.addr = msg->l2h[0];
                if (!(mctx.addr & 0x01)) {
-                       printf("we don't support multibyte addresses (discarding)\n");
+                       LOGP(DLAPDM, LOGL_ERROR, "we don't support "
+                               "multibyte addresses (discarding)\n");
                        return -EINVAL;
                }
                mctx.ctrl = msg->l2h[1];
@@ -630,13 +640,13 @@ int l2_ph_data_ind(struct msgb *msg, struct lapdm_entity *le, struct l1ctl_info_
                break;
        case LAPDm_FMT_Bbis:
                /* directly pass up to layer3 */
-               printf("UI ");
+               DEBUGPC(DLAPDM, "UI ");
                msg->l3h = msg->l2h;
                msgb_pull_l2h(msg);
                rc = send_rslms_rll_l3(RSL_MT_UNIT_DATA_IND, &mctx, msg);
                break;
        }
-       printf("\n");
+       DEBUGPC(DLAPDM, "\n");
 
        return rc;
 }
@@ -653,7 +663,7 @@ static int rslms_rx_rll_est_req(struct msgb *msg, struct lapdm_datalink *dl)
        struct tlv_parsed tv;
        uint8_t len;
 
-       printf("RSL_MT_EST_REQ ");
+       DEBUGP(DRSL, "RSL_MT_EST_REQ ");
 
        rsl_tlv_parse(&tv, rllh->data, msgb_l2len(msg)-sizeof(*rllh));
        if (TLVP_PRESENT(&tv, RSL_IE_L3_INFO)) {
@@ -662,14 +672,16 @@ static int rslms_rx_rll_est_req(struct msgb *msg, struct lapdm_datalink *dl)
                        /* 5.4.1.4: The data link layer shall, however, ignore any such
                         * service request if it is not in the idle state when the
                         * request is received. */
-                       printf("DL state != IDLE (discarding)\n");
+                       LOGP(DRSL, LOGL_INFO,
+                               "DL state != IDLE (discarding)\n");
                        msgb_free(msg);
                        return 0;
                }
                if (sapi != 0) {
                        /* According to clause 6, the contention resolution
                         * procedure is only permitted with SAPI value 0 */
-                       printf("SAPI != 0 but contention resolution (discarding)\n");
+                       LOGP(DRSL, LOGL_INFO, "SAPI != 0 but contention"
+                               "resolution (discarding)\n");
                        msgb_free(msg);
                        return -EINVAL;
                }
@@ -736,7 +748,8 @@ static int rslms_rx_rll_data_req(struct msgb *msg, struct lapdm_datalink *dl)
        case LAPDm_STATE_MF_EST:
                break;
        default:
-               printf("refusing RLL DATA REQ during DL state %u\n", dl->state);
+               LOGP(DRSL, LOGL_NOTICE, "refusing RLL DATA REQ during "
+                    "DL state %u\n", dl->state);
                return -EIO;
                break;
        }
@@ -805,7 +818,7 @@ static int rslms_rx_rll(struct msgb *msg, struct osmocom_ms *ms)
        case RSL_MT_REL_REQ:
                /* FIXME: create and send DISC command */
        default:
-               printf("unknown RLL message type 0x%02x\n",
+               LOGP(DRSL, LOGL_NOTICE, "unknown RLL message type 0x%02x\n",
                        rllh->c.msg_type);
                break;
        }
@@ -821,12 +834,12 @@ int rslms_recvmsg(struct msgb *msg, struct osmocom_ms *ms)
 
        switch (rslh->msg_discr & 0xfe) {
        case ABIS_RSL_MDISC_RLL:
-               printf("rslms_recvmsg(ABIS_RSL_MDISC_RLL)\n");
+               DEBUGP(DRSL, "rslms_recvmsg(ABIS_RSL_MDISC_RLL)\n");
                rc = rslms_rx_rll(msg, ms);
                break;
        default:
-               printf("unknown RSLms message discriminator 0x%02x",
-                       rslh->msg_discr);
+               LOGP(DRSL, LOGL_ERROR, "unknown RSLms message "
+                       "discriminator 0x%02x", rslh->msg_discr);
                msgb_free(msg);
                return -EINVAL;
        }
index ea6491e..9062546 100644 (file)
@@ -7,6 +7,7 @@
 #include <osmocore/tlv.h>
 #include <osmocore/protocol/gsm_04_08.h>
 
+#include <osmocom/logging.h>
 #include <osmocom/lapdm.h>
 #include <osmocom/rslms.h>
 #include <osmocom/layer3.h>
@@ -133,7 +134,7 @@ static int gsm48_tx_loc_upd_req(struct osmocom_ms *ms, uint8_t chan_nr)
        struct gsm48_hdr *gh;
        struct gsm48_loc_upd_req *lu_r;
 
-       printf("gsm48_tx_loc_upd_req()\n");
+       DEBUGP(DMM, "chan_nr=%u\n", chan_nr);
 
        msg->l3h = msgb_put(msg, sizeof(*gh));
        gh = (struct gsm48_hdr *) msg->l3h;
@@ -158,8 +159,9 @@ static int gsm48_rx_imm_ass(struct msgb *msg, struct osmocom_ms *ms)
        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);
 
-       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,
+       DEBUGP(DRR, "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);
 
        /* FIXME: compare RA and GSM time with when we sent RACH req */
@@ -167,7 +169,7 @@ static int gsm48_rx_imm_ass(struct msgb *msg, struct osmocom_ms *ms)
        /* 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");
+               DEBUGPC(DRR, "UNSUPPORTED!\n");
                return 0;
        }
 
@@ -177,6 +179,8 @@ static int gsm48_rx_imm_ass(struct msgb *msg, struct osmocom_ms *ms)
        /* request L2 to establish the SAPI0 connection */
        gsm48_tx_loc_upd_req(ms, ia->chan_desc.chan_nr);
 
+       DEBUGPC(DRR, "\n");
+
        return 0;
 }
 
@@ -186,7 +190,7 @@ int gsm48_rx_ccch(struct msgb *msg, struct osmocom_ms *ms)
        int rc = 0;
 
        if (sih->rr_protocol_discriminator != GSM48_PDISC_RR)
-               printf("PCH pdisc != RR\n");
+               LOGP(DRR, LOGL_ERROR, "PCH pdisc != RR\n");
        
        switch (sih->system_information) {
        case GSM48_MT_RR_PAG_REQ_1:
@@ -198,7 +202,8 @@ int gsm48_rx_ccch(struct msgb *msg, struct osmocom_ms *ms)
                rc = gsm48_rx_imm_ass(msg, ms);
                break;
        default:
-               printf("unknown PCH/AGCH type 0x%02x\n", sih->system_information);
+               LOGP(DRR, LOGL_NOTICE, "unknown PCH/AGCH type 0x%02x\n",
+                       sih->system_information);
                rc = -EINVAL;
        }
 
diff --git a/src/host/layer23/src/logging.c b/src/host/layer23/src/logging.c
new file mode 100644 (file)
index 0000000..f2642ce
--- /dev/null
@@ -0,0 +1,87 @@
+/* Logging/Debug support of the layer2/3 stack */
+
+/* (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 <osmocore/utils.h>
+#include <osmocore/logging.h>
+#include <osmocom/logging.h>
+
+static const struct log_info_cat default_categories[] = {
+       [DRSL] = {
+               .name = "DRSL",
+               .description = "Radio Signalling Link (MS)",
+               .color = "\033[1;35m",
+               .enabled = 1, .loglevel = LOGL_DEBUG,
+       },
+       [DRR] = {
+               .name = "DRR",
+               .description = "Radio Resource",
+               .color = "\033[1;34m",
+               .enabled = 1, .loglevel = LOGL_DEBUG,
+       },
+       [DMM] = {
+               .name = "DMM",
+               .description = "Mobility Management",
+               .color = "\033[1;33m",
+               .enabled = 1, .loglevel = LOGL_DEBUG,
+       },
+       [DCC] = {
+               .name = "DCC",
+               .description = "Call Control",
+               .color = "\033[1;32m",
+               .enabled = 1, .loglevel = LOGL_DEBUG,
+       },
+       [DSMS] = {
+               .name = "DSMS",
+               .description = "Short Message Service",
+               .color = "\033[1;37m",
+               .enabled = 1, .loglevel = LOGL_DEBUG,
+       },
+       [DMEAS] = {
+               .name = "DMEAS",
+               .description = "MEasurement Reporting",
+               .enabled = 1, .loglevel = LOGL_DEBUG,
+       },
+       [DPAG] = {
+               .name = "DPAG",
+               .description = "Paging",
+               .enabled = 1, .loglevel = LOGL_DEBUG,
+       },
+       [DLAPDM] = {
+               .name = "DLAPDM",
+               .description = "LAPDm Layer2",
+               .enabled = 1, .loglevel = LOGL_DEBUG,
+       },
+       [DL1C]  = {
+               .name = "DL1C",
+               .description = "Layer 1 Control",
+               .color = "\033[1;31m",
+               .enabled = 1, .loglevel = LOGL_DEBUG,
+       },
+};
+
+const struct log_info log_info = {
+       .filter_fn = NULL,
+       .cat = default_categories,
+       .num_cat = ARRAY_SIZE(default_categories),
+};
+
index ae48d64..8345546 100644 (file)
@@ -25,8 +25,8 @@
 #include <osmocom/l1ctl.h>
 #include <osmocom/lapdm.h>
 #include <osmocom/gsmtap_util.h>
+#include <osmocom/logging.h>
 
-#include <osmocore/logging.h>
 #include <osmocore/msgb.h>
 #include <osmocore/talloc.h>
 #include <osmocore/select.h>
@@ -43,6 +43,7 @@
 #include <errno.h>
 #include <fcntl.h>
 
+static struct log_target *stderr_target;
 
 #define GSM_L2_LENGTH 256
 
@@ -150,10 +151,11 @@ static void handle_options(int argc, char **argv)
                        {"socket", 1, 0, 's'},
                        {"arfcn", 1, 0, 'a'},
                        {"gsmtap-ip", 1, 0, 'i'},
+                       {"debug", 1, 0, 'd'},
                        {0, 0, 0, 0},
                };
 
-               c = getopt_long(argc, argv, "hs:a:i:",
+               c = getopt_long(argc, argv, "hs:a:i:d:",
                                long_options, &option_index);
                if (c == -1)
                        break;
@@ -177,6 +179,9 @@ static void handle_options(int argc, char **argv)
                        }
                        gsmtap_ip = ntohl(gsmtap.sin_addr.s_addr);
                        break;
+               case 'd':
+                       log_parse_category_mask(stderr_target, optarg);
+                       break;
                default:
                        break;
                }
@@ -188,6 +193,11 @@ int main(int argc, char **argv)
        int rc;
        struct sockaddr_un local;
 
+       log_init(&log_info);
+       stderr_target = log_target_create_stderr();
+       log_add_target(stderr_target);
+       log_set_all_filter(stderr_target, 1);
+
        l2_ctx = talloc_named_const(NULL, 1, "layer2 context");
 
        ms = talloc_zero(l2_ctx, struct osmocom_ms);
@@ -243,6 +253,5 @@ int main(int argc, char **argv)
                bsc_select_main(0);
        }
 
-
        return 0;
 }
index 86079ac..5b1cc06 100644 (file)
@@ -29,6 +29,7 @@
 #include <osmocore/tlv.h>
 #include <osmocore/protocol/gsm_04_08.h>
 
+#include <osmocom/logging.h>
 #include <osmocom/lapdm.h>
 #include <osmocom/rslms.h>
 #include <osmocom/layer3.h>
@@ -63,12 +64,12 @@ static int rslms_rx_udata_ind(struct msgb *msg, struct osmocom_ms *ms)
        struct tlv_parsed tv;
        int rc = 0;
        
-       printf("RSLms UNIT DATA IND chan_nr=0x%02x link_id=0x%02x\n",
+       DEBUGP(DRSL, "RSLms UNIT DATA IND chan_nr=0x%02x link_id=0x%02x\n",
                rllh->chan_nr, rllh->link_id);
 
        rsl_tlv_parse(&tv, rllh->data, msgb_l2len(msg)-sizeof(*rllh));
        if (!TLVP_PRESENT(&tv, RSL_IE_L3_INFO)) {
-               printf("UNIT_DATA_IND without L3 INFO ?!?\n");
+               DEBUGP(DRSL, "UNIT_DATA_IND without L3 INFO ?!?\n");
                return -EIO;
        }
        msg->l3h = (uint8_t *) TLVP_VAL(&tv, RSL_IE_L3_INFO);
@@ -93,30 +94,31 @@ static int rslms_rx_rll(struct msgb *msg, struct osmocom_ms *ms)
 
        switch (rllh->c.msg_type) {
        case RSL_MT_DATA_IND:
-               printf("RSLms DATA IND\n");
+               DEBUGP(DRSL, "RSLms DATA IND\n");
                /* FIXME: implement this */
                break;
        case RSL_MT_UNIT_DATA_IND:
                rc = rslms_rx_udata_ind(msg, ms);
                break;
        case RSL_MT_EST_IND:
-               printf("RSLms EST IND\n");
+               DEBUGP(DRSL, "RSLms EST IND\n");
                /* FIXME: implement this */
                break;
        case RSL_MT_EST_CONF:
-               printf("RSLms EST CONF\n");
+               DEBUGP(DRSL, "RSLms EST CONF\n");
                /* FIXME: implement this */
                break;
        case RSL_MT_REL_CONF:
-               printf("RSLms REL CONF\n");
+               DEBUGP(DRSL, "RSLms REL CONF\n");
                /* FIXME: implement this */
                break;
        case RSL_MT_ERROR_IND:
-               printf("RSLms ERR IND\n");
+               DEBUGP(DRSL, "RSLms ERR IND\n");
                /* FIXME: implement this */
                break;
        default:
-               printf("unknown RSLms message type 0x%02x\n", rllh->c.msg_type);
+               LOGP(DRSL, LOGL_NOTICE, "unknown RSLms message type "
+                       "0x%02x\n", rllh->c.msg_type);
                rc = -EINVAL;
                break;
        }
@@ -135,7 +137,8 @@ int rslms_sendmsg(struct msgb *msg, struct osmocom_ms *ms)
                break;
        default:
                /* FIXME: implement this */
-               printf("unknown RSLms msg_discr 0x%02x\n", rslh->msg_discr);
+               LOGP(DRSL, LOGL_NOTICE, "unknown RSLms msg_discr 0x%02x\n",
+                       rslh->msg_discr);
                rc = -EINVAL;
                break;
        }