si: Fix range1024 encoding

f0 is currently set to arfcns[0] in range_enc_determine_range(),
while GSM 04.08 requires f0 to be ARFCN 0 in range1024 encoding.

This patch modifies range_enc_determine_range() to force f0 to be 0
if this encoding is used. This way the case distinction in
range_enc_filter_arfcns() is not longer necessary.

Sponsored-by: On-Waves ehf
diff --git a/openbsc/tests/gsm0408/gsm0408_test.c b/openbsc/tests/gsm0408/gsm0408_test.c
index 3a6bbdd..894eb0f 100644
--- a/openbsc/tests/gsm0408/gsm0408_test.c
+++ b/openbsc/tests/gsm0408/gsm0408_test.c
@@ -152,12 +152,12 @@
 	arfcns_used = arfcns_num;
 	memmove(arfcns, orig_arfcns, sizeof(arfcns));
 
-	f0 = arfcns[0];
+	f0 = range == ARFCN_RANGE_1024 ? 0 : arfcns[0];
 	/*
 	 * Manipulate the ARFCN list according to the rules in J4 depending
 	 * on the selected range.
 	 */
-	arfcns_used = range_enc_filter_arfcns(range, arfcns, arfcns_used,
+	arfcns_used = range_enc_filter_arfcns(arfcns, arfcns_used,
 					      f0, &f0_included);
 
 	memset(w, 0, sizeof(w));
@@ -354,28 +354,28 @@
 
 	/* check that the arfcn is taken out. f0_included is only set for Range1024 */
 	f0_included = 24;
-	res = range_enc_filter_arfcns(ARFCN_RANGE_512, arfcns, ARRAY_SIZE(arfcns),
-			arfcns[0], &f0_included);
-	VERIFY(res, ==, ARRAY_SIZE(arfcns) - 1);
-	VERIFY(f0_included, ==, 0);
-	for (i = 0; i < res; ++i)
-		VERIFY(arfcns[i], ==, ((i+2) * 2) - (2+1));
-
-	/* check with range1024 */
-	for (i = 0; i < ARRAY_SIZE(arfcns); ++i)
-		arfcns[i] = (i + 1) * 2;
-	res = range_enc_filter_arfcns(ARFCN_RANGE_1024, arfcns, ARRAY_SIZE(arfcns),
+	res = range_enc_filter_arfcns(arfcns, ARRAY_SIZE(arfcns),
 			arfcns[0], &f0_included);
 	VERIFY(res, ==, ARRAY_SIZE(arfcns) - 1);
 	VERIFY(f0_included, ==, 1);
 	for (i = 0; i < res; ++i)
-		VERIFY(arfcns[i], ==, ((i + 2) * 2) - 1);
+		VERIFY(arfcns[i], ==, ((i+2) * 2) - (2+1));
 
-	/* check with range1024, not included */
+	/* check with range1024, ARFCN 0 is included */
+	for (i = 0; i < ARRAY_SIZE(arfcns); ++i)
+		arfcns[i] = i * 2;
+	res = range_enc_filter_arfcns(arfcns, ARRAY_SIZE(arfcns),
+			0, &f0_included);
+	VERIFY(res, ==, ARRAY_SIZE(arfcns) - 1);
+	VERIFY(f0_included, ==, 1);
+	for (i = 0; i < res; ++i)
+		VERIFY(arfcns[i], ==, (i + 1) * 2 - 1);
+
+	/* check with range1024, ARFCN 0 not included */
 	for (i = 0; i < ARRAY_SIZE(arfcns); ++i)
 		arfcns[i] = (i + 1) * 2;
-	res = range_enc_filter_arfcns(ARFCN_RANGE_1024, arfcns, ARRAY_SIZE(arfcns),
-			11, &f0_included);
+	res = range_enc_filter_arfcns(arfcns, ARRAY_SIZE(arfcns),
+			0, &f0_included);
 	VERIFY(res, ==, ARRAY_SIZE(arfcns));
 	VERIFY(f0_included, ==, 0);
 	for (i = 0; i < res; ++i)