From b84968418172040f12dc150d770f9b06d6df335d Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 29 Jun 2011 20:42:14 +0200 Subject: deactivate RF + exit when the Abis link is gone The idea is that the BTS process is re-spawned from init/upstart/systemd --- include/osmo-bts/bts.h | 1 + include/osmo-bts/bts_model.h | 2 ++ src/common/abis.c | 8 ++++++++ src/common/bts.c | 21 +++++++++++++++++++++ src/osmo-bts-sysmo/bts_model.c | 9 +++++++++ src/osmo-bts-sysmo/l1_if.h | 1 + src/osmo-bts-sysmo/main.c | 6 +++--- 7 files changed, 45 insertions(+), 3 deletions(-) diff --git a/include/osmo-bts/bts.h b/include/osmo-bts/bts.h index 0d0a0b44..1a5a7fd6 100644 --- a/include/osmo-bts/bts.h +++ b/include/osmo-bts/bts.h @@ -6,6 +6,7 @@ extern void *tall_bts_ctx; int bts_init(struct gsm_bts *bts); +void bts_shutdown(struct gsm_bts *bts); struct gsm_bts *create_bts(uint8_t num_trx, char *id); int create_ms(struct gsm_bts_trx *trx, int maskc, uint8_t *maskv_tx, diff --git a/include/osmo-bts/bts_model.h b/include/osmo-bts/bts_model.h index e7a0d040..62c5c72b 100644 --- a/include/osmo-bts/bts_model.h +++ b/include/osmo-bts/bts_model.h @@ -31,4 +31,6 @@ int bts_model_rsl_chan_act(struct gsm_lchan *lchan, struct tlv_parsed *tp); int bts_model_rsl_chan_rel(struct gsm_lchan *lchan); int bts_model_rsl_deact_sacch(struct gsm_lchan *lchan); +int bts_model_trx_deact_rf(struct gsm_bts_trx *trx); + #endif diff --git a/src/common/abis.c b/src/common/abis.c index 79a9d4d0..c1e1c4f3 100644 --- a/src/common/abis.c +++ b/src/common/abis.c @@ -513,5 +513,13 @@ void abis_close(struct ipabis_link *link) if (osmo_timer_pending(&link->timer)) osmo_timer_del(&link->timer); + + /* for now, we simply terminate the program and re-spawn */ + if (link->bts) + bts_shutdown(link->bts); + else if (link->trx) + bts_shutdown(link->trx->bts); + else + exit(43); } diff --git a/src/common/bts.c b/src/common/bts.c index 02cb0fe1..19a3e430 100644 --- a/src/common/bts.c +++ b/src/common/bts.c @@ -56,6 +56,27 @@ int bts_init(struct gsm_bts *bts) return bts_model_init(bts); } +static void shutdown_timer_cb(void *data) +{ + exit(42); +} + +static struct osmo_timer_list shutdown_timer = { + .cb = &shutdown_timer_cb, +}; + +void bts_shutdown(struct gsm_bts *bts) +{ + struct gsm_bts_trx *trx; + + llist_for_each_entry(trx, &bts->trx_list, list) + bts_model_trx_deact_rf(trx); + + /* shedule a timer to make sure select loop logic can run again + * to dispatch any pending primitives */ + osmo_timer_schedule(&shutdown_timer, 3, 0); +} + #if 0 struct osmobts_lchan *lchan_by_channelnr(struct osmobts_trx *trx, uint8_t channelnr) diff --git a/src/osmo-bts-sysmo/bts_model.c b/src/osmo-bts-sysmo/bts_model.c index 7e9ffee2..ac4e2055 100644 --- a/src/osmo-bts-sysmo/bts_model.c +++ b/src/osmo-bts-sysmo/bts_model.c @@ -23,6 +23,8 @@ #include #include +#include "l1_if.h" + int bts_model_rsl_chan_act(struct gsm_lchan *lchan, struct tlv_parsed *tp) { uint8_t mode = *TLVP_VAL(tp, RSL_IE_CHAN_MODE); @@ -44,3 +46,10 @@ int bts_model_rsl_deact_sacch(struct gsm_lchan *lchan) { return lchan_deactivate_sacch(lchan); } + +int bts_model_trx_deact_rf(struct gsm_bts_trx *trx) +{ + struct femtol1_hdl *fl1 = trx_femtol1_hdl(trx); + + return l1if_activate_rf(fl1, 0); +} diff --git a/src/osmo-bts-sysmo/l1_if.h b/src/osmo-bts-sysmo/l1_if.h index 7dcae537..7268fe21 100644 --- a/src/osmo-bts-sysmo/l1_if.h +++ b/src/osmo-bts-sysmo/l1_if.h @@ -40,6 +40,7 @@ int l1if_req_compl(struct femtol1_hdl *fl1h, struct msgb *msg, struct femtol1_hdl *l1if_open(void *priv); int l1if_close(struct femtol1_hdl *hdl); int l1if_reset(struct femtol1_hdl *hdl); +int l1if_activate_rf(struct femtol1_hdl *hdl, int on); struct msgb *l1p_msgb_alloc(void); struct msgb *sysp_msgb_alloc(void); diff --git a/src/osmo-bts-sysmo/main.c b/src/osmo-bts-sysmo/main.c index e2afdf7a..bc4f916a 100644 --- a/src/osmo-bts-sysmo/main.c +++ b/src/osmo-bts-sysmo/main.c @@ -160,6 +160,8 @@ static void handle_options(int argc, char **argv) } } +static struct gsm_bts *bts; + static void signal_handler(int signal) { fprintf(stderr, "signal %u received\n", signal); @@ -167,8 +169,7 @@ static void signal_handler(int signal) switch (signal) { case SIGINT: //osmo_signal_dispatch(SS_GLOBAL, S_GLOBAL_SHUTDOWN, NULL); - sleep(3); - exit(0); + bts_shutdown(bts); break; case SIGABRT: case SIGUSR1: @@ -182,7 +183,6 @@ static void signal_handler(int signal) int main(int argc, char **argv) { - struct gsm_bts *bts; struct ipabis_link *link; void *tall_msgb_ctx; int rc; -- cgit v1.2.3