blob: 42f64ac9198d5395677c4c21e1b10af5487e56e9 [file] [log] [blame]
Ericb7253c62022-11-28 19:21:08 +01001/*
2 * (C) 2022 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
3 * All Rights Reserved
4 *
5 * Author: Eric Wild <ewild@sysmocom.de>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22extern "C" {
23#include <osmocom/bb/trxcon/trxcon.h>
24#include <osmocom/bb/trxcon/trxcon_fsm.h>
25#include <osmocom/bb/trxcon/l1ctl_server.h>
26}
Eric135d64b2023-04-21 13:59:56 +020027#include "ms_trxcon_if.h"
Ericb7253c62022-11-28 19:21:08 +010028
29static struct l1ctl_server_cfg server_cfg;
30static struct l1ctl_server *server = NULL;
Ericb7253c62022-11-28 19:21:08 +010031
32static int l1ctl_rx_cb(struct l1ctl_client *l1c, struct msgb *msg)
33{
34 struct trxcon_inst *trxcon = (struct trxcon_inst *)l1c->priv;
35
36 return trxcon_l1ctl_receive(trxcon, msg);
37}
38
39static void l1ctl_conn_accept_cb(struct l1ctl_client *l1c)
40{
Eric135d64b2023-04-21 13:59:56 +020041 l1c->log_prefix = talloc_strdup(l1c, g_trxcon->log_prefix);
42 l1c->priv = g_trxcon;
43 g_trxcon->l2if = l1c;
Ericb7253c62022-11-28 19:21:08 +010044}
45
46static void l1ctl_conn_close_cb(struct l1ctl_client *l1c)
47{
48 struct trxcon_inst *trxcon = (struct trxcon_inst *)l1c->priv;
49
50 if (trxcon == NULL || trxcon->fi == NULL)
51 return;
52
53 osmo_fsm_inst_dispatch(trxcon->fi, TRXCON_EV_L2IF_FAILURE, NULL);
54}
55
Ericb7253c62022-11-28 19:21:08 +010056bool trxc_l1ctl_init(void *tallctx)
57{
58 /* Start the L1CTL server */
59 server_cfg = (struct l1ctl_server_cfg){
60 /* TODO: make path configurable */
Eric135d64b2023-04-21 13:59:56 +020061 .sock_path = "/tmp/osmocom_l2", .num_clients_max = 1,
62 .conn_read_cb = &l1ctl_rx_cb, .conn_accept_cb = &l1ctl_conn_accept_cb,
Ericb7253c62022-11-28 19:21:08 +010063 .conn_close_cb = &l1ctl_conn_close_cb,
64 };
65
66 server = l1ctl_server_alloc(tallctx, &server_cfg);
67 if (server == NULL) {
68 return false;
69 }
70 return true;
71}