L1CTL is sending PH-DATA.ind, not PH-DATA.req up to LAPDm
[osmocom-bb.git] / src / host / layer23 / src / common / l1ctl.c
index ac8bac8..867f5c5 100644 (file)
 
 #include <l1ctl_proto.h>
 
-#include <osmocore/signal.h>
-#include <osmocore/logging.h>
-#include <osmocore/timer.h>
-#include <osmocore/msgb.h>
-#include <osmocore/tlv.h>
-#include <osmocore/gsm_utils.h>
-#include <osmocore/gsmtap_util.h>
-#include <osmocore/protocol/gsm_04_08.h>
-#include <osmocore/protocol/gsm_08_58.h>
-#include <osmocore/rsl.h>
+#include <osmocom/core/signal.h>
+#include <osmocom/core/logging.h>
+#include <osmocom/core/timer.h>
+#include <osmocom/core/msgb.h>
+#include <osmocom/gsm/tlv.h>
+#include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/core/gsmtap_util.h>
+#include <osmocom/gsm/protocol/gsm_04_08.h>
+#include <osmocom/gsm/protocol/gsm_08_58.h>
+#include <osmocom/gsm/rsl.h>
 
 #include <osmocom/bb/common/l1ctl.h>
 #include <osmocom/bb/common/osmocom_data.h>
@@ -47,6 +47,8 @@
 #include <osmocom/bb/common/lapdm.h>
 #include <osmocom/bb/common/logging.h>
 
+extern struct gsmtap_inst *gsmtap_inst;
+
 static struct msgb *osmo_l1_alloc(uint8_t msg_type)
 {
        struct l1ctl_hdr *l1h;
@@ -92,7 +94,7 @@ static int rx_l1_fbsb_conf(struct osmocom_ms *ms, struct msgb *msg)
 
        if (sb->result != 0) {
                LOGP(DL1C, LOGL_ERROR, "FBSB RESP: result=%u\n", sb->result);
-               dispatch_signal(SS_L1CTL, S_L1CTL_FBSB_ERR, ms);
+               osmo_signal_dispatch(SS_L1CTL, S_L1CTL_FBSB_ERR, ms);
                return 0;
        }
 
@@ -102,13 +104,15 @@ static int rx_l1_fbsb_conf(struct osmocom_ms *ms, struct msgb *msg)
        fr.ms = ms;
        fr.snr = dl->snr;
        fr.bsic = sb->bsic;
-       dispatch_signal(SS_L1CTL, S_L1CTL_FBSB_RESP, &fr);
+       osmo_signal_dispatch(SS_L1CTL, S_L1CTL_FBSB_RESP, &fr);
 
        return 0;
 }
 
 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_l2len(msg) < sizeof(*dl)) {
@@ -120,15 +124,18 @@ static int rx_l1_rach_conf(struct osmocom_ms *ms, struct msgb *msg)
 
        dl = (struct l1ctl_info_dl *) msg->l1h;
 
-       l2_ph_chan_conf(msg, ms, dl);
+       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 0;
+       return lapdm_phsap_up(&pp.oph, le);
 }
 
 /* Receive L1CTL_DATA_IND (Data Indication from L1) */
 static int rx_ph_data_ind(struct osmocom_ms *ms, struct msgb *msg)
 {
-       struct l1ctl_info_dl *dl, dl_cpy;
+       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;
@@ -152,7 +159,7 @@ static int rx_ph_data_ind(struct osmocom_ms *ms, struct msgb *msg)
        DEBUGP(DL1C, "%s (%.4u/%.2u/%.2u) %d dBm: %s\n",
                rsl_chan_nr_str(dl->chan_nr), tm.t1, tm.t2, tm.t3,
                (int)dl->rx_level-110,
-               hexdump(ccch->data, sizeof(ccch->data)));
+               osmo_hexdump(ccch->data, sizeof(ccch->data)));
 
        meas->last_fn = ntohl(dl->frame_nr);
        meas->frames++;
