Change in osmo-hnodeb[master]: Move existing vty code to its own vty.c/h file

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Tue Nov 2 12:00:31 UTC 2021


pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-hnodeb/+/25997 )

Change subject: Move existing vty code to its own vty.c/h file
......................................................................

Move existing vty code to its own vty.c/h file

Change-Id: I88107e9ed03ff8f807b57a3ea0d189fd70864861
---
M include/osmocom/hnodeb/Makefile.am
M include/osmocom/hnodeb/hnodeb.h
A include/osmocom/hnodeb/vty.h
M src/osmo-hnodeb/Makefile.am
M src/osmo-hnodeb/main.c
A src/osmo-hnodeb/vty.c
6 files changed, 195 insertions(+), 123 deletions(-)

Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, approved



diff --git a/include/osmocom/hnodeb/Makefile.am b/include/osmocom/hnodeb/Makefile.am
index 9f8963a..339f8a3 100644
--- a/include/osmocom/hnodeb/Makefile.am
+++ b/include/osmocom/hnodeb/Makefile.am
@@ -2,4 +2,5 @@
 	hnodeb.h \
 	ranap.h \
 	rua.h \
+	vty.h \
 	$(NULL)
diff --git a/include/osmocom/hnodeb/hnodeb.h b/include/osmocom/hnodeb/hnodeb.h
index ef11ab7..e36311e 100644
--- a/include/osmocom/hnodeb/hnodeb.h
+++ b/include/osmocom/hnodeb/hnodeb.h
@@ -19,6 +19,8 @@
  */
 #pragma once
 
+#include <asn1c/asn1helpers.h>
+
 #include <osmocom/core/select.h>
 #include <osmocom/core/linuxlist.h>
 #include <osmocom/core/write_queue.h>
@@ -101,4 +103,10 @@
 void hnb_nas_rx_dtap(struct hnb *hnb, void *data, int len);
 void hnb_rx_secmode_cmd(struct hnb *hnb, long ip_alg);
 
+int hnb_ue_register_tx(struct hnb *hnb, const char *imsi_str);
+void hnb_send_register_req(struct hnb *hnb);
+void hnb_send_deregister_req(struct hnb *hnb);
+struct msgb *gen_initue_lu(int is_ps, uint32_t conn_id, const char *imsi);
+
+extern void *tall_hnb_ctx;
 extern struct hnb g_hnb;
diff --git a/include/osmocom/hnodeb/vty.h b/include/osmocom/hnodeb/vty.h
new file mode 100644
index 0000000..7e3f29f
--- /dev/null
+++ b/include/osmocom/hnodeb/vty.h
@@ -0,0 +1,31 @@
+/* (C) 2015 by Daniel Willmann <dwillmann at sysmocom.de>
+ * (C) 2021 by sysmocom - s.f.m.c. GmbH <info at sysmocom.de>
+ * Author: Pau Espin Pedrol <pespin at sysmocom.de>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/lienses/>.
+ *
+ */
+
+#pragma once
+
+#include <osmocom/vty/vty.h>
+#include <osmocom/vty/buffer.h>
+#include <osmocom/vty/command.h>
+
+enum hnb_vty_nodes {
+	CHAN_NODE = _LAST_OSMOVTY_NODE,
+};
+
+void hnb_vty_init(void);
diff --git a/src/osmo-hnodeb/Makefile.am b/src/osmo-hnodeb/Makefile.am
index 9f09a0a..d1cd3ec 100644
--- a/src/osmo-hnodeb/Makefile.am
+++ b/src/osmo-hnodeb/Makefile.am
@@ -33,6 +33,7 @@
 	debug.c \
 	ranap.c \
 	rua.c \
+	vty.c \
 	$(NULL)
 
 osmo_hnodeb_LDADD = \
diff --git a/src/osmo-hnodeb/main.c b/src/osmo-hnodeb/main.c
index 9a2aaf9..ae9403d 100644
--- a/src/osmo-hnodeb/main.c
+++ b/src/osmo-hnodeb/main.c
@@ -54,7 +54,6 @@
 #include <osmocom/hnbap/hnbap_common.h>
 #include <osmocom/hnbap/hnbap_ies_defs.h>
 #include <osmocom/rua/rua_msg_factory.h>
