diff options
author | Harald Welte <laforge@gnumonks.org> | 2011-06-23 23:55:20 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2011-06-23 23:55:20 +0200 |
commit | 3538c38835b9120d7cf062fa533f7657768bf0d3 (patch) | |
tree | 5d1193b58c7c086fcda1a6c5127291439a70a11b /src/host/layer23/src/common | |
parent | 5d65fcba6caf949c910dd86e43e7d1bef3b219d2 (diff) |
further decouple lapdm code from osmocom_ms and l1ctl
we introduce a new primitive layer betwen PH and DL, enabling the
use of the LAPDm code in applications that are not based on L1CTL
Diffstat (limited to 'src/host/layer23/src/common')
-rw-r--r-- | src/host/layer23/src/common/Makefile.am | 2 | ||||
-rw-r--r-- | src/host/layer23/src/common/l1ctl.c | 28 | ||||
-rw-r--r-- | src/host/layer23/src/common/l1ctl_lapdm_glue.c | 62 | ||||
-rw-r--r-- | src/host/layer23/src/common/lapdm.c | 119 |
4 files changed, 174 insertions, 37 deletions
diff --git a/src/host/layer23/src/common/Makefile.am b/src/host/layer23/src/common/Makefile.am index f6e3f83c..aca2eb48 100644 --- a/src/host/layer23/src/common/Makefile.am +++ b/src/host/layer23/src/common/Makefile.am @@ -3,4 +3,4 @@ AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) noinst_LIBRARIES = liblayer23.a liblayer23_a_SOURCES = l1ctl.c l1l2_interface.c sap_interface.c lapdm.c \ - logging.c networks.c sim.c sysinfo.c gps.c + logging.c networks.c sim.c sysinfo.c gps.c l1ctl_lapdm_glue.c diff --git a/src/host/layer23/src/common/l1ctl.c b/src/host/layer23/src/common/l1ctl.c index f3c2b744..e53df1e9 100644 --- a/src/host/layer23/src/common/l1ctl.c +++ b/src/host/layer23/src/common/l1ctl.c @@ -111,6 +111,8 @@ static int rx_l1_fbsb_conf(struct osmocom_ms *ms, struct msgb *msg) 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)) { @@ -122,14 +124,17 @@ 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, ntohl(dl->frame_nr)); + 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 osmo_phsap_prim pp; struct l1ctl_info_dl *dl; struct l1ctl_data_ind *ccch; struct lapdm_entity *le; @@ -230,19 +235,24 @@ printf("Dropping frame with %u bit errors\n", dl->num_biterr); 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->chan_nr, dl->link_id); + osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_DATA, + PRIM_OP_REQUEST, 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) @@ -251,9 +261,7 @@ static int rx_ph_data_conf(struct osmocom_ms *ms, struct msgb *msg) 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 */ diff --git a/src/host/layer23/src/common/l1ctl_lapdm_glue.c b/src/host/layer23/src/common/l1ctl_lapdm_glue.c new file mode 100644 index 00000000..db071a35 --- /dev/null +++ b/src/host/layer23/src/common/l1ctl_lapdm_glue.c @@ -0,0 +1,62 @@ +/* Glue code between L1CTL and LAPDm */ + +/* (C) 2011 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 <stdint.h> + +#include <l1ctl_proto.h> + +#include <osmocom/gsm/prim.h> + +#include <osmocom/bb/common/l1ctl.h> +#include <osmocom/bb/common/lapdm.h> + +/* LAPDm wants to send a PH-* primitive to the physical layer (L1) */ +int l1ctl_ph_prim_cb(struct osmo_prim_hdr *oph, void *ctx) +{ + struct osmocom_ms *ms = ctx; + struct osmo_phsap_prim *pp = (struct osmo_phsap_prim *) oph; + int rc = 0; + + if (oph->sap != SAP_GSM_PH) + return -ENODEV; + + if (oph->operation != PRIM_OP_REQUEST) + return -EINVAL; + + switch (oph->primitive) { + case PRIM_PH_DATA: + rc = l1ctl_tx_data_req(ms, oph->msg, pp->u.data.chan_nr, + pp->u.data.link_id); + break; + case PRIM_PH_RACH: + l1ctl_tx_param_req(ms, pp->u.rach_req.ta, + pp->u.rach_req.tx_power); + rc = l1ctl_tx_rach_req(ms, pp->u.rach_req.ra, + pp->u.rach_req.offset, + pp->u.rach_req.is_combined_ccch); + break; + default: + rc = -EINVAL; + } + + return rc; +} diff --git a/src/host/layer23/src/common/lapdm.c b/src/host/layer23/src/common/lapdm.c index c766e0b2..52b06ebb 100644 --- a/src/host/layer23/src/common/lapdm.c +++ b/src/host/layer23/src/common/lapdm.c @@ -62,6 +62,7 @@ #include <osmocom/gsm/tlv.h> #include <osmocom/core/utils.h> #include <osmocom/gsm/rsl.h> +#include <osmocom/gsm/prim.h> #include <osmocom/gsm/protocol/gsm_04_08.h> #include <osmocom/gsm/protocol/gsm_08_58.h> @@ -69,8 +70,6 @@ #include <osmocom/bb/common/lapdm.h> #include <osmocom/bb/common/logging.h> -#include <osmocom/bb/common/l1ctl.h> - /* TS 04.06 Figure 4 / Section 3.2 */ #define LAPDm_LPD_NORMAL 0 #define LAPDm_LPD_SMSCB 1 @@ -307,6 +306,12 @@ static int tx_ph_data_enqueue(struct lapdm_datalink *dl, struct msgb *msg, uint8_t chan_nr, uint8_t link_id, uint8_t n201) { struct lapdm_entity *le = dl->entity; + struct osmo_phsap_prim pp; + + osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_RACH, + PRIM_OP_REQUEST, msg); + pp.u.data.chan_nr = chan_nr; + pp.u.data.link_id = link_id; /* if there is a pending message, queue it */ if (le->tx_pending) { @@ -320,24 +325,27 @@ static int tx_ph_data_enqueue(struct lapdm_datalink *dl, struct msgb *msg, /* send the frame now */ le->tx_pending = 0; /* disabled flow control */ lapdm_pad_msgb(msg, n201); - return l1ctl_tx_data_req(le->l1_ctx, msg, chan_nr, link_id); + + return le->l1_prim_cb(&pp.oph, le->l1_ctx); } /* get next frame from the tx queue. because the ms has multiple datalinks, * each datalink's queue is read round-robin. */ -int l2_ph_data_conf(struct msgb *msg, struct lapdm_entity *le) +static int l2_ph_data_conf(struct msgb *msg, struct lapdm_entity *le) { struct lapdm_datalink *dl; int last = le->last_tx_dequeue; int i = last, n = ARRAY_SIZE(le->datalink); - uint8_t chan_nr, link_id, n201; + struct osmo_phsap_prim pp; + uint8_t n201; /* we may send again */ le->tx_pending = 0; /* free confirm message */ - msgb_free(msg); + if (msg) + msgb_free(msg); /* round-robin dequeue */ do { @@ -352,10 +360,13 @@ int l2_ph_data_conf(struct msgb *msg, struct lapdm_entity *le) if (!msg) return 0; + osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_DATA, + PRIM_OP_REQUEST, msg); + /* Pull chan_nr and link_id */ - chan_nr = *msg->data; + pp.u.data.chan_nr = *msg->data; msgb_pull(msg, 1); - link_id = *msg->data; + pp.u.data.link_id = *msg->data; msgb_pull(msg, 1); n201 = *msg->data; msgb_pull(msg, 1); @@ -366,7 +377,8 @@ int l2_ph_data_conf(struct msgb *msg, struct lapdm_entity *le) /* Pad the frame, we can transmit now */ le->tx_pending = 1; lapdm_pad_msgb(msg, n201); - return l1ctl_tx_data_req(le->l1_ctx, msg, chan_nr, link_id); + + return le->l1_prim_cb(&pp.oph, le->l1_ctx); } /* Create RSLms various RSLms messages */ @@ -1515,7 +1527,7 @@ static int lapdm_ph_data_ind(struct msgb *msg, struct lapdm_msg_ctx *mctx) } /* input into layer2 (from layer 1) */ -int l2_ph_data_ind(struct msgb *msg, struct lapdm_entity *le, uint8_t chan_nr, uint8_t link_id) +static int l2_ph_data_ind(struct msgb *msg, struct lapdm_entity *le, uint8_t chan_nr, uint8_t link_id) { uint8_t cbits = chan_nr >> 3; uint8_t sapi = link_id & 7; @@ -1600,6 +1612,50 @@ int l2_ph_data_ind(struct msgb *msg, struct lapdm_entity *le, uint8_t chan_nr, u return rc; } +static int l2_ph_chan_conf(struct msgb *msg, struct lapdm_entity *le, uint32_t frame_nr); + +int lapdm_phsap_up(struct osmo_prim_hdr *oph, struct lapdm_entity *le) +{ + struct osmo_phsap_prim *pp = (struct osmo_phsap_prim *) oph; + int rc = 0; + + if (oph->sap != SAP_GSM_PH) + return -ENODEV; + + if (oph->operation != PRIM_OP_INDICATION) + return -ENODEV; + + switch (oph->primitive) { + case PRIM_PH_DATA: + if (oph->operation != PRIM_OP_INDICATION) + return -ENODEV; + rc = l2_ph_data_ind(oph->msg, le, pp->u.data.chan_nr, + pp->u.data.link_id); + break; + case PRIM_PH_RTS: + if (oph->operation != PRIM_OP_INDICATION) + return -ENODEV; + rc = l2_ph_data_conf(oph->msg, le); + break; + case PRIM_PH_RACH: + switch (oph->operation) { + case PRIM_OP_INDICATION: +#warning FIX BTS + //rc = l2_ph_rach_ind(le, pp->u.rach_ind.ra, pp->u.rach_ind.fn); + break; + case PRIM_OP_CONFIRM: + rc = l2_ph_chan_conf(oph->msg, le, pp->u.rach_ind.fn); + break; + default: + return -EIO; + } + break; + } + + return rc; +} + + /* L3 -> L2 / RSLMS -> LAPDm */ /* L3 requests establishment of data link */ @@ -2051,7 +2107,10 @@ static int rslms_rx_chan_rqd(struct lapdm_channel *lc, struct msgb *msg) { struct abis_rsl_cchan_hdr *cch = msgb_l2(msg); void *l1ctx = lc->lapdm_dcch.l1_ctx; - int rc; + struct osmo_phsap_prim pp; + + osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_RACH, + PRIM_OP_REQUEST, NULL); if (msgb_l2len(msg) < sizeof(*cch) + 4 + 2 + 2) { LOGP(DRSL, LOGL_ERROR, "Message too short for CHAN RQD!\n"); @@ -2061,28 +2120,30 @@ static int rslms_rx_chan_rqd(struct lapdm_channel *lc, struct msgb *msg) LOGP(DRSL, LOGL_ERROR, "Missing REQ REFERENCE IE\n"); return -EINVAL; } + pp.u.rach_req.ra = cch->data[1]; + pp.u.rach_req.offset = ((cch->data[2] & 0x7f) << 8) | cch->data[3]; + pp.u.rach_req.is_combined_ccch = cch->data[2] >> 7; + if (cch->data[4] != RSL_IE_ACCESS_DELAY) { LOGP(DRSL, LOGL_ERROR, "Missing ACCESS_DELAY IE\n"); return -EINVAL; } + /* TA = 0 - delay */ + pp.u.rach_req.ta = 0 - cch->data[5]; + if (cch->data[6] != RSL_IE_MS_POWER) { LOGP(DRSL, LOGL_ERROR, "Missing MS POWER IE\n"); return -EINVAL; } - - /* TA = 0 - delay */ - rc = l1ctl_tx_param_req(l1ctx, 0 - cch->data[5], cch->data[7]); - - rc = l1ctl_tx_rach_req(l1ctx, cch->data[1], - ((cch->data[2] & 0x7f) << 8) | cch->data[3], cch->data[2] >> 7); + pp.u.rach_req.tx_power = cch->data[7]; msgb_free(msg); - return rc; + return lc->lapdm_dcch.l1_prim_cb(&pp.oph, l1ctx); } /* L1 confirms channel request */ -int l2_ph_chan_conf(struct msgb *msg, struct osmocom_ms *ms, uint32_t frame_nr) +static int l2_ph_chan_conf(struct msgb *msg, struct lapdm_entity *le, uint32_t frame_nr) { struct abis_rsl_cchan_hdr *ch; struct gsm_time tm; @@ -2102,7 +2163,7 @@ int l2_ph_chan_conf(struct msgb *msg, struct osmocom_ms *ms, uint32_t frame_nr) ref->t3_low = tm.t3 & 0x7; ref->t3_high = tm.t3 >> 3; - return rslms_sendmsg(msg, &ms->lapdm_channel.lapdm_dcch); + return rslms_sendmsg(msg, le); } /* Names for Radio Link Layer Management */ @@ -2304,12 +2365,18 @@ int lapdm_rslms_recvmsg(struct msgb *msg, struct lapdm_channel *lc) return rc; } -int osmol2_register_handler(struct osmocom_ms *ms, lapdm_cb_t cb) +void lapdm_channel_set_l1(struct lapdm_channel *lc, osmo_prim_cb cb, void *ctx) { - ms->lapdm_channel.lapdm_acch.l3_cb = cb; - ms->lapdm_channel.lapdm_dcch.l3_cb = cb; - ms->lapdm_channel.lapdm_acch.l3_ctx = ms; - ms->lapdm_channel.lapdm_dcch.l3_ctx = ms; + lc->lapdm_dcch.l1_prim_cb = cb; + lc->lapdm_acch.l1_prim_cb = cb; + lc->lapdm_dcch.l1_ctx = ctx; + lc->lapdm_acch.l1_ctx = ctx; +} - return 0; +void lapdm_channel_set_l3(struct lapdm_channel *lc, lapdm_cb_t cb, void *ctx) +{ + lc->lapdm_dcch.l3_cb = cb; + lc->lapdm_acch.l3_cb = cb; + lc->lapdm_dcch.l3_ctx = ctx; + lc->lapdm_acch.l3_ctx = ctx; } |