Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 1 | /* OpenBSC VTY common helpers */ |
| 2 | /* (C) 2009-2012 by Harald Welte <laforge@gnumonks.org> |
| 3 | * (C) 2009-2010 by Holger Hans Peter Freyther |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 14 | * GNU General Public License for more details. |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 15 | * |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | |
| 24 | #include <osmocom/core/talloc.h> |
Harald Welte | 8eda90d | 2012-06-17 12:58:46 +0800 | [diff] [blame] | 25 | #include <osmocom/core/logging.h> |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 26 | |
| 27 | #include <osmocom/vty/telnet_interface.h> |
| 28 | #include <osmocom/vty/command.h> |
| 29 | #include <osmocom/vty/buffer.h> |
| 30 | #include <osmocom/vty/vty.h> |
| 31 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 32 | #include <osmocom/gprs/gprs_msgb.h> |
| 33 | |
| 34 | #include "common_vty.h" |
| 35 | |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 36 | /* Down vty node level. */ |
| 37 | gDEFUN(libgb_exit, |
| 38 | libgb_exit_cmd, "exit", "Exit current mode and down to previous mode\n") |
| 39 | { |
| 40 | switch (vty->node) { |
| 41 | case L_NS_NODE: |
| 42 | case L_BSSGP_NODE: |
| 43 | vty->node = CONFIG_NODE; |
| 44 | vty->index = NULL; |
| 45 | break; |
| 46 | default: |
| 47 | break; |
| 48 | } |
| 49 | return CMD_SUCCESS; |
| 50 | } |
| 51 | |
| 52 | /* End of configuration. */ |
| 53 | gDEFUN(libgb_end, |
| 54 | libgb_end_cmd, "end", "End current mode and change to enable mode.") |
| 55 | { |
| 56 | switch (vty->node) { |
| 57 | case L_NS_NODE: |
| 58 | case L_BSSGP_NODE: |
| 59 | vty_config_unlock(vty); |
| 60 | vty->node = ENABLE_NODE; |
| 61 | vty->index = NULL; |
| 62 | vty->index_sub = NULL; |
| 63 | break; |
| 64 | default: |
| 65 | break; |
| 66 | } |
| 67 | return CMD_SUCCESS; |
| 68 | } |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 69 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 70 | int gprs_log_filter_fn(const struct log_context *ctx, |
| 71 | struct log_target *tar) |
| 72 | { |
| 73 | const struct gprs_nsvc *nsvc = ctx->ctx[GPRS_CTX_NSVC]; |
Harald Welte | 8eda90d | 2012-06-17 12:58:46 +0800 | [diff] [blame] | 74 | const struct gprs_bvc *bvc = ctx->ctx[GPRS_CTX_BVC]; |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 75 | |
| 76 | /* Filter on the NS Virtual Connection */ |
| 77 | if ((tar->filter_map & (1 << FLT_NSVC)) != 0 |
| 78 | && nsvc && (nsvc == tar->filter_data[FLT_NSVC])) |
| 79 | return 1; |
| 80 | |
| 81 | /* Filter on the NS Virtual Connection */ |
| 82 | if ((tar->filter_map & (1 << FLT_BVC)) != 0 |
| 83 | && bvc && (bvc == tar->filter_data[FLT_BVC])) |
| 84 | return 1; |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 90 | int DNS, DBSSGP; |