blob: b809b2a4654dc38f97c6d867454eaa8fc6fc550d [file] [log] [blame]
Neels Hofmeyraae68b22017-07-05 14:38:52 +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>
21#include <string.h>
22
23#include <osmocom/core/logging.h>
24#include <osmocom/vty/command.h>
25#include <osmocom/vty/logging.h>
26#include <osmocom/sigtran/osmo_ss7.h>
27#include <osmocom/sigtran/sccp_sap.h>
28
29#include <osmocom/ranap/iu_client.h>
30
31static enum ranap_nsap_addr_enc *g_rab_assign_addr_enc = NULL;
32
33DEFUN(cfg_iu_asn1_debug,
34 cfg_iu_asn1_debug_cmd,
35 "asn1 debug (1|0)",
36 "ASN.1 settings\n"
37 "Enable ASN.1 debug messages\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(cfg_iu_asn1_xer_print,
46 cfg_iu_asn1_xer_print_cmd,
47 "asn1 xer-print (1|0)",
48 "ASN.1 settings\n"
49 "Log human readable representations of all ASN.1 messages to stderr\n"
50 "Log XML representation of all ASN.1 messages to stderr\n"
51 "Do not log decoded ASN.1 messages to stderr\n")
52{
53 asn1_xer_print = atoi(argv[0]);
54 return CMD_SUCCESS;
55}
56
57#define IU_STR "Iu interface protocol options\n"
58DEFUN(cfg_iu_rab_assign_addr_enc, cfg_iu_rab_assign_addr_enc_cmd,
59 "iu rab-assign-addr-enc (x213|v4raw)",
60 IU_STR
61 "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")
64{
65 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 = RANAP_NSAP_ADDR_ENC_V4RAW;
73 else
74 *g_rab_assign_addr_enc = RANAP_NSAP_ADDR_ENC_X213;
75 return CMD_SUCCESS;
76}
77
78extern struct osmo_sccp_addr local_sccp_addr;
79
80DEFUN(cfg_iu_local_addr_pc, cfg_iu_local_addr_pc_cmd,
81 "iu local-address point-code PC",
82 IU_STR "Local SCCP Address\n")
83{
84 local_sccp_addr.presence = OSMO_SCCP_ADDR_T_PC | OSMO_SCCP_ADDR_T_SSN;
85 local_sccp_addr.ri = OSMO_SCCP_RI_SSN_PC;
86 local_sccp_addr.pc = osmo_ss7_pointcode_parse(NULL, argv[0]);
87
88 return CMD_SUCCESS;
89}
90
91/* TODO: GT address configuration, in line with 4.5.1.1.1 of TS 25.410 */
92
93int ranap_iu_vty_config_write(struct vty *vty, const char *indent)
94{
95 if (!g_rab_assign_addr_enc) {
96 vty_out(vty, "%%RAB Assignment Transport Layer Address"
97 " encoding not available%s", VTY_NEWLINE);
98 return CMD_WARNING;
99 }
100
101 switch (*g_rab_assign_addr_enc) {
102 case RANAP_NSAP_ADDR_ENC_V4RAW:
103 vty_out(vty, "%siu rab-assign-addr-enc v4raw%s", indent,
104 VTY_NEWLINE);
105 break;
106 case RANAP_NSAP_ADDR_ENC_X213:
107 /* default value, no need to write anything */
108 break;
109 default:
110 LOGP(0, LOGL_ERROR, "Invalid value for"
111 " iu.rab_assign_addr_enc: %d\n",
112 *g_rab_assign_addr_enc);
113 return CMD_WARNING;
114 }
115
116 vty_out(vty, "%siu local-address point-code %s%s", indent,
117 osmo_ss7_pointcode_print(NULL, local_sccp_addr.pc), VTY_NEWLINE);
118
119 if (asn_debug)
120 vty_out(vty, "%sasn1 debug 1%s", indent, VTY_NEWLINE);
121
122 if (asn1_xer_print)
123 vty_out(vty, "%sasn1 xer-print 1%s", indent, VTY_NEWLINE);
124
125 return CMD_SUCCESS;
126}
127
128void ranap_iu_vty_init(int iu_parent_node, enum ranap_nsap_addr_enc *rab_assign_addr_enc)
129{
130 g_rab_assign_addr_enc = rab_assign_addr_enc;
131
132 install_element(iu_parent_node, &cfg_iu_rab_assign_addr_enc_cmd);
133 install_element(iu_parent_node, &cfg_iu_local_addr_pc_cmd);
134
135 /* Technically, these are global ASN.1 settings and not necessarily limited to the Iu interface.
136 * Practically, only Iu users will use ASN.1 in Osmocom programs -- at least so far. So it is
137 * easiest to have these commands under 'iu'. */
138 install_element(iu_parent_node, &cfg_iu_asn1_debug_cmd);
139 install_element(iu_parent_node, &cfg_iu_asn1_xer_print_cmd);
140}