gprs_ns2: nsvc: react on STATUS PDUs with cause code NSVC UNKNOWN/NSVC BLOCKED

A STATUS PDU with cause code NSVC UNKNOWN/NSVC BLOCKED informs the other
side about a state mismatch between the side.

Change-Id: Ib6a2424f3027a30f14ef0a9fc2230e6aae9a2a04
diff --git a/src/gb/gprs_ns2_vc_fsm.c b/src/gb/gprs_ns2_vc_fsm.c
index 989a00c..03a355b 100644
--- a/src/gb/gprs_ns2_vc_fsm.c
+++ b/src/gb/gprs_ns2_vc_fsm.c
@@ -616,7 +616,9 @@
 {
 	struct gprs_ns2_vc_priv *priv = fi->priv;
 	struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi);
+	struct tlv_parsed *tp;
 	struct msgb *msg = data;
+	uint8_t cause;
 
 	switch (event) {
 	case GPRS_NS2_EV_REQ_OM_RESET:
@@ -707,6 +709,27 @@
 		if (fi->state == GPRS_NS2_ST_BLOCKED)
 			osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0);
 		break;
+	case GPRS_NS2_EV_RX_STATUS:
+		tp = data;
+		cause = tlvp_val8(tp, NS_IE_CAUSE, 0);
+		switch (cause) {
+		case NS_CAUSE_NSVC_BLOCKED:
+			if (fi->state != GPRS_NS2_ST_BLOCKED) {
+				LOG_NS_SIGNAL(priv->nsvc, "Rx", NS_PDUT_STATUS, LOGL_ERROR, ": remote side reported blocked state.\n");
+				priv->initiate_block = false;
+				priv->accept_unitdata = false;
+				osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0);
+			}
+			break;
+		case NS_CAUSE_NSVC_UNKNOWN:
+			if (fi->state != GPRS_NS2_ST_RESET && fi->state != GPRS_NS2_ST_UNCONFIGURED) {
+				LOG_NS_SIGNAL(priv->nsvc, "Rx", NS_PDUT_STATUS, LOGL_ERROR, ": remote side reported unknown nsvc.\n");
+				osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0);
+			}
+			break;
+		}
+
+		break;
 	}
 }
 
@@ -726,6 +749,7 @@
 			       S(GPRS_NS2_EV_RX_RESET) |
 			       S(GPRS_NS2_EV_RX_ALIVE) |
 			       S(GPRS_NS2_EV_RX_ALIVE_ACK) |
+			       S(GPRS_NS2_EV_RX_STATUS) |
 			       S(GPRS_NS2_EV_REQ_FORCE_UNCONFIGURED) |
 			       S(GPRS_NS2_EV_REQ_OM_RESET) |
 			       S(GPRS_NS2_EV_REQ_OM_BLOCK) |
@@ -894,6 +918,9 @@
 		/* UNITDATA have to free msg because it might send the msg layer upwards */
 		osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_UNITDATA, msg);
 		return 0;
+	case NS_PDUT_STATUS:
+		osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_STATUS, tp);
+		break;
 	default:
 		LOGPFSML(fi, LOGL_ERROR, "NSEI=%u Rx unknown NS PDU type %s\n", nsvc->nse->nsei,
 			 get_value_string(gprs_ns_pdu_strings, nsh->pdu_type));