-#include "asn1helpers.h"
 #include <osmocom/ranap/iu_helpers.h>
 
 #include <osmocom/ranap/ranap_msg_factory.h>
@@ -70,9 +69,10 @@
 
 #include <osmocom/hnodeb/rua.h>
 #include <osmocom/hnodeb/ranap.h>
+#include <osmocom/hnodeb/vty.h>
 #include <osmocom/hnodeb/hnodeb.h>
 
-static void *tall_hnb_ctx;
+void *tall_hnb_ctx;
 
 struct hnb g_hnb = {
 	.gw_addr = "127.0.0.1",
@@ -113,7 +113,7 @@
 }
 #endif
 
-static int hnb_ue_register_tx(struct hnb *hnb, const char *imsi_str)
+int hnb_ue_register_tx(struct hnb *hnb, const char *imsi_str)
 {
 	struct msgb *msg;
 	int rc, imsi_len;
@@ -649,7 +649,7 @@
 	return rc;
 }
 
-static void hnb_send_register_req(struct hnb *hnb)
+void hnb_send_register_req(struct hnb *hnb)
 {
 	HNBAP_HNBRegisterRequest_t request_out;
 	struct msgb *msg;
@@ -698,7 +698,7 @@
 	osmo_wqueue_enqueue(&hnb->wqueue, msg);
 }
 
-static void hnb_send_deregister_req(struct hnb *hnb)
+void hnb_send_deregister_req(struct hnb *hnb)
 {
 	struct msgb *msg;
 	int rc;
@@ -744,79 +744,8 @@
 	return rc;
 }
 
-#define HNBAP_STR	"HNBAP related commands\n"
-#define HNB_STR		"HomeNodeB commands\n"
-#define UE_STR		"User Equipment commands\n"
-#define RANAP_STR	"RANAP related commands\n"
-#define CSPS_STR	"Circuit Switched\n" "Packet Switched\n"
 
