Add the option to write the communication on the D Channel to a pcap file

When using ISDN as network type and using a fake LAPD encapsulation
wireshark should be able to recognize some bits if dump.

Append a dummy LAPD header. It is not clear to me if the Control field
of the LAPD frame is part of the msg or if we need to add it as well.

TODO:
    - Do the same for the B Channel
    - Write out time
    - Check if more of the LAPD frame needs to be prepended. The
      information from the mISDNhead comes into mind. Maybe it makes
      sense to start a custom wireshark mISDN dissector.
diff --git a/src/bsc_hack.c b/src/bsc_hack.c
index 9fa0157..c59024a 100644
--- a/src/bsc_hack.c
+++ b/src/bsc_hack.c
@@ -27,6 +27,8 @@
 #include <string.h>
 #include <errno.h>
 #include <signal.h>
+#include <fcntl.h>
+#include <sys/stat.h>
 
 #define _GNU_SOURCE
 #include <getopt.h>
@@ -689,6 +691,20 @@
 	return 0;
 }
 
+
+static void create_pcap_file(char *file)
+{
+	mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
+	int fd = open(file, O_WRONLY|O_TRUNC|O_CREAT, mode);
+
+	if (fd < 0) {
+		perror("Failed to open file for pcap");
+		return;
+	}
+
+	mi_set_pcap_fd(fd);
+}
+
 static void print_usage()
 {
 	printf("Usage: bsc_hack\n");
@@ -704,6 +720,7 @@
 	printf("  -l --database db-name The database to use\n");
 	printf("  -a --authorize-everyone Allow everyone into the network.\n");
 	printf("  -r --reject-cause number The reject cause for LOCATION UPDATING REJECT.\n");
+	printf("  -p --pcap file  The filename of the pcap file\n");
 	printf("  -h --help this text\n");
 }
 
@@ -720,10 +737,11 @@
 			{"database", 1, 0, 'l'},
 			{"authorize-everyone", 0, 0, 'a'},
 			{"reject-cause", 1, 0, 'r'},
+			{"pcap", 1, 0, 'p'},
 			{0, 0, 0, 0}
 		};
 
-		c = getopt_long(argc, argv, "hc:n:d:sar:",
+		c = getopt_long(argc, argv, "hc:n:d:sar:p:",
 				long_options, &option_index);
 		if (c == -1)
 			break;
@@ -754,6 +772,9 @@
 		case 'r':
 			gsm0408_set_reject_cause(atoi(optarg));
 			break;
+		case 'p':
+			create_pcap_file(optarg);
+			break;
 		default:
 			/* ignore */
 			break;