@@ -177,7 +184,7 @@ static int rx_ph_data_ind(struct osmocom_ms *ms, struct msgb *msg)
                        if (meas->dsc > 0)
                                break;
                        meas->ds_fail = 0;
-                       dispatch_signal(SS_L1CTL, S_L1CTL_LOSS_IND, ms);
+                       osmo_signal_dispatch(SS_L1CTL, S_L1CTL_LOSS_IND, ms);
                        break;
                }
        } else {
@@ -199,7 +206,7 @@ static int rx_ph_data_ind(struct osmocom_ms *ms, struct msgb *msg)
                        if (meas->s > 0)
                                break;
                        meas->rl_fail = 0;
-                       dispatch_signal(SS_L1CTL, S_L1CTL_LOSS_IND, ms);
+                       osmo_signal_dispatch(SS_L1CTL, S_L1CTL_LOSS_IND, ms);
                        break;
                }
        }
@@ -208,52 +215,53 @@ static int rx_ph_data_ind(struct osmocom_ms *ms, struct msgb *msg)
 printf("Dropping frame with %u bit errors\n", dl->num_biterr);
                LOGP(DL1C, LOGL_NOTICE, "Dropping frame with %u bit errors\n",
                        dl->num_biterr);
+               msgb_free(msg);
                return 0;
        }
 
        /* send CCCH data via GSMTAP */
        gsmtap_chan_type = chantype_rsl2gsmtap(chan_type, dl->link_id);
-       gsmtap_sendmsg(ntohs(dl->band_arfcn), chan_ts, gsmtap_chan_type, chan_ss,
-                       tm.fn, dl->rx_level-110, dl->snr, ccch->data,
-                       sizeof(ccch->data));
+       gsmtap_send(gsmtap_inst, ntohs(dl->band_arfcn), chan_ts,
+                   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->l2_entity.lapdm_acch;
+               le = &ms->lapdm_channel.lapdm_acch;
        else
-               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));
+               le = &ms->lapdm_channel.lapdm_dcch;
 
        /* pull the L1 header from the msgb */
        msgb_pull(msg, msg->l2h - (msg->l1h-sizeof(struct l1ctl_hdr)));
        msg->l1h = NULL;
 
-       /* send it up into LAPDm */
-       l2_ph_data_ind(msg, le, &dl_cpy);
+       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;
 
-       return 0;
+       /* send it up into LAPDm */
+       return lapdm_phsap_up(&pp.oph, le);
 }
 
 /* Receive L1CTL_DATA_CONF (Data Confirm from L1) */
 static int rx_ph_data_conf(struct osmocom_ms *ms, struct msgb *msg)
 {
-       struct l1ctl_info_dl *dl;
+       struct osmo_phsap_prim pp;
+       struct l1ctl_info_dl *dl = (struct l1ctl_info_dl *) msg->l1h;
        struct lapdm_entity *le;
 
-       dl = (struct l1ctl_info_dl *) msg->l1h;
+       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->l2_entity.lapdm_acch;
+               le = &ms->lapdm_channel.lapdm_acch;
        else
-               le = &ms->l2_entity.lapdm_dcch;
+               le = &ms->lapdm_channel.lapdm_dcch;
 
        /* send it up into LAPDm */
-       l2_ph_data_conf(msg, le);
-
-       return 0;
+       return lapdm_phsap_up(&pp.oph, le);
 }
 
 /* Transmit L1CTL_DATA_REQ */
