summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2012-03-01 22:37:53 +0100
committerSylvain Munaut <tnt@246tNt.com>2012-03-01 22:37:53 +0100
commitb445cce26b154d753a15193150f97179f9914f7c (patch)
tree88d8fd8debc8b95b4b3609669816224794b8fbcb
parentb4a8badc45a05283944859e2822a202197eed1c4 (diff)
parenta9efc12ccd6ee20752d21ce0deaff457ef9fe0b0 (diff)
Merge commit 'a9efc12ccd6ee20752d21ce0deaff457ef9fe0b0'
-rw-r--r--src/shared/libosmocore/include/osmocom/core/gsmtap.h8
-rw-r--r--src/shared/libosmocore/include/osmocom/vty/telnet_interface.h1
-rw-r--r--src/shared/libosmocore/src/vty/telnet_interface.c57
3 files changed, 31 insertions, 35 deletions
diff --git a/src/shared/libosmocore/include/osmocom/core/gsmtap.h b/src/shared/libosmocore/include/osmocom/core/gsmtap.h
index 5dc869d..a4e5d42 100644
--- a/src/shared/libosmocore/include/osmocom/core/gsmtap.h
+++ b/src/shared/libosmocore/include/osmocom/core/gsmtap.h
@@ -82,6 +82,14 @@
#define GSMTAP_CHANNEL_PDCH 0x0d
#define GSMTAP_CHANNEL_PTCCH 0x0e
#define GSMTAP_CHANNEL_CBCH51 0x0f
+
+/* GPRS Coding Scheme CS1..4 */
+#define GSMTAP_GPRS_CS_BASE 0x20
+#define GSMTAP_GPRS_CS(N) (GSMTAP_GPRS_CS_BASE + N)
+/* (E) GPRS Coding Scheme MCS0..9 */
+#define GSMTAP_GPRS_MCS_BASE 0x30
+#define GSMTAP_GPRS_MCS(N) (GSMTAP_GPRS_MCS_BASE + N)
+
#define GSMTAP_CHANNEL_ACCH 0x80
/* ====== DO NOT MAKE UNAPPROVED MODIFICATIONS HERE ===== */
diff --git a/src/shared/libosmocore/include/osmocom/vty/telnet_interface.h b/src/shared/libosmocore/include/osmocom/vty/telnet_interface.h
index 2de4f19..65a1dd9 100644
--- a/src/shared/libosmocore/include/osmocom/vty/telnet_interface.h
+++ b/src/shared/libosmocore/include/osmocom/vty/telnet_interface.h
@@ -47,6 +47,7 @@ struct telnet_connection {
};
int telnet_init(void *tall_ctx, void *priv, int port);
+int telnet_init_dynif(void *tall_ctx, void *priv, const char *ip, int port);
void telnet_exit(void);
diff --git a/src/shared/libosmocore/src/vty/telnet_interface.c b/src/shared/libosmocore/src/vty/telnet_interface.c
index 167acc1..001b016 100644
--- a/src/shared/libosmocore/src/vty/telnet_interface.c
+++ b/src/shared/libosmocore/src/vty/telnet_interface.c
@@ -20,12 +20,14 @@
#include <sys/socket.h>
#include <netinet/in.h>
+#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <osmocom/core/msgb.h>
+#include <osmocom/core/socket.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/logging.h>
@@ -52,53 +54,38 @@ static struct osmo_fd server_socket = {
.priv_nr = 0,
};
-/*! \brief Initialize telnet based VTY interface
+/*! \brief Initialize telnet based VTY interface listening to 127.0.0.1
* \param[in] tall_ctx \ref talloc context
* \param[in] priv private data to be passed to callback
* \param[in] port UDP port number
*/
int telnet_init(void *tall_ctx, void *priv, int port)
{
- struct sockaddr_in sock_addr;
- int fd, rc, on = 1;
-
- tall_telnet_ctx = talloc_named_const(tall_ctx, 1,
- "telnet_connection");
-
- /* FIXME: use new socket.c code of libosmocore */
- fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
-
- if (fd < 0) {
- LOGP(0, LOGL_ERROR, "Telnet interface socket creation failed\n");
- return fd;
- }
-
- setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
+ return telnet_init_dynif(tall_ctx, priv, "127.0.0.1", port);
+}
- memset(&sock_addr, 0, sizeof(sock_addr));
- sock_addr.sin_family = AF_INET;
- sock_addr.sin_port = htons(port);
- sock_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+/*! \brief Initialize telnet based VTY interface
+ * \param[in] tall_ctx \ref talloc context
+ * \param[in] priv private data to be passed to callback
+ * \param[in] ip IP to listen to ('::1' for localhost, '::0' for all, ...)
+ * \param[in] port UDP port number
+ */
+int telnet_init_dynif(void *tall_ctx, void *priv, const char *ip, int port)
+{
+ int rc;
- rc = bind(fd, (struct sockaddr*)&sock_addr, sizeof(sock_addr));
- if (rc < 0) {
- LOGP(0, LOGL_ERROR, "Telnet interface failed to bind\n");
- close(fd);
- return rc;
- }
+ tall_telnet_ctx = talloc_named_const(tall_ctx, 1,
+ "telnet_connection");
- rc = listen(fd, 0);
- if (rc < 0) {
- LOGP(0, LOGL_ERROR, "Telnet interface failed to listen\n");
- close(fd);
- return rc;
- }
+ rc = osmo_sock_init_ofd(
+ &server_socket,
+ AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP,
+ ip, port, OSMO_SOCK_F_BIND
+ );
server_socket.data = priv;
- server_socket.fd = fd;
- osmo_fd_register(&server_socket);
- return 0;
+ return (rc < 0) ? -1 : 0;
}
extern struct host host;