[PATCH 4/4] Add filtering and additional information printing to cell_log.

Max Max.Suraev at fairwaves.ru
Thu Aug 29 15:50:09 UTC 2013


---
 src/host/layer23/src/misc/app_cell_log.c | 53 ++++++++++++++++++++++++++------
 src/host/layer23/src/misc/cell_log.c     | 52 +++++++++++++++++++++----------
 2 files changed, 78 insertions(+), 27 deletions(-)

diff --git a/src/host/layer23/src/misc/app_cell_log.c b/src/host/layer23/src/misc/app_cell_log.c
index a7f42c3..1f69c31 100644
--- a/src/host/layer23/src/misc/app_cell_log.c
+++ b/src/host/layer23/src/misc/app_cell_log.c
@@ -27,6 +27,7 @@
 
 #include <osmocom/bb/common/osmocom_data.h>
 #include <osmocom/bb/common/l1ctl.h>
+#include <osmocom/bb/common/networks.h>
 #include <osmocom/bb/common/l23_app.h>
 #include <osmocom/bb/common/logging.h>
 #include <osmocom/bb/common/gps.h>
@@ -45,6 +46,7 @@ extern uint16_t (*band_range)[][2];
 
 char *logname = "/var/log/osmocom.log";
 int RACH_MAX = 2;
+uint16_t MCC = 0, MNC = 0, QUIET_PRINT = 0, PRINT_XTRA = 0, SCAN_ONCE = 0;
 
 int _scan_work(struct osmocom_ms *ms)
 {
@@ -94,16 +96,21 @@ static int l23_cfg_supported()
 static int l23_getopt_options(struct option **options)
 {
 	static struct option opts [] = {
-		{"logfile", 1, 0, 'l'},
-		{"rach", 1, 0, 'r'},
-		{"no-rach", 1, 0, 'n'},
+		{"logfile", required_argument, NULL, 'l'},
+		{"rach", required_argument, NULL, 'r'},
+		{"no-rach", no_argument, NULL, 'n'},
 #ifdef _HAVE_GPSD
-		{"gpsd-host", 1, 0, 'g'},
-		{"gpsd-port", 1, 0, 'p'},
+		{"gpsd-host", required_argument, NULL, 'g'},
+		{"gpsd-port", required_argument, NULL, 'p'},
 #endif
-		{"gps", 1, 0, 'g'},
-		{"baud", 1, 0, 'b'},
-		{"arfcns", 1, 0, 'A'}
+		{"gps", required_argument, NULL, 'g'},
+		{"baud", required_argument, NULL, 'b'},
+		{"arfcns", required_argument, NULL, 'A'},
+		{"mcc", required_argument, NULL, 'c'},
+		{"mnc", required_argument, NULL, 'm'},
+		{"quiet", no_argument, NULL, 'q'},
+		{"extra", no_argument, NULL, 'x'},
+		{"once", no_argument, NULL, 'o'}
 	};
 
 	*options = opts;
@@ -162,7 +169,11 @@ static int l23_cfg_print_help()
 	printf("  -f --gps DEVICE	/dev/ttyACM0. GPS serial device.\n");
 	printf("  -b --baud BAUDRAT	The baud rate of the GPS device\n");
 	printf("  -A --arfcns ARFCNS    The list of arfcns to be monitored\n");
-
+	printf("  -c --mcc 000          The MCC to look for.\n");
+	printf("  -m --mnc 00           The MNC to look for.\n");
+	printf("  -q --quiet            Do not print additional information.\n");
+	printf("  -x --extra            Print additional info from SI.\n");
+	printf("  -o --once             Exit after first scan is complete.\n");
 	return 0;
 }
 
@@ -180,6 +191,15 @@ static int l23_cfg_handle(int c, const char *optarg)
 	case 'n':
 		RACH_MAX = 0;
 		break;
+	case 'q':
+		QUIET_PRINT = 1;
+		break;
+	case 'x':
+		PRINT_XTRA = 1;
+		break;
+	case 'o':
+		SCAN_ONCE = 1;
+		break;
 	case 'g':
 #ifdef _HAVE_GPSD
 		snprintf(g.gpsd_host, ARRAY_SIZE(g.gpsd_host), "%s", optarg);
@@ -224,6 +244,19 @@ static int l23_cfg_handle(int c, const char *optarg)
 		parse_band_range((char*)optarg);
 		printf("New frequencies range: %s\n", print_band_range(*band_range, buf, sizeof(buf)));
 		break;
+	case 'c':
+	        MCC = atoi(optarg);
+		if (GSM_INPUT_INVALID == MCC) MCC = 0;
+		else LOGP(DGPS, LOGL_INFO, "Target MCC is %s (%s)\n", gsm_print_mcc(MCC), gsm_get_mcc(MCC));
+		break;
+	case 'm':
+	        MNC = gsm_input_mnc(optarg);
+		if (GSM_INPUT_INVALID == MNC) MNC = 0;
+		if (0 != MCC)
+		    LOGP(DGPS, LOGL_INFO, "Target MNC is %s (%s)\n", gsm_print_mnc(MNC), gsm_get_mnc(MCC, MNC));
+		else
+		    LOGP(DGPS, LOGL_INFO, "Target MNC is %s\n", gsm_print_mnc(MNC));
+		break;
 	}
 	return 0;
 
