msc_a fsm: ignore state chg to same state

We sometimes see errors like

   libmsc/msc_a.c:361 msc_a(...){MSC_A_ST_RELEASING}: transition to state MSC_A_ST_RELEASING not permitted!

i.e. changing state to the state msc_a is already in.

Ignore re-entering the same state for most state changes. However, there is one
state change in msc_a where re-entering the MSC_A_ST_VALIDATE_L3 is necessary
to start the timeout.

Hence add msc_a_state_chg_always() and use that for re-entering
MSC_A_ST_VALIDATE_L3. Change msc_a_state_chg() to skip no-op state changes.

This should silence all no-op state change error messages for msc_a.

Related: OS#4169
Change-Id: I0c74c10b5fa7bbdd6ae3674926cc0393edf15a35
diff --git a/src/libmsc/msc_a.c b/src/libmsc/msc_a.c
index a082cb8..b414574 100644
--- a/src/libmsc/msc_a.c
+++ b/src/libmsc/msc_a.c
@@ -63,9 +63,15 @@
 /* Transition to a state, using the T timer defined in msc_a_fsm_timeouts.
  * The actual timeout value is in turn obtained from network->T_defs.
  * Assumes local variable fi exists. */
-#define msc_a_state_chg(msc_a, state) \
+#define msc_a_state_chg_always(msc_a, state) \
 	osmo_tdef_fsm_inst_state_chg((msc_a)->c.fi, state, msc_a_fsm_timeouts, (msc_a)->c.ran->tdefs, 5)
 
+/* Same as msc_a_state_chg_always() but ignore if the msc_a already is in the target state. */
+#define msc_a_state_chg(msc_a, STATE) do { \
+		if ((msc_a)->c.fi->state != STATE) \
+			msc_a_state_chg_always(msc_a, STATE); \
+	} while(0)
+
 struct gsm_network *msc_a_net(const struct msc_a *msc_a)
 {
 	return msub_net(msc_a->c.msub);
@@ -1036,7 +1042,7 @@
 	};
 	osmo_use_count_make_static_entries(&msc_a->use_count, msc_a->use_count_buf, ARRAY_SIZE(msc_a->use_count_buf));
 	/* Start timeout for first state */
-	msc_a_state_chg(msc_a, MSC_A_ST_VALIDATE_L3);
+	msc_a_state_chg_always(msc_a, MSC_A_ST_VALIDATE_L3);
 	return msc_a;
 }