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> |
Holger Hans Peter Freyther | 0e4e35f | 2010-09-30 03:04:28 +0800 | [diff] [blame] | 26 | #include <osmocore/gsm48.h> |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 27 | |
| 28 | #include <osmocom/vty/command.h> |
| 29 | #include <osmocom/vty/vty.h> |
| 30 | |
| 31 | #include <unistd.h> |
| 32 | #include <netdb.h> |
| 33 | |
| 34 | #undef PACKAGE_NAME |
| 35 | #undef PACKAGE_VERSION |
| 36 | #undef PACKAGE_BUGREPORT |
| 37 | #undef PACKAGE_TARNAME |
| 38 | #undef PACKAGE_STRING |
| 39 | #include <cellmgr_config.h> |
| 40 | |
| 41 | extern struct bsc_data bsc; |
| 42 | |
| 43 | static struct vty_app_info vty_info = { |
| 44 | .name = "Cellmgr-ng", |
| 45 | .version = VERSION, |
| 46 | .go_parent_cb = NULL, |
| 47 | }; |
| 48 | |
| 49 | /* vty code */ |
| 50 | enum cellmgr_node { |
| 51 | CELLMGR_NODE = _LAST_OSMOVTY_NODE, |
| 52 | }; |
| 53 | |
| 54 | static struct cmd_node cell_node = { |
| 55 | CELLMGR_NODE, |
| 56 | "%s(cellmgr)#", |
| 57 | 1, |
| 58 | }; |
| 59 | |
Holger Hans Peter Freyther | 2656e8f | 2010-09-30 00:41:37 +0800 | [diff] [blame] | 60 | static int config_write_cell(struct vty *vty) |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 61 | { |
Holger Hans Peter Freyther | 2656e8f | 2010-09-30 00:41:37 +0800 | [diff] [blame] | 62 | vty_out(vty, "cellmgr%s", VTY_NEWLINE); |
| 63 | vty_out(vty, " mtp dpc %d%s", bsc.dpc, VTY_NEWLINE); |
| 64 | vty_out(vty, " mtp opc %d%s", bsc.opc, VTY_NEWLINE); |
Holger Hans Peter Freyther | 7a72556 | 2011-01-01 13:34:58 +0100 | [diff] [blame^] | 65 | vty_out(vty, " mtp sccp-opc %d%s", bsc.sccp_opc, VTY_NEWLINE); |
Holger Hans Peter Freyther | b38b33b | 2010-11-26 21:21:04 +0100 | [diff] [blame] | 66 | vty_out(vty, " mtp ni %d%s", bsc.ni_ni, VTY_NEWLINE); |
| 67 | vty_out(vty, " mtp spare %d%s", bsc.ni_spare, VTY_NEWLINE); |
Holger Hans Peter Freyther | 3bbb58b | 2010-11-26 21:25:38 +0100 | [diff] [blame] | 68 | vty_out(vty, " mtp sltm once %d%s", bsc.once, VTY_NEWLINE); |
Holger Hans Peter Freyther | 0e4e35f | 2010-09-30 03:04:28 +0800 | [diff] [blame] | 69 | vty_out(vty, " country-code %d%s", bsc.mcc, VTY_NEWLINE); |
| 70 | vty_out(vty, " network-code %d%s", bsc.mnc, VTY_NEWLINE); |
| 71 | vty_out(vty, " location-area-code %d%s", bsc.lac, VTY_NEWLINE); |
Holger Hans Peter Freyther | 2656e8f | 2010-09-30 00:41:37 +0800 | [diff] [blame] | 72 | if (bsc.udp_ip) |
| 73 | vty_out(vty, " udp dest ip %s%s", bsc.udp_ip, VTY_NEWLINE); |
| 74 | vty_out(vty, " udp dest port %d%s", bsc.udp_port, VTY_NEWLINE); |
| 75 | vty_out(vty, " udp src port %d%s", bsc.src_port, VTY_NEWLINE); |
| 76 | vty_out(vty, " udp reset %d%s", bsc.link.udp.reset_timeout, VTY_NEWLINE); |
Holger Hans Peter Freyther | 2656e8f | 2010-09-30 00:41:37 +0800 | [diff] [blame] | 77 | vty_out(vty, " msc ip %s%s", bsc.msc_address, VTY_NEWLINE); |
| 78 | vty_out(vty, " msc ip-dscp %d%s", bsc.msc_ip_dscp, VTY_NEWLINE); |
| 79 | vty_out(vty, " msc token %s%s", bsc.token, VTY_NEWLINE); |
| 80 | |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 81 | return CMD_SUCCESS; |
| 82 | } |
| 83 | |
| 84 | DEFUN(cfg_cell, cfg_cell_cmd, |
| 85 | "cellmgr", "Configure the Cellmgr") |
| 86 | { |
| 87 | vty->node = CELLMGR_NODE; |
| 88 | return CMD_SUCCESS; |
| 89 | } |
| 90 | |
| 91 | DEFUN(cfg_net_dpc, cfg_net_dpc_cmd, |
| 92 | "mtp dpc DPC_NR", |
| 93 | "Set the DPC to be used.") |
| 94 | { |
| 95 | bsc.dpc = atoi(argv[0]); |
| 96 | return CMD_SUCCESS; |
| 97 | } |
| 98 | |
| 99 | DEFUN(cfg_net_opc, cfg_net_opc_cmd, |
| 100 | "mtp opc OPC_NR", |
| 101 | "Set the OPC to be used.") |
| 102 | { |
| 103 | bsc.opc = atoi(argv[0]); |
| 104 | return CMD_SUCCESS; |
| 105 | } |
| 106 | |
Holger Hans Peter Freyther | 7a72556 | 2011-01-01 13:34:58 +0100 | [diff] [blame^] | 107 | DEFUN(cfg_net_sccp_opc, cfg_net_sccp_opc_cmd, |
| 108 | "mtp sccp-opc OPC_NR", |
| 109 | "Set the SCCP OPC to be used.") |
| 110 | { |
| 111 | bsc.sccp_opc = atoi(argv[0]); |
| 112 | return CMD_SUCCESS; |
| 113 | } |
| 114 | |
Holger Hans Peter Freyther | b38b33b | 2010-11-26 21:21:04 +0100 | [diff] [blame] | 115 | DEFUN(cfg_net_mtp_ni, cfg_net_mtp_ni_cmd, |
| 116 | "mtp ni NR", |
| 117 | "Set the MTP NI to be used.\n" "NR") |
| 118 | { |
| 119 | bsc.ni_ni = atoi(argv[0]); |
| 120 | return CMD_SUCCESS; |
| 121 | } |
| 122 | |
| 123 | DEFUN(cfg_net_mtp_spare, cfg_net_mtp_spare_cmd, |
| 124 | "mtp spare NR", |
| 125 | "Set the MTP Spare to be used.\n" "NR") |
| 126 | { |
| 127 | bsc.ni_spare = atoi(argv[0]); |
| 128 | return CMD_SUCCESS; |
| 129 | } |
| 130 | |
| 131 | |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 132 | DEFUN(cfg_udp_dst_ip, cfg_udp_dst_ip_cmd, |
| 133 | "udp dest ip IP", |
| 134 | "Set the IP when UDP mode is supposed to be used.") |
| 135 | { |
| 136 | struct hostent *hosts; |
| 137 | struct in_addr *addr; |
| 138 | |
| 139 | hosts = gethostbyname(argv[0]); |
| 140 | if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) { |
| 141 | vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE); |
| 142 | return CMD_WARNING; |
| 143 | } |
| 144 | |
| 145 | addr = (struct in_addr *) hosts->h_addr_list[0]; |
| 146 | bsc.udp_ip = talloc_strdup(NULL, inet_ntoa(*addr)); |
| 147 | return CMD_SUCCESS; |
| 148 | } |
| 149 | |
| 150 | DEFUN(cfg_udp_dst_port, cfg_udp_dst_port_cmd, |
| 151 | "udp dest port PORT_NR", |
| 152 | "If UDP mode is used specify the UDP dest port") |
| 153 | { |
| 154 | bsc.udp_port = atoi(argv[0]); |
| 155 | return CMD_SUCCESS; |
| 156 | } |
| 157 | |
| 158 | DEFUN(cfg_udp_src_port, cfg_udp_src_port_cmd, |
| 159 | "udp src port PORT_NR", |
| 160 | "Set the UDP source port to be used.") |
| 161 | { |
| 162 | bsc.src_port = atoi(argv[0]); |
| 163 | return CMD_SUCCESS; |
| 164 | } |
| 165 | |
| 166 | DEFUN(cfg_udp_reset, cfg_udp_reset_cmd, |
| 167 | "udp reset TIMEOUT", |
| 168 | "Set the timeout to take the link down") |
| 169 | { |
| 170 | bsc.link.udp.reset_timeout = atoi(argv[0]); |
| 171 | return CMD_SUCCESS; |
| 172 | } |
| 173 | |
| 174 | DEFUN(cfg_sltm_once, cfg_sltm_once_cmd, |
| 175 | "mtp sltm once (0|1)", |
| 176 | "Send SLTMs until the link is established.") |
| 177 | { |
| 178 | bsc.once = !!atoi(argv[0]); |
| 179 | return CMD_SUCCESS; |
| 180 | } |
| 181 | |
| 182 | DEFUN(cfg_msc_ip, cfg_msc_ip_cmd, |
| 183 | "msc ip IP", |
| 184 | "Set the MSC IP") |
| 185 | { |
| 186 | struct hostent *hosts; |
| 187 | struct in_addr *addr; |
| 188 | |
| 189 | hosts = gethostbyname(argv[0]); |
| 190 | if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) { |
| 191 | vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE); |
| 192 | return CMD_WARNING; |
| 193 | } |
| 194 | |
| 195 | addr = (struct in_addr *) hosts->h_addr_list[0]; |
| 196 | |
| 197 | bsc.msc_address = talloc_strdup(NULL, inet_ntoa(*addr)); |
| 198 | return CMD_SUCCESS; |
| 199 | } |
| 200 | |
| 201 | DEFUN(cfg_msc_ip_dscp, cfg_msc_ip_dscp_cmd, |
| 202 | "msc ip-dscp <0-255>", |
| 203 | "Set the IP DSCP on the A-link\n" |
| 204 | "Set the DSCP in IP packets to the MSC") |
| 205 | { |
| 206 | bsc.msc_ip_dscp = atoi(argv[0]); |
| 207 | return CMD_SUCCESS; |
| 208 | } |
| 209 | |
| 210 | ALIAS_DEPRECATED(cfg_msc_ip_dscp, cfg_msc_ip_tos_cmd, |
| 211 | "msc ip-tos <0-255>", |
| 212 | "Set the IP DSCP on the A-link\n" |
| 213 | "Set the DSCP in IP packets to the MSC") |
| 214 | |
| 215 | DEFUN(cfg_msc_token, cfg_msc_token_cmd, |
| 216 | "msc token TOKEN", |
| 217 | "Set the Token to be used for the MSC") |
| 218 | { |
| 219 | bsc.token = talloc_strdup(NULL, argv[0]); |
| 220 | return CMD_SUCCESS; |
| 221 | } |
| 222 | |
| 223 | DEFUN(cfg_ping_time, cfg_ping_time_cmd, |
| 224 | "timeout ping NR", |
| 225 | "Set the PING interval. Negative to disable it") |
| 226 | { |
| 227 | bsc.ping_time = atoi(argv[0]); |
| 228 | return CMD_SUCCESS; |
| 229 | } |
| 230 | |
| 231 | DEFUN(cfg_pong_time, cfg_pong_time_cmd, |
| 232 | "timeout pong NR", |
| 233 | "Set the PING interval. Negative to disable it") |
| 234 | { |
| 235 | bsc.pong_time = atoi(argv[0]); |
| 236 | return CMD_SUCCESS; |
| 237 | } |
| 238 | |
| 239 | DEFUN(cfg_msc_time, cfg_msc_time_cmd, |
| 240 | "timeout msc NR", |
| 241 | "Set the MSC connect timeout") |
| 242 | { |
| 243 | bsc.msc_time = atoi(argv[0]); |
| 244 | return CMD_SUCCESS; |
| 245 | } |
| 246 | |
Holger Hans Peter Freyther | 0e4e35f | 2010-09-30 03:04:28 +0800 | [diff] [blame] | 247 | static void update_lai(struct bsc_data *bsc) |
| 248 | { |
| 249 | gsm48_generate_lai(&bsc->lai, bsc->mcc, bsc->mnc, bsc->lac); |
| 250 | } |
| 251 | |
| 252 | DEFUN(cfg_mnc, cfg_mnc_cmd, |
| 253 | "network-code NR", |
| 254 | "Set the Mobile Network Code\n" "Number\n") |
| 255 | { |
| 256 | bsc.mnc = atoi(argv[0]); |
| 257 | update_lai(&bsc); |
| 258 | return CMD_SUCCESS; |
| 259 | } |
| 260 | |
| 261 | DEFUN(cfg_mcc, cfg_mcc_cmd, |
| 262 | "country-code NR", |
| 263 | "Set the Mobile Country Code\n" "Number\n") |
| 264 | { |
| 265 | bsc.mcc = atoi(argv[0]); |
| 266 | update_lai(&bsc); |
| 267 | return CMD_SUCCESS; |
| 268 | } |
| 269 | |
| 270 | DEFUN(cfg_lac, cfg_lac_cmd, |
| 271 | "location-area-code NR", |
| 272 | "Set the Location Area Code\n" "Number\n") |
| 273 | { |
| 274 | bsc.lac = atoi(argv[0]); |
| 275 | update_lai(&bsc); |
| 276 | return CMD_SUCCESS; |
| 277 | } |
| 278 | |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 279 | void cell_vty_init(void) |
| 280 | { |
| 281 | cmd_init(1); |
| 282 | vty_init(&vty_info); |
| 283 | |
| 284 | install_element(CONFIG_NODE, &cfg_cell_cmd); |
| 285 | install_node(&cell_node, config_write_cell); |
| 286 | |
| 287 | install_element(CELLMGR_NODE, &cfg_net_dpc_cmd); |
| 288 | install_element(CELLMGR_NODE, &cfg_net_opc_cmd); |
Holger Hans Peter Freyther | 7a72556 | 2011-01-01 13:34:58 +0100 | [diff] [blame^] | 289 | install_element(CELLMGR_NODE, &cfg_net_sccp_opc_cmd); |
Holger Hans Peter Freyther | b38b33b | 2010-11-26 21:21:04 +0100 | [diff] [blame] | 290 | install_element(CELLMGR_NODE, &cfg_net_mtp_ni_cmd); |
| 291 | install_element(CELLMGR_NODE, &cfg_net_mtp_spare_cmd); |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 292 | install_element(CELLMGR_NODE, &cfg_udp_dst_ip_cmd); |
| 293 | install_element(CELLMGR_NODE, &cfg_udp_dst_port_cmd); |
| 294 | install_element(CELLMGR_NODE, &cfg_udp_src_port_cmd); |
| 295 | install_element(CELLMGR_NODE, &cfg_udp_reset_cmd); |
| 296 | install_element(CELLMGR_NODE, &cfg_sltm_once_cmd); |
| 297 | install_element(CELLMGR_NODE, &cfg_msc_ip_cmd); |
| 298 | install_element(CELLMGR_NODE, &cfg_msc_token_cmd); |
| 299 | install_element(CELLMGR_NODE, &cfg_msc_ip_dscp_cmd); |
| 300 | install_element(CELLMGR_NODE, &cfg_msc_ip_tos_cmd); |
| 301 | install_element(CELLMGR_NODE, &cfg_ping_time_cmd); |
| 302 | install_element(CELLMGR_NODE, &cfg_pong_time_cmd); |
| 303 | install_element(CELLMGR_NODE, &cfg_msc_time_cmd); |
Holger Hans Peter Freyther | 0e4e35f | 2010-09-30 03:04:28 +0800 | [diff] [blame] | 304 | install_element(CELLMGR_NODE, &cfg_mcc_cmd); |
| 305 | install_element(CELLMGR_NODE, &cfg_mnc_cmd); |
| 306 | install_element(CELLMGR_NODE, &cfg_lac_cmd); |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | const char *openbsc_copyright = ""; |