Change in osmocom-bb[master]: trxcon: abstract out trx_if.c from struct trxcon_inst
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/30029 ) Change subject: trxcon: abstract out trx_if.c from struct trxcon_inst ...................................................................... trxcon: abstract out trx_if.c from struct trxcon_inst The PHYIF implementation shall not have direct access to the struct trxcon_inst it belongs to. All communication shall be done via the abstract PHYIF interface (see <include/osmocom/bb/trxcon/phyif.h>). * Introduce struct trx_if_params containing all necessary params. * Make trx_if_open() accept a struct trx_if_params pointer. Change-Id: I1a97c4c783ab671636ca33700eca97dede2a4a09 Related: OS#5599 --- M src/host/trxcon/include/osmocom/bb/trxcon/trx_if.h M src/host/trxcon/src/trx_if.c M src/host/trxcon/src/trxcon.c 3 files changed, 47 insertions(+), 31 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/29/30029/1 diff --git a/src/host/trxcon/include/osmocom/bb/trxcon/trx_if.h b/src/host/trxcon/include/osmocom/bb/trxcon/trx_if.h index 9628f72..bfab0ad 100644 --- a/src/host/trxcon/include/osmocom/bb/trxcon/trx_if.h +++ b/src/host/trxcon/include/osmocom/bb/trxcon/trx_if.h @@ -10,9 +10,6 @@ #define TRXC_BUF_SIZE 1024 #define TRXD_BUF_SIZE 512 -/* Forward declaration to avoid mutual include */ -struct trxcon_inst; - enum trx_fsm_states { TRX_STATE_OFFLINE = 0, TRX_STATE_IDLE, @@ -21,9 +18,6 @@ }; struct trx_instance { - /* trxcon instance we belong to */ - struct trxcon_inst *trxcon; - struct osmo_fd trx_ofd_ctrl; struct osmo_fd trx_ofd_data; @@ -38,6 +32,9 @@ /* GSM L1 specific */ uint16_t pm_band_arfcn_start; uint16_t pm_band_arfcn_stop; + + /* Some private data */ + void *priv; }; struct trx_ctrl_msg { @@ -48,8 +45,18 @@ int cmd_len; }; -struct trx_instance *trx_if_open(struct trxcon_inst *trxcon, - const char *local_host, const char *remote_host, uint16_t port); +struct trx_if_params { + const char *local_host; + const char *remote_host; + uint16_t base_port; + uint8_t instance; + + struct osmo_fsm_inst *parent_fi; + uint32_t parent_term_event; + void *priv; +}; + +struct trx_instance *trx_if_open(const struct trx_if_params *params); void trx_if_close(struct trx_instance *trx); int trx_if_handle_phyif_burst_req(struct trx_instance *trx, const struct phyif_burst_req *br); diff --git a/src/host/trxcon/src/trx_if.c b/src/host/trxcon/src/trx_if.c index 4074ba8..928ad5d 100644 --- a/src/host/trxcon/src/trx_if.c +++ b/src/host/trxcon/src/trx_if.c @@ -40,7 +40,6 @@ #include <osmocom/gsm/gsm_utils.h> -#include <osmocom/bb/trxcon/trxcon.h> #include <osmocom/bb/trxcon/trx_if.h> #include <osmocom/bb/trxcon/logging.h> @@ -740,29 +739,31 @@ } /* Init TRX interface (TRXC, TRXD sockets and FSM) */ -struct trx_instance *trx_if_open(struct trxcon_inst *trxcon, - const char *local_host, const char *remote_host, - uint16_t base_port) +struct trx_instance *trx_if_open(const struct trx_if_params *params) { - const unsigned int offset = trxcon->id * 2; + const unsigned int offset = params->instance * 2; struct trx_instance *trx; struct osmo_fsm_inst *fi; int rc; - LOGPFSML(trxcon->fi, LOGL_NOTICE, "Init transceiver interface " - "(%s:%u/%u)\n", remote_host, base_port, trxcon->id); + LOGPFSML(params->parent_fi, LOGL_NOTICE, + "Init transceiver interface (%s:%u/%u)\n", + params->remote_host, params->base_port, + params->instance); /* Allocate a new dedicated state machine */ - fi = osmo_fsm_inst_alloc_child(&trx_fsm, trxcon->fi, TRXCON_EV_PHYIF_FAILURE); + fi = osmo_fsm_inst_alloc_child(&trx_fsm, params->parent_fi, + params->parent_term_event); if (fi == NULL) { - LOGPFSML(trxcon->fi, LOGL_ERROR, "Failed to allocate an instance " - "of FSM '%s'\n", trx_fsm.name); + LOGPFSML(params->parent_fi, LOGL_ERROR, + "Failed to allocate an instance of FSM '%s'\n", + trx_fsm.name); return NULL; } trx = talloc_zero(fi, struct trx_instance); if (!trx) { - LOGPFSML(trxcon->fi, LOGL_ERROR, "Failed to allocate memory\n"); + LOGPFSML(params->parent_fi, LOGL_ERROR, "Failed to allocate memory\n"); osmo_fsm_inst_free(fi); return NULL; } @@ -772,27 +773,27 @@ /* Open sockets */ rc = trx_udp_open(trx, &trx->trx_ofd_ctrl, /* TRXC */ - local_host, base_port + 101 + offset, - remote_host, base_port + 1 + offset, + params->local_host, params->base_port + 101 + offset, + params->remote_host, params->base_port + 1 + offset, trx_ctrl_read_cb); if (rc < 0) goto udp_error; rc = trx_udp_open(trx, &trx->trx_ofd_data, /* TRXD */ - local_host, base_port + 102 + offset, - remote_host, base_port + 2 + offset, + params->local_host, params->base_port + 102 + offset, + params->remote_host, params->base_port + 2 + offset, trx_data_rx_cb); if (rc < 0) goto udp_error; - trx->trxcon = trxcon; + trx->priv = params->priv; fi->priv = trx; trx->fi = fi; return trx; udp_error: - LOGPFSML(trx->fi, LOGL_ERROR, "Couldn't establish UDP connection\n"); + LOGPFSML(params->parent_fi, LOGL_ERROR, "Couldn't establish UDP connection\n"); osmo_fsm_inst_free(trx->fi); return NULL; } diff --git a/src/host/trxcon/src/trxcon.c b/src/host/trxcon/src/trxcon.c index 2ea2c40..306a8fe 100644 --- a/src/host/trxcon/src/trxcon.c +++ b/src/host/trxcon/src/trxcon.c @@ -149,7 +149,7 @@ int phyif_handle_burst_ind(void *phyif, const struct phyif_burst_ind *bi) { struct trx_instance *trx = phyif; - struct trxcon_inst *trxcon = trx->trxcon; + struct trxcon_inst *trxcon = trx->priv; const struct l1sched_meas_set meas = { .fn = bi->fn, .toa256 = bi->toa256, @@ -180,7 +180,7 @@ int phyif_handle_rsp(void *phyif, const struct phyif_rsp *rsp) { struct trx_instance *trx = phyif; - struct trxcon_inst *trxcon = trx->trxcon; + struct trxcon_inst *trxcon = trx->priv; switch (rsp->type) { case PHYIF_CMDT_MEASURE: @@ -356,11 +356,19 @@ /* Logging context to be used by both l1ctl and l1sched modules */ trxcon->log_prefix = talloc_asprintf(trxcon, "%s: ", osmo_fsm_inst_name(fi)); + const struct trx_if_params phyif_params = { + .local_host = app_data.trx_bind_ip, + .remote_host = app_data.trx_remote_ip, + .base_port = app_data.trx_base_port, + .instance = trxcon->id, + + .parent_fi = trxcon->fi, + .parent_term_event = TRXCON_EV_PHYIF_FAILURE, + .priv = trxcon, + }; + /* Init transceiver interface */ - trxcon->phyif = trx_if_open(trxcon, - app_data.trx_bind_ip, - app_data.trx_remote_ip, - app_data.trx_base_port); + trxcon->phyif = trx_if_open(&phyif_params); if (trxcon->phyif == NULL) { trxcon_inst_free(trxcon); return NULL; -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30029 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: I1a97c4c783ab671636ca33700eca97dede2a4a09 Gerrit-Change-Number: 30029 Gerrit-PatchSet: 1 Gerrit-Owner: fixeria <vyanitskiy@sysmocom.de> Gerrit-MessageType: newchange
participants (1)
-
fixeria