summaryrefslogtreecommitdiffstats
path: root/src/host/virt_phy/src/virt_prim_pdch.c
blob: 7125a70bdf8d3a6990e9b2f943df8929dc87a86b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * (C) 2023 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
 * Author: Vadim Yanitskiy <vyanitskiy@sysmocom.de>
 *
 * 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.
 *
 */

#include <stdint.h>

#include <osmocom/core/msgb.h>
#include <osmocom/core/utils.h>
#include <osmocom/gsm/gsm_utils.h>
#include <osmocom/gsm/protocol/gsm_08_58.h>

#include <osmocom/bb/virtphy/l1ctl_sap.h>
#include <osmocom/bb/virtphy/virt_l1_sched.h>
#include <osmocom/bb/virtphy/gsmtapl1_if.h>
#include <osmocom/bb/virtphy/logging.h>

#include <osmocom/bb/l1ctl_proto.h>
#include <osmocom/bb/l1gprs.h>

void l1ctl_rx_gprs_uldl_tbf_cfg_req(struct l1_model_ms *ms, struct msgb *msg)
{
	const struct l1ctl_hdr *l1h = (struct l1ctl_hdr *)msg->data;

	if (OSMO_UNLIKELY(ms->gprs == NULL)) {
		LOGPMS(DL1C, LOGL_ERROR, ms, "l1gprs is not initialized\n");
		return;
	}

	msg->l1h = msgb_pull(msg, sizeof(*l1h));

	if (l1h->msg_type == L1CTL_GPRS_UL_TBF_CFG_REQ)
		l1gprs_handle_ul_tbf_cfg_req(ms->gprs, msg);
	else
		l1gprs_handle_dl_tbf_cfg_req(ms->gprs, msg);
}

void l1ctl_rx_gprs_ul_block_req(struct l1_model_ms *ms, struct msgb *msg)
{
	const struct l1ctl_hdr *l1h = (struct l1ctl_hdr *)msg->data;
	struct l1gprs_prim_ul_block_req req;
	uint32_t fn_sched;

	if (OSMO_UNLIKELY(ms->gprs == NULL)) {
		LOGPMS(DL1P, LOGL_ERROR, ms, "l1gprs is not initialized\n");
		return;
	}

	msg->l1h = (void *)l1h->data;
	if (l1gprs_handle_ul_block_req(ms->gprs, &req, msg) != 0)
		return;
	msg->l2h = (void *)&req.data[0];

	fn_sched = sched_fn_ul(ms->state.current_time,
			       RSL_CHAN_OSMO_PDCH | req.hdr.tn, 0x00);
	if (OSMO_UNLIKELY(fn_sched != req.hdr.fn)) {
		LOGPMS(DL1P, LOGL_ERROR, ms,
		       "GPRS UL BLOCK.req: fn_sched(%u) != fn_req(%u)\n",
		       fn_sched, req.hdr.fn);
		/* FIXME: return; */
	}

	virt_l1_sched_schedule(ms, msg, fn_sched, req.hdr.tn,
			       &gsmtapl1_tx_to_virt_um_inst);
}

void l1ctl_tx_gprs_dl_block_ind(struct l1_model_ms *ms, const struct msgb *msg,
				uint32_t fn, uint8_t tn, uint8_t rxlev)
{
	struct l1gprs_prim_dl_block_ind ind;
	struct msgb *nmsg;

	if (ms->gprs == NULL)
		return;

	ind = (struct l1gprs_prim_dl_block_ind) {
		.hdr = {
			.fn = fn,
			.tn = tn,
		},
		.meas = {
			.ber10k = 0, /* perfect Um, no errors */
			.ci_cb = 180, /* 18 dB */
			.rx_lev = rxlev,
		},
		.data = msgb_data(msg),
		.data_len = msgb_length(msg),
	};

	nmsg = l1gprs_handle_dl_block_ind(ms->gprs, &ind);
	if (nmsg != NULL)
		l1ctl_sap_tx_to_l23_inst(ms, nmsg);
}