-DEFUN(hnb_register, hnb_register_cmd,
-	"hnbap hnb register", HNBAP_STR HNB_STR "Send HNB-REGISTER REQUEST")
-{
-	hnb_send_register_req(&g_hnb);
-
-	return CMD_SUCCESS;
-}
-
-DEFUN(hnb_deregister, hnb_deregister_cmd,
-	"hnbap hnb deregister", HNBAP_STR HNB_STR "Send HNB-DEREGISTER REQUEST")
-{
-	hnb_send_deregister_req(&g_hnb);
-
-	return CMD_SUCCESS;
-}
-
-DEFUN(ue_register, ue_register_cmd,
-	"hnbap ue register IMSI", HNBAP_STR UE_STR "Send UE-REGISTER REQUEST")
-{
-	hnb_ue_register_tx(&g_hnb, argv[0]);
-
-	return CMD_SUCCESS;
-}
-
-DEFUN(asn_dbg, asn_dbg_cmd,
-	"asn-debug (1|0)", "Enable or disable libasn1c debugging")
-{
-	asn_debug = atoi(argv[0]);
-
-	return CMD_SUCCESS;
-}
-
-DEFUN(ranap_reset, ranap_reset_cmd,
-	"ranap reset (cs|ps)", RANAP_STR "Send RANAP RESET\n" CSPS_STR)
-{
-	int is_ps = 0;
-	struct msgb *msg, *rua;
-
-	RANAP_Cause_t cause = {
-		.present = RANAP_Cause_PR_transmissionNetwork,
-		.choice.transmissionNetwork = RANAP_CauseTransmissionNetwork_signalling_transport_resource_failure,
-	};
-
-	if (!strcmp(argv[0], "ps"))
-		is_ps = 1;
-
-	msg = ranap_new_msg_reset(is_ps, &cause);
-	rua = rua_new_udt(msg);
-	//msgb_free(msg);
-	osmo_wqueue_enqueue(&g_hnb.wqueue, rua);
-
-	return CMD_SUCCESS;
-}
-
-
-enum my_vty_nodes {
-	CHAN_NODE = _LAST_OSMOVTY_NODE,
-};
-
-static struct cmd_node chan_node = {
-	CHAN_NODE,
-	"%s(chan)> ",
-	1,
-};
-
-
-static struct msgb *gen_initue_lu(int is_ps, uint32_t conn_id, const char *imsi)
+struct msgb *gen_initue_lu(int is_ps, uint32_t conn_id, const char *imsi)
 {
 	uint8_t lu[] = { GSM48_PDISC_MM, GSM48_MT_MM_LOC_UPD_REQUEST,
 		         0x70, 0x62, 0xf2, 0x30, 0xff, 0xf3, 0x57,
@@ -848,52 +777,6 @@
 	return ranap_new_msg_initial_ue(conn_id, is_ps, &rnc_id, lu, sizeof(lu));
 }
 
-DEFUN(chan, chan_cmd,
-	"channel (cs|ps) lu imsi IMSI",
-	"Open a new Signalling Connection\n"
-	"To Circuit-Switched CN\n"
-	"To Packet-Switched CN\n"
-	"Performing a Location Update\n"
-	)
-{
-	struct hnb_chan *chan;
-	struct msgb *msg, *rua;
-	static uint16_t conn_id = 42;
-
-	chan = talloc_zero(tall_hnb_ctx, struct hnb_chan);
-	if (!strcmp(argv[0], "ps"))
-		chan->is_ps = 1;
-	chan->imsi = talloc_strdup(chan, argv[1]);
-	chan->conn_id = conn_id;
-	conn_id++;
-
-	msg = gen_initue_lu(chan->is_ps, chan->conn_id, chan->imsi);
-	rua = rua_new_conn(chan->is_ps, chan->conn_id, msg);
-
-	osmo_wqueue_enqueue(&g_hnb.wqueue, rua);
-
-	vty->index = chan;
-	vty->node = CHAN_NODE;
-
-	if (!chan->is_ps)
-		g_hnb.cs.chan = chan;
-
-
-	return CMD_SUCCESS;
-}
-
-static void hnb_vty_init(void)
-{
-	install_element_ve(&asn_dbg_cmd);
-	install_element_ve(&hnb_register_cmd);
-	install_element_ve(&hnb_deregister_cmd);
-	install_element_ve(&ue_register_cmd);
-	install_element_ve(&ranap_reset_cmd);
-	install_element_ve(&chan_cmd);
-
-	install_node(&chan_node, NULL);
-}
-
 static void handle_options(int argc, char **argv)
 {
 	while (1) {
diff --git a/src/osmo-hnodeb/vty.c b/src/osmo-hnodeb/vty.c
new file mode 100644
index 0000000..ccca6d0
--- /dev/null
+++ b/src/osmo-hnodeb/vty.c
@@ -0,0 +1,148 @@
+/* (C) 2015 by Daniel Willmann <dwillmann at sysmocom.de>
+ * (C) 2021 by sysmocom - s.f.m.c. GmbH <info at sysmocom.de>
+ * Author: Pau Espin Pedrol <pespin at sysmocom.de>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/lienses/>.
+ *
+ */
+
+#include "config.h"
+
+#include <unistd.h>
+
+#include <osmocom/vty/telnet_interface.h>
+#include <osmocom/vty/logging.h>
+#include <osmocom/vty/command.h>
+#include <osmocom/core/msgb.h>
+
+#include <osmocom/rua/rua_msg_factory.h>
+
+#include <osmocom/ranap/ranap_common.h>
+#include <osmocom/ranap/ranap_msg_factory.h>
+
+#include <osmocom/hnodeb/vty.h>
+#include <osmocom/hnodeb/hnodeb.h>
+
+static struct cmd_node chan_node = {
+	CHAN_NODE,
+	"%s(chan)> ",
+	1,
+};
+
+#define HNBAP_STR	"HNBAP related commands\n"
+#define HNB_STR		"HomeNodeB commands\n"
+#define UE_STR		"User Equipment commands\n"
+#define RANAP_STR	"RANAP related commands\n"
+#define CSPS_STR	"Circuit Switched\n" "Packet Switched\n"
+
+DEFUN(hnb_register, hnb_register_cmd,
+	"hnbap hnb register", HNBAP_STR HNB_STR "Send HNB-REGISTER REQUEST")
+{
+	hnb_send_register_req(&g_hnb);
+
+	return CMD_SUCCESS;
+}
+
+DEFUN(hnb_deregister, hnb_deregister_cmd,
+	"hnbap hnb deregister", HNBAP_STR HNB_STR "Send HNB-DEREGISTER REQUEST")
+{
+	hnb_send_deregister_req(&g_hnb);
+
+	return CMD_SUCCESS;
+}
+
+DEFUN(ue_register, ue_register_cmd,
+	"hnbap ue register IMSI", HNBAP_STR UE_STR "Send UE-REGISTER REQUEST")
+{
+	hnb_ue_register_tx(&g_hnb, argv[0]);
+
+	return CMD_SUCCESS;
+}
+
+DEFUN(asn_dbg, asn_dbg_cmd,
+	"asn-debug (1|0)", "Enable or disable libasn1c debugging")
+{
+	asn_debug = atoi(argv[0]);
+
+	return CMD_SUCCESS;
+}
+
+DEFUN(ranap_reset, ranap_reset_cmd,
+	"ranap reset (cs|ps)", RANAP_STR "Send RANAP RESET\n" CSPS_STR)
+{
+	int is_ps = 0;
+	struct msgb *msg, *rua;
+
+	RANAP_Cause_t cause = {
+		.present = RANAP_Cause_PR_transmissionNetwork,
+		.choice.transmissionNetwork = RANAP_CauseTransmissionNetwork_signalling_transport_resource_failure,
+	};
+
+	if (!strcmp(argv[0], "ps"))
+		is_ps = 1;
+
+	msg = ranap_new_msg_reset(is_ps, &cause);
+	rua = rua_new_udt(msg);
+	//msgb_free(msg);
+	osmo_wqueue_enqueue(&g_hnb.wqueue, rua);
+
+	return CMD_SUCCESS;
+}
+
+DEFUN(chan, chan_cmd,
+	"channel (cs|ps) lu imsi IMSI",
+	"Open a new Signalling Connection\n"
+	"To Circuit-Switched CN\n"
+	"To Packet-Switched CN\n"
+	"Performing a Location Update\n"
+	)
+{
+	struct hnb_chan *chan;
+	struct msgb *msg, *rua;
+	static uint16_t conn_id = 42;
+
+	chan = talloc_zero(tall_hnb_ctx, struct hnb_chan);
+	if (!strcmp(argv[0], "ps"))
+		chan->is_ps = 1;
+	chan->imsi = talloc_strdup(chan, argv[1]);
+	chan->conn_id = conn_id;
+	conn_id++;
+
+	msg = gen_initue_lu(chan->is_ps, chan->conn_id, chan->imsi);
+	rua = rua_new_conn(chan->is_ps, chan->conn_id, msg);
+
+	osmo_wqueue_enqueue(&g_hnb.wqueue, rua);
+
+	vty->index = chan;
+	vty->node = CHAN_NODE;
+
+	if (!chan->is_ps)
+		g_hnb.cs.chan = chan;
+
+
+	return CMD_SUCCESS;
+}
+
+void hnb_vty_init(void)
+{
+	install_element_ve(&asn_dbg_cmd);
+	install_element_ve(&hnb_register_cmd);
+	install_element_ve(&hnb_deregister_cmd);
+	install_element_ve(&ue_register_cmd);
+	install_element_ve(&ranap_reset_cmd);
+	install_element_ve(&chan_cmd);
+
+	install_node(&chan_node, NULL);
+}

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-hnodeb/+/25997
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hnodeb
Gerrit-Branch: master
Gerrit-Change-Id: I88107e9ed03ff8f807b57a3ea0d189fd70864861
Gerrit-Change-Number: 25997
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211102/aae2c2cb/attachment.htm>


More information about the gerrit-log mailing list