[system_information] Print more debugging about what's going on
diff --git a/openbsc/src/bsc_init.c b/openbsc/src/bsc_init.c
index ef68ef9..aed0dad 100644
--- a/openbsc/src/bsc_init.c
+++ b/openbsc/src/bsc_init.c
@@ -684,25 +684,31 @@
 	}
 #ifdef GPRS
 	rc = gsm_generate_si(si_tmp, trx->bts, RSL_SYSTEM_INFO_13);
-	if (rc < 0)
+	if (rc < 0) {
+		i = 13;
 		goto err_out;
+	}
 	rsl_bcch_info(trx, RSL_SYSTEM_INFO_13, si_tmp, rc);
 #endif
 	rc = gsm_generate_si(si_tmp, trx->bts, 5);
-	if (rc < 0)
+	if (rc < 0) {
+		i = 5;
 		goto err_out;
+	}
 	rsl_sacch_filling(trx, RSL_SYSTEM_INFO_5, si_tmp, rc);
 
 	rc = gsm_generate_si(si_tmp, trx->bts, 6);
-	if (rc < 0)
+	if (rc < 0) {
+		i = 6;
 		goto err_out;
+	}
 	rsl_sacch_filling(trx, RSL_SYSTEM_INFO_6, si_tmp, rc);
 
 	return 0;
 err_out:
-	fprintf(stderr, "Cannot generate SI for BTS %u, most likely "
+	fprintf(stderr, "Cannot generate SI %u for BTS %u, most likely "
 		"a problem with neighbor cell list generation\n",
-		trx->bts->nr);
+		i, trx->bts->nr);
 	return rc;
 }
 
diff --git a/openbsc/src/system_information.c b/openbsc/src/system_information.c
index 2d4ba20..644abb4 100644
--- a/openbsc/src/system_information.c
+++ b/openbsc/src/system_information.c
@@ -32,6 +32,7 @@
 #include <openbsc/abis_rsl.h>
 #include <openbsc/rest_octets.h>
 #include <openbsc/bitvec.h>
+#include <openbsc/debug.h>
 
 #define GSM48_CELL_CHAN_DESC_SIZE	16
 #define GSM_MACBLOCK_LEN 		23
@@ -73,10 +74,14 @@
 	if (arfcn == min_arfcn)
 		return 0;
 
-	if (arfcn < min_arfcn)
+	if (arfcn < min_arfcn) {
+		DEBUGP(DRR, "arfcn(%u) < min(%u)\n", arfcn, min_arfcn);
 		return -EINVAL;
-	if (arfcn > min_arfcn + 111)
+	}
+	if (arfcn > min_arfcn + 111) {
+		DEBUGP(DRR, "arfcn(%u) > min(%u) + 111\n", arfcn, min_arfcn);
 		return -EINVAL;
+	}
 
 	bitno = (arfcn - min_arfcn);
 	byte = bitno / 8;
@@ -121,17 +126,21 @@
 		}
 	}
 
-	if ((max - min) > 111)
+	if ((max - min) > 111) {
+		DEBUGP(DRR, "min_arfcn=%u, max_arfcn=%u, distance > 111\n", min, max);
 		return -EINVAL;
+	}
 
 	chan_list[0] |= (min >> 9) & 1;
 	chan_list[1] = (min >> 1);
 	chan_list[2] = (min & 1) << 7;
 
 	for (i = 0; i < bv->data_len*8; i++) {
-		rc = freq_list_bmrel_set_arfcn(chan_list, i);
-		if (rc < 0)
-			return rc;
+		if (bitvec_get_bit_pos(bv, i)) {
+			rc = freq_list_bmrel_set_arfcn(chan_list, i);
+			if (rc < 0)
+				return rc;
+		}
 	}
 
 	return 0;