@@ -265,7 +273,7 @@ int l1ctl_tx_data_req(struct osmocom_ms *ms, struct msgb *msg,
        uint8_t chan_type, chan_ts, chan_ss;
        uint8_t gsmtap_chan_type;
 
-       DEBUGP(DL1C, "(%s)\n", hexdump(msg->l2h, msgb_l2len(msg)));
+       DEBUGP(DL1C, "(%s)\n", osmo_hexdump(msg->l2h, msgb_l2len(msg)));
 
        if (msgb_l2len(msg) > 23) {
                LOGP(DL1C, LOGL_ERROR, "L1 cannot handle message length "
@@ -279,8 +287,8 @@ int l1ctl_tx_data_req(struct osmocom_ms *ms, struct msgb *msg,
        /* send copy via GSMTAP */
        rsl_dec_chan_nr(chan_nr, &chan_type, &chan_ss, &chan_ts);
        gsmtap_chan_type = chantype_rsl2gsmtap(chan_type, link_id);
-       gsmtap_sendmsg(0|0x4000, chan_ts, gsmtap_chan_type, chan_ss,
-                       0, 127, 255, msg->l2h, msgb_l2len(msg));
+       gsmtap_send(gsmtap_inst, 0|0x4000, chan_ts, gsmtap_chan_type,
+                   chan_ss, 0, 127, 255, msg->l2h, msgb_l2len(msg));
 
        /* prepend uplink info header */
        l1i_ul = (struct l1ctl_info_ul *) msgb_push(msg, sizeof(*l1i_ul));
@@ -603,7 +611,7 @@ static int rx_l1_sim_conf(struct osmocom_ms *ms, struct msgb *msg)
        uint16_t len = msg->len - sizeof(struct l1ctl_hdr);
        uint8_t *data = msg->data + sizeof(struct l1ctl_hdr);
        
-       LOGP(DL1C, LOGL_INFO, "SIM %s\n", hexdump(data, len));
+       LOGP(DL1C, LOGL_INFO, "SIM %s\n", osmo_hexdump(data, len));
        
        /* pull the L1 header from the msgb */
        msgb_pull(msg, sizeof(struct l1ctl_hdr));
@@ -655,7 +663,7 @@ int l1ctl_tx_reset_req(struct osmocom_ms *ms, uint8_t type)
 static int rx_l1_reset(struct osmocom_ms *ms)
 {
        LOGP(DL1C, LOGL_INFO, "Layer1 Reset indication\n");
-       dispatch_signal(SS_L1CTL, S_L1CTL_RESET, ms);
+       osmo_signal_dispatch(SS_L1CTL, S_L1CTL_RESET, ms);
 
        return 0;
 }
@@ -673,7 +681,7 @@ static int rx_l1_pm_conf(struct osmocom_ms *ms, struct msgb *msg)
                mr.band_arfcn = ntohs(pmr->band_arfcn);
                mr.rx_lev = pmr->pm[0];
                mr.ms = ms;
-               dispatch_signal(SS_L1CTL, S_L1CTL_PM_RES, &mr);
+               osmo_signal_dispatch(SS_L1CTL, S_L1CTL_PM_RES, &mr);
        }
        return 0;
 }
@@ -696,7 +704,7 @@ static int rx_l1_ccch_mode_conf(struct osmocom_ms *ms, struct msgb *msg)
 
        mc.ccch_mode = conf->ccch_mode;
        mc.ms = ms;
-       dispatch_signal(SS_L1CTL, S_L1CTL_CCCH_MODE_CONF, &mc);
+       osmo_signal_dispatch(SS_L1CTL, S_L1CTL_CCCH_MODE_CONF, &mc);
 
        return 0;
 }
@@ -719,7 +727,7 @@ static int rx_l1_tch_mode_conf(struct osmocom_ms *ms, struct msgb *msg)
 
        mc.tch_mode = conf->tch_mode;
        mc.ms = ms;
-       dispatch_signal(SS_L1CTL, S_L1CTL_TCH_MODE_CONF, &mc);
+       osmo_signal_dispatch(SS_L1CTL, S_L1CTL_TCH_MODE_CONF, &mc);
 
        return 0;
 }
@@ -763,7 +771,7 @@ int l1ctl_recv(struct osmocom_ms *ms, struct msgb *msg)
        case L1CTL_PM_CONF:
                rc = rx_l1_pm_conf(ms, msg);
                if (l1h->flags & L1CTL_F_DONE)
-                       dispatch_signal(SS_L1CTL, S_L1CTL_PM_DONE, ms);
+                       osmo_signal_dispatch(SS_L1CTL, S_L1CTL_PM_DONE, ms);
                msgb_free(msg);
                break;
        case L1CTL_RACH_CONF: