Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame^] | 1 | /* VTY code for the Cellmgr */ |
| 2 | /* |
| 3 | * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 4 | * (C) 2010 by On-Waves |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <bsc_data.h> |
| 24 | |
| 25 | #include <osmocore/talloc.h> |
| 26 | |
| 27 | #include <osmocom/vty/command.h> |
| 28 | #include <osmocom/vty/vty.h> |
| 29 | |
| 30 | #include <unistd.h> |
| 31 | #include <netdb.h> |
| 32 | |
| 33 | #undef PACKAGE_NAME |
| 34 | #undef PACKAGE_VERSION |
| 35 | #undef PACKAGE_BUGREPORT |
| 36 | #undef PACKAGE_TARNAME |
| 37 | #undef PACKAGE_STRING |
| 38 | #include <cellmgr_config.h> |
| 39 | |
| 40 | extern struct bsc_data bsc; |
| 41 | |
| 42 | static struct vty_app_info vty_info = { |
| 43 | .name = "Cellmgr-ng", |
| 44 | .version = VERSION, |
| 45 | .go_parent_cb = NULL, |
| 46 | }; |
| 47 | |
| 48 | /* vty code */ |
| 49 | enum cellmgr_node { |
| 50 | CELLMGR_NODE = _LAST_OSMOVTY_NODE, |
| 51 | }; |
| 52 | |
| 53 | static struct cmd_node cell_node = { |
| 54 | CELLMGR_NODE, |
| 55 | "%s(cellmgr)#", |
| 56 | 1, |
| 57 | }; |
| 58 | |
| 59 | static int config_write_cell() |
| 60 | { |
| 61 | return CMD_SUCCESS; |
| 62 | } |
| 63 | |
| 64 | DEFUN(cfg_cell, cfg_cell_cmd, |
| 65 | "cellmgr", "Configure the Cellmgr") |
| 66 | { |
| 67 | vty->node = CELLMGR_NODE; |
| 68 | return CMD_SUCCESS; |
| 69 | } |
| 70 | |
| 71 | DEFUN(cfg_net_dpc, cfg_net_dpc_cmd, |
| 72 | "mtp dpc DPC_NR", |
| 73 | "Set the DPC to be used.") |
| 74 | { |
| 75 | bsc.dpc = atoi(argv[0]); |
| 76 | return CMD_SUCCESS; |
| 77 | } |
| 78 | |
| 79 | DEFUN(cfg_net_opc, cfg_net_opc_cmd, |
| 80 | "mtp opc OPC_NR", |
| 81 | "Set the OPC to be used.") |
| 82 | { |
| 83 | bsc.opc = atoi(argv[0]); |
| 84 | return CMD_SUCCESS; |
| 85 | } |
| 86 | |
| 87 | DEFUN(cfg_udp_dst_ip, cfg_udp_dst_ip_cmd, |
| 88 | "udp dest ip IP", |
| 89 | "Set the IP when UDP mode is supposed to be used.") |
| 90 | { |
| 91 | struct hostent *hosts; |
| 92 | struct in_addr *addr; |
| 93 | |
| 94 | hosts = gethostbyname(argv[0]); |
| 95 | if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) { |
| 96 | vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE); |
| 97 | return CMD_WARNING; |
| 98 | } |
| 99 | |
| 100 | addr = (struct in_addr *) hosts->h_addr_list[0]; |
| 101 | bsc.udp_ip = talloc_strdup(NULL, inet_ntoa(*addr)); |
| 102 | return CMD_SUCCESS; |
| 103 | } |
| 104 | |
| 105 | DEFUN(cfg_udp_dst_port, cfg_udp_dst_port_cmd, |
| 106 | "udp dest port PORT_NR", |
| 107 | "If UDP mode is used specify the UDP dest port") |
| 108 | { |
| 109 | bsc.udp_port = atoi(argv[0]); |
| 110 | return CMD_SUCCESS; |
| 111 | } |
| 112 | |
| 113 | DEFUN(cfg_udp_src_port, cfg_udp_src_port_cmd, |
| 114 | "udp src port PORT_NR", |
| 115 | "Set the UDP source port to be used.") |
| 116 | { |
| 117 | bsc.src_port = atoi(argv[0]); |
| 118 | return CMD_SUCCESS; |
| 119 | } |
| 120 | |
| 121 | DEFUN(cfg_udp_reset, cfg_udp_reset_cmd, |
| 122 | "udp reset TIMEOUT", |
| 123 | "Set the timeout to take the link down") |
| 124 | { |
| 125 | bsc.link.udp.reset_timeout = atoi(argv[0]); |
| 126 | return CMD_SUCCESS; |
| 127 | } |
| 128 | |
| 129 | DEFUN(cfg_sltm_once, cfg_sltm_once_cmd, |
| 130 | "mtp sltm once (0|1)", |
| 131 | "Send SLTMs until the link is established.") |
| 132 | { |
| 133 | bsc.once = !!atoi(argv[0]); |
| 134 | return CMD_SUCCESS; |
| 135 | } |
| 136 | |
| 137 | DEFUN(cfg_msc_ip, cfg_msc_ip_cmd, |
| 138 | "msc ip IP", |
| 139 | "Set the MSC IP") |
| 140 | { |
| 141 | struct hostent *hosts; |
| 142 | struct in_addr *addr; |
| 143 | |
| 144 | hosts = gethostbyname(argv[0]); |
| 145 | if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) { |
| 146 | vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE); |
| 147 | return CMD_WARNING; |
| 148 | } |
| 149 | |
| 150 | addr = (struct in_addr *) hosts->h_addr_list[0]; |
| 151 | |
| 152 | bsc.msc_address = talloc_strdup(NULL, inet_ntoa(*addr)); |
| 153 | return CMD_SUCCESS; |
| 154 | } |
| 155 | |
| 156 | DEFUN(cfg_msc_ip_dscp, cfg_msc_ip_dscp_cmd, |
| 157 | "msc ip-dscp <0-255>", |
| 158 | "Set the IP DSCP on the A-link\n" |
| 159 | "Set the DSCP in IP packets to the MSC") |
| 160 | { |
| 161 | bsc.msc_ip_dscp = atoi(argv[0]); |
| 162 | return CMD_SUCCESS; |
| 163 | } |
| 164 | |
| 165 | ALIAS_DEPRECATED(cfg_msc_ip_dscp, cfg_msc_ip_tos_cmd, |
| 166 | "msc ip-tos <0-255>", |
| 167 | "Set the IP DSCP on the A-link\n" |
| 168 | "Set the DSCP in IP packets to the MSC") |
| 169 | |
| 170 | DEFUN(cfg_msc_token, cfg_msc_token_cmd, |
| 171 | "msc token TOKEN", |
| 172 | "Set the Token to be used for the MSC") |
| 173 | { |
| 174 | bsc.token = talloc_strdup(NULL, argv[0]); |
| 175 | return CMD_SUCCESS; |
| 176 | } |
| 177 | |
| 178 | DEFUN(cfg_ping_time, cfg_ping_time_cmd, |
| 179 | "timeout ping NR", |
| 180 | "Set the PING interval. Negative to disable it") |
| 181 | { |
| 182 | bsc.ping_time = atoi(argv[0]); |
| 183 | return CMD_SUCCESS; |
| 184 | } |
| 185 | |
| 186 | DEFUN(cfg_pong_time, cfg_pong_time_cmd, |
| 187 | "timeout pong NR", |
| 188 | "Set the PING interval. Negative to disable it") |
| 189 | { |
| 190 | bsc.pong_time = atoi(argv[0]); |
| 191 | return CMD_SUCCESS; |
| 192 | } |
| 193 | |
| 194 | DEFUN(cfg_msc_time, cfg_msc_time_cmd, |
| 195 | "timeout msc NR", |
| 196 | "Set the MSC connect timeout") |
| 197 | { |
| 198 | bsc.msc_time = atoi(argv[0]); |
| 199 | return CMD_SUCCESS; |
| 200 | } |
| 201 | |
| 202 | void cell_vty_init(void) |
| 203 | { |
| 204 | cmd_init(1); |
| 205 | vty_init(&vty_info); |
| 206 | |
| 207 | install_element(CONFIG_NODE, &cfg_cell_cmd); |
| 208 | install_node(&cell_node, config_write_cell); |
| 209 | |
| 210 | install_element(CELLMGR_NODE, &cfg_net_dpc_cmd); |
| 211 | install_element(CELLMGR_NODE, &cfg_net_opc_cmd); |
| 212 | install_element(CELLMGR_NODE, &cfg_udp_dst_ip_cmd); |
| 213 | install_element(CELLMGR_NODE, &cfg_udp_dst_port_cmd); |
| 214 | install_element(CELLMGR_NODE, &cfg_udp_src_port_cmd); |
| 215 | install_element(CELLMGR_NODE, &cfg_udp_reset_cmd); |
| 216 | install_element(CELLMGR_NODE, &cfg_sltm_once_cmd); |
| 217 | install_element(CELLMGR_NODE, &cfg_msc_ip_cmd); |
| 218 | install_element(CELLMGR_NODE, &cfg_msc_token_cmd); |
| 219 | install_element(CELLMGR_NODE, &cfg_msc_ip_dscp_cmd); |
| 220 | install_element(CELLMGR_NODE, &cfg_msc_ip_tos_cmd); |
| 221 | install_element(CELLMGR_NODE, &cfg_ping_time_cmd); |
| 222 | install_element(CELLMGR_NODE, &cfg_pong_time_cmd); |
| 223 | install_element(CELLMGR_NODE, &cfg_msc_time_cmd); |
| 224 | } |
| 225 | |
| 226 | const char *openbsc_copyright = ""; |