@@ -234,7 +267,7 @@ cmd_line_error:
 
 static struct l23_app_info info = {
 	.copyright	= "Copyright (C) 2010 Andreas Eversberg\n",
-	.getopt_string	= "g:p:l:r:nf:b:A:",
+	.getopt_string	= "g:p:l:r:noqxf:b:A:c:m:",
 	.cfg_supported	= l23_cfg_supported,
 	.cfg_getopt_opt = l23_getopt_options,
 	.cfg_handle_opt	= l23_cfg_handle,
diff --git a/src/host/layer23/src/misc/cell_log.c b/src/host/layer23/src/misc/cell_log.c
index 7340dcb..8740965 100644
--- a/src/host/layer23/src/misc/cell_log.c
+++ b/src/host/layer23/src/misc/cell_log.c
@@ -37,6 +37,7 @@
 #include <osmocom/gsm/protocol/gsm_04_08.h>
 #include <osmocom/gsm/rsl.h>
 
+#include <osmocom/bb/common/l23_app.h>
 #include <osmocom/bb/common/l1ctl.h>
 #include <osmocom/bb/common/osmocom_data.h>
 #include <osmocom/bb/common/logging.h>
@@ -78,7 +79,7 @@ static struct pm_info {
 	int8_t rxlev_dbm;
 } pm[1024];
 
-static int started = 0;
+static int started = 0, measured = 0;
 static int state;
 static int8_t min_rxlev_dbm = MIN_RXLEV_DBM;
 static int sync_count;
@@ -89,7 +90,11 @@ static int rach_count;
 static FILE *logfp = NULL;
 extern char *logname;
 extern int RACH_MAX;
-
+extern uint16_t QUIET_PRINT;
+extern uint16_t PRINT_XTRA;
+extern uint16_t SCAN_ONCE;
+extern uint16_t MCC;
+extern uint16_t MNC;
 
 static struct gsm48_sysinfo sysinfo;
 
@@ -135,14 +140,17 @@ static void log_time(void)
 	LOGFILE("time %lu\n", now);
 }
 
-static void log_frame(char *tag, uint8_t *data)
+static void si_printer(void *priv, const char *fmt, ...)
 {
-	int i;
+    va_list a;
+    va_start(a, fmt);
+    fprintf(priv, fmt, a);
+    va_end(a);
+}
 
-	LOGFILE("%s", tag);
-	for (i = 0; i < 23; i++)
-		LOGFILE(" %02x", *data++);
-	LOGFILE("\n");
+static void log_frame(char *tag, uint8_t *data)
+{
+    LOGFILE("%s %s\n", tag, osmo_hexdump(data, 23));
 }
 
 static void log_pm(void)
@@ -183,6 +191,8 @@ static void log_sysinfo(void)
 	int8_t rxlev_dbm;
 	char ta_str[32] = "";
 
+	if (((0 != MCC) && (s->mcc != MCC)) || ((0 != MNC) && (s->mnc != MNC))) return;
+
 	if (log_si.ta != 0xff)
 		sprintf(ta_str, " TA=%d", log_si.ta);
 
@@ -198,20 +208,21 @@ static void log_sysinfo(void)
 	rxlev_dbm = meas->rxlev / meas->frames - 110;
 	LOGFILE("rxlev %d\n", rxlev_dbm);
 	if (s->si1)
-		log_frame("si1", s->si1_msg);
+	    log_frame("si1", s->si1_msg);
 	if (s->si2)
-		log_frame("si2", s->si2_msg);
+	    log_frame("si2", s->si2_msg);
 	if (s->si2bis)
-		log_frame("si2bis", s->si2b_msg);
+	    log_frame("si2bis", s->si2b_msg);
 	if (s->si2ter)
-		log_frame("si2ter", s->si2t_msg);
+	    log_frame("si2ter", s->si2t_msg);
 	if (s->si3)
-		log_frame("si3", s->si3_msg);
+	    log_frame("si3", s->si3_msg);
 	if (s->si4)
-		log_frame("si4", s->si4_msg);
+	    log_frame("si4", s->si4_msg);
 	if (log_si.ta != 0xff)
 		LOGFILE("ta %d\n", log_si.ta);
-
+	if (PRINT_XTRA)
+	    gsm48_sysinfo_dump_ext(s, s->arfcn, si_printer, logfp, NULL, 1, 0);
 	LOGFILE("\n");
 	LOGFLUSH();
 }
@@ -337,8 +348,10 @@ static void start_sync(void)
 		return;
 	}
 	pm[arfcn].flags |= INFO_FLG_SYNC;
-	LOGP(DSUM, LOGL_INFO, "Sync ARFCN %d (rxlev %d, %d syncs left)%s\n",
-		arfcn, pm[arfcn].rxlev_dbm, sync_count--, dist_str);
+	if (!QUIET_PRINT) {
+	    LOGP(DSUM, LOGL_INFO, "Sync ARFCN %d (rxlev %d, %d syncs left)%s\n",
+		 arfcn, pm[arfcn].rxlev_dbm, sync_count--, dist_str);
+	}
 	memset(&sysinfo, 0, sizeof(sysinfo));
 	sysinfo.arfcn = arfcn;
 	state = SCAN_STATE_SYNC;
@@ -351,12 +364,17 @@ static void start_pm(void)
 {
 	uint16_t from, to;
 
+	if (measured && SCAN_ONCE) {
+	    l23_app_exit(NULL);
+	    exit(0);
+	}
 	state = SCAN_STATE_PM;
 	from = (*band_range)[pm_index][0];
 	to = (*band_range)[pm_index][1];
 
 	if (from == 0 && to == 0) {
 		LOGP(DSUM, LOGL_INFO, "Measurement done\n");
+		measured = 1;
 		pm_gps_valid = g.enable && g.valid;
 		if (pm_gps_valid)
 			geo2space(&pm_gps_x, &pm_gps_y, &pm_gps_z,
-- 
1.8.1.2


--------------000206000400030101050401--




More information about the baseband-devel mailing list