Revert "pdch_ul_controller: migrate from fn_cmp() to gsm0502_fncmp()"

In preparation for an 1.4.0 osmo-pcu release that should not require a
new libosmocore, revert this patch.

This reverts commit a155fe85de9151d26fdfad7a6593a95592ac9770.

Change-Id: I714efdc9c9403d3ff74e18df1629e2de6876e9d7
diff --git a/TODO-RELEASE b/TODO-RELEASE
index 73ad83b..cbfda24 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -7,4 +7,3 @@
 # If any interfaces have been added since the last public release: c:r:a + 1.
 # If any interfaces have been removed or changed since the last public release: c:r:0.
 #library        what            description / commit summary line
-libosmocore > 1.9.0		added gsm0502_fncmp()
diff --git a/src/pdch_ul_controller.c b/src/pdch_ul_controller.c
index 661957b..c0e26de 100644
--- a/src/pdch_ul_controller.c
+++ b/src/pdch_ul_controller.c
@@ -17,8 +17,6 @@
 #include <unistd.h>
 #include <talloc.h>
 
-#include <osmocom/gsm/gsm0502.h>
-
 #include "pdch_ul_controller.h"
 #include "bts.h"
 #include "sba.h"
@@ -45,6 +43,20 @@
 	{ 0, NULL }
 };
 
+#define GSM_MAX_FN_THRESH (GSM_MAX_FN >> 1)
+/* 0: equal, -1: fn1 BEFORE fn2, 1: fn1 AFTER fn2 */
+static inline int fn_cmp(uint32_t fn1, uint32_t fn2)
+{
+	if (fn1 == fn2)
+		return 0;
+	/* FN1 goes before FN2: */
+	if ((fn1 < fn2 && (fn2 - fn1) < GSM_MAX_FN_THRESH) ||
+	    (fn1 > fn2 && (fn1 - fn2) > GSM_MAX_FN_THRESH))
+		return -1;
+	/* FN1 goes after FN2: */
+	return 1;
+}
+
 struct pdch_ulc *pdch_ulc_alloc(struct gprs_rlcmac_pdch *pdch, void *ctx)
 {
 	struct pdch_ulc* ulc;
@@ -66,7 +78,7 @@
 
 	while (node) {
 		it = rb_entry(node, struct pdch_ulc_node, node);
-		res = gsm0502_fncmp(it->fn, fn);
+		res = fn_cmp(it->fn, fn);
 		if (res > 0) /* it->fn AFTER fn */
 			node = node->rb_left;
 		else if (res < 0) /* it->fn BEFORE fn */
@@ -155,7 +167,7 @@
 
 	for (node = rb_first(&ulc->tree_root); node; node = rb_next(node)) {
 		it = container_of(node, struct pdch_ulc_node, node);
-		res = gsm0502_fncmp(it->fn, check_fn);
+		res = fn_cmp(it->fn, check_fn);
 		if (res > 0) { /* it->fn AFTER check_fn */
 			/* Next reserved FN is passed check_fn, hence it means check_fn is free */
 			return check_fn;
@@ -191,7 +203,7 @@
 		it = container_of(*n, struct pdch_ulc_node, node);
 
 		parent = *n;
-		res = gsm0502_fncmp(item->fn, it->fn);
+		res = fn_cmp(item->fn, it->fn);
 		if (res < 0) { /* item->fn "BEFORE" it->fn */
 			n = &((*n)->rb_left);
 		} else if (res > 0) { /* item->fn "AFTER" it->fn */
@@ -293,7 +305,7 @@
 	struct rb_node *first;
 	while ((first = rb_first(&ulc->tree_root))) {
 		item = container_of(first, struct pdch_ulc_node, node);
-		res = gsm0502_fncmp(item->fn, fn);
+		res = fn_cmp(item->fn, fn);
 		if (res > 0) /* item->fn AFTER fn */
 			break;
 		if (res < 0) { /* item->fn BEFORE fn */