aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2018-10-02 21:22:18 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2018-10-03 12:10:43 +0200
commitb5cfc6b019dbb31ceb52e8747c422bbaa0f60ac9 (patch)
treec0a8033aadbc820fea0f5db2eafc04dd16849e23
parentdd95eb64800945a564d45ccb8d74fcca6daf568e (diff)
ipaccess: Simplify handling of ipaccess e1line ts
Handle encoding specifics behind a macro to make code easier to understand and follow. Change-Id: Ibf251673bff95b7a0b066b19ef4dc6c0f94fff6b
-rw-r--r--include/osmocom/abis/e1_input.h2
-rw-r--r--src/input/ipaccess.c40
-rw-r--r--tests/e1inp_ipa_bsc_test.c8
-rw-r--r--tests/e1inp_ipa_bts_test.c8
4 files changed, 36 insertions, 22 deletions
diff --git a/include/osmocom/abis/e1_input.h b/include/osmocom/abis/e1_input.h
index 79455e1..f9b4850 100644
--- a/include/osmocom/abis/e1_input.h
+++ b/include/osmocom/abis/e1_input.h
@@ -201,6 +201,8 @@ struct e1inp_line {
struct e1inp_driver *driver;
void *driver_data;
};
+#define e1inp_line_ipa_oml_ts(line) (&line->ts[0])
+#define e1inp_line_ipa_rsl_ts(line, trx_id) (&line->ts[1 + (trx_id)])
/* SS_L_INPUT signals */
enum e1inp_signal_input {
diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c
index f8e8e09..8c02996 100644
--- a/src/input/ipaccess.c
+++ b/src/input/ipaccess.c
@@ -62,8 +62,11 @@ static void *tall_ipa_ctx;
static int ipaccess_drop(struct osmo_fd *bfd, struct e1inp_line *line)
{
int ret = 1;
- unsigned int ts_nr = bfd->priv_nr;
- struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
+ struct e1inp_ts *e1i_ts;
+ if (bfd->priv_nr == E1INP_SIGN_OML)
+ e1i_ts = e1inp_line_ipa_oml_ts(line);
+ else
+ e1i_ts = e1inp_line_ipa_rsl_ts(line, bfd->priv_nr - E1INP_SIGN_RSL);
/* Error case: we did not see any ID_RESP yet for this socket. */
if (bfd->fd != -1) {
@@ -185,7 +188,7 @@ static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg,
* this RSL link, attach it to this socket. */
bfd->data = new_line = sign_link->ts->line;
e1inp_line_get(new_line);
- ts = &new_line->ts[E1INP_SIGN_RSL+unit_data.trx_id-1];
+ ts = e1inp_line_ipa_rsl_ts(new_line, unit_data.trx_id);
newbfd = &ts->driver.ipaccess.fd;
/* get rid of our old temporary bfd */
@@ -223,12 +226,17 @@ static int handle_ts1_read(struct osmo_fd *bfd)
{
struct e1inp_line *line = bfd->data;
unsigned int ts_nr = bfd->priv_nr;
- struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
+ struct e1inp_ts *e1i_ts;
struct e1inp_sign_link *link;
struct ipaccess_head *hh;
struct msgb *msg = NULL;
int ret, rc;
+ if (bfd->priv_nr == E1INP_SIGN_OML)
+ e1i_ts = e1inp_line_ipa_oml_ts(line);
+ else
+ e1i_ts = e1inp_line_ipa_rsl_ts(line, bfd->priv_nr - E1INP_SIGN_RSL);
+
ret = ipa_msg_recv_buffered(bfd->fd, &msg, &e1i_ts->pending_msg);
if (ret < 0) {
if (ret == -EAGAIN)
@@ -312,11 +320,16 @@ static void timeout_ts1_write(void *data)
static int __handle_ts1_write(struct osmo_fd *bfd, struct e1inp_line *line)
{
unsigned int ts_nr = bfd->priv_nr;
- struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
+ struct e1inp_ts *e1i_ts;
struct e1inp_sign_link *sign_link;
struct msgb *msg;
int ret;
+ if (bfd->priv_nr == E1INP_SIGN_OML)
+ e1i_ts = e1inp_line_ipa_oml_ts(line);
+ else
+ e1i_ts = e1inp_line_ipa_rsl_ts(line, bfd->priv_nr - E1INP_SIGN_RSL);
+
bfd->when &= ~BSC_FD_WRITE;
/* get the next msg for this timeslot */
@@ -454,7 +467,6 @@ static void update_fd_settings(struct e1inp_line *line, int fd)
static int ipaccess_bsc_oml_cb(struct ipa_server_link *link, int fd)
{
int ret;
- int idx = 0;
int i;
struct e1inp_line *line;
struct e1inp_ts *e1i_ts;
@@ -468,13 +480,13 @@ static int ipaccess_bsc_oml_cb(struct ipa_server_link *link, int fd)
}
/* create virrtual E1 timeslots for signalling */
- e1inp_ts_config_sign(&line->ts[E1INP_SIGN_OML-1], line);
+ e1inp_ts_config_sign(e1inp_line_ipa_oml_ts(line), line);
/* initialize the fds */
for (i = 0; i < ARRAY_SIZE(line->ts); ++i)
line->ts[i].driver.ipaccess.fd.fd = -1;
- e1i_ts = &line->ts[idx];
+ e1i_ts = e1inp_line_ipa_oml_ts(line);
bfd = &e1i_ts->driver.ipaccess.fd;
osmo_fd_setup(bfd, fd, BSC_FD_READ, ipaccess_fd_cb, line, E1INP_SIGN_OML);
@@ -524,9 +536,9 @@ static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd)
/* we need this to initialize this in case to avoid crashes in case
* that the socket is closed before we've seen an ID_RESP. */
- e1inp_ts_config_sign(&line->ts[E1INP_SIGN_OML-1], line);
+ e1inp_ts_config_sign(e1inp_line_ipa_oml_ts(line), line);
- e1i_ts = &line->ts[E1INP_SIGN_RSL-1];
+ e1i_ts = e1inp_line_ipa_rsl_ts(line, 0);
bfd = &e1i_ts->driver.ipaccess.fd;
osmo_fd_setup(bfd, fd, BSC_FD_READ, ipaccess_fd_cb, line, E1INP_SIGN_RSL);
@@ -763,9 +775,9 @@ static int ipaccess_bts_read_cb(struct ipa_client_conn *link, struct msgb *msg)
msgb_free(msg);
return ret;
} else if (link->port == IPA_TCP_PORT_OML)
- e1i_ts = &link->line->ts[0];
+ e1i_ts = e1inp_line_ipa_oml_ts(link->line);
else if (link->port == IPA_TCP_PORT_RSL)
- e1i_ts = &link->line->ts[link->ofd->priv_nr-1];
+ e1i_ts = e1inp_line_ipa_rsl_ts(link->line, link->ofd->priv_nr - E1INP_SIGN_RSL);
OSMO_ASSERT(e1i_ts != NULL);
@@ -870,7 +882,7 @@ static int ipaccess_line_update(struct e1inp_line *line)
IPA_TCP_PORT_OML);
link = ipa_client_conn_create(tall_ipa_ctx,
- &line->ts[E1INP_SIGN_OML-1],
+ e1inp_line_ipa_oml_ts(line),
E1INP_SIGN_OML,
line->ops->cfg.ipa.addr,
IPA_TCP_PORT_OML,
@@ -920,7 +932,7 @@ int e1inp_ipa_bts_rsl_connect_n(struct e1inp_line *line,
}
rsl_link = ipa_client_conn_create(tall_ipa_ctx,
- &line->ts[E1INP_SIGN_RSL+trx_nr-1],
+ e1inp_line_ipa_rsl_ts(line, trx_nr),
E1INP_SIGN_RSL+trx_nr,
rem_addr, rem_port,
ipaccess_bts_updown_cb,
diff --git a/tests/e1inp_ipa_bsc_test.c b/tests/e1inp_ipa_bsc_test.c
index 9064d0a..a7317f8 100644
--- a/tests/e1inp_ipa_bsc_test.c
+++ b/tests/e1inp_ipa_bsc_test.c
@@ -30,9 +30,9 @@ sign_link_up(void *dev, struct e1inp_line *line, enum e1inp_sign_type type)
switch(type) {
case E1INP_SIGN_OML:
LOGP(DBSCTEST, LOGL_NOTICE, "OML link up request received.\n");
- e1inp_ts_config_sign(&line->ts[E1INP_SIGN_OML - 1], line);
+ e1inp_ts_config_sign(e1inp_line_ipa_oml_ts(line), line);
sign_link = oml_sign_link =
- e1inp_sign_link_create(&line->ts[E1INP_SIGN_OML - 1],
+ e1inp_sign_link_create(e1inp_line_ipa_oml_ts(line),
E1INP_SIGN_OML, NULL, 255, 0);
break;
case E1INP_SIGN_RSL:
@@ -45,10 +45,10 @@ sign_link_up(void *dev, struct e1inp_line *line, enum e1inp_sign_type type)
/* We have to use the same line that the OML link. */
oml_line = oml_sign_link->ts->line;
- e1inp_ts_config_sign(&oml_line->ts[E1INP_SIGN_RSL - 1],
+ e1inp_ts_config_sign(e1inp_line_ipa_rsl_ts(oml_line, 0),
oml_line);
sign_link = rsl_sign_link =
- e1inp_sign_link_create(&oml_line->ts[E1INP_SIGN_RSL - 1],
+ e1inp_sign_link_create(e1inp_line_ipa_rsl_ts(oml_line, 0),
E1INP_SIGN_RSL, NULL, 0, 0);
break;
default:
diff --git a/tests/e1inp_ipa_bts_test.c b/tests/e1inp_ipa_bts_test.c
index 48a5c59..10fe0e8 100644
--- a/tests/e1inp_ipa_bts_test.c
+++ b/tests/e1inp_ipa_bts_test.c
@@ -51,9 +51,9 @@ sign_link_up(void *unit, struct e1inp_line *line, enum e1inp_sign_type type)
case E1INP_SIGN_OML:
LOGP(DBTSTEST, LOGL_NOTICE, "OML link up request received.\n");
- e1inp_ts_config_sign(&line->ts[E1INP_SIGN_OML - 1], line);
+ e1inp_ts_config_sign(e1inp_line_ipa_oml_ts(line), line);
sign_link = oml_sign_link =
- e1inp_sign_link_create(&line->ts[E1INP_SIGN_OML - 1],
+ e1inp_sign_link_create(e1inp_line_ipa_oml_ts(line),
E1INP_SIGN_OML, NULL, 255, 0);
if (!oml_sign_link) {
LOGP(DBTSTEST, LOGL_ERROR,
@@ -76,10 +76,10 @@ sign_link_up(void *unit, struct e1inp_line *line, enum e1inp_sign_type type)
case E1INP_SIGN_RSL:
LOGP(DBTSTEST, LOGL_NOTICE, "RSL link up request received.\n");
- e1inp_ts_config_sign(&line->ts[E1INP_SIGN_RSL - 1], line);
+ e1inp_ts_config_sign(e1inp_line_ipa_rsl_ts(line, 0), line);
sign_link = rsl_sign_link =
- e1inp_sign_link_create(&line->ts[E1INP_SIGN_RSL - 1],
+ e1inp_sign_link_create(e1inp_line_ipa_rsl_ts(line, 0),
E1INP_SIGN_RSL, NULL, 0, 0);
if (!rsl_sign_link) {
LOGP(DBTSTEST, LOGL_ERROR,