diff options
author | Sylvain Munaut <tnt@246tNt.com> | 2010-09-17 14:40:56 +0200 |
---|---|---|
committer | Sylvain Munaut <tnt@246tNt.com> | 2010-09-17 14:40:56 +0200 |
commit | 8f553d57cb44c8797d456a27adfb6637aa1bd1c6 (patch) | |
tree | f3d908122b9f00bbf49ade0e839ff43e5ea04f27 /src/shared | |
parent | 66d8352a24a0dae83605b7e31c0e0427365ce1ac (diff) | |
parent | af5ee34c353ea2868a4b04b227bc1b511e1ac42b (diff) |
Merge commit 'af5ee34c353ea2868a4b04b227bc1b511e1ac42b'
Diffstat (limited to 'src/shared')
32 files changed, 408 insertions, 21 deletions
diff --git a/src/shared/libosmocore/configure.in b/src/shared/libosmocore/configure.in index c3e00610..1684aaa3 100644 --- a/src/shared/libosmocore/configure.in +++ b/src/shared/libosmocore/configure.in @@ -77,6 +77,17 @@ then AC_DEFINE([PANIC_INFLOOP],[1],[Use infinite loop on panic rather than fprintf/abort]) fi +AC_ARG_ENABLE(bsc_fd_check, + [AS_HELP_STRING( + [--enable-bsc-fd-check], + [Instrument bsc_register_fd to check that the fd is registered] + )], + [fd_check=1], [fd_check=0]) +if test "x$fd_check" = "x1" +then + AC_DEFINE([BSC_FD_CHECK],[1],[Instrument the bsc_register_fd]) +fi + AC_OUTPUT( libosmocore.pc diff --git a/src/shared/libosmocore/debian/changelog b/src/shared/libosmocore/debian/changelog new file mode 100644 index 00000000..5783127f --- /dev/null +++ b/src/shared/libosmocore/debian/changelog @@ -0,0 +1,5 @@ +libosmocore (0.1.17-1) unstable; urgency=low + + * Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP> + + -- Harald Welte <laforge@gnumonks.org> Tue, 24 Aug 2010 10:55:04 +0200 diff --git a/src/shared/libosmocore/debian/compat b/src/shared/libosmocore/debian/compat new file mode 100644 index 00000000..7f8f011e --- /dev/null +++ b/src/shared/libosmocore/debian/compat @@ -0,0 +1 @@ +7 diff --git a/src/shared/libosmocore/debian/control b/src/shared/libosmocore/debian/control new file mode 100644 index 00000000..1348ec30 --- /dev/null +++ b/src/shared/libosmocore/debian/control @@ -0,0 +1,27 @@ +Source: libosmocore +Section: libs +Priority: optional +Maintainer: Harald Welte <laforge@gnumonks.org> +Build-Depends: debhelper (>= 7.0.50~), autotools-dev +Standards-Version: 3.8.4 +Homepage: http://bb.osmocom.org/trac/wiki/libosmocore +Vcs-Git: git://git.osmocom.org/libosmocore.git +Vcs-Browser: http://git.osmocom.org/gitweb?p=libosmocore.git;a=summary + +Package: libosmocore +Section: libs +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: Open Source MObile COMmunications CORE library + +Package: libosmocore-dev +Section: libdevel +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: Development headers for Open Source MObile COMmunications CORE library + +#Package: libosmocore-dbg +#Section: libdevel +#Architecture: any +#Depends: ${shlibs:Depends}, ${misc:Depends} +#Description: Debug symbols for Open Source MObile COMmunications CORE library diff --git a/src/shared/libosmocore/debian/copyright b/src/shared/libosmocore/debian/copyright new file mode 100644 index 00000000..c450be58 --- /dev/null +++ b/src/shared/libosmocore/debian/copyright @@ -0,0 +1,54 @@ +This work was packaged for Debian by: + + Harald Welte <laforge@gnumonks.org> on Tue, 24 Aug 2010 10:55:04 +0200 + +It was downloaded from: + + git://git.osmocom.org/libosmocore.git + +Upstream Author(s): + + Harald Welte <laforge@gnumonks.org> + Holger Hans Peter Freyther <zecke@selfish.org> + Sylvain Munaut <tnt@246tNt.com> + Daniel Willmann <daniel@totalueberwachung.de> + Golde <nico@ngolde.de> + For src/talloc.c and include/osmocore/talloc.h: + Andrew Tridgell + Stefan Metzmacher + For src/vty/* and include/osmocom/vty/* + Kunihiro Ishiguro + +Copyright: + + Copyright (C) 2008-2010 Harald Welte <laforge@gnumonks.org> + Copyright (C) 2008-2010 Holger Hans Peter Freyther <zecke@selfish.org> + Copyright (C) 2009-2010 Sylvain Munaut <tnt@246tNt.com> + Copyright (C) 2009-2010 On-Waves + Copyright (C) 2008 Daniel Willmann <daniel@totalueberwachung.de> + Copyright (C) 2010 Nico Golde <nico@ngolde.de> + For src/talloc.c and include/osmocore/talloc.h: + Copyright (C) 2004 Andrew Tridgell + Copyright (C) 2006 Stefan Metzmacher + For src/vty/* and include/osmocom/vty/* + Copyright (C) 1998 Kunihiro Ishiguro + +License: + + GNU General Public License, Version 2 or later + +The Debian packaging is: + + Copyright (C) 2010 Harald Welte <laforge@gnumonks.org> + +# Please chose a license for your packaging work. If the program you package +# uses a mainstream license, using the same license is the safest choice. +# Please avoid to pick license terms that are more restrictive than the +# packaged work, as it may make Debian's contributions unacceptable upstream. +# If you just want it to be GPL version 3, leave the following lines in. + +and is licensed under the GPL version 3, +see "/usr/share/common-licenses/GPL-3". + +# Please also look if there are files or directories which have a +# different copyright/license attached and list them here. diff --git a/src/shared/libosmocore/debian/docs b/src/shared/libosmocore/debian/docs new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/shared/libosmocore/debian/docs diff --git a/src/shared/libosmocore/debian/libosmocore-dbg.debhelper.log b/src/shared/libosmocore/debian/libosmocore-dbg.debhelper.log new file mode 100644 index 00000000..2742cb47 --- /dev/null +++ b/src/shared/libosmocore/debian/libosmocore-dbg.debhelper.log @@ -0,0 +1,6 @@ +dh_auto_configure +dh_auto_build +dh_auto_test +dh_prep +dh_installdirs +dh_auto_install diff --git a/src/shared/libosmocore/debian/libosmocore-dbg.dirs b/src/shared/libosmocore/debian/libosmocore-dbg.dirs new file mode 100644 index 00000000..af59b0a9 --- /dev/null +++ b/src/shared/libosmocore/debian/libosmocore-dbg.dirs @@ -0,0 +1 @@ +usr/lib/debug/lib diff --git a/src/shared/libosmocore/debian/libosmocore-dbg.install b/src/shared/libosmocore/debian/libosmocore-dbg.install new file mode 100644 index 00000000..7ce02127 --- /dev/null +++ b/src/shared/libosmocore/debian/libosmocore-dbg.install @@ -0,0 +1 @@ +usr/lib/debug/lib/* diff --git a/src/shared/libosmocore/debian/libosmocore-dev.dirs b/src/shared/libosmocore/debian/libosmocore-dev.dirs new file mode 100644 index 00000000..e168dc66 --- /dev/null +++ b/src/shared/libosmocore/debian/libosmocore-dev.dirs @@ -0,0 +1,5 @@ +usr/lib +usr/include +usr/include/osmocore +usr/include/osmocom +usr/include/osmocom/vty diff --git a/src/shared/libosmocore/debian/libosmocore-dev.install b/src/shared/libosmocore/debian/libosmocore-dev.install new file mode 100644 index 00000000..eec0e15e --- /dev/null +++ b/src/shared/libosmocore/debian/libosmocore-dev.install @@ -0,0 +1,5 @@ +usr/include/* +usr/lib/lib*.a +usr/lib/lib*.so +usr/lib/lib*.la +usr/lib/pkgconfig/* diff --git a/src/shared/libosmocore/debian/libosmocore.dirs b/src/shared/libosmocore/debian/libosmocore.dirs new file mode 100644 index 00000000..e168dc66 --- /dev/null +++ b/src/shared/libosmocore/debian/libosmocore.dirs @@ -0,0 +1,5 @@ +usr/lib +usr/include +usr/include/osmocore +usr/include/osmocom +usr/include/osmocom/vty diff --git a/src/shared/libosmocore/debian/libosmocore.install b/src/shared/libosmocore/debian/libosmocore.install new file mode 100644 index 00000000..d0dbfd18 --- /dev/null +++ b/src/shared/libosmocore/debian/libosmocore.install @@ -0,0 +1 @@ +usr/lib/lib*.so.* diff --git a/src/shared/libosmocore/debian/patches/debian-changes-0.1.17-1 b/src/shared/libosmocore/debian/patches/debian-changes-0.1.17-1 new file mode 100644 index 00000000..c0a54bd7 --- /dev/null +++ b/src/shared/libosmocore/debian/patches/debian-changes-0.1.17-1 @@ -0,0 +1,46 @@ +Description: Upstream changes introduced in version 0.1.17-1 + This patch has been created by dpkg-source during the package build. + Here's the last changelog entry, hopefully it gives details on why + those changes were made: + . + libosmocore (0.1.17-1) unstable; urgency=low + . + * Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP> + . + The person named in the Author field signed this changelog entry. +Author: Harald Welte <laforge@gnumonks.org> + +--- +The information above should follow the Patch Tagging Guidelines, please +checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here +are templates for supplementary fields that you might want to add: + +Origin: <vendor|upstream|other>, <url of original patch> +Bug: <url in upstream bugtracker> +Bug-Debian: http://bugs.debian.org/<bugnumber> +Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber> +Forwarded: <no|not-needed|url proving that it has been forwarded> +Reviewed-By: <name and email of someone who approved the patch> +Last-Update: <YYYY-MM-DD> + +--- /dev/null ++++ libosmocore-0.1.17/.version +@@ -0,0 +1 @@ ++0.1.17 +--- /dev/null ++++ libosmocore-0.1.17/copyright +@@ -0,0 +1,14 @@ ++Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=135 ++Name: libosmocore ++Maintainer: Harald Welte <laforge@gnumonks.org> ++Source: git://git.osmocom.org/libosmocore.git ++ ++Copyright: 2008-2010 Harald Welte <laforge@gnumonks.org> ++License: GPL-2+ ++ ++Files: src/talloc.c include/osmocore/talloc.h ++Copyright: 2004 Andrew Tridgell ++License: LGPL-3+ ++ ++Files: include/osmocore/linuxlist.h ++License: GPL-2 diff --git a/src/shared/libosmocore/debian/patches/series b/src/shared/libosmocore/debian/patches/series new file mode 100644 index 00000000..0ca407b1 --- /dev/null +++ b/src/shared/libosmocore/debian/patches/series @@ -0,0 +1 @@ +debian-changes-0.1.17-1 diff --git a/src/shared/libosmocore/debian/rules b/src/shared/libosmocore/debian/rules new file mode 100755 index 00000000..a81850a2 --- /dev/null +++ b/src/shared/libosmocore/debian/rules @@ -0,0 +1,19 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +CFLAGS = -Wall -g + +%: + dh $@ + +#override_dh_strip: +# dh_strip --dbg-package=libosmocore-dbg + diff --git a/src/shared/libosmocore/debian/source/format b/src/shared/libosmocore/debian/source/format new file mode 100644 index 00000000..163aaf8d --- /dev/null +++ b/src/shared/libosmocore/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/src/shared/libosmocore/include/osmocom/vty/vty.h b/src/shared/libosmocore/include/osmocom/vty/vty.h index e7399ba1..8035585d 100644 --- a/src/shared/libosmocore/include/osmocom/vty/vty.h +++ b/src/shared/libosmocore/include/osmocom/vty/vty.h @@ -133,6 +133,7 @@ struct vty_app_info { const char *copyright; void *tall_ctx; enum node_type (*go_parent_cb)(struct vty *vty); + int (*is_config_node)(struct vty *vty, int node); }; /* Prototypes. */ @@ -154,6 +155,8 @@ int vty_config_unlock (struct vty *); int vty_shell (struct vty *); int vty_shell_serv (struct vty *); void vty_hello (struct vty *); +void *vty_current_index(struct vty *); +int vty_current_node(struct vty *vty); -void *tall_vty_ctx; +extern void *tall_vty_ctx; #endif diff --git a/src/shared/libosmocore/include/osmocore/Makefile.am b/src/shared/libosmocore/include/osmocore/Makefile.am index ecdc65c9..c8b614f6 100644 --- a/src/shared/libosmocore/include/osmocore/Makefile.am +++ b/src/shared/libosmocore/include/osmocore/Makefile.am @@ -2,7 +2,7 @@ osmocore_HEADERS = signal.h linuxlist.h timer.h select.h msgb.h \ tlv.h bitvec.h comp128.h statistics.h gsm_utils.h utils.h \ gsmtap.h write_queue.h rsl.h gsm48.h rxlev_stat.h mncc.h \ gsm48_ie.h logging.h gsm0808.h rate_ctr.h gsmtap_util.h \ - plugin.h crc16.h panic.h + plugin.h crc16.h panic.h process.h if ENABLE_TALLOC osmocore_HEADERS += talloc.h diff --git a/src/shared/libosmocore/include/osmocore/logging.h b/src/shared/libosmocore/include/osmocore/logging.h index 7bf24403..7f33155a 100644 --- a/src/shared/libosmocore/include/osmocore/logging.h +++ b/src/shared/libosmocore/include/osmocore/logging.h @@ -84,7 +84,8 @@ struct log_target { union { struct { FILE *out; - } tgt_stdout; + const char *fname; + } tgt_file; struct { int priority; @@ -123,7 +124,11 @@ void log_set_category_filter(struct log_target *target, int category, /* management of the targets */ struct log_target *log_target_create(void); +void log_target_destroy(struct log_target *target); struct log_target *log_target_create_stderr(void); +struct log_target *log_target_create_file(const char *fname); +int log_target_file_reopen(struct log_target *tgt); + void log_add_target(struct log_target *target); void log_del_target(struct log_target *target); diff --git a/src/shared/libosmocore/include/osmocore/process.h b/src/shared/libosmocore/include/osmocore/process.h new file mode 100644 index 00000000..2d663828 --- /dev/null +++ b/src/shared/libosmocore/include/osmocore/process.h @@ -0,0 +1,6 @@ +#ifndef _OSMO_PROCESS_H +#define _OSMO_PROCESS_H + +int osmo_daemonize(void); + +#endif diff --git a/src/shared/libosmocore/include/osmocore/protocol/gsm_04_08.h b/src/shared/libosmocore/include/osmocore/protocol/gsm_04_08.h index 80a455dd..3ad7dfdc 100644 --- a/src/shared/libosmocore/include/osmocore/protocol/gsm_04_08.h +++ b/src/shared/libosmocore/include/osmocore/protocol/gsm_04_08.h @@ -356,6 +356,14 @@ struct gsm48_ass_cmd { uint8_t data[0]; } __attribute__((packed)); +/* Chapter 9.1.13 */ +struct gsm48_frq_redef { + /* Semantic is from 10.5.2.5a */ + struct gsm48_chan_desc chan_desc; + uint8_t mob_alloc_len; + uint8_t mob_alloc[0]; +} __attribute__((packed)); + /* Chapter 10.5.2.2 */ struct gsm48_cell_desc { uint8_t bcc:3, @@ -597,6 +605,17 @@ struct gsm48_ass_fail { uint8_t rr_cause; } __attribute__((packed)); +/* Section 9.1.3 */ +struct gsm48_ho_cpl { + uint8_t rr_cause; + uint8_t data[0]; +} __attribute__((packed)); + +/* Section 9.1.4 */ +struct gsm48_ho_fail { + uint8_t rr_cause; +} __attribute__((packed)); + /* Section 9.1.7 */ struct gsm48_chan_rel { uint8_t rr_cause; @@ -607,8 +626,8 @@ struct gsm48_chan_rel { struct gsm48_cip_mode_cmd { uint8_t sc:1, alg_id:3, - spare:3, - cr:1; + cr:1, + spare:3; } __attribute__((packed)); /* Section 9.1.11 */ diff --git a/src/shared/libosmocore/src/Makefile.am b/src/shared/libosmocore/src/Makefile.am index e197e179..1e97bb9b 100644 --- a/src/shared/libosmocore/src/Makefile.am +++ b/src/shared/libosmocore/src/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS=vty +SUBDIRS=. vty # This is _NOT_ the library release version, it's an API version. # Please read Chapter 6 "Library interface versions" of the libtool documentation before making any modification @@ -13,7 +13,7 @@ libosmocore_la_SOURCES = timer.c select.c signal.c msgb.c rxlev_stat.c \ tlv_parser.c bitvec.c comp128.c gsm_utils.c statistics.c \ write_queue.c utils.c rsl.c gsm48.c gsm48_ie.c \ logging.c gsm0808.c rate_ctr.c gsmtap_util.c \ - gprs_cipher_core.c crc16.c panic.c + gprs_cipher_core.c crc16.c panic.c process.c if ENABLE_PLUGIN libosmocore_la_SOURCES += plugin.c diff --git a/src/shared/libosmocore/src/gsm0808.c b/src/shared/libosmocore/src/gsm0808.c index c8dc6645..42a73b9f 100644 --- a/src/shared/libosmocore/src/gsm0808.c +++ b/src/shared/libosmocore/src/gsm0808.c @@ -302,6 +302,8 @@ static const struct tlv_definition bss_att_tlvdef = { [GSM0808_IE_CELL_IDENTIFIER] = { TLV_TYPE_TLV }, [GSM0808_IE_CHOSEN_CHANNEL] = { TLV_TYPE_TV }, [GSM0808_IE_LAYER_3_INFORMATION] = { TLV_TYPE_TLV }, + [GSM0808_IE_SPEECH_VERSION] = { TLV_TYPE_TV }, + [GSM0808_IE_CHOSEN_ENCR_ALG] = { TLV_TYPE_TV }, }, }; diff --git a/src/shared/libosmocore/src/logging.c b/src/shared/libosmocore/src/logging.c index 30316a5f..b3b5cb69 100644 --- a/src/shared/libosmocore/src/logging.c +++ b/src/shared/libosmocore/src/logging.c @@ -294,14 +294,11 @@ void log_set_category_filter(struct log_target *target, int category, target->categories[category].loglevel = level; } -/* since C89/C99 says stderr is a macro, we can safely do this! */ -#ifdef stderr -static void _stderr_output(struct log_target *target, const char *log) +static void _file_output(struct log_target *target, const char *log) { - fprintf(target->tgt_stdout.out, "%s", log); - fflush(target->tgt_stdout.out); + fprintf(target->tgt_file.out, "%s", log); + fflush(target->tgt_file.out); } -#endif struct log_target *log_target_create(void) { @@ -340,14 +337,68 @@ struct log_target *log_target_create_stderr(void) if (!target) return NULL; - target->tgt_stdout.out = stderr; - target->output = _stderr_output; + target->tgt_file.out = stderr; + target->output = _file_output; return target; #else return NULL; #endif /* stderr */ } +struct log_target *log_target_create_file(const char *fname) +{ + struct log_target *target; + + target = log_target_create(); + if (!target) + return NULL; + + target->tgt_file.out = fopen(fname, "a"); + if (!target->tgt_file.out) + return NULL; + + target->output = _file_output; + + target->tgt_file.fname = talloc_strdup(target, fname); + + return target; +} + +void log_target_destroy(struct log_target *target) +{ + + /* just in case, to make sure we don't have any references */ + log_del_target(target); + + if (target->output == &_file_output) { +/* since C89/C99 says stderr is a macro, we can safely do this! */ +#ifdef stderr + /* don't close stderr */ + if (target->tgt_file.out != stderr) +#endif + { + fclose(target->tgt_file.out); + target->tgt_file.out = NULL; + } + } + + talloc_free(target); +} + +/* close and re-open a log file (for log file rotation) */ +int log_target_file_reopen(struct log_target *target) +{ + fclose(target->tgt_file.out); + + target->tgt_file.out = fopen(target->tgt_file.fname, "a"); + if (!target->tgt_file.out) + return -errno; + + /* we assume target->output already to be set */ + + return 0; +} + const char *log_vty_level_string(struct log_info *info) { const struct value_string *vs; diff --git a/src/shared/libosmocore/src/plugin.c b/src/shared/libosmocore/src/plugin.c index e953508a..3ba2d431 100644 --- a/src/shared/libosmocore/src/plugin.c +++ b/src/shared/libosmocore/src/plugin.c @@ -29,6 +29,7 @@ #include <dlfcn.h> #include <stdio.h> #include <errno.h> +#include <limits.h> #include <osmocore/plugin.h> diff --git a/src/shared/libosmocore/src/process.c b/src/shared/libosmocore/src/process.c new file mode 100644 index 00000000..180efa51 --- /dev/null +++ b/src/shared/libosmocore/src/process.c @@ -0,0 +1,74 @@ +/* Process handling support code */ + +/* (C) 2010 by Harald Welte <laforge@gnumonks.org> + * 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 <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> + +int osmo_daemonize(void) +{ + int rc; + pid_t pid, sid; + + /* Check if parent PID == init, in which case we are already a daemon */ + if (getppid() == 1) + return -EEXIST; + + /* Fork from the parent process */ + pid = fork(); + if (pid < 0) { + /* some error happened */ + return pid; + } + + if (pid > 0) { + /* if we have received a positive PID, then we are the parent + * and can exit */ + exit(0); + } + + /* FIXME: do we really want this? */ + umask(0); + + /* Create a new session and set process group ID */ + sid = setsid(); + if (sid < 0) + return sid; + + /* Change to the /tmp directory, which prevents the CWD from being locked + * and unable to remove it */ + rc = chdir("/tmp"); + if (rc < 0) + return rc; + + /* Redirect stdio to /dev/null */ +/* since C89/C99 says stderr is a macro, we can safely do this! */ +#ifdef stderr + freopen("/dev/null", "r", stdin); + freopen("/dev/null", "w", stdout); + freopen("/dev/null", "w", stderr); +#endif + + return 0; +} diff --git a/src/shared/libosmocore/src/select.c b/src/shared/libosmocore/src/select.c index 2f6afa7f..f52b0a0c 100644 --- a/src/shared/libosmocore/src/select.c +++ b/src/shared/libosmocore/src/select.c @@ -19,6 +19,8 @@ */ #include <fcntl.h> +#include <stdio.h> + #include <osmocore/select.h> #include <osmocore/linuxlist.h> #include <osmocore/timer.h> @@ -48,6 +50,16 @@ int bsc_register_fd(struct bsc_fd *fd) if (fd->fd > maxfd) maxfd = fd->fd; +#ifdef BSC_FD_CHECK + struct bsc_fd *entry; + llist_for_each_entry(entry, &bsc_fds, list) { + if (entry == fd) { + fprintf(stderr, "Adding a bsc_fd that is already in the list.\n"); + return 0; + } + } +#endif + llist_add_tail(&fd->list, &bsc_fds); return 0; diff --git a/src/shared/libosmocore/src/vty/Makefile.am b/src/shared/libosmocore/src/vty/Makefile.am index f2859cff..7353ab84 100644 --- a/src/shared/libosmocore/src/vty/Makefile.am +++ b/src/shared/libosmocore/src/vty/Makefile.am @@ -10,4 +10,5 @@ lib_LTLIBRARIES = libosmovty.la libosmovty_la_SOURCES = buffer.c command.c vty.c vector.c utils.c \ telnet_interface.c logging_vty.c +libosmovty_la_LIBADD = $(top_builddir)/src/libosmocore.la endif diff --git a/src/shared/libosmocore/src/vty/command.c b/src/shared/libosmocore/src/vty/command.c index 598e63cc..7525df65 100644 --- a/src/shared/libosmocore/src/vty/command.c +++ b/src/shared/libosmocore/src/vty/command.c @@ -139,6 +139,18 @@ static int cmp_desc(const void *p, const void *q) return strcmp(a->cmd, b->cmd); } +static int is_config(struct vty *vty) +{ + if (vty->node <= CONFIG_NODE) + return 0; + else if (vty->node > CONFIG_NODE && vty->node < _LAST_OSMOVTY_NODE) + return 1; + else if (host.app_info->is_config_node) + return host.app_info->is_config_node(vty, vty->node); + else + return vty->node > CONFIG_NODE; +} + /* Sort each node's command element according to command string. */ void sort_node() { @@ -1947,9 +1959,9 @@ cmd_execute_command(vector vline, struct vty *vty, struct cmd_element **cmd, if (vtysh) return saved_ret; - /* This assumes all nodes above CONFIG_NODE are childs of CONFIG_NODE */ + /* Go to parent for config nodes to attempt to find the right command */ while (ret != CMD_SUCCESS && ret != CMD_WARNING - && vty->node > CONFIG_NODE) { + && is_config(vty)) { vty_go_parent(vty); ret = cmd_execute_command_real(vline, vty, cmd); tried = 1; @@ -2097,7 +2109,7 @@ int config_from_file(struct vty *vty, FILE * fp) /* Try again with setting node to CONFIG_NODE */ while (ret != CMD_SUCCESS && ret != CMD_WARNING && ret != CMD_ERR_NOTHING_TODO - && vty->node != CONFIG_NODE) { + && vty->node != CONFIG_NODE && is_config(vty)) { vty_go_parent(vty); ret = cmd_execute_command_strict(vline, vty, NULL); } diff --git a/src/shared/libosmocore/src/vty/telnet_interface.c b/src/shared/libosmocore/src/vty/telnet_interface.c index 90690960..1523a899 100644 --- a/src/shared/libosmocore/src/vty/telnet_interface.c +++ b/src/shared/libosmocore/src/vty/telnet_interface.c @@ -31,6 +31,7 @@ #include <osmocom/vty/telnet_interface.h> #include <osmocom/vty/buffer.h> +#include <osmocom/vty/command.h> /* per connection data */ LLIST_HEAD(active_connections); @@ -89,16 +90,18 @@ int telnet_init(void *tall_ctx, void *priv, int port) return 0; } -extern const char *openbsc_copyright; +extern struct host host; static void print_welcome(int fd) { int ret; static char *msg = - "Welcome to the OpenBSC Control interface\n"; + "Welcome to the OpenBSC Control interface\r\n"; ret = write(fd, msg, strlen(msg)); - ret = write(fd, openbsc_copyright, strlen(openbsc_copyright)); + + if (host.app_info->copyright) + ret = write(fd, host.app_info->copyright, strlen(host.app_info->copyright)); } int telnet_close_client(struct bsc_fd *fd) diff --git a/src/shared/libosmocore/src/vty/vty.c b/src/shared/libosmocore/src/vty/vty.c index ff17abf6..5c5a908d 100644 --- a/src/shared/libosmocore/src/vty/vty.c +++ b/src/shared/libosmocore/src/vty/vty.c @@ -248,6 +248,15 @@ int vty_out_newline(struct vty *vty) return 0; } +void *vty_current_index(struct vty *vty) +{ + return vty->index; +} +int vty_current_node(struct vty *vty) +{ + return vty->node; +} + int vty_config_lock(struct vty *vty) { if (vty_config == 0) { |