[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).
This commit is contained in:
Holger Freyther 2009-04-22 22:08:07 +00:00
parent dda22c18b5
commit b5c00f5587
5 changed files with 24 additions and 9 deletions

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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 */

View File

@ -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;