abis_nm: Introduce & use a nm_is_running function to test gsm_nm_state

This returns true if the gsm_nm_state can be considered 'running'.
Note that we also accept availability==0xff (which is a code for
no value) because according to 12.21 it is perfectly valid.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
diff --git a/openbsc/src/chan_alloc.c b/openbsc/src/chan_alloc.c
index 48f87f2..ab26fca 100644
--- a/openbsc/src/chan_alloc.c
+++ b/openbsc/src/chan_alloc.c
@@ -39,8 +39,7 @@
 {
 	/* FIXME: How does this behave for BS-11 ? */
 	if (is_ipaccess_bts(ts->trx->bts)) {
-		if (ts->nm_state.operational != NM_OPSTATE_ENABLED ||
-		    ts->nm_state.availability != NM_AVSTATE_OK)
+		if (!nm_is_running(&ts->nm_state))
 			return 0;
 	}
 
@@ -51,10 +50,8 @@
 {
 	/* FIXME: How does this behave for BS-11 ? */
 	if (is_ipaccess_bts(trx->bts)) {
-		if (trx->nm_state.operational != NM_OPSTATE_ENABLED ||
-		    trx->nm_state.availability != NM_AVSTATE_OK ||
-		    trx->bb_transc.nm_state.operational != NM_OPSTATE_ENABLED ||
-		    trx->bb_transc.nm_state.availability != NM_AVSTATE_OK)
+		if (!nm_is_running(&trx->nm_state) ||
+		    !nm_is_running(&trx->bb_transc.nm_state))
 			return 0;
 	}
 
@@ -380,8 +377,8 @@
 		int i;
 
 		/* skip administratively deactivated tranxsceivers */
-		if (trx->nm_state.availability != NM_AVSTATE_OK ||
-		    trx->bb_transc.nm_state.availability != NM_AVSTATE_OK)
+		if (!nm_is_running(&trx->nm_state) ||
+		    !nm_is_running(&trx->bb_transc.nm_state))
 			continue;
 
 		for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
@@ -390,7 +387,7 @@
 			int j;
 
 			/* skip administratively deactivated timeslots */
-			if (ts->nm_state.availability != NM_AVSTATE_OK)
+			if (!nm_is_running(&ts->nm_state))
 				continue;
 
 			for (j = 0; j < subslots_per_pchan[ts->pchan]; j++) {