trxcon: abstract L1CTL codec from the l1ctl_server API

The L1CTL codec (implemented in l1ctl.c) is going to be part of the
upcoming libtrxcon, so let's uncouple it from the l1ctl_server API.

Change-Id: I8d80af240b0e57f76263907c552288d4184876c0
Related: OS#5599
This commit is contained in:
Vadim Yanitskiy 2022-11-11 16:57:07 +07:00
parent 724502d0f4
commit 394793b1c1
5 changed files with 128 additions and 110 deletions

View File

@ -1,24 +1,22 @@
#pragma once
#include <stdint.h>
#include <osmocom/core/msgb.h>
#include <osmocom/bb/trxcon/l1ctl_server.h>
struct msgb;
struct trxcon_param_rx_data_ind;
struct trxcon_param_tx_data_cnf;
struct trxcon_param_tx_access_burst_cnf;
/* Event handlers */
int l1ctl_rx_cb(struct l1ctl_client *l1c, struct msgb *msg);
int l1ctl_tx_fbsb_conf(struct trxcon_inst *trxcon, uint16_t band_arfcn, uint8_t bsic);
int l1ctl_tx_fbsb_fail(struct trxcon_inst *trxcon, uint16_t band_arfcn);
int l1ctl_tx_ccch_mode_conf(struct trxcon_inst *trxcon, uint8_t mode);
int l1ctl_tx_pm_conf(struct trxcon_inst *trxcon, uint16_t band_arfcn, int dbm, int last);
int l1ctl_tx_reset_conf(struct trxcon_inst *trxcon, uint8_t type);
int l1ctl_tx_reset_ind(struct trxcon_inst *trxcon, uint8_t type);
int l1ctl_tx_fbsb_conf(struct l1ctl_client *l1c, uint16_t band_arfcn, uint8_t bsic);
int l1ctl_tx_fbsb_fail(struct l1ctl_client *l1c, uint16_t band_arfcn);
int l1ctl_tx_ccch_mode_conf(struct l1ctl_client *l1c, uint8_t mode);
int l1ctl_tx_pm_conf(struct l1ctl_client *l1c, uint16_t band_arfcn,
int dbm, int last);
int l1ctl_tx_reset_conf(struct l1ctl_client *l1c, uint8_t type);
int l1ctl_tx_reset_ind(struct l1ctl_client *l1c, uint8_t type);
int l1ctl_tx_dt_ind(struct l1ctl_client *l1c,
int l1ctl_tx_dt_ind(struct trxcon_inst *trxcon,
const struct trxcon_param_rx_data_ind *ind);
int l1ctl_tx_dt_conf(struct l1ctl_client *l1c,
int l1ctl_tx_dt_conf(struct trxcon_inst *trxcon,
const struct trxcon_param_tx_data_cnf *cnf);
int l1ctl_tx_rach_conf(struct l1ctl_client *l1c,
int l1ctl_tx_rach_conf(struct trxcon_inst *trxcon,
const struct trxcon_param_tx_access_burst_cnf *cnf);

View File

@ -4,6 +4,7 @@
struct osmo_fsm_inst;
struct l1sched_state;
struct msgb;
struct trxcon_inst {
struct osmo_fsm_inst *fi;
@ -32,3 +33,7 @@ struct trxcon_inst {
struct trxcon_inst *trxcon_inst_alloc(void *ctx, unsigned int id, uint32_t fn_advance);
void trxcon_inst_free(struct trxcon_inst *trxcon);
int trxcon_l1ctl_receive(struct trxcon_inst *trxcon, struct msgb *msg);
int trxcon_l1ctl_send(struct trxcon_inst *trxcon, struct msgb *msg);
void trxcon_l1ctl_close(struct trxcon_inst *trxcon);

View File

@ -38,11 +38,13 @@
#include <osmocom/gsm/protocol/gsm_08_58.h>
#include <osmocom/bb/trxcon/logging.h>
#include <osmocom/bb/trxcon/l1ctl_server.h>
#include <osmocom/bb/trxcon/l1ctl_proto.h>
#include <osmocom/bb/trxcon/trxcon.h>
#include <osmocom/bb/trxcon/trxcon_fsm.h>
#define L1CTL_LENGTH 256
#define L1CTL_HEADROOM 32
static const char *arfcn2band_name(uint16_t arfcn)
{
enum gsm_band band;
@ -76,10 +78,9 @@ static struct msgb *l1ctl_alloc_msg(uint8_t msg_type)
return msg;
}
int l1ctl_tx_pm_conf(struct l1ctl_client *l1c, uint16_t band_arfcn,
int dbm, int last)
int l1ctl_tx_pm_conf(struct trxcon_inst *trxcon, uint16_t band_arfcn, int dbm, int last)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct osmo_fsm_inst *fi = trxcon->fi;
struct l1ctl_pm_conf *pmc;
struct msgb *msg;
@ -102,12 +103,12 @@ int l1ctl_tx_pm_conf(struct l1ctl_client *l1c, uint16_t band_arfcn,
l1h->flags |= L1CTL_F_DONE;
}
return l1ctl_client_send(l1c, msg);
return trxcon_l1ctl_send(trxcon, msg);
}
int l1ctl_tx_reset_ind(struct l1ctl_client *l1c, uint8_t type)
int l1ctl_tx_reset_ind(struct trxcon_inst *trxcon, uint8_t type)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct osmo_fsm_inst *fi = trxcon->fi;
struct msgb *msg;
struct l1ctl_reset *res;
@ -120,12 +121,12 @@ int l1ctl_tx_reset_ind(struct l1ctl_client *l1c, uint8_t type)
res = (struct l1ctl_reset *) msgb_put(msg, sizeof(*res));
res->type = type;
return l1ctl_client_send(l1c, msg);
return trxcon_l1ctl_send(trxcon, msg);
}
int l1ctl_tx_reset_conf(struct l1ctl_client *l1c, uint8_t type)
int l1ctl_tx_reset_conf(struct trxcon_inst *trxcon, uint8_t type)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct osmo_fsm_inst *fi = trxcon->fi;
struct msgb *msg;
struct l1ctl_reset *res;
@ -137,7 +138,7 @@ int l1ctl_tx_reset_conf(struct l1ctl_client *l1c, uint8_t type)
res = (struct l1ctl_reset *) msgb_put(msg, sizeof(*res));
res->type = type;
return l1ctl_client_send(l1c, msg);
return trxcon_l1ctl_send(trxcon, msg);
}
static struct l1ctl_info_dl *put_dl_info_hdr(struct msgb *msg,
@ -165,9 +166,9 @@ static struct l1ctl_fbsb_conf *fbsb_conf_make(struct msgb *msg, uint8_t result,
return conf;
}
int l1ctl_tx_fbsb_fail(struct l1ctl_client *l1c, uint16_t band_arfcn)
int l1ctl_tx_fbsb_fail(struct trxcon_inst *trxcon, uint16_t band_arfcn)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct osmo_fsm_inst *fi = trxcon->fi;
struct l1ctl_info_dl *dl;
struct msgb *msg;
@ -184,12 +185,12 @@ int l1ctl_tx_fbsb_fail(struct l1ctl_client *l1c, uint16_t band_arfcn)
LOGPFSMSL(fi, DL1C, LOGL_DEBUG, "Send FBSB Conf (timeout)\n");
return l1ctl_client_send(l1c, msg);
return trxcon_l1ctl_send(trxcon, msg);
}
int l1ctl_tx_fbsb_conf(struct l1ctl_client *l1c, uint16_t band_arfcn, uint8_t bsic)
int l1ctl_tx_fbsb_conf(struct trxcon_inst *trxcon, uint16_t band_arfcn, uint8_t bsic)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct osmo_fsm_inst *fi = trxcon->fi;
struct l1ctl_fbsb_conf *conf;
struct l1ctl_info_dl *dl;
struct msgb *msg;
@ -212,10 +213,10 @@ int l1ctl_tx_fbsb_conf(struct l1ctl_client *l1c, uint16_t band_arfcn, uint8_t bs
"Send FBSB Conf (result=%u, bsic=%u)\n",
conf->result, conf->bsic);
return l1ctl_client_send(l1c, msg);
return trxcon_l1ctl_send(trxcon, msg);
}
int l1ctl_tx_ccch_mode_conf(struct l1ctl_client *l1c, uint8_t mode)
int l1ctl_tx_ccch_mode_conf(struct trxcon_inst *trxcon, uint8_t mode)
{
struct l1ctl_ccch_mode_conf *conf;
struct msgb *msg;
@ -227,13 +228,13 @@ int l1ctl_tx_ccch_mode_conf(struct l1ctl_client *l1c, uint8_t mode)
conf = (struct l1ctl_ccch_mode_conf *) msgb_put(msg, sizeof(*conf));
conf->ccch_mode = mode;
return l1ctl_client_send(l1c, msg);
return trxcon_l1ctl_send(trxcon, msg);
}
/**
* Handles both L1CTL_DATA_IND and L1CTL_TRAFFIC_IND.
*/
int l1ctl_tx_dt_ind(struct l1ctl_client *l1c,
int l1ctl_tx_dt_ind(struct trxcon_inst *trxcon,
const struct trxcon_param_rx_data_ind *ind)
{
struct msgb *msg;
@ -260,10 +261,10 @@ int l1ctl_tx_dt_ind(struct l1ctl_client *l1c,
memcpy(msgb_put(msg, ind->data_len), ind->data, ind->data_len);
/* Put message to upper layers */
return l1ctl_client_send(l1c, msg);
return trxcon_l1ctl_send(trxcon, msg);
}
int l1ctl_tx_rach_conf(struct l1ctl_client *l1c,
int l1ctl_tx_rach_conf(struct trxcon_inst *trxcon,
const struct trxcon_param_tx_access_burst_cnf *cnf)
{
struct msgb *msg;
@ -279,14 +280,14 @@ int l1ctl_tx_rach_conf(struct l1ctl_client *l1c,
put_dl_info_hdr(msg, &dl_hdr);
return l1ctl_client_send(l1c, msg);
return trxcon_l1ctl_send(trxcon, msg);
}
/**
* Handles both L1CTL_DATA_CONF and L1CTL_TRAFFIC_CONF.
*/
int l1ctl_tx_dt_conf(struct l1ctl_client *l1c,
int l1ctl_tx_dt_conf(struct trxcon_inst *trxcon,
struct trxcon_param_tx_data_cnf *cnf)
{
struct msgb *msg;
@ -305,7 +306,7 @@ int l1ctl_tx_dt_conf(struct l1ctl_client *l1c,
/* Copy DL frame header from source message */
put_dl_info_hdr(msg, &dl_hdr);
return l1ctl_client_send(l1c, msg);
return trxcon_l1ctl_send(trxcon, msg);
}
static enum gsm_phys_chan_config l1ctl_ccch_mode2pchan_config(enum ccch_mode mode)
@ -328,9 +329,9 @@ static enum gsm_phys_chan_config l1ctl_ccch_mode2pchan_config(enum ccch_mode mod
}
}
static int l1ctl_rx_fbsb_req(struct l1ctl_client *l1c, struct msgb *msg)
static int l1ctl_rx_fbsb_req(struct trxcon_inst *trxcon, struct msgb *msg)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct osmo_fsm_inst *fi = trxcon->fi;
struct l1ctl_fbsb_req *fbsb;
int rc = 0;
@ -362,9 +363,9 @@ exit:
return rc;
}
static int l1ctl_rx_pm_req(struct l1ctl_client *l1c, struct msgb *msg)
static int l1ctl_rx_pm_req(struct trxcon_inst *trxcon, struct msgb *msg)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct osmo_fsm_inst *fi = trxcon->fi;
struct l1ctl_pm_req *pmr;
int rc = 0;
@ -395,9 +396,9 @@ exit:
return rc;
}
static int l1ctl_rx_reset_req(struct l1ctl_client *l1c, struct msgb *msg)
static int l1ctl_rx_reset_req(struct trxcon_inst *trxcon, struct msgb *msg)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct osmo_fsm_inst *fi = trxcon->fi;
struct l1ctl_reset *res;
int rc = 0;
@ -427,16 +428,16 @@ static int l1ctl_rx_reset_req(struct l1ctl_client *l1c, struct msgb *msg)
}
/* Confirm */
rc = l1ctl_tx_reset_conf(l1c, res->type);
rc = l1ctl_tx_reset_conf(trxcon, res->type);
exit:
msgb_free(msg);
return rc;
}
static int l1ctl_rx_echo_req(struct l1ctl_client *l1c, struct msgb *msg)
static int l1ctl_rx_echo_req(struct trxcon_inst *trxcon, struct msgb *msg)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct osmo_fsm_inst *fi = trxcon->fi;
struct l1ctl_hdr *l1h;
LOGPFSMSL(fi, DL1C, LOGL_NOTICE, "Recv Echo Req\n");
@ -447,12 +448,12 @@ static int l1ctl_rx_echo_req(struct l1ctl_client *l1c, struct msgb *msg)
l1h->msg_type = L1CTL_ECHO_CONF;
msg->data = msg->l1h;
return l1ctl_client_send(l1c, msg);
return trxcon_l1ctl_send(trxcon, msg);
}
static int l1ctl_rx_ccch_mode_req(struct l1ctl_client *l1c, struct msgb *msg)
static int l1ctl_rx_ccch_mode_req(struct trxcon_inst *trxcon, struct msgb *msg)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct osmo_fsm_inst *fi = trxcon->fi;
struct l1ctl_ccch_mode_req *mode_req;
int rc;
@ -475,17 +476,17 @@ static int l1ctl_rx_ccch_mode_req(struct l1ctl_client *l1c, struct msgb *msg)
rc = osmo_fsm_inst_dispatch(fi, TRXCON_EV_SET_CCCH_MODE_REQ, &req);
if (rc == 0 && req.applied)
l1ctl_tx_ccch_mode_conf(l1c, mode_req->ccch_mode);
l1ctl_tx_ccch_mode_conf(trxcon, mode_req->ccch_mode);
exit:
msgb_free(msg);
return rc;
}
static int l1ctl_rx_rach_req(struct l1ctl_client *l1c, struct msgb *msg, bool is_11bit)
static int l1ctl_rx_rach_req(struct trxcon_inst *trxcon, struct msgb *msg, bool is_11bit)
{
struct trxcon_param_tx_access_burst_req req;
struct osmo_fsm_inst *fi = l1c->priv;
struct osmo_fsm_inst *fi = trxcon->fi;
struct l1ctl_info_ul *ul;
ul = (struct l1ctl_info_ul *) msg->l1h;
@ -581,9 +582,9 @@ static int l1ctl_proc_est_req_h1(struct osmo_fsm_inst *fi,
return 0;
}
static int l1ctl_rx_dm_est_req(struct l1ctl_client *l1c, struct msgb *msg)
static int l1ctl_rx_dm_est_req(struct trxcon_inst *trxcon, struct msgb *msg)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct osmo_fsm_inst *fi = trxcon->fi;
struct l1ctl_dm_est_req *est_req;
struct l1ctl_info_ul *ul;
int rc;
@ -618,9 +619,9 @@ exit:
return rc;
}
static int l1ctl_rx_dm_rel_req(struct l1ctl_client *l1c, struct msgb *msg)
static int l1ctl_rx_dm_rel_req(struct trxcon_inst *trxcon, struct msgb *msg)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct osmo_fsm_inst *fi = trxcon->fi;
LOGPFSMSL(fi, DL1C, LOGL_NOTICE, "Received L1CTL_DM_REL_REQ\n");
@ -633,10 +634,9 @@ static int l1ctl_rx_dm_rel_req(struct l1ctl_client *l1c, struct msgb *msg)
/**
* Handles both L1CTL_DATA_REQ and L1CTL_TRAFFIC_REQ.
*/
static int l1ctl_rx_dt_req(struct l1ctl_client *l1c,
struct msgb *msg, bool traffic)
static int l1ctl_rx_dt_req(struct trxcon_inst *trxcon, struct msgb *msg, bool traffic)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct osmo_fsm_inst *fi = trxcon->fi;
struct l1ctl_info_ul *ul;
/* Extract UL frame header */
@ -669,9 +669,9 @@ static int l1ctl_rx_dt_req(struct l1ctl_client *l1c,
return 0;
}
static int l1ctl_rx_param_req(struct l1ctl_client *l1c, struct msgb *msg)
static int l1ctl_rx_param_req(struct trxcon_inst *trxcon, struct msgb *msg)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct osmo_fsm_inst *fi = trxcon->fi;
struct l1ctl_par_req *par_req;
struct l1ctl_info_ul *ul;
@ -696,9 +696,9 @@ static int l1ctl_rx_param_req(struct l1ctl_client *l1c, struct msgb *msg)
return 0;
}
static int l1ctl_rx_tch_mode_req(struct l1ctl_client *l1c, struct msgb *msg)
static int l1ctl_rx_tch_mode_req(struct trxcon_inst *trxcon, struct msgb *msg)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct osmo_fsm_inst *fi = trxcon->fi;
struct l1ctl_tch_mode_req *mode_req;
int rc;
@ -728,12 +728,12 @@ static int l1ctl_rx_tch_mode_req(struct l1ctl_client *l1c, struct msgb *msg)
struct l1ctl_hdr *l1h = (struct l1ctl_hdr *) msg->data;
l1h->msg_type = L1CTL_TCH_MODE_CONF;
return l1ctl_client_send(l1c, msg);
return trxcon_l1ctl_send(trxcon, msg);
}
static int l1ctl_rx_crypto_req(struct l1ctl_client *l1c, struct msgb *msg)
static int l1ctl_rx_crypto_req(struct trxcon_inst *trxcon, struct msgb *msg)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct osmo_fsm_inst *fi = trxcon->fi;
struct l1ctl_crypto_req *cr;
struct l1ctl_info_ul *ul;
@ -757,9 +757,8 @@ static int l1ctl_rx_crypto_req(struct l1ctl_client *l1c, struct msgb *msg)
return 0;
}
int l1ctl_rx_cb(struct l1ctl_client *l1c, struct msgb *msg)
int trxcon_l1ctl_receive(struct trxcon_inst *trxcon, struct msgb *msg)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct l1ctl_hdr *l1h;
l1h = (struct l1ctl_hdr *) msg->l1h;
@ -767,33 +766,33 @@ int l1ctl_rx_cb(struct l1ctl_client *l1c, struct msgb *msg)
switch (l1h->msg_type) {
case L1CTL_FBSB_REQ:
return l1ctl_rx_fbsb_req(l1c, msg);
return l1ctl_rx_fbsb_req(trxcon, msg);
case L1CTL_PM_REQ:
return l1ctl_rx_pm_req(l1c, msg);
return l1ctl_rx_pm_req(trxcon, msg);
case L1CTL_RESET_REQ:
return l1ctl_rx_reset_req(l1c, msg);
return l1ctl_rx_reset_req(trxcon, msg);
case L1CTL_ECHO_REQ:
return l1ctl_rx_echo_req(l1c, msg);
return l1ctl_rx_echo_req(trxcon, msg);
case L1CTL_CCCH_MODE_REQ:
return l1ctl_rx_ccch_mode_req(l1c, msg);
return l1ctl_rx_ccch_mode_req(trxcon, msg);
case L1CTL_RACH_REQ:
return l1ctl_rx_rach_req(l1c, msg, false);
return l1ctl_rx_rach_req(trxcon, msg, false);
case L1CTL_EXT_RACH_REQ:
return l1ctl_rx_rach_req(l1c, msg, true);
return l1ctl_rx_rach_req(trxcon, msg, true);
case L1CTL_DM_EST_REQ:
return l1ctl_rx_dm_est_req(l1c, msg);
return l1ctl_rx_dm_est_req(trxcon, msg);
case L1CTL_DM_REL_REQ:
return l1ctl_rx_dm_rel_req(l1c, msg);
return l1ctl_rx_dm_rel_req(trxcon, msg);
case L1CTL_DATA_REQ:
return l1ctl_rx_dt_req(l1c, msg, false);
return l1ctl_rx_dt_req(trxcon, msg, false);
case L1CTL_TRAFFIC_REQ:
return l1ctl_rx_dt_req(l1c, msg, true);
return l1ctl_rx_dt_req(trxcon, msg, true);
case L1CTL_PARAM_REQ:
return l1ctl_rx_param_req(l1c, msg);
return l1ctl_rx_param_req(trxcon, msg);
case L1CTL_TCH_MODE_REQ:
return l1ctl_rx_tch_mode_req(l1c, msg);
return l1ctl_rx_tch_mode_req(trxcon, msg);
case L1CTL_CRYPTO_REQ:
return l1ctl_rx_crypto_req(l1c, msg);
return l1ctl_rx_crypto_req(trxcon, msg);
/* Not (yet) handled messages */
case L1CTL_NEIGH_PM_REQ:
@ -801,13 +800,13 @@ int l1ctl_rx_cb(struct l1ctl_client *l1c, struct msgb *msg)
case L1CTL_TBF_CFG_REQ:
case L1CTL_DM_FREQ_REQ:
case L1CTL_SIM_REQ:
LOGPFSMSL(fi, DL1C, LOGL_NOTICE,
LOGPFSMSL(trxcon->fi, DL1C, LOGL_NOTICE,
"Ignoring unsupported message (type=%u)\n",
l1h->msg_type);
msgb_free(msg);
return -ENOTSUP;
default:
LOGPFSMSL(fi, DL1C, LOGL_ERROR, "Unknown MSG type %u: %s\n",
LOGPFSMSL(trxcon->fi, DL1C, LOGL_ERROR, "Unknown MSG type %u: %s\n",
l1h->msg_type, osmo_hexdump(msgb_data(msg), msgb_length(msg)));
msgb_free(msg);
return -EINVAL;

View File

@ -114,7 +114,7 @@ static int trxcon_timer_cb(struct osmo_fsm_inst *fi)
switch (fi->state) {
case TRXCON_ST_FBSB_SEARCH:
l1ctl_tx_fbsb_fail(trxcon->l2if, trxcon->l1p.band_arfcn);
l1ctl_tx_fbsb_fail(trxcon, trxcon->l1p.band_arfcn);
osmo_fsm_inst_state_chg(fi, TRXCON_ST_RESET, 0, 0);
return 0;
default:
@ -233,12 +233,12 @@ static void trxcon_st_full_power_scan_action(struct osmo_fsm_inst *fi,
}
if (res->band_arfcn < req->band_arfcn_stop) {
l1ctl_tx_pm_conf(trxcon->l2if, res->band_arfcn, res->dbm, false);
l1ctl_tx_pm_conf(trxcon, res->band_arfcn, res->dbm, false);
/* trxcon_st_full_power_scan_onenter() sends the next PHYIF_CMDT_MEASURE */
req->band_arfcn_start = res->band_arfcn + 1;
osmo_fsm_inst_state_chg(fi, TRXCON_ST_FULL_POWER_SCAN, 0, 0); /* TODO: timeout */
} else {
l1ctl_tx_pm_conf(trxcon->l2if, res->band_arfcn, res->dbm, true);
l1ctl_tx_pm_conf(trxcon, res->band_arfcn, res->dbm, true);
LOGPFSML(fi, LOGL_INFO, "Full power scan completed\n");
TALLOC_FREE(trxcon->fi_data);
}
@ -260,9 +260,7 @@ static void trxcon_st_fbsb_search_action(struct osmo_fsm_inst *fi,
switch (event) {
case TRXCON_EV_FBSB_SEARCH_RES:
osmo_fsm_inst_state_chg(fi, TRXCON_ST_BCCH_CCCH, 0, 0);
l1ctl_tx_fbsb_conf(trxcon->l2if,
trxcon->l1p.band_arfcn,
trxcon->sched->bsic);
l1ctl_tx_fbsb_conf(trxcon, trxcon->l1p.band_arfcn, trxcon->sched->bsic);
break;
default:
OSMO_ASSERT(0);
@ -302,7 +300,7 @@ static void trxcon_st_bcch_ccch_action(struct osmo_fsm_inst *fi,
handle_tx_access_burst_req(fi, data);
break;
case TRXCON_EV_TX_ACCESS_BURST_CNF:
l1ctl_tx_rach_conf(trxcon->l2if, (const struct trxcon_param_tx_access_burst_cnf *)data);
l1ctl_tx_rach_conf(trxcon, (const struct trxcon_param_tx_access_burst_cnf *)data);
break;
case TRXCON_EV_SET_CCCH_MODE_REQ:
{
@ -388,7 +386,7 @@ static void trxcon_st_bcch_ccch_action(struct osmo_fsm_inst *fi,
break;
}
case TRXCON_EV_RX_DATA_IND:
l1ctl_tx_dt_ind(trxcon->l2if, (const struct trxcon_param_rx_data_ind *)data);
l1ctl_tx_dt_ind(trxcon, (const struct trxcon_param_rx_data_ind *)data);
break;
default:
OSMO_ASSERT(0);
@ -405,7 +403,7 @@ static void trxcon_st_dedicated_action(struct osmo_fsm_inst *fi,
handle_tx_access_burst_req(fi, data);
break;
case TRXCON_EV_TX_ACCESS_BURST_CNF:
l1ctl_tx_rach_conf(trxcon->l2if, (const struct trxcon_param_tx_access_burst_cnf *)data);
l1ctl_tx_rach_conf(trxcon, (const struct trxcon_param_tx_access_burst_cnf *)data);
break;
case TRXCON_EV_DEDICATED_RELEASE_REQ:
l1sched_reset(trxcon->sched, false);
@ -495,10 +493,10 @@ static void trxcon_st_dedicated_action(struct osmo_fsm_inst *fi,
break;
}
case TRXCON_EV_TX_DATA_CNF:
l1ctl_tx_dt_conf(trxcon->l2if, (const struct trxcon_param_tx_data_cnf *)data);
l1ctl_tx_dt_conf(trxcon, (const struct trxcon_param_tx_data_cnf *)data);
break;
case TRXCON_EV_RX_DATA_IND:
l1ctl_tx_dt_ind(trxcon->l2if, (const struct trxcon_param_rx_data_ind *)data);
l1ctl_tx_dt_ind(trxcon, (const struct trxcon_param_rx_data_ind *)data);
break;
default:
OSMO_ASSERT(0);
@ -515,7 +513,7 @@ static void trxcon_st_packet_data_action(struct osmo_fsm_inst *fi,
handle_tx_access_burst_req(fi, data);
break;
case TRXCON_EV_TX_ACCESS_BURST_CNF:
l1ctl_tx_rach_conf(trxcon->l2if, (const struct trxcon_param_tx_access_burst_cnf *)data);
l1ctl_tx_rach_conf(trxcon, (const struct trxcon_param_tx_access_burst_cnf *)data);
break;
case TRXCON_EV_RX_DATA_IND:
{
@ -548,13 +546,8 @@ static void trxcon_fsm_pre_term_cb(struct osmo_fsm_inst *fi,
if (trxcon->sched != NULL)
l1sched_free(trxcon->sched);
/* Close active connections */
if (trxcon->l2if != NULL) {
/* Avoid use-after-free: both *fi and *trxcon are children of
* the L2IF (L1CTL connection), so we need to re-parent *fi
* to NULL before calling l1ctl_client_conn_close(). */
talloc_steal(NULL, fi);
l1ctl_client_conn_close(trxcon->l2if);
}
if (trxcon->l2if != NULL)
trxcon_l1ctl_close(trxcon);
if (trxcon->phyif != NULL)
phyif_close(trxcon->phyif);

View File

@ -336,6 +336,29 @@ int l1sched_handle_data_cnf(struct l1sched_lchan_state *lchan,
return rc;
}
void trxcon_l1ctl_close(struct trxcon_inst *trxcon)
{
/* Avoid use-after-free: both *fi and *trxcon are children of
* the L2IF (L1CTL connection), so we need to re-parent *fi
* to NULL before calling l1ctl_client_conn_close(). */
talloc_steal(NULL, trxcon->fi);
l1ctl_client_conn_close(trxcon->l2if);
}
int trxcon_l1ctl_send(struct trxcon_inst *trxcon, struct msgb *msg)
{
struct l1ctl_client *l1c = trxcon->l2if;
return l1ctl_client_send(l1c, msg);
}
static int l1ctl_rx_cb(struct l1ctl_client *l1c, struct msgb *msg)
{
struct trxcon_inst *trxcon = l1c->priv;
return trxcon_l1ctl_receive(trxcon, msg);
}
static void l1ctl_conn_accept_cb(struct l1ctl_client *l1c)
{
struct trxcon_inst *trxcon;
@ -347,7 +370,7 @@ static void l1ctl_conn_accept_cb(struct l1ctl_client *l1c)
}
l1c->log_prefix = talloc_strdup(l1c, trxcon->log_prefix);
l1c->priv = trxcon->fi;
l1c->priv = trxcon;
trxcon->l2if = l1c;
const struct trx_if_params phyif_params = {
@ -372,12 +395,12 @@ static void l1ctl_conn_accept_cb(struct l1ctl_client *l1c)
static void l1ctl_conn_close_cb(struct l1ctl_client *l1c)
{
struct osmo_fsm_inst *fi = l1c->priv;
struct trxcon_inst *trxcon = l1c->priv;
if (fi == NULL)
if (trxcon == NULL || trxcon->fi == NULL)
return;
osmo_fsm_inst_dispatch(fi, TRXCON_EV_L2IF_FAILURE, NULL);
osmo_fsm_inst_dispatch(trxcon->fi, TRXCON_EV_L2IF_FAILURE, NULL);
}
static void print_usage(const char *app)