blob: 73ad126baf67cb91052c02b42fe88258346b9fc5 [file] [log] [blame]
Neels Hofmeyr9bc42ec2016-08-29 13:02:12 +02001/* 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 Hofmeyr2188a772016-05-20 21:59:55 +020021#include <string.h>
Neels Hofmeyr9bc42ec2016-08-29 13:02:12 +020022
Neels Hofmeyr2188a772016-05-20 21:59:55 +020023#include <osmocom/core/logging.h>
Neels Hofmeyr9bc42ec2016-08-29 13:02:12 +020024#include <osmocom/vty/command.h>
25#include <osmocom/vty/logging.h>
26
Neels Hofmeyr2188a772016-05-20 21:59:55 +020027#include <openbsc/iu.h>
28
29static enum nsap_addr_enc *g_rab_assign_addr_enc = NULL;
Neels Hofmeyr9bc42ec2016-08-29 13:02:12 +020030
31DEFUN(logging_asn_debug,
32 logging_asn_debug_cmd,
33 "logging asn1-debug (1|0)",
34 LOGGING_STR
Neels Hofmeyr2188a772016-05-20 21:59:55 +020035 "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
43DEFUN(logging_asn_xer_print,
44 logging_asn_xer_print_cmd,
45 "logging asn1-xer-print (1|0)",
46 LOGGING_STR
Neels Hofmeyr9bc42ec2016-08-29 13:02:12 +020047 "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 Hofmeyr2188a772016-05-20 21:59:55 +020051 asn1_xer_print = atoi(argv[0]);
Neels Hofmeyr9bc42ec2016-08-29 13:02:12 +020052 return CMD_SUCCESS;
53}
54
Neels Hofmeyr2188a772016-05-20 21:59:55 +020055DEFUN(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 Hofmeyr9bc42ec2016-08-29 13:02:12 +020061{
Neels Hofmeyr2188a772016-05-20 21:59:55 +020062 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
75int 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
101void 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 Hofmeyr9bc42ec2016-08-29 13:02:12 +0200104
105 install_element(CFG_LOG_NODE, &logging_asn_debug_cmd);
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200106 install_element(CFG_LOG_NODE, &logging_asn_xer_print_cmd);
107 install_element(iu_parent_node, &cfg_iu_rab_assign_addr_enc_cmd);
Neels Hofmeyr9bc42ec2016-08-29 13:02:12 +0200108}