summaryrefslogtreecommitdiffstats
path: root/src/host/trxcon/trx_if.c
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2019-01-17 11:03:48 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2019-01-17 11:03:48 +0700
commit382736448edd65fffc910489a464c63eed309922 (patch)
treeb1cb85077b946f828180de8f2c9588c877769d5b /src/host/trxcon/trx_if.c
parent1b6be6fc24a4ffecbd3c87550561070b9bca1ffe (diff)
trxcon/trx_if: refactor trx_if_open()
The main changes are: - return pointer to the allocated trx_instance or NULL, - extend debug message with TRX address and base port, - accept the talloc context as 'tall_ctx' argument, - rename goto label 'error' to 'udp_error', - rename argument 'port' to 'base_port'. Change-Id: I39b24afee2f09d6a6c500cfc26ac45f206589c5c
Diffstat (limited to 'src/host/trxcon/trx_if.c')
-rw-r--r--src/host/trxcon/trx_if.c55
1 files changed, 26 insertions, 29 deletions
diff --git a/src/host/trxcon/trx_if.c b/src/host/trxcon/trx_if.c
index bff73ccf..4c10da6c 100644
--- a/src/host/trxcon/trx_if.c
+++ b/src/host/trxcon/trx_if.c
@@ -626,58 +626,55 @@ int trx_if_tx_burst(struct trx_instance *trx, uint8_t tn, uint32_t fn,
return 0;
}
-/*
- * Open/close OsmoTRX connection
- */
-
-int trx_if_open(struct trx_instance **trx, const char *local_host,
- const char *remote_host, uint16_t port)
+/* Init TRX interface (TRXC, TRXD sockets and FSM) */
+struct trx_instance *trx_if_open(void *tall_ctx,
+ const char *local_host, const char *remote_host,
+ uint16_t base_port)
{
- struct trx_instance *trx_new;
+ struct trx_instance *trx;
int rc;
- LOGP(DTRX, LOGL_NOTICE, "Init transceiver interface\n");
+ LOGP(DTRX, LOGL_NOTICE, "Init transceiver interface "
+ "(%s:%u)\n", remote_host, base_port);
/* Try to allocate memory */
- trx_new = talloc_zero(tall_trx_ctx, struct trx_instance);
- if (!trx_new) {
+ trx = talloc_zero(tall_ctx, struct trx_instance);
+ if (!trx) {
LOGP(DTRX, LOGL_ERROR, "Failed to allocate memory\n");
- return -ENOMEM;
+ return NULL;
}
/* Allocate a new dedicated state machine */
- trx_new->fsm = osmo_fsm_inst_alloc(&trx_fsm, trx_new,
+ trx->fsm = osmo_fsm_inst_alloc(&trx_fsm, trx,
NULL, LOGL_DEBUG, "trx_interface");
- if (trx_new->fsm == NULL) {
+ if (trx->fsm == NULL) {
LOGP(DTRX, LOGL_ERROR, "Failed to allocate an instance "
"of FSM '%s'\n", trx_fsm.name);
- talloc_free(trx_new);
- return -ENOMEM;
+ talloc_free(trx);
+ return NULL;
}
/* Initialize CTRL queue */
- INIT_LLIST_HEAD(&trx_new->trx_ctrl_list);
+ INIT_LLIST_HEAD(&trx->trx_ctrl_list);
/* Open sockets */
- rc = trx_udp_open(trx_new, &trx_new->trx_ofd_ctrl, local_host,
- port + 101, remote_host, port + 1, trx_ctrl_read_cb);
+ rc = trx_udp_open(trx, &trx->trx_ofd_ctrl, local_host,
+ base_port + 101, remote_host, base_port + 1, trx_ctrl_read_cb);
if (rc < 0)
- goto error;
+ goto udp_error;
- rc = trx_udp_open(trx_new, &trx_new->trx_ofd_data, local_host,
- port + 102, remote_host, port + 2, trx_data_rx_cb);
+ rc = trx_udp_open(trx, &trx->trx_ofd_data, local_host,
+ base_port + 102, remote_host, base_port + 2, trx_data_rx_cb);
if (rc < 0)
- goto error;
+ goto udp_error;
- *trx = trx_new;
+ return trx;
- return 0;
-
-error:
+udp_error:
LOGP(DTRX, LOGL_ERROR, "Couldn't establish UDP connection\n");
- osmo_fsm_inst_free(trx_new->fsm);
- talloc_free(trx_new);
- return rc;
+ osmo_fsm_inst_free(trx->fsm);
+ talloc_free(trx);
+ return NULL;
}
/* Flush pending control messages */