Hi Gus, I hope the following two changes (see attachment) will solve the problem. They are already included in current libosmo-abis.git master.
-- - Harald Welte <[email protected]> http://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6)
>From 14078eaffe37689061ea92963bb0a1da67fb9638 Mon Sep 17 00:00:00 2001 From: Harald Welte <[email protected]> Date: Wed, 24 Aug 2011 09:45:11 +0200 Subject: [PATCH 1/2] LAPD: Add function to release/free a LAPD instance --- include/osmocom/abis/lapd.h | 1 + src/input/lapd.c | 7 +++++++ 2 files changed, 8 insertions(+), 0 deletions(-) diff --git a/include/osmocom/abis/lapd.h b/include/osmocom/abis/lapd.h index dd22028..92dc2c3 100644 --- a/include/osmocom/abis/lapd.h +++ b/include/osmocom/abis/lapd.h @@ -48,6 +48,7 @@ struct lapd_instance *lapd_instance_alloc(int network_side, void (*tx_cb)(uint8_t *data, int len, void *cbdata), void *cbdata); +void lapd_instance_free(struct lapd_instance *li); /* Start a (user-side) SAP for the specified TEI/SAPI on the LAPD instance */ int lapd_sap_start(struct lapd_instance *li, uint8_t tei, uint8_t sapi); diff --git a/src/input/lapd.c b/src/input/lapd.c index 0287e14..d94af58 100644 --- a/src/input/lapd.c +++ b/src/input/lapd.c @@ -730,3 +730,10 @@ struct lapd_instance *lapd_instance_alloc(int network_side, return li; } + +void lapd_instance_free(struct lapd_instance *li) +{ + /* tei and sapis are allocated hierarchically of the lapd + * instance, so one free is sufficient here */ + talloc_free(li); +} -- 1.7.5.4
>From cfc9f1f7cc199d2d61e27f0a0b76c4e170435ec6 Mon Sep 17 00:00:00 2001 From: Harald Welte <[email protected]> Date: Wed, 24 Aug 2011 09:45:36 +0200 Subject: [PATCH 2/2] DAHDI: Make sure dahdi_e1_setup() can be called multiple times In case we have multiple BTS attached to the same E1 line, the e1inp_driver::line_update() function will be called multiple times, and we need to make sure this is handled gracefully. --- src/input/dahdi.c | 27 ++++++++++++++++++++++++--- 1 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/input/dahdi.c b/src/input/dahdi.c index a4dbd03..66bf53f 100644 --- a/src/input/dahdi.c +++ b/src/input/dahdi.c @@ -393,6 +393,10 @@ static int dahdi_e1_setup(struct e1inp_line *line) struct osmo_fd *bfd = &e1i_ts->driver.dahdi.fd; int dev_nr; + /* unregister FD if it was already registered */ + if (bfd->list.next && bfd->list.next != LLIST_POISON1) + osmo_fd_unregister(bfd); + /* DAHDI device names/numbers just keep incrementing * even over multiple boards. So TS1 of the second * board will be 32 */ @@ -405,10 +409,20 @@ static int dahdi_e1_setup(struct e1inp_line *line) switch (e1i_ts->type) { case E1INP_TS_TYPE_NONE: + /* close/release LAPD instance, if any */ + if (e1i_ts->lapd) { + lapd_instance_free(e1i_ts->lapd); + e1i_ts->lapd = NULL; + } + if (bfd->fd) { + close(bfd->fd); + bfd->fd = 0; + } continue; break; case E1INP_TS_TYPE_SIGN: - bfd->fd = open(openstr, O_RDWR | O_NONBLOCK); + if (!bfd->fd) + bfd->fd = open(openstr, O_RDWR | O_NONBLOCK); if (bfd->fd == -1) { fprintf(stderr, "%s could not open %s %s\n", __func__, openstr, strerror(errno)); @@ -416,10 +430,17 @@ static int dahdi_e1_setup(struct e1inp_line *line) } bfd->when = BSC_FD_READ | BSC_FD_EXCEPT; dahdi_set_bufinfo(bfd->fd, 1); - e1i_ts->lapd = lapd_instance_alloc(1, dahdi_write_msg, bfd); + if (!e1i_ts->lapd) + e1i_ts->lapd = lapd_instance_alloc(1, dahdi_write_msg, bfd); break; case E1INP_TS_TYPE_TRAU: - bfd->fd = open(openstr, O_RDWR | O_NONBLOCK); + /* close/release LAPD instance, if any */ + if (e1i_ts->lapd) { + lapd_instance_free(e1i_ts->lapd); + e1i_ts->lapd = NULL; + } + if (!bfd->fd) + bfd->fd = open(openstr, O_RDWR | O_NONBLOCK); if (bfd->fd == -1) { fprintf(stderr, "%s could not open %s %s\n", __func__, openstr, strerror(errno)); -- 1.7.5.4
