make point codes configurable by SCCP address book

In the vty config, use the SCCP address book to configure the local and remote
SCCP addresses. Add VTY commands to set the remote SCCP addresses by name,
derive the ss7 instance from these addresses:

  cs7 instance 1
   point-code 0.23.0
   sccp-address msc
    point-code 0.0.1
   sccp-address sgsn
    point-code 0.0.2
  hnbgw
   iucs
    remote-addr msc
   iups
    remote-addr sgsn

Enforce that both IuCS and IuPS use the same ss7 instance. In the future, we
may add the feature to use two separate instances.

Depends: libosmo-sccp I75c67d289693f1c2a049ac61cf2b2097d6e5687d,
         Ie1aedd7894acd69ddc887cd65a8a0df4b888838c,
         I85b46269dbe7909e52873ace3f720f6292a4516c

Change-Id: I33a7ba11eb7c2d9a5dc74d10fb0cf04bf664477b
diff --git a/src/hnbgw_vty.c b/src/hnbgw_vty.c
index 59871da..ddea578 100644
--- a/src/hnbgw_vty.c
+++ b/src/hnbgw_vty.c
@@ -90,7 +90,6 @@
 		vty->node = HNBGW_NODE;
 		vty->index = NULL;
 		break;
-	default:
 	case HNBGW_NODE:
 		vty->node = CONFIG_NODE;
 		vty->index = NULL;
@@ -99,6 +98,9 @@
 		vty->node = ENABLE_NODE;
 		vty->index = NULL;
 		break;
+	default:
+		osmo_ss7_vty_go_parent(vty);
+		break;
 	}
 
 	return vty->node;
@@ -182,37 +184,23 @@
 	return CMD_SUCCESS;
 }
 
-DEFUN(cfg_hnbgw_iucs_remote_ip, cfg_hnbgw_iucs_remote_ip_cmd, "remote-ip A.B.C.D",
-      "Address to establish IuCS core network link to\n"
-      "Remote IuCS IP address (default: " HNBGW_IUCS_REMOTE_IP_DEFAULT ")")
+DEFUN(cfg_hnbgw_iucs_remote_addr,
+      cfg_hnbgw_iucs_remote_addr_cmd,
+      "remote-addr NAME",
+      "SCCP address to send IuCS to (MSC)\n"
+      "SCCP address book entry name (see 'cs7-instance')\n")
 {
-	talloc_free((void*)g_hnb_gw->config.iucs_remote_ip);
-	g_hnb_gw->config.iucs_remote_ip = talloc_strdup(tall_hnb_ctx, argv[0]);
+	g_hnb_gw->config.iucs_remote_addr_name = talloc_strdup(g_hnb_gw, argv[0]);
 	return CMD_SUCCESS;
 }
 
-DEFUN(cfg_hnbgw_iucs_remote_port, cfg_hnbgw_iucs_remote_port_cmd, "remote-port <1-65535>",
-      "Remote port to establish IuCS core network link to\n"
-      "Remote IuCS port (default: 14001)")
+DEFUN(cfg_hnbgw_iups_remote_addr,
+      cfg_hnbgw_iups_remote_addr_cmd,
+      "remote-addr NAME",
+      "SCCP address to send IuPS to (SGSN)\n"
+      "SCCP address book entry name (see 'cs7-instance')\n")
 {
-	g_hnb_gw->config.iucs_remote_port = atoi(argv[0]);
-	return CMD_SUCCESS;
-}
-
-DEFUN(cfg_hnbgw_iups_remote_ip, cfg_hnbgw_iups_remote_ip_cmd, "remote-ip A.B.C.D",
-      "Address to establish IuPS core network link to\n"
-      "Remote IuPS IP address (default: " HNBGW_IUPS_REMOTE_IP_DEFAULT ")")
-{
-	talloc_free((void*)g_hnb_gw->config.iups_remote_ip);
-	g_hnb_gw->config.iups_remote_ip = talloc_strdup(tall_hnb_ctx, argv[0]);
-	return CMD_SUCCESS;
-}
-
-DEFUN(cfg_hnbgw_iups_remote_port, cfg_hnbgw_iups_remote_port_cmd, "remote-port <1-65535>",
-      "Remote port to establish IuPS core network link to\n"
-      "Remote IuPS port (default: 14001)")
-{
-	g_hnb_gw->config.iups_remote_port = atoi(argv[0]);
+	g_hnb_gw->config.iups_remote_addr_name = talloc_strdup(g_hnb_gw, argv[0]);
 	return CMD_SUCCESS;
 }
 
@@ -248,15 +236,12 @@
 	const char *addr;
 	uint16_t port;
 
+	if (!g_hnb_gw->config.iucs_remote_addr_name)
+		return CMD_SUCCESS;
+
 	vty_out(vty, " iucs%s", VTY_NEWLINE);
-
-	addr = g_hnb_gw->config.iucs_remote_ip;
-	if (addr && (strcmp(addr, HNBGW_IUCS_REMOTE_IP_DEFAULT) != 0))
-		vty_out(vty, "  remote-ip %s%s", addr, VTY_NEWLINE);
-
-	port = g_hnb_gw->config.iucs_remote_port;
-	if (port && port != SUA_PORT)
-		vty_out(vty, "  remote-port %u%s", port, VTY_NEWLINE);
+	vty_out(vty, "  remote-addr %s%s", g_hnb_gw->config.iucs_remote_addr_name,
+		VTY_NEWLINE);
 
 	return CMD_SUCCESS;
 }
@@ -266,15 +251,12 @@
 	const char *addr;
 	uint16_t port;
 
+	if (!g_hnb_gw->config.iups_remote_addr_name)
+		return CMD_SUCCESS;
+
 	vty_out(vty, " iups%s", VTY_NEWLINE);
-
-	addr = g_hnb_gw->config.iups_remote_ip;
-	if (addr && (strcmp(addr, HNBGW_IUPS_REMOTE_IP_DEFAULT) != 0))
-		vty_out(vty, "  remote-ip %s%s", addr, VTY_NEWLINE);
-
-	port = g_hnb_gw->config.iups_remote_port;
-	if (port && port != SUA_PORT)
-		vty_out(vty, "  remote-port %u%s", port, VTY_NEWLINE);
+	vty_out(vty, "  remote-addr %s%s", g_hnb_gw->config.iups_remote_addr_name,
+		VTY_NEWLINE);
 
 	return CMD_SUCCESS;
 }
@@ -300,15 +282,13 @@
 	install_node(&iucs_node, config_write_hnbgw_iucs);
 	vty_install_default(IUCS_NODE);
 
-	install_element(IUCS_NODE, &cfg_hnbgw_iucs_remote_ip_cmd);
-	install_element(IUCS_NODE, &cfg_hnbgw_iucs_remote_port_cmd);
+	install_element(IUCS_NODE, &cfg_hnbgw_iucs_remote_addr_cmd);
 
 	install_element(HNBGW_NODE, &cfg_hnbgw_iups_cmd);
 	install_node(&iups_node, config_write_hnbgw_iups);
 	vty_install_default(IUPS_NODE);
 
-	install_element(IUPS_NODE, &cfg_hnbgw_iups_remote_ip_cmd);
-	install_element(IUPS_NODE, &cfg_hnbgw_iups_remote_port_cmd);
+	install_element(IUPS_NODE, &cfg_hnbgw_iups_remote_addr_cmd);
 
 	install_element_ve(&show_hnb_cmd);
 	install_element_ve(&show_ue_cmd);