diff --git a/src/host/virt_phy/include/virtphy/l1ctl_sap.h b/src/host/virt_phy/include/virtphy/l1ctl_sap.h index c11c5fe4d..b82745c86 100644 --- a/src/host/virt_phy/include/virtphy/l1ctl_sap.h +++ b/src/host/virt_phy/include/virtphy/l1ctl_sap.h @@ -20,6 +20,8 @@ void l1ctl_sap_init(struct l1_model_ms *model); void prim_rach_init(struct l1_model_ms *model); +void prim_data_init(struct l1_model_ms *model); +void prim_traffic_init(struct l1_model_ms *model); void prim_fbsb_init(struct l1_model_ms *model); void l1ctl_sap_tx_to_l23_inst(struct l1ctl_sock_inst *lsi, struct msgb *msg); void l1ctl_sap_tx_to_l23(struct msgb *msg); diff --git a/src/host/virt_phy/src/Makefile.am b/src/host/virt_phy/src/Makefile.am index fd8d5d97b..ae14ef6f2 100644 --- a/src/host/virt_phy/src/Makefile.am +++ b/src/host/virt_phy/src/Makefile.am @@ -4,7 +4,7 @@ AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(top_srcdir)/../layer2 CFLAGS = "-g -O0" sbin_PROGRAMS = virtphy -virtphy_SOURCES = virtphy.c l1ctl_sock.c gsmtapl1_if.c l1ctl_sap.c virt_prim_fbsb.c virt_prim_rach.c virt_l1_sched_simple.c logging.c virt_l1_model.c shared/virtual_um.c shared/osmo_mcast_sock.c +virtphy_SOURCES = virtphy.c l1ctl_sock.c gsmtapl1_if.c l1ctl_sap.c virt_prim_fbsb.c virt_prim_rach.c virt_prim_data.c virt_prim_traffic.c virt_l1_sched_simple.c logging.c virt_l1_model.c shared/virtual_um.c shared/osmo_mcast_sock.c virtphy_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) virtphy_LDFLAGS = -pthread diff --git a/src/host/virt_phy/src/gsmtapl1_if.c b/src/host/virt_phy/src/gsmtapl1_if.c index 3762cdc2a..6ab9edc70 100644 --- a/src/host/virt_phy/src/gsmtapl1_if.c +++ b/src/host/virt_phy/src/gsmtapl1_if.c @@ -145,6 +145,11 @@ void gsmtapl1_tx_to_virt_um(struct msgb *msg) gsmtapl1_tx_to_virt_um_inst(l1_model_ms->vui, msg); } +/** + * @see virt_prim_fbsb.c + */ +extern void prim_fbsb_sync(struct msgb *msg); + /** * Receive a gsmtap message from the virt um. */ diff --git a/src/host/virt_phy/src/l1ctl_sap.c b/src/host/virt_phy/src/l1ctl_sap.c index 6e42e5d90..1fb4a4288 100644 --- a/src/host/virt_phy/src/l1ctl_sap.c +++ b/src/host/virt_phy/src/l1ctl_sap.c @@ -41,6 +41,8 @@ void l1ctl_sap_init(struct l1_model_ms *model) l1_model_ms = model; prim_rach_init(model); prim_fbsb_init(model); + prim_data_init(model); + prim_traffic_init(model); } /** @@ -374,40 +376,6 @@ void l1ctl_rx_param_req(struct msgb *msg) par_req->ta, par_req->tx_power); } -/** - * @brief Handler for received L1CTL_DATA_REQ from L23. - * - * -- data request -- - * - * @param [in] msg the received message. - * - * Transmit message on a signalling channel. FACCH/SDCCH or SACCH depending on the headers set link id (TS 8.58 - 9.3.2). - * - * TODO: Check if a msg on FACCH is coming in here and needs special handling. - */ -void l1ctl_rx_data_req(struct msgb *msg) -{ - struct l1ctl_hdr *l1h = (struct l1ctl_hdr *)msg->data; - struct l1ctl_info_ul *ul = (struct l1ctl_info_ul *)l1h->data; - struct l1ctl_data_ind *data_ind = (struct l1ctl_data_ind *)ul->payload; - // TODO: calc the scheduled fn - uint32_t fn_sched = l1_model_ms->state->downlink_time.fn; - - DEBUGP(DL1C, - "Received and handled from l23 - L1CTL_DATA_REQ (link_id=0x%02x, ul=%p, ul->payload=%p, data_ind=%p, data_ind->data=%p l3h=%p)\n", - ul->link_id, ul, ul->payload, data_ind, data_ind->data, - msg->l3h); - - msg->l2h = data_ind->data; - - // TODO: append to scheduler queue instead of sending here directly - gsmtapl1_tx_to_virt_um(msg); - - // send confirm to layer23 - msg = l1ctl_create_l2_msg(L1CTL_DATA_CONF, fn_sched, 0, 0); - l1ctl_sap_tx_to_l23(msg); -} - /** * @brief Handler for received L1CTL_PM_REQ from L23. * @@ -583,36 +551,6 @@ void l1ctl_rx_neigh_pm_req(struct msgb *msg) pm_req->n); } -/** - * @brief Handler for received L1CTL_TRAFFIC_REQ from L23. - * - * -- traffic request -- - * - * @param [in] msg the received message. - * - * Enqueue the message (traffic frame) to the L1 state machine's transmit queue. In virtual layer1 just submit it to the virt um. - * - */ -void l1ctl_rx_traffic_req(struct msgb *msg) -{ - struct l1ctl_hdr *l1h = (struct l1ctl_hdr *)msg->data; - struct l1ctl_info_ul *ul = (struct l1ctl_info_ul *)l1h->data; - struct l1ctl_traffic_req *tr = (struct l1ctl_traffic_req *)ul->payload; - // TODO: calc the scheduled fn - uint32_t fn_sched = l1_model_ms->state->downlink_time.fn; - - DEBUGP(DL1C, "Received and handled from l23 - L1CTL_TRAFFIC_REQ\n"); - - msg->l2h = tr->data; - - // TODO: append to scheduler queue instead of sending here directly - gsmtapl1_tx_to_virt_um(msg); - - // send confirm to layer23 - msg = l1ctl_create_l2_msg(L1CTL_TRAFFIC_CONF, fn_sched, 0, 0); - l1ctl_sap_tx_to_l23(msg); -} - /** * @brief Handler for received L1CTL_SIM_REQ from L23. * diff --git a/src/host/virt_phy/src/l1ctl_sock.c b/src/host/virt_phy/src/l1ctl_sock.c index c28da6072..ada251c38 100644 --- a/src/host/virt_phy/src/l1ctl_sock.c +++ b/src/host/virt_phy/src/l1ctl_sock.c @@ -82,7 +82,7 @@ static int l1ctl_sock_data_cb(struct osmo_fd *ofd, unsigned int what) if (rc == len) { msgb_put(msg, rc); - l1h = msgb_data(msg); + l1h = (void *) msgb_data(msg); msg->l1h = l1h; lsi->recv_cb(lsi, msg); return 0; diff --git a/src/host/virt_phy/src/virt_prim_data.c b/src/host/virt_phy/src/virt_prim_data.c new file mode 100644 index 000000000..25036ccb0 --- /dev/null +++ b/src/host/virt_phy/src/virt_prim_data.c @@ -0,0 +1,98 @@ +/* Layer 1 normal data burst tx handling */ + +/* (C) 2010 by Dieter Spaar + * (C) 2010 by Harald Welte + * + * 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 +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +static struct l1_model_ms *l1_model_ms = NULL; +static void virt_l1_sched_handler_cb(struct msgb * msg); + +/** + * @brief Handler callback function for DATA request. + * + * @param [in] msg the msg to sent over virtual um. + */ +static void virt_l1_sched_handler_cb(struct msgb * msg) +{ + gsmtapl1_tx_to_virt_um(msg); + // send confirm to layer23 + // FIXME: as we might send multiple burst, the base fn may be another one than the current + msg = l1ctl_create_l2_msg(L1CTL_DATA_CONF, l1_model_ms->state->current_time.fn, 0, 0); + l1ctl_sap_tx_to_l23(msg); +} + +/** + * @brief Handler for received L1CTL_DATA_REQ from L23. + * + * -- data request -- + * + * @param [in] msg the received message. + * + * Transmit message on a signalling channel. FACCH/SDCCH or SACCH depending on the headers set link id (TS 8.58 - 9.3.2). + * + * TODO: Check if a msg on FACCH is coming in here and needs special handling. + * TODO: Check if msg contains data of a burst or data of 4 bursts! + */ +void l1ctl_rx_data_req(struct msgb *msg) +{ + struct l1ctl_hdr *l1h = (struct l1ctl_hdr *)msg->data; + struct l1ctl_info_ul *ul = (struct l1ctl_info_ul *)l1h->data; + struct l1ctl_data_ind *data_ind = (struct l1ctl_data_ind *)ul->payload; + // TODO: calc the scheduled fn + uint32_t fn_sched = l1_model_ms->state->current_time.fn; + uint8_t rsl_chantype, subslot, timeslot; + rsl_dec_chan_nr(ul->chan_nr, &rsl_chantype, &subslot, ×lot); + + + DEBUGP(DL1C, + "Received and handled from l23 - L1CTL_DATA_REQ (link_id=0x%02x, ul=%p, ul->payload=%p, data_ind=%p, data_ind->data=%p l3h=%p)\n", + ul->link_id, ul, ul->payload, data_ind, data_ind->data, + msg->l3h); + + msg->l2h = data_ind->data; + + virt_l1_sched_schedule(msg, fn_sched, timeslot, &virt_l1_sched_handler_cb); + +} + +/** + * @brief Initialize virtual prim data. + * + * @param [in] model the l1 model instance + */ +void prim_data_init(struct l1_model_ms *model) +{ + l1_model_ms = model; +} diff --git a/src/host/virt_phy/src/virt_prim_traffic.c b/src/host/virt_phy/src/virt_prim_traffic.c new file mode 100644 index 000000000..56609455d --- /dev/null +++ b/src/host/virt_phy/src/virt_prim_traffic.c @@ -0,0 +1,92 @@ +/* Layer 1 normal data burst tx handling */ + +/* (C) 2010 by Dieter Spaar + * (C) 2010 by Harald Welte + * + * 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 +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +static struct l1_model_ms *l1_model_ms = NULL; +static void virt_l1_sched_handler_cb(struct msgb * msg); + +/** + * @brief Handler callback function for TRAFFIC request. + * + * @param [in] msg the msg to sent over virtual um. + */ +static void virt_l1_sched_handler_cb(struct msgb * msg) +{ + gsmtapl1_tx_to_virt_um(msg); + // send confirm to layer23 + msg = l1ctl_create_l2_msg(L1CTL_TRAFFIC_CONF, + l1_model_ms->state->current_time.fn, 0, 0); + l1ctl_sap_tx_to_l23(msg); +} + +/** + * @brief Handler for received L1CTL_TRAFFIC_REQ from L23. + * + * -- traffic request -- + * + * @param [in] msg the received message. + * + * Enqueue the message (traffic frame) to the L1 state machine's transmit queue. In virtual layer1 just submit it to the virt um. + * + */ +void l1ctl_rx_traffic_req(struct msgb *msg) +{ + struct l1ctl_hdr *l1h = (struct l1ctl_hdr *)msg->data; + struct l1ctl_info_ul *ul = (struct l1ctl_info_ul *)l1h->data; + struct l1ctl_traffic_req *tr = (struct l1ctl_traffic_req *)ul->payload; + // TODO: calc the scheduled fn + uint32_t fn_sched = l1_model_ms->state->current_time.fn; + uint8_t rsl_chantype, subslot, timeslot; + rsl_dec_chan_nr(ul->chan_nr, &rsl_chantype, &subslot, ×lot); + + DEBUGP(DL1C, "Received and handled from l23 - L1CTL_TRAFFIC_REQ\n"); + + msg->l2h = tr->data; + + virt_l1_sched_schedule(msg, fn_sched, timeslot, + &virt_l1_sched_handler_cb); +} + +/** + * @brief Initialize virtual prim traffic. + * + * @param [in] model the l1 model instance + */ +void prim_traffic_init(struct l1_model_ms *model) +{ + l1_model_ms = model; +} diff --git a/src/host/virt_phy/src/virtphy.c b/src/host/virt_phy/src/virtphy.c index c9e7bdd3d..70265a05b 100644 --- a/src/host/virt_phy/src/virtphy.c +++ b/src/host/virt_phy/src/virtphy.c @@ -44,7 +44,7 @@ int main( int argc, char *argv[] ) virt_l1_sched_init(model); LOGP(DVIRPHY, LOGL_INFO, "Virtual physical layer ready...\n \ - Waiting for l23 app on", l1ctl_sock_path); + Waiting for l23 app on %s", l1ctl_sock_path); while (1) { // handle osmocom fd READ events (l1ctl-unix-socket, virtual-um-mcast-socket)