ns2: Add a VTY command to reset NSVC FSM

Mainly useful for testing so implemented as a hidden command

Change-Id: I83b9cd7381c25da0e8aa847038a2d422c8dd63cf
Related: SYS#5002
diff --git a/src/gb/gprs_ns2_vty.c b/src/gb/gprs_ns2_vty.c
index 65fe88e..63331b9 100644
--- a/src/gb/gprs_ns2_vty.c
+++ b/src/gb/gprs_ns2_vty.c
@@ -34,6 +34,7 @@
 
 #include <osmocom/core/msgb.h>
 #include <osmocom/core/byteswap.h>
+#include <osmocom/core/fsm.h>
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/select.h>
 #include <osmocom/core/rate_ctr.h>
@@ -354,6 +355,36 @@
 	return CMD_SUCCESS;
 }
 
+static int nsvc_force_unconf_cb(struct gprs_ns2_vc *nsvc, void *ctx)
+{
+	gprs_ns2_vc_force_unconfigured(nsvc);
+	return 0;
+}
+
+DEFUN_HIDDEN(nsvc_force_unconf, nsvc_force_unconf_cmd,
+	"nsvc nsei <0-65535> force-unconfigured",
+	"NS Virtual Connection\n"
+	"The NSEI\n"
+	"Reset the NSVCs back to initial state\n"
+	)
+{
+	struct gprs_ns2_inst *nsi = vty_nsi;
+	struct gprs_ns2_nse *nse;
+
+	uint16_t id = atoi(argv[0]);
+
+	nse = gprs_ns2_nse_by_nsei(nsi, id);
+	if (!nse) {
+		vty_out(vty, "Could not find NSE for NSEI %u%s", id, VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	/* Perform the operation for all nsvc */
+	gprs_ns2_nse_foreach_nsvc(nse, nsvc_force_unconf_cb, NULL);
+
+	return CMD_SUCCESS;
+}
+
 #define NSE_CMD_STR "Persistent NS Entity\n" "NS Entity ID (NSEI)\n"
 
 DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd,
@@ -699,6 +730,8 @@
 	install_lib_element_ve(&show_nse_cmd);
 	install_lib_element_ve(&logging_fltr_nsvc_cmd);
 
+	install_lib_element(ENABLE_NODE, &nsvc_force_unconf_cmd);
+
 	install_lib_element(CFG_LOG_NODE, &logging_fltr_nsvc_cmd);
 
 	install_lib_element(CONFIG_NODE, &cfg_ns_cmd);