Merge branch 'on-waves/mgcp'
diff --git a/openbsc/include/openbsc/Makefile.am b/openbsc/include/openbsc/Makefile.am
index 6a87782..259e6d6 100644
--- a/openbsc/include/openbsc/Makefile.am
+++ b/openbsc/include/openbsc/Makefile.am
@@ -5,7 +5,8 @@
ipaccess.h rs232.h openbscdefines.h rtp_proxy.h \
bsc_rll.h mncc.h transaction.h ussd.h gsm_04_80.h \
silent_call.h mgcp.h meas_rep.h rest_octets.h \
- system_information.h handover.h mgcp_internal.h
+ system_information.h handover.h mgcp_internal.h \
+ vty.h
openbsc_HEADERS = gsm_04_08.h meas_rep.h bsc_api.h
openbscdir = $(includedir)/openbsc
diff --git a/openbsc/include/openbsc/vty.h b/openbsc/include/openbsc/vty.h
new file mode 100644
index 0000000..40e2191
--- /dev/null
+++ b/openbsc/include/openbsc/vty.h
@@ -0,0 +1,6 @@
+#ifndef OPENBSC_VTY_H
+#define OPENBSC_VTY_H
+
+void openbsc_vty_add_cmds(void);
+
+#endif
diff --git a/openbsc/src/Makefile.am b/openbsc/src/Makefile.am
index cbc809d..f4d1c01 100644
--- a/openbsc/src/Makefile.am
+++ b/openbsc/src/Makefile.am
@@ -17,7 +17,7 @@
input/misdn.c input/ipaccess.c \
talloc_ctx.c system_information.c rest_octets.c \
rtp_proxy.c bts_siemens_bs11.c bts_ipaccess_nanobts.c \
- bts_unknown.c bsc_version.c bsc_api.c
+ bts_unknown.c bsc_version.c bsc_api.c vty_interface_cmds.c
libmsc_a_SOURCES = gsm_subscriber.c db.c telnet_interface.c \
mncc.c gsm_04_08.c gsm_04_11.c transaction.c \
diff --git a/openbsc/src/db.c b/openbsc/src/db.c
index 312d0f2..8bf47ab 100644
--- a/openbsc/src/db.c
+++ b/openbsc/src/db.c
@@ -288,6 +288,8 @@
return subscr;
}
+static_assert(sizeof(unsigned char) == sizeof(struct gsm48_classmark1), classmark1_size);
+
static int get_equipment_by_subscr(struct gsm_subscriber *subscr)
{
dbi_result result;
@@ -316,9 +318,10 @@
strncpy(equip->imei, string, sizeof(equip->imei));
string = dbi_result_get_string(result, "classmark1");
- if (string)
- cm1 = atoi(string) & 0xff;
- equip->classmark1 = *((struct gsm48_classmark1 *) &cm1);
+ if (string) {
+ cm1 = atoi(string) & 0xff;
+ memcpy(&equip->classmark1, &cm1, sizeof(equip->classmark1));
+ }
equip->classmark2_len = dbi_result_get_field_length(result, "classmark2");
cm2 = dbi_result_get_binary(result, "classmark2");
diff --git a/openbsc/src/input/misdn.c b/openbsc/src/input/misdn.c
index 56930d4..83b01f2 100644
--- a/openbsc/src/input/misdn.c
+++ b/openbsc/src/input/misdn.c
@@ -262,7 +262,7 @@
ret = send(bfd->fd, tx_buf, sizeof(*hh) + BCHAN_TX_GRAN, 0);
if (ret < sizeof(*hh) + BCHAN_TX_GRAN)
- DEBUGP(DMIB, "send returns %d instead of %lu\n", ret,
+ DEBUGP(DMIB, "send returns %d instead of %zu\n", ret,
sizeof(*hh) + BCHAN_TX_GRAN);
return ret;
diff --git a/openbsc/src/ipaccess/ipaccess-proxy.c b/openbsc/src/ipaccess/ipaccess-proxy.c
index 73ce2df..3860813 100644
--- a/openbsc/src/ipaccess/ipaccess-proxy.c
+++ b/openbsc/src/ipaccess/ipaccess-proxy.c
@@ -550,6 +550,7 @@
}
/* lookup BTS, create sign_link, ... */
+ site_id = bts_id = trx_id = 0;
parse_unitid((char *)TLVP_VAL(&tlvp, IPAC_IDTAG_UNIT),
&site_id, &bts_id, &trx_id);
ipbc = find_bts_by_unitid(ipp, site_id, bts_id);
diff --git a/openbsc/src/vty_interface.c b/openbsc/src/vty_interface.c
index f2ac12d..b5bdbc8 100644
--- a/openbsc/src/vty_interface.c
+++ b/openbsc/src/vty_interface.c
@@ -38,6 +38,7 @@
#include <openbsc/db.h>
#include <osmocore/talloc.h>
#include <openbsc/telnet_interface.h>
+#include <openbsc/vty.h>
static struct gsm_network *gsmnet;
@@ -615,7 +616,7 @@
vty_out(vty, " No Subscriber%s", VTY_NEWLINE);
if (is_ipaccess_bts(lchan->ts->trx->bts)) {
struct in_addr ia;
- ia.s_addr = lchan->abis_ip.bound_ip;
+ ia.s_addr = htonl(lchan->abis_ip.bound_ip);
vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s",
inet_ntoa(ia), lchan->abis_ip.bound_port,
lchan->abis_ip.rtp_payload2, lchan->abis_ip.conn_id,
@@ -878,204 +879,6 @@
return CMD_SUCCESS;
}
-static void _vty_output(struct log_target *tgt, const char *line)
-{
- struct vty *vty = tgt->tgt_vty.vty;
- vty_out(vty, "%s", line);
- /* This is an ugly hack, but there is no easy way... */
- if (strchr(line, '\n'))
- vty_out(vty, "\r");
-}
-
-struct log_target *log_target_create_vty(struct vty *vty)
-{
- struct log_target *target;
-
- target = log_target_create();
- if (!target)
- return NULL;
-
- target->tgt_vty.vty = vty;
- target->output = _vty_output;
- return target;
-}
-
-DEFUN(enable_logging,
- enable_logging_cmd,
- "logging enable",
- "Enables logging to this vty\n")
-{
- struct telnet_connection *conn;
-
- conn = (struct telnet_connection *) vty->priv;
- if (conn->dbg) {
- vty_out(vty, "Logging already enabled.%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- conn->dbg = log_target_create_vty(vty);
- if (!conn->dbg)
- return CMD_WARNING;
-
- log_add_target(conn->dbg);
- return CMD_SUCCESS;
-}
-
-DEFUN(logging_fltr_imsi,
- logging_fltr_imsi_cmd,
- "logging filter imsi IMSI",
- "Print all messages related to a IMSI\n")
-{
- struct telnet_connection *conn;
-
- conn = (struct telnet_connection *) vty->priv;
- if (!conn->dbg) {
- vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- log_set_imsi_filter(conn->dbg, argv[0]);
- return CMD_SUCCESS;
-}
-
-DEFUN(logging_fltr_all,
- logging_fltr_all_cmd,
- "logging filter all <0-1>",
- "Print all messages to the console\n")
-{
- struct telnet_connection *conn;
-
- conn = (struct telnet_connection *) vty->priv;
- if (!conn->dbg) {
- vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- log_set_all_filter(conn->dbg, atoi(argv[0]));
- return CMD_SUCCESS;
-}
-
-DEFUN(logging_use_clr,
- logging_use_clr_cmd,
- "logging color <0-1>",
- "Use color for printing messages\n")
-{
- struct telnet_connection *conn;
-
- conn = (struct telnet_connection *) vty->priv;
- if (!conn->dbg) {
- vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- log_set_use_color(conn->dbg, atoi(argv[0]));
- return CMD_SUCCESS;
-}
-
-DEFUN(logging_prnt_timestamp,
- logging_prnt_timestamp_cmd,
- "logging timestamp <0-1>",
- "Print the timestamp of each message\n")
-{
- struct telnet_connection *conn;
-
- conn = (struct telnet_connection *) vty->priv;
- if (!conn->dbg) {
- vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- log_set_print_timestamp(conn->dbg, atoi(argv[0]));
- return CMD_SUCCESS;
-}
-
-/* FIXME: those have to be kept in sync with the log levels and categories */
-#define VTY_DEBUG_CATEGORIES "(rll|cc|mm|rr|rsl|nm|sms|pag|mncc|inp|mi|mib|mux|meas|sccp|msc|mgcp|ho|db|ref)"
-#define VTY_DEBUG_LEVELS "(everything|debug|info|notice|error|fatal)"
-DEFUN(logging_level,
- logging_level_cmd,
- "logging level " VTY_DEBUG_CATEGORIES " " VTY_DEBUG_LEVELS,
- "Set the log level for a specified category\n")
-{
- struct telnet_connection *conn;
- int category = log_parse_category(argv[0]);
- int level = log_parse_level(argv[1]);
-
- conn = (struct telnet_connection *) vty->priv;
- if (!conn->dbg) {
- vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- if (category < 0) {
- vty_out(vty, "Invalid category `%s'%s", argv[0], VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- if (level < 0) {
- vty_out(vty, "Invalid level `%s'%s", argv[1], VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- conn->dbg->categories[category].enabled = 1;
- conn->dbg->categories[category].loglevel = level;
-
- return CMD_SUCCESS;
-}
-
-DEFUN(logging_set_category_mask,
- logging_set_category_mask_cmd,
- "logging set log mask MASK",
- "Decide which categories to output.\n")
-{
- struct telnet_connection *conn;
-
- conn = (struct telnet_connection *) vty->priv;
- if (!conn->dbg) {
- vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- log_parse_category_mask(conn->dbg, argv[0]);
- return CMD_SUCCESS;
-}
-
-DEFUN(logging_set_log_level,
- logging_set_log_level_cmd,
- "logging set log level <0-8>",
- "Set the global log level. The value 0 implies no filtering.\n")
-{
- struct telnet_connection *conn;
-
- conn = (struct telnet_connection *) vty->priv;
- if (!conn->dbg) {
- vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- log_set_log_level(conn->dbg, atoi(argv[0]));
- return CMD_SUCCESS;
-}
-
-DEFUN(diable_logging,
- disable_logging_cmd,
- "logging disable",
- "Disables logging to this vty\n")
-{
- struct telnet_connection *conn;
-
- conn = (struct telnet_connection *) vty->priv;
- if (!conn->dbg) {
- vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- log_del_target(conn->dbg);
- talloc_free(conn->dbg);
- conn->dbg = NULL;
- return CMD_SUCCESS;
-}
-
DEFUN(show_stats,
show_stats_cmd,
"show statistics",
@@ -1957,15 +1760,7 @@
install_element(VIEW_NODE, &show_paging_cmd);
install_element(VIEW_NODE, &show_stats_cmd);
- install_element(VIEW_NODE, &enable_logging_cmd);
- install_element(VIEW_NODE, &disable_logging_cmd);
- install_element(VIEW_NODE, &logging_fltr_imsi_cmd);
- install_element(VIEW_NODE, &logging_fltr_all_cmd);
- install_element(VIEW_NODE, &logging_use_clr_cmd);
- install_element(VIEW_NODE, &logging_prnt_timestamp_cmd);
- install_element(VIEW_NODE, &logging_set_category_mask_cmd);
- install_element(VIEW_NODE, &logging_level_cmd);
- install_element(VIEW_NODE, &logging_set_log_level_cmd);
+ openbsc_vty_add_cmds();
install_element(CONFIG_NODE, &cfg_net_cmd);
install_node(&net_node, config_write_net);
diff --git a/openbsc/src/vty_interface_cmds.c b/openbsc/src/vty_interface_cmds.c
new file mode 100644
index 0000000..d494584
--- /dev/null
+++ b/openbsc/src/vty_interface_cmds.c
@@ -0,0 +1,243 @@
+/* OpenBSC logging helper for the VTY */
+/* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2009-2010 by Holger Hans Peter Freyther
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <openbsc/vty.h>
+#include <openbsc/telnet_interface.h>
+
+#include <osmocore/talloc.h>
+
+#include <vty/command.h>
+#include <vty/buffer.h>
+#include <vty/vty.h>
+
+#include <stdlib.h>
+
+static void _vty_output(struct log_target *tgt, const char *line)
+{
+ struct vty *vty = tgt->tgt_vty.vty;
+ vty_out(vty, "%s", line);
+ /* This is an ugly hack, but there is no easy way... */
+ if (strchr(line, '\n'))
+ vty_out(vty, "\r");
+}
+
+struct log_target *log_target_create_vty(struct vty *vty)
+{
+ struct log_target *target;
+
+ target = log_target_create();
+ if (!target)
+ return NULL;
+
+ target->tgt_vty.vty = vty;
+ target->output = _vty_output;
+ return target;
+}
+
+DEFUN(enable_logging,
+ enable_logging_cmd,
+ "logging enable",
+ "Enables logging to this vty\n")
+{
+ struct telnet_connection *conn;
+
+ conn = (struct telnet_connection *) vty->priv;
+ if (conn->dbg) {
+ vty_out(vty, "Logging already enabled.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ conn->dbg = log_target_create_vty(vty);
+ if (!conn->dbg)
+ return CMD_WARNING;
+
+ log_add_target(conn->dbg);
+ return CMD_SUCCESS;
+}
+
+DEFUN(logging_fltr_imsi,
+ logging_fltr_imsi_cmd,
+ "logging filter imsi IMSI",
+ "Print all messages related to a IMSI\n")
+{
+ struct telnet_connection *conn;
+
+ conn = (struct telnet_connection *) vty->priv;
+ if (!conn->dbg) {
+ vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ log_set_imsi_filter(conn->dbg, argv[0]);
+ return CMD_SUCCESS;
+}
+
+DEFUN(logging_fltr_all,
+ logging_fltr_all_cmd,
+ "logging filter all <0-1>",
+ "Print all messages to the console\n")
+{
+ struct telnet_connection *conn;
+
+ conn = (struct telnet_connection *) vty->priv;
+ if (!conn->dbg) {
+ vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ log_set_all_filter(conn->dbg, atoi(argv[0]));
+ return CMD_SUCCESS;
+}
+
+DEFUN(logging_use_clr,
+ logging_use_clr_cmd,
+ "logging color <0-1>",
+ "Use color for printing messages\n")
+{
+ struct telnet_connection *conn;
+
+ conn = (struct telnet_connection *) vty->priv;
+ if (!conn->dbg) {
+ vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ log_set_use_color(conn->dbg, atoi(argv[0]));
+ return CMD_SUCCESS;
+}
+
+DEFUN(logging_prnt_timestamp,
+ logging_prnt_timestamp_cmd,
+ "logging timestamp <0-1>",
+ "Print the timestamp of each message\n")
+{
+ struct telnet_connection *conn;
+
+ conn = (struct telnet_connection *) vty->priv;
+ if (!conn->dbg) {
+ vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ log_set_print_timestamp(conn->dbg, atoi(argv[0]));
+ return CMD_SUCCESS;
+}
+
+/* FIXME: those have to be kept in sync with the log levels and categories */
+#define VTY_DEBUG_CATEGORIES "(rll|cc|mm|rr|rsl|nm|sms|pag|mncc|inp|mi|mib|mux|meas|sccp|msc|mgcp|ho|db|ref)"
+#define VTY_DEBUG_LEVELS "(everything|debug|info|notice|error|fatal)"
+DEFUN(logging_level,
+ logging_level_cmd,
+ "logging level " VTY_DEBUG_CATEGORIES " " VTY_DEBUG_LEVELS,
+ "Set the log level for a specified category\n")
+{
+ struct telnet_connection *conn;
+ int category = log_parse_category(argv[0]);
+ int level = log_parse_level(argv[1]);
+
+ conn = (struct telnet_connection *) vty->priv;
+ if (!conn->dbg) {
+ vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (category < 0) {
+ vty_out(vty, "Invalid category `%s'%s", argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (level < 0) {
+ vty_out(vty, "Invalid level `%s'%s", argv[1], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ conn->dbg->categories[category].enabled = 1;
+ conn->dbg->categories[category].loglevel = level;
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(logging_set_category_mask,
+ logging_set_category_mask_cmd,
+ "logging set log mask MASK",
+ "Decide which categories to output.\n")
+{
+ struct telnet_connection *conn;
+
+ conn = (struct telnet_connection *) vty->priv;
+ if (!conn->dbg) {
+ vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ log_parse_category_mask(conn->dbg, argv[0]);
+ return CMD_SUCCESS;
+}
+
+DEFUN(logging_set_log_level,
+ logging_set_log_level_cmd,
+ "logging set log level <0-8>",
+ "Set the global log level. The value 0 implies no filtering.\n")
+{
+ struct telnet_connection *conn;
+
+ conn = (struct telnet_connection *) vty->priv;
+ if (!conn->dbg) {
+ vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ log_set_log_level(conn->dbg, atoi(argv[0]));
+ return CMD_SUCCESS;
+}
+
+DEFUN(diable_logging,
+ disable_logging_cmd,
+ "logging disable",
+ "Disables logging to this vty\n")
+{
+ struct telnet_connection *conn;
+
+ conn = (struct telnet_connection *) vty->priv;
+ if (!conn->dbg) {
+ vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ log_del_target(conn->dbg);
+ talloc_free(conn->dbg);
+ conn->dbg = NULL;
+ return CMD_SUCCESS;
+}
+
+void openbsc_vty_add_cmds()
+{
+ install_element(VIEW_NODE, &enable_logging_cmd);
+ install_element(VIEW_NODE, &disable_logging_cmd);
+ install_element(VIEW_NODE, &logging_fltr_imsi_cmd);
+ install_element(VIEW_NODE, &logging_fltr_all_cmd);
+ install_element(VIEW_NODE, &logging_use_clr_cmd);
+ install_element(VIEW_NODE, &logging_prnt_timestamp_cmd);
+ install_element(VIEW_NODE, &logging_set_category_mask_cmd);
+ install_element(VIEW_NODE, &logging_level_cmd);
+ install_element(VIEW_NODE, &logging_set_log_level_cmd);
+
+}