Vadim Yanitskiy has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/12582 )

Change subject: trxcon/trx_if: refactor trx_if_open()
......................................................................

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
---
M src/host/trxcon/trx_if.c
M src/host/trxcon/trx_if.h
M src/host/trxcon/trxcon.c
3 files changed, 32 insertions(+), 34 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved



diff --git a/src/host/trxcon/trx_if.c b/src/host/trxcon/trx_if.c
index bff73cc..4c10da6 100644
--- a/src/host/trxcon/trx_if.c
+++ b/src/host/trxcon/trx_if.c
@@ -626,58 +626,55 @@
        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 d551252..0b3f36f 100644
--- a/src/host/trxcon/trx_if.h
+++ b/src/host/trxcon/trx_if.h
@@ -52,8 +52,8 @@
        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 874f893..501d0c7 100644
--- a/src/host/trxcon/trxcon.c
+++ b/src/host/trxcon/trxcon.c
@@ -284,9 +284,10 @@
                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 */

--
To view, visit https://gerrit.osmocom.org/12582
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I39b24afee2f09d6a6c500cfc26ac45f206589c5c
Gerrit-Change-Number: 12582
Gerrit-PatchSet: 2
Gerrit-Owner: Vadim Yanitskiy <axilira...@gmail.com>
Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Vadim Yanitskiy <axilira...@gmail.com>

Reply via email to