Make si2q scheduling optional

Previously si2quater SI messages were always scheduled. Check for
neighbor configuration and only schedule si2q when necessary. Add
corresponding unit test.

Change-Id: Ibe997803ffb894133fd4d838410fe735791d414f
Fixes: OS#1727
Reviewed-on: https://gerrit.osmocom.org/81
Tested-by: Jenkins Builder
Reviewed-by: Holger Freyther <holger@freyther.de>
diff --git a/openbsc/tests/gsm0408/gsm0408_test.c b/openbsc/tests/gsm0408/gsm0408_test.c
index 9262667..7acc93f 100644
--- a/openbsc/tests/gsm0408/gsm0408_test.c
+++ b/openbsc/tests/gsm0408/gsm0408_test.c
@@ -21,7 +21,7 @@
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
-
+#include <stdbool.h>
 #include <arpa/inet.h>
 
 #include <openbsc/gsm_04_08.h>
@@ -95,9 +95,15 @@
 
 static inline void gen(struct gsm_bts *bts)
 {
+	bts->si_valid = 0;
+	bts->si_valid |= (1 << SYSINFO_TYPE_2quater);
+	/* should be no-op as entire buffer is filled with padding: */
+	memset(bts->si_buf[SYSINFO_TYPE_2quater], 0xAE, GSM_MACBLOCK_LEN);
 	int r = gsm_generate_si(bts, SYSINFO_TYPE_2quater);
+	bool v = bts->si_valid & (1 << SYSINFO_TYPE_2quater);
 	if (r > 0)
-		printf("generated SI2quater: [%d] %s\n", r,
+		printf("generated %s SI2quater: [%d] %s\n",
+		       v ? "valid" : "invalid", r,
 		       osmo_hexdump(bts->si_buf[SYSINFO_TYPE_2quater], r));
 	else
 		printf("failed to generate SI2quater: %s\n", strerror(-r));
@@ -123,6 +129,9 @@
 		exit(1);
 	bts = gsm_bts_alloc(network);
 
+	/* first generate invalid SI as no UARFCN added */
+	gen(bts);
+	/* subsequent calls should produce valid SI if there's enough memory */
 	_bts_uarfcn_add(bts, 1982, 13, 1);
 	_bts_uarfcn_add(bts, 1982, 44, 0);
 	_bts_uarfcn_add(bts, 1982, 61, 1);
@@ -155,7 +164,9 @@
 	bts->si_common.si2quater_neigh_list.thresh_hi = 5;
 
 	osmo_earfcn_init(&bts->si_common.si2quater_neigh_list);
-
+	/* first generate invalid SI as no EARFCN added */
+	gen(bts);
+	/* subsequent calls should produce valid SI if there's enough memory */
 	add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1917, 1);
 	gen(bts);