blob: 3fd3cd15ce053bf7e8aa294eb115c98709785fff [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>
Philipp Maierefe85d32017-04-09 12:32:51 +020026#include <osmocom/sigtran/osmo_ss7.h>
27#include <osmocom/sigtran/sccp_sap.h>
Neels Hofmeyr9bc42ec2016-08-29 13:02:12 +020028
Neels Hofmeyr2188a772016-05-20 21:59:55 +020029#include <openbsc/iu.h>
30
31static enum nsap_addr_enc *g_rab_assign_addr_enc = NULL;
Neels Hofmeyr9bc42ec2016-08-29 13:02:12 +020032
33DEFUN(logging_asn_debug,
34 logging_asn_debug_cmd,
35 "logging asn1-debug (1|0)",
36 LOGGING_STR
Neels Hofmeyr2188a772016-05-20 21:59:55 +020037 "Log ASN.1 debug messages to stderr\n"
38 "Log ASN.1 debug messages to stderr\n"
39 "Do not log ASN.1 debug messages to stderr\n")
40{
41 asn_debug = atoi(argv[0]);
42 return CMD_SUCCESS;
43}
44
45DEFUN(logging_asn_xer_print,
46 logging_asn_xer_print_cmd,
47 "logging asn1-xer-print (1|0)",
48 LOGGING_STR
Neels Hofmeyr9bc42ec2016-08-29 13:02:12 +020049 "Log human readable representations of all ASN.1 messages to stderr\n"
50 "Log decoded ASN.1 messages to stderr\n"
51 "Do not log decoded ASN.1 messages to stderr\n")
52{
Neels Hofmeyr2188a772016-05-20 21:59:55 +020053 asn1_xer_print = atoi(argv[0]);
Neels Hofmeyr9bc42ec2016-08-29 13:02:12 +020054 return CMD_SUCCESS;
55}
56
Philipp Maierefe85d32017-04-09 12:32:51 +020057#define IU_STR "Iu interface protocol options\n"
Neels Hofmeyr2188a772016-05-20 21:59:55 +020058DEFUN(cfg_iu_rab_assign_addr_enc, cfg_iu_rab_assign_addr_enc_cmd,
59 "iu rab-assign-addr-enc (x213|v4raw)",
Philipp Maierefe85d32017-04-09 12:32:51 +020060 IU_STR
Neels Hofmeyr2188a772016-05-20 21:59:55 +020061 "Choose RAB Assignment's Transport Layer Address encoding\n"
62 "ITU-T X.213 compliant address encoding (default)\n"
63 "32bit length raw IPv4 address (for ip.access nano3G)\n")
Neels Hofmeyr9bc42ec2016-08-29 13:02:12 +020064{
Neels Hofmeyr2188a772016-05-20 21:59:55 +020065 if (!g_rab_assign_addr_enc) {
66 vty_out(vty, "%%RAB Assignment Transport Layer Address"
67 " encoding not available%s", VTY_NEWLINE);
68 return CMD_WARNING;
69 }
70
71 if (strcmp(argv[0], "v4raw") == 0)
72 *g_rab_assign_addr_enc = NSAP_ADDR_ENC_V4RAW;
73 else
74 *g_rab_assign_addr_enc = NSAP_ADDR_ENC_X213;
75 return CMD_SUCCESS;
76}
77
Philipp Maierefe85d32017-04-09 12:32:51 +020078extern struct osmo_sccp_addr local_sccp_addr;
79
80/* Note from the future: change-id Ib8c4fcdb4766c5e575618b95ce16dce51063206b will move this file to
81 * osmo-iuh, and there, change-id I3bb7fc1cd5261d214c6ba0cccfe95f637e6db087 will drop this vty command
82 * and use the point code defined via libosmo-sccp vty commands instead. */
83DEFUN(cfg_iu_local_addr_pc, cfg_iu_local_addr_pc_cmd,
84 "iu local-address point-code PC",
85 IU_STR "Local SCCP Address\n" "Set local point code\n" "point code\n")
86{
87 local_sccp_addr.presence = OSMO_SCCP_ADDR_T_PC | OSMO_SCCP_ADDR_T_SSN;
88 local_sccp_addr.ri = OSMO_SCCP_RI_SSN_PC;
89 local_sccp_addr.pc = osmo_ss7_pointcode_parse(NULL, argv[0]);
90
91 return CMD_SUCCESS;
92}
93
94/* TODO: GT address configuration, in line with 4.5.1.1.1 of TS 25.410 */
95
Neels Hofmeyr2188a772016-05-20 21:59:55 +020096int iu_vty_config_write(struct vty *vty, const char *indent)
97{
98 if (!g_rab_assign_addr_enc) {
99 vty_out(vty, "%%RAB Assignment Transport Layer Address"
100 " encoding not available%s", VTY_NEWLINE);
101 return CMD_WARNING;
102 }
103
104 switch (*g_rab_assign_addr_enc) {
105 case NSAP_ADDR_ENC_V4RAW:
106 vty_out(vty, "%siu rab-assign-addr-enc v4raw%s", indent,
107 VTY_NEWLINE);
108 break;
109 case NSAP_ADDR_ENC_X213:
110 /* default value, no need to write anything */
111 break;
112 default:
113 LOGP(0, LOGL_ERROR, "Invalid value for"
114 " net.iu.rab_assign_addr_enc: %d\n",
115 *g_rab_assign_addr_enc);
116 return CMD_WARNING;
117 }
118
Philipp Maierefe85d32017-04-09 12:32:51 +0200119 vty_out(vty, "%siu local-address point-code %s%s", indent,
120 osmo_ss7_pointcode_print(NULL, local_sccp_addr.pc), VTY_NEWLINE);
121
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200122 return CMD_SUCCESS;
123}
124
125void iu_vty_init(int iu_parent_node, enum nsap_addr_enc *rab_assign_addr_enc)
126{
127 g_rab_assign_addr_enc = rab_assign_addr_enc;
Neels Hofmeyr9bc42ec2016-08-29 13:02:12 +0200128
129 install_element(CFG_LOG_NODE, &logging_asn_debug_cmd);
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200130 install_element(CFG_LOG_NODE, &logging_asn_xer_print_cmd);
131 install_element(iu_parent_node, &cfg_iu_rab_assign_addr_enc_cmd);
Philipp Maierefe85d32017-04-09 12:32:51 +0200132 install_element(iu_parent_node, &cfg_iu_local_addr_pc_cmd);
Neels Hofmeyr9bc42ec2016-08-29 13:02:12 +0200133}