diff options
author | Vadim Yanitskiy <axilirator@gmail.com> | 2019-01-17 11:03:48 +0700 |
---|---|---|
committer | Vadim Yanitskiy <axilirator@gmail.com> | 2019-01-17 11:03:48 +0700 |
commit | 382736448edd65fffc910489a464c63eed309922 (patch) | |
tree | b1cb85077b946f828180de8f2c9588c877769d5b /src/host | |
parent | 1b6be6fc24a4ffecbd3c87550561070b9bca1ffe (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')
-rw-r--r-- | src/host/trxcon/trx_if.c | 55 | ||||
-rw-r--r-- | src/host/trxcon/trx_if.h | 4 | ||||
-rw-r--r-- | src/host/trxcon/trxcon.c | 7 |
3 files changed, 32 insertions, 34 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 */ diff --git a/src/host/trxcon/trx_if.h b/src/host/trxcon/trx_if.h index d5512527..0b3f36f7 100644 --- a/src/host/trxcon/trx_if.h +++ b/src/host/trxcon/trx_if.h @@ -52,8 +52,8 @@ struct trx_ctrl_msg { int cmd_len; }; -int trx_if_open(struct trx_instance **trx, const char *local_host, - const char *remote_host, uint16_t port); +struct trx_instance *trx_if_open(void *tall_ctx, + const char *local_host, const char *remote_host, uint16_t port); void trx_if_flush_ctrl(struct trx_instance *trx); void trx_if_close(struct trx_instance *trx); diff --git a/src/host/trxcon/trxcon.c b/src/host/trxcon/trxcon.c index 874f893b..501d0c72 100644 --- a/src/host/trxcon/trxcon.c +++ b/src/host/trxcon/trxcon.c @@ -284,9 +284,10 @@ int main(int argc, char **argv) goto exit; /* Init transceiver interface */ - rc = trx_if_open(&app_data.trx, - app_data.trx_bind_ip, app_data.trx_remote_ip, app_data.trx_base_port); - if (rc) + app_data.trx = trx_if_open(tall_trx_ctx, + app_data.trx_bind_ip, app_data.trx_remote_ip, + app_data.trx_base_port); + if (!app_data.trx) goto exit; /* Bind L1CTL with TRX and vice versa */ |