Neels Hofmeyr | 9bc42ec | 2016-08-29 13:02:12 +0200 | [diff] [blame] | 1 | /* OpenBSC Iu related interface to quagga VTY */ |
| 2 | /* (C) 2016 by sysmocom s.m.f.c. GmbH <info@sysmocom.de> |
| 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU Affero General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU Affero General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Affero General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <stdlib.h> |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame^] | 21 | #include <string.h> |
Neels Hofmeyr | 9bc42ec | 2016-08-29 13:02:12 +0200 | [diff] [blame] | 22 | |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame^] | 23 | #include <osmocom/core/logging.h> |
Neels Hofmeyr | 9bc42ec | 2016-08-29 13:02:12 +0200 | [diff] [blame] | 24 | #include <osmocom/vty/command.h> |
| 25 | #include <osmocom/vty/logging.h> |
| 26 | |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame^] | 27 | #include <openbsc/iu.h> |
| 28 | |
| 29 | static enum nsap_addr_enc *g_rab_assign_addr_enc = NULL; |
Neels Hofmeyr | 9bc42ec | 2016-08-29 13:02:12 +0200 | [diff] [blame] | 30 | |
| 31 | DEFUN(logging_asn_debug, |
| 32 | logging_asn_debug_cmd, |
| 33 | "logging asn1-debug (1|0)", |
| 34 | LOGGING_STR |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame^] | 35 | "Log ASN.1 debug messages to stderr\n" |
| 36 | "Log ASN.1 debug messages to stderr\n" |
| 37 | "Do not log ASN.1 debug messages to stderr\n") |
| 38 | { |
| 39 | asn_debug = atoi(argv[0]); |
| 40 | return CMD_SUCCESS; |
| 41 | } |
| 42 | |
| 43 | DEFUN(logging_asn_xer_print, |
| 44 | logging_asn_xer_print_cmd, |
| 45 | "logging asn1-xer-print (1|0)", |
| 46 | LOGGING_STR |
Neels Hofmeyr | 9bc42ec | 2016-08-29 13:02:12 +0200 | [diff] [blame] | 47 | "Log human readable representations of all ASN.1 messages to stderr\n" |
| 48 | "Log decoded ASN.1 messages to stderr\n" |
| 49 | "Do not log decoded ASN.1 messages to stderr\n") |
| 50 | { |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame^] | 51 | asn1_xer_print = atoi(argv[0]); |
Neels Hofmeyr | 9bc42ec | 2016-08-29 13:02:12 +0200 | [diff] [blame] | 52 | return CMD_SUCCESS; |
| 53 | } |
| 54 | |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame^] | 55 | DEFUN(cfg_iu_rab_assign_addr_enc, cfg_iu_rab_assign_addr_enc_cmd, |
| 56 | "iu rab-assign-addr-enc (x213|v4raw)", |
| 57 | "Iu interface protocol options\n" |
| 58 | "Choose RAB Assignment's Transport Layer Address encoding\n" |
| 59 | "ITU-T X.213 compliant address encoding (default)\n" |
| 60 | "32bit length raw IPv4 address (for ip.access nano3G)\n") |
Neels Hofmeyr | 9bc42ec | 2016-08-29 13:02:12 +0200 | [diff] [blame] | 61 | { |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame^] | 62 | if (!g_rab_assign_addr_enc) { |
| 63 | vty_out(vty, "%%RAB Assignment Transport Layer Address" |
| 64 | " encoding not available%s", VTY_NEWLINE); |
| 65 | return CMD_WARNING; |
| 66 | } |
| 67 | |
| 68 | if (strcmp(argv[0], "v4raw") == 0) |
| 69 | *g_rab_assign_addr_enc = NSAP_ADDR_ENC_V4RAW; |
| 70 | else |
| 71 | *g_rab_assign_addr_enc = NSAP_ADDR_ENC_X213; |
| 72 | return CMD_SUCCESS; |
| 73 | } |
| 74 | |
| 75 | int iu_vty_config_write(struct vty *vty, const char *indent) |
| 76 | { |
| 77 | if (!g_rab_assign_addr_enc) { |
| 78 | vty_out(vty, "%%RAB Assignment Transport Layer Address" |
| 79 | " encoding not available%s", VTY_NEWLINE); |
| 80 | return CMD_WARNING; |
| 81 | } |
| 82 | |
| 83 | switch (*g_rab_assign_addr_enc) { |
| 84 | case NSAP_ADDR_ENC_V4RAW: |
| 85 | vty_out(vty, "%siu rab-assign-addr-enc v4raw%s", indent, |
| 86 | VTY_NEWLINE); |
| 87 | break; |
| 88 | case NSAP_ADDR_ENC_X213: |
| 89 | /* default value, no need to write anything */ |
| 90 | break; |
| 91 | default: |
| 92 | LOGP(0, LOGL_ERROR, "Invalid value for" |
| 93 | " net.iu.rab_assign_addr_enc: %d\n", |
| 94 | *g_rab_assign_addr_enc); |
| 95 | return CMD_WARNING; |
| 96 | } |
| 97 | |
| 98 | return CMD_SUCCESS; |
| 99 | } |
| 100 | |
| 101 | void iu_vty_init(int iu_parent_node, enum nsap_addr_enc *rab_assign_addr_enc) |
| 102 | { |
| 103 | g_rab_assign_addr_enc = rab_assign_addr_enc; |
Neels Hofmeyr | 9bc42ec | 2016-08-29 13:02:12 +0200 | [diff] [blame] | 104 | |
| 105 | install_element(CFG_LOG_NODE, &logging_asn_debug_cmd); |
Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +0200 | [diff] [blame^] | 106 | install_element(CFG_LOG_NODE, &logging_asn_xer_print_cmd); |
| 107 | install_element(iu_parent_node, &cfg_iu_rab_assign_addr_enc_cmd); |
Neels Hofmeyr | 9bc42ec | 2016-08-29 13:02:12 +0200 | [diff] [blame] | 108 | } |