From b5c00f5587d7e01393e9ca7024a80cea2b2f6e7f Mon Sep 17 00:00:00 2001 From: Holger Freyther Date: Wed, 22 Apr 2009 22:08:07 +0000 Subject: [PATCH] [misdn] Add option to automatically release layer2 on exit Patch by Andreas Eversberg to automatically release layer2 on exit of the application. Made the naming of the variables consistent (only release_l2 and not both release_l2 and l2_release). --- include/openbsc/e1_input.h | 2 +- include/openbsc/misdn.h | 2 +- src/bsc_hack.c | 10 ++++++++-- src/e1_config.c | 4 ++-- src/input/misdn.c | 15 ++++++++++++--- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/include/openbsc/e1_input.h b/include/openbsc/e1_input.h index b717c6106..db565bfb4 100644 --- a/include/openbsc/e1_input.h +++ b/include/openbsc/e1_input.h @@ -145,7 +145,7 @@ void e1_set_pcap_fd(int fd); struct subch_mux *e1inp_get_mux(u_int8_t e1_nr, u_int8_t ts_nr); /* e1_config.c */ -int e1_config(struct gsm_bts *bts, int cardnr); +int e1_config(struct gsm_bts *bts, int cardnr, int release_l2); int ia_config(struct gsm_bts *bts); int ipaccess_setup(struct e1inp_line *line); diff --git a/include/openbsc/misdn.h b/include/openbsc/misdn.h index b6bd391ad..d3631e794 100644 --- a/include/openbsc/misdn.h +++ b/include/openbsc/misdn.h @@ -22,7 +22,7 @@ #include "e1_input.h" -int mi_setup(int cardnr, struct e1inp_line *line); +int mi_setup(int cardnr, struct e1inp_line *line, int release_l2); int _abis_nm_sendmsg(struct msgb *msg); #endif diff --git a/src/bsc_hack.c b/src/bsc_hack.c index 38fa5c45f..10667295b 100644 --- a/src/bsc_hack.c +++ b/src/bsc_hack.c @@ -56,6 +56,7 @@ static int MNC = 1; static int LAC = 1; static int ARFCN = HARDCODED_ARFCN; static int cardnr = 0; +static int release_l2 = 0; static enum gsm_bts_type BTS_TYPE = GSM_BTS_TYPE_BS11; static const char *database_name = "hlr.sqlite3"; @@ -927,7 +928,7 @@ static int bootstrap_network(void) /* E1 mISDN input setup */ if (BTS_TYPE == GSM_BTS_TYPE_BS11) - return e1_config(bts, cardnr); + return e1_config(bts, cardnr, release_l2); else return ia_config(bts); } @@ -965,6 +966,7 @@ static void print_help() printf(" -p --pcap file The filename of the pcap file\n"); printf(" -t --bts-type type The BTS type (bs11, nanobts900, nanobts1800)\n"); printf(" -C --cardnr number For bs11 select E1 card number other than 0\n"); + printf(" -R --release-l2 Releases mISDN layer 2 after exit, to unload driver.\n"); printf(" -h --help this text\n"); } @@ -986,10 +988,11 @@ static void handle_options(int argc, char** argv) {"arfcn", 1, 0, 'f'}, {"bts-type", 1, 0, 't'}, {"cardnr", 1, 0, 'C'}, + {"release-l2", 0, 0, 'R'}, {0, 0, 0, 0} }; - c = getopt_long(argc, argv, "hc:n:d:sar:p:f:t:C:L:", + c = getopt_long(argc, argv, "hc:n:d:sar:p:f:t:C:RL:", long_options, &option_index); if (c == -1) break; @@ -1035,6 +1038,9 @@ static void handle_options(int argc, char** argv) case 'C': cardnr = atoi(optarg); break; + case 'R': + release_l2 = 1; + break; default: /* ignore */ break; diff --git a/src/e1_config.c b/src/e1_config.c index 080ca4f92..a52b0375d 100644 --- a/src/e1_config.c +++ b/src/e1_config.c @@ -15,7 +15,7 @@ #define TEI_RSL 1 /* do some compiled-in configuration for our BTS/E1 setup */ -int e1_config(struct gsm_bts *bts, int cardnr) +int e1_config(struct gsm_bts *bts, int cardnr, int release_l2) { struct e1inp_line *line; struct e1inp_ts *sign_ts; @@ -68,7 +68,7 @@ int e1_config(struct gsm_bts *bts, int cardnr) bts->trx[1].rsl_link = rsl_link; #endif - return mi_setup(cardnr, line); + return mi_setup(cardnr, line, release_l2); } /* do some compiled-in configuration for our BTS/E1 setup */ diff --git a/src/input/misdn.c b/src/input/misdn.c index 245df50d8..a5860a0ca 100644 --- a/src/input/misdn.c +++ b/src/input/misdn.c @@ -350,7 +350,7 @@ struct e1inp_driver misdn_driver = { .want_write = ts_want_write, }; -static int mi_e1_setup(struct e1inp_line *line) +static int mi_e1_setup(struct e1inp_line *line, int release_l2) { struct mi_e1_handle *e1h = line->driver_data; int ts, ret; @@ -416,6 +416,15 @@ static int mi_e1_setup(struct e1inp_line *line) return -EIO; } + if (e1i_ts->type == E1INP_TS_TYPE_SIGN && release_l2) { + int clean = 1; + ret = ioctl(bfd->fd, IMCLEAR_L2, &clean); + if (ret < 0) { + fprintf(stderr, "could not send IOCTL IMCLEAN_L2 %s\n", strerror(errno)); + return -EIO; + } + } + /* FIXME: only activate B-Channels once we start to * use them to conserve CPU power */ if (e1i_ts->type == E1INP_TS_TYPE_TRAU) @@ -432,7 +441,7 @@ static int mi_e1_setup(struct e1inp_line *line) return 0; } -int mi_setup(int cardnr, struct e1inp_line *line) +int mi_setup(int cardnr, struct e1inp_line *line, int release_l2) { struct mi_e1_handle *e1h; int sk, ret, cnt; @@ -486,7 +495,7 @@ int mi_setup(int cardnr, struct e1inp_line *line) fprintf(stdout, " name: %s\n", devinfo.name); #endif - ret = mi_e1_setup(line); + ret = mi_e1_setup(line, release_l2); if (ret) return ret;