[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).
diff --git a/src/input/misdn.c b/src/input/misdn.c
index 245df50..a5860a0 100644
--- a/src/input/misdn.c
+++ b/src/input/misdn.c
@@ -350,7 +350,7 @@
 	.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 @@
 			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 @@
 	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 @@
 	fprintf(stdout, "        name:           %s\n", devinfo.name);
 #endif
 
-	ret = mi_e1_setup(line);
+	ret = mi_e1_setup(line, release_l2);
 	if (ret)
 		return ret;