Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 1 | /* OpenBSC NAT interface to quagga VTY */ |
| 2 | /* (C) 2010 by Holger Hans Peter Freyther |
| 3 | * (C) 2010 by On-Waves |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <vty/command.h> |
| 23 | #include <vty/buffer.h> |
| 24 | #include <vty/vty.h> |
| 25 | |
| 26 | #include <openbsc/bsc_nat.h> |
Holger Hans Peter Freyther | 8e2e0ac | 2010-05-11 19:07:39 +0800 | [diff] [blame] | 27 | #include <openbsc/bsc_msc.h> |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 28 | #include <openbsc/gsm_04_08.h> |
Holger Hans Peter Freyther | 3660e4d | 2010-06-15 18:50:26 +0800 | [diff] [blame] | 29 | #include <openbsc/mgcp.h> |
Holger Hans Peter Freyther | b372fad | 2010-04-06 12:01:15 +0200 | [diff] [blame] | 30 | #include <openbsc/vty.h> |
Holger Hans Peter Freyther | 3b96089 | 2010-06-15 19:06:18 +0800 | [diff] [blame] | 31 | |
| 32 | #include <osmocore/talloc.h> |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 33 | |
| 34 | #include <sccp/sccp.h> |
| 35 | |
| 36 | #include <stdlib.h> |
| 37 | |
| 38 | static struct bsc_nat *_nat; |
| 39 | |
| 40 | static struct cmd_node nat_node = { |
| 41 | NAT_NODE, |
| 42 | "%s(nat)#", |
| 43 | 1, |
| 44 | }; |
| 45 | |
| 46 | static struct cmd_node bsc_node = { |
| 47 | BSC_NODE, |
| 48 | "%s(bsc)#", |
| 49 | 1, |
| 50 | }; |
| 51 | |
| 52 | static int config_write_nat(struct vty *vty) |
| 53 | { |
| 54 | vty_out(vty, "nat%s", VTY_NEWLINE); |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 55 | if (_nat->imsi_allow) |
| 56 | vty_out(vty, " imsi allow %s%s", _nat->imsi_allow, VTY_NEWLINE); |
| 57 | if (_nat->imsi_deny) |
Holger Hans Peter Freyther | 88cc5d6 | 2010-05-14 23:06:09 +0800 | [diff] [blame^] | 58 | vty_out(vty, " imsi deny %s%s", _nat->imsi_deny, VTY_NEWLINE); |
Holger Hans Peter Freyther | 9226d70 | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 59 | vty_out(vty, " msc ip %s%s", _nat->msc_ip, VTY_NEWLINE); |
Holger Hans Peter Freyther | bace202 | 2010-04-17 07:48:45 +0200 | [diff] [blame] | 60 | vty_out(vty, " msc port %d%s", _nat->msc_port, VTY_NEWLINE); |
Holger Hans Peter Freyther | acd3078 | 2010-05-05 16:57:38 +0800 | [diff] [blame] | 61 | vty_out(vty, " timeout auth %d%s", _nat->auth_timeout, VTY_NEWLINE); |
| 62 | vty_out(vty, " timeout ping %d%s", _nat->ping_timeout, VTY_NEWLINE); |
| 63 | vty_out(vty, " timeout pong %d%s", _nat->pong_timeout, VTY_NEWLINE); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 64 | return CMD_SUCCESS; |
| 65 | } |
| 66 | |
| 67 | static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc) |
| 68 | { |
| 69 | vty_out(vty, " bsc %u%s", bsc->nr, VTY_NEWLINE); |
| 70 | vty_out(vty, " token %s%s", bsc->token, VTY_NEWLINE); |
Holger Hans Peter Freyther | 085ea30 | 2010-04-16 16:52:20 +0200 | [diff] [blame] | 71 | vty_out(vty, " location_area_code %u%s", bsc->lac, VTY_NEWLINE); |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 72 | if (bsc->imsi_allow) |
| 73 | vty_out(vty, " imsi allow %s%s", bsc->imsi_allow, VTY_NEWLINE); |
| 74 | if (bsc->imsi_deny) |
| 75 | vty_out(vty, " imsi deny %s%s", bsc->imsi_deny, VTY_NEWLINE); |
Holger Hans Peter Freyther | 7acf462 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 76 | vty_out(vty, " paging forbidden %d%s", bsc->forbid_paging, VTY_NEWLINE); |
Holger Hans Peter Freyther | 6f00907 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 77 | if (bsc->description) |
| 78 | vty_out(vty, " description %s%s", bsc->description, VTY_NEWLINE); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static int config_write_bsc(struct vty *vty) |
| 82 | { |
| 83 | struct bsc_config *bsc; |
| 84 | |
| 85 | llist_for_each_entry(bsc, &_nat->bsc_configs, entry) |
| 86 | config_write_bsc_single(vty, bsc); |
| 87 | return CMD_SUCCESS; |
| 88 | } |
| 89 | |
| 90 | |
Holger Hans Peter Freyther | 17f8c95 | 2010-04-19 16:06:43 +0800 | [diff] [blame] | 91 | DEFUN(show_sccp, show_sccp_cmd, "show sccp connections", |
| 92 | SHOW_STR "Display information about current SCCP connections") |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 93 | { |
| 94 | struct sccp_connections *con; |
Holger Hans Peter Freyther | dbdd30f | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 95 | vty_out(vty, "Listing all opening SCCP connections%s", VTY_NEWLINE); |
Holger Hans Peter Freyther | 0a3a853 | 2010-04-27 13:11:18 +0800 | [diff] [blame] | 96 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 97 | llist_for_each_entry(con, &_nat->sccp_connections, list_entry) { |
Holger Hans Peter Freyther | 0a3a853 | 2010-04-27 13:11:18 +0800 | [diff] [blame] | 98 | vty_out(vty, "For BSC Nr: %d lac: %d; BSC ref: 0x%x; MUX ref: 0x%x; Network has ref: %d ref: 0x%x MSC/BSC mux: 0x%x/0x%x%s", |
Holger Hans Peter Freyther | bfcf519 | 2010-04-06 15:11:34 +0200 | [diff] [blame] | 99 | con->bsc->cfg ? con->bsc->cfg->nr : -1, |
| 100 | con->bsc->cfg ? con->bsc->cfg->lac : -1, |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 101 | sccp_src_ref_to_int(&con->real_ref), |
Holger Hans Peter Freyther | 32aba23 | 2010-04-05 10:10:33 +0200 | [diff] [blame] | 102 | sccp_src_ref_to_int(&con->patched_ref), |
Holger Hans Peter Freyther | 0a3a853 | 2010-04-27 13:11:18 +0800 | [diff] [blame] | 103 | con->has_remote_ref, |
| 104 | sccp_src_ref_to_int(&con->remote_ref), |
Holger Hans Peter Freyther | 32aba23 | 2010-04-05 10:10:33 +0200 | [diff] [blame] | 105 | con->msc_timeslot, con->bsc_timeslot, |
| 106 | VTY_NEWLINE); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | return CMD_SUCCESS; |
| 110 | } |
| 111 | |
Holger Hans Peter Freyther | 17f8c95 | 2010-04-19 16:06:43 +0800 | [diff] [blame] | 112 | DEFUN(show_bsc, show_bsc_cmd, "show bsc connections", |
| 113 | SHOW_STR "Display information about current BSCs") |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 114 | { |
| 115 | struct bsc_connection *con; |
Holger Hans Peter Freyther | 9e53e97 | 2010-04-08 10:35:20 +0200 | [diff] [blame] | 116 | struct sockaddr_in sock; |
| 117 | socklen_t len = sizeof(sock); |
| 118 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 119 | llist_for_each_entry(con, &_nat->bsc_connections, list_entry) { |
Holger Hans Peter Freyther | 9e53e97 | 2010-04-08 10:35:20 +0200 | [diff] [blame] | 120 | getpeername(con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len); |
Holger Hans Peter Freyther | ffc051f | 2010-05-01 15:32:32 +0800 | [diff] [blame] | 121 | vty_out(vty, "BSC nr: %d lac: %d auth: %d fd: %d peername: %s%s", |
Holger Hans Peter Freyther | bfcf519 | 2010-04-06 15:11:34 +0200 | [diff] [blame] | 122 | con->cfg ? con->cfg->nr : -1, |
| 123 | con->cfg ? con->cfg->lac : -1, |
Holger Hans Peter Freyther | 9e53e97 | 2010-04-08 10:35:20 +0200 | [diff] [blame] | 124 | con->authenticated, con->write_queue.bfd.fd, |
| 125 | inet_ntoa(sock.sin_addr), VTY_NEWLINE); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | return CMD_SUCCESS; |
| 129 | } |
| 130 | |
Holger Hans Peter Freyther | 936aed7 | 2010-04-22 13:36:46 +0800 | [diff] [blame] | 131 | DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config", |
| 132 | SHOW_STR "Display information about known BSC configs") |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 133 | { |
| 134 | struct bsc_config *conf; |
| 135 | llist_for_each_entry(conf, &_nat->bsc_configs, entry) { |
| 136 | vty_out(vty, "BSC token: '%s' lac: %u nr: %u%s", |
| 137 | conf->token, conf->lac, conf->nr, VTY_NEWLINE); |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 138 | vty_out(vty, " imsi_allow: '%s' imsi_deny: '%s'%s", |
| 139 | conf->imsi_allow ? conf->imsi_allow: "any", |
| 140 | conf->imsi_deny ? conf->imsi_deny : "none", |
| 141 | VTY_NEWLINE); |
Holger Hans Peter Freyther | 7acf462 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 142 | vty_out(vty, " paging forbidden: %d%s", |
| 143 | conf->forbid_paging, VTY_NEWLINE); |
Holger Hans Peter Freyther | 6f00907 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 144 | if (conf->description) |
| 145 | vty_out(vty, " description: %s%s", conf->description, VTY_NEWLINE); |
| 146 | else |
| 147 | vty_out(vty, " No description.%s", VTY_NEWLINE); |
| 148 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | return CMD_SUCCESS; |
| 152 | } |
| 153 | |
Holger Hans Peter Freyther | 02e1c7d | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 154 | DEFUN(show_stats, |
| 155 | show_stats_cmd, |
Holger Hans Peter Freyther | 44d534c | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 156 | "show statistics [NR]", |
Holger Hans Peter Freyther | dbdd30f | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 157 | SHOW_STR "Display network statistics") |
Holger Hans Peter Freyther | 02e1c7d | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 158 | { |
| 159 | struct bsc_config *conf; |
| 160 | |
Holger Hans Peter Freyther | 44d534c | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 161 | int nr = -1; |
| 162 | |
| 163 | if (argc == 1) |
| 164 | nr = atoi(argv[0]); |
| 165 | |
Holger Hans Peter Freyther | 02e1c7d | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 166 | vty_out(vty, "NAT statistics%s", VTY_NEWLINE); |
| 167 | vty_out(vty, " SCCP Connections %lu total, %lu calls%s", |
| 168 | counter_get(_nat->stats.sccp.conn), |
| 169 | counter_get(_nat->stats.sccp.calls), VTY_NEWLINE); |
| 170 | vty_out(vty, " MSC Connections %lu%s", |
| 171 | counter_get(_nat->stats.msc.reconn), VTY_NEWLINE); |
| 172 | vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s", |
| 173 | counter_get(_nat->stats.bsc.reconn), |
| 174 | counter_get(_nat->stats.bsc.auth_fail), VTY_NEWLINE); |
| 175 | |
| 176 | llist_for_each_entry(conf, &_nat->bsc_configs, entry) { |
Holger Hans Peter Freyther | 44d534c | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 177 | if (argc == 1 && nr != conf->nr) |
| 178 | continue; |
| 179 | |
Holger Hans Peter Freyther | 02e1c7d | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 180 | vty_out(vty, " BSC lac: %d nr: %d%s", |
| 181 | conf->lac, conf->nr, VTY_NEWLINE); |
| 182 | vty_out(vty, " SCCP Connnections %lu total, %lu calls%s", |
| 183 | counter_get(conf->stats.sccp.conn), |
| 184 | counter_get(conf->stats.sccp.calls), VTY_NEWLINE); |
| 185 | vty_out(vty, " BSC Connections %lu total%s", |
| 186 | counter_get(conf->stats.net.reconn), VTY_NEWLINE); |
| 187 | } |
| 188 | |
| 189 | return CMD_SUCCESS; |
| 190 | } |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 191 | |
Holger Hans Peter Freyther | 8e2e0ac | 2010-05-11 19:07:39 +0800 | [diff] [blame] | 192 | DEFUN(show_msc, |
| 193 | show_msc_cmd, |
| 194 | "show msc connection", |
| 195 | SHOW_STR "Show the status of the MSC connection.") |
| 196 | { |
| 197 | if (!_nat->msc_con) { |
| 198 | vty_out(vty, "The MSC is not yet configured.\n"); |
| 199 | return CMD_WARNING; |
| 200 | } |
| 201 | |
| 202 | vty_out(vty, "MSC on %s:%d is connected: %d%s\n", |
| 203 | _nat->msc_con->ip, _nat->msc_con->port, |
| 204 | _nat->msc_con->is_connected, VTY_NEWLINE); |
| 205 | return CMD_SUCCESS; |
| 206 | } |
| 207 | |
Holger Hans Peter Freyther | 1512dc2 | 2010-04-27 13:21:39 +0800 | [diff] [blame] | 208 | DEFUN(close_bsc, |
| 209 | close_bsc_cmd, |
| 210 | "close bsc connection BSC_NR", |
Holger Hans Peter Freyther | dbdd30f | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 211 | "Close the connection with the BSC identified by the config number.") |
Holger Hans Peter Freyther | 1512dc2 | 2010-04-27 13:21:39 +0800 | [diff] [blame] | 212 | { |
| 213 | struct bsc_connection *bsc; |
| 214 | int bsc_nr = atoi(argv[0]); |
| 215 | |
| 216 | llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) { |
| 217 | if (!bsc->cfg || bsc->cfg->nr != bsc_nr) |
| 218 | continue; |
| 219 | bsc_close_connection(bsc); |
| 220 | break; |
| 221 | } |
| 222 | |
| 223 | return CMD_SUCCESS; |
| 224 | } |
| 225 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 226 | DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT") |
| 227 | { |
| 228 | vty->index = _nat; |
| 229 | vty->node = NAT_NODE; |
| 230 | |
| 231 | return CMD_SUCCESS; |
| 232 | } |
| 233 | |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 234 | DEFUN(cfg_nat_imsi_allow, |
| 235 | cfg_nat_imsi_allow_cmd, |
| 236 | "imsi allow [REGEXP]", |
| 237 | "Allow matching IMSIs to talk to the MSC. " |
| 238 | "The defualt is to allow everyone.") |
| 239 | { |
Holger Hans Peter Freyther | dac2dee | 2010-05-14 18:38:29 +0800 | [diff] [blame] | 240 | bsc_parse_reg(_nat, &_nat->imsi_allow_re, &_nat->imsi_allow, argc, argv); |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 241 | return CMD_SUCCESS; |
| 242 | } |
| 243 | |
| 244 | DEFUN(cfg_nat_imsi_deny, |
| 245 | cfg_nat_imsi_deny_cmd, |
| 246 | "imsi deny [REGEXP]", |
| 247 | "Deny matching IMSIs to talk to the MSC. " |
| 248 | "The defualt is to not deny.") |
| 249 | { |
Holger Hans Peter Freyther | dac2dee | 2010-05-14 18:38:29 +0800 | [diff] [blame] | 250 | bsc_parse_reg(_nat, &_nat->imsi_deny_re, &_nat->imsi_deny, argc, argv); |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 251 | return CMD_SUCCESS; |
| 252 | } |
| 253 | |
Holger Hans Peter Freyther | 9226d70 | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 254 | DEFUN(cfg_nat_msc_ip, |
| 255 | cfg_nat_msc_ip_cmd, |
Holger Hans Peter Freyther | f7cd800 | 2010-05-14 02:36:42 +0800 | [diff] [blame] | 256 | "msc ip A.B.C.D", |
Holger Hans Peter Freyther | 9226d70 | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 257 | "Set the IP address of the MSC.") |
| 258 | { |
| 259 | bsc_nat_set_msc_ip(_nat, argv[0]); |
| 260 | return CMD_SUCCESS; |
| 261 | } |
| 262 | |
Holger Hans Peter Freyther | bace202 | 2010-04-17 07:48:45 +0200 | [diff] [blame] | 263 | DEFUN(cfg_nat_msc_port, |
| 264 | cfg_nat_msc_port_cmd, |
| 265 | "msc port <1-65500>", |
| 266 | "Set the port of the MSC.") |
| 267 | { |
| 268 | _nat->msc_port = atoi(argv[0]); |
| 269 | return CMD_SUCCESS; |
| 270 | } |
| 271 | |
Holger Hans Peter Freyther | acd3078 | 2010-05-05 16:57:38 +0800 | [diff] [blame] | 272 | DEFUN(cfg_nat_auth_time, |
| 273 | cfg_nat_auth_time_cmd, |
| 274 | "timeout auth <1-256>", |
| 275 | "The time to wait for an auth response.") |
| 276 | { |
| 277 | _nat->auth_timeout = atoi(argv[0]); |
| 278 | return CMD_SUCCESS; |
| 279 | } |
| 280 | |
| 281 | DEFUN(cfg_nat_ping_time, |
| 282 | cfg_nat_ping_time_cmd, |
| 283 | "timeout ping NR", |
| 284 | "Send a ping every NR seconds. Negative to disable.") |
| 285 | { |
| 286 | _nat->ping_timeout = atoi(argv[0]); |
| 287 | return CMD_SUCCESS; |
| 288 | } |
| 289 | |
| 290 | DEFUN(cfg_nat_pong_time, |
| 291 | cfg_nat_pong_time_cmd, |
| 292 | "timeout pong NR", |
| 293 | "Wait NR seconds for the PONG response. Should be smaller than ping.") |
| 294 | { |
| 295 | _nat->pong_timeout = atoi(argv[0]); |
| 296 | return CMD_SUCCESS; |
| 297 | } |
| 298 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 299 | /* per BSC configuration */ |
Holger Hans Peter Freyther | dbdd30f | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 300 | DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure") |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 301 | { |
| 302 | int bsc_nr = atoi(argv[0]); |
| 303 | struct bsc_config *bsc; |
| 304 | |
| 305 | if (bsc_nr > _nat->num_bsc) { |
| 306 | vty_out(vty, "%% The next unused BSC number is %u%s", |
| 307 | _nat->num_bsc, VTY_NEWLINE); |
| 308 | return CMD_WARNING; |
| 309 | } else if (bsc_nr == _nat->num_bsc) { |
| 310 | /* allocate a new one */ |
| 311 | bsc = bsc_config_alloc(_nat, "unknown", 0); |
| 312 | } else |
| 313 | bsc = bsc_config_num(_nat, bsc_nr); |
| 314 | |
| 315 | if (!bsc) |
| 316 | return CMD_WARNING; |
| 317 | |
| 318 | vty->index = bsc; |
| 319 | vty->node = BSC_NODE; |
| 320 | |
| 321 | return CMD_SUCCESS; |
| 322 | } |
| 323 | |
| 324 | DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token") |
| 325 | { |
| 326 | struct bsc_config *conf = vty->index; |
| 327 | |
| 328 | if (conf->token) |
| 329 | talloc_free(conf->token); |
| 330 | conf->token = talloc_strdup(conf, argv[0]); |
| 331 | return CMD_SUCCESS; |
| 332 | } |
| 333 | |
| 334 | DEFUN(cfg_bsc_lac, cfg_bsc_lac_cmd, "location_area_code <0-65535>", |
Holger Hans Peter Freyther | dbdd30f | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 335 | "Set the Location Area Code (LAC) of this BSC") |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 336 | { |
Holger Hans Peter Freyther | 435a5c1 | 2010-03-30 06:08:56 +0200 | [diff] [blame] | 337 | struct bsc_config *tmp; |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 338 | struct bsc_config *conf = vty->index; |
| 339 | |
| 340 | int lac = atoi(argv[0]); |
| 341 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 342 | if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) { |
| 343 | vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s", |
| 344 | lac, VTY_NEWLINE); |
| 345 | return CMD_WARNING; |
| 346 | } |
| 347 | |
Holger Hans Peter Freyther | 435a5c1 | 2010-03-30 06:08:56 +0200 | [diff] [blame] | 348 | /* verify that the LACs are unique */ |
| 349 | llist_for_each_entry(tmp, &_nat->bsc_configs, entry) { |
| 350 | if (tmp->lac == lac) { |
| 351 | vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE); |
| 352 | return CMD_ERR_INCOMPLETE; |
| 353 | } |
| 354 | } |
| 355 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 356 | conf->lac = lac; |
| 357 | |
| 358 | return CMD_SUCCESS; |
| 359 | } |
| 360 | |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 361 | DEFUN(cfg_bsc_imsi_allow, |
| 362 | cfg_bsc_imsi_allow_cmd, |
| 363 | "imsi allow [REGEXP]", |
| 364 | "Allow IMSIs with the following network to talk to the MSC." |
| 365 | "The default is to allow everyone)") |
| 366 | { |
| 367 | struct bsc_config *conf = vty->index; |
| 368 | |
Holger Hans Peter Freyther | dac2dee | 2010-05-14 18:38:29 +0800 | [diff] [blame] | 369 | bsc_parse_reg(conf, &conf->imsi_allow_re, &conf->imsi_allow, argc, argv); |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 370 | return CMD_SUCCESS; |
| 371 | } |
| 372 | |
| 373 | DEFUN(cfg_bsc_imsi_deny, |
| 374 | cfg_bsc_imsi_deny_cmd, |
| 375 | "imsi deny [REGEXP]", |
| 376 | "Deny IMSIs with the following network to talk to the MSC." |
| 377 | "The default is to not deny anyone.)") |
| 378 | { |
| 379 | struct bsc_config *conf = vty->index; |
| 380 | |
Holger Hans Peter Freyther | dac2dee | 2010-05-14 18:38:29 +0800 | [diff] [blame] | 381 | bsc_parse_reg(conf, &conf->imsi_deny_re, &conf->imsi_deny, argc, argv); |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 382 | return CMD_SUCCESS; |
| 383 | } |
| 384 | |
Holger Hans Peter Freyther | 7acf462 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 385 | DEFUN(cfg_bsc_paging, |
| 386 | cfg_bsc_paging_cmd, |
| 387 | "paging forbidden (0|1)", |
| 388 | "Forbid sending PAGING REQUESTS to the BSC.") |
| 389 | { |
| 390 | struct bsc_config *conf = vty->index; |
| 391 | |
Holger Hans Peter Freyther | e6ac5de | 2010-04-21 20:07:07 +0800 | [diff] [blame] | 392 | if (strcmp("1", argv[0]) == 0) |
Holger Hans Peter Freyther | 7acf462 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 393 | conf->forbid_paging = 1; |
| 394 | else |
| 395 | conf->forbid_paging = 0; |
| 396 | |
| 397 | return CMD_SUCCESS; |
| 398 | } |
| 399 | |
Holger Hans Peter Freyther | 6f00907 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 400 | DEFUN(cfg_bsc_desc, |
| 401 | cfg_bsc_desc_cmd, |
| 402 | "description DESC", |
| 403 | "Provide a description for the given BSC.") |
| 404 | { |
| 405 | struct bsc_config *conf = vty->index; |
| 406 | |
| 407 | if (conf->description) |
| 408 | talloc_free(conf->description); |
| 409 | conf->description = talloc_strdup(conf, argv[0]); |
| 410 | return CMD_SUCCESS; |
| 411 | } |
| 412 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 413 | int bsc_nat_vty_init(struct bsc_nat *nat) |
| 414 | { |
| 415 | _nat = nat; |
| 416 | |
| 417 | cmd_init(1); |
| 418 | vty_init(); |
| 419 | |
| 420 | /* show commands */ |
| 421 | install_element(VIEW_NODE, &show_sccp_cmd); |
| 422 | install_element(VIEW_NODE, &show_bsc_cmd); |
| 423 | install_element(VIEW_NODE, &show_bsc_cfg_cmd); |
Holger Hans Peter Freyther | 02e1c7d | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 424 | install_element(VIEW_NODE, &show_stats_cmd); |
Holger Hans Peter Freyther | 1512dc2 | 2010-04-27 13:21:39 +0800 | [diff] [blame] | 425 | install_element(VIEW_NODE, &close_bsc_cmd); |
Holger Hans Peter Freyther | 8e2e0ac | 2010-05-11 19:07:39 +0800 | [diff] [blame] | 426 | install_element(VIEW_NODE, &show_msc_cmd); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 427 | |
Holger Hans Peter Freyther | b372fad | 2010-04-06 12:01:15 +0200 | [diff] [blame] | 428 | openbsc_vty_add_cmds(); |
| 429 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 430 | /* nat group */ |
| 431 | install_element(CONFIG_NODE, &cfg_nat_cmd); |
| 432 | install_node(&nat_node, config_write_nat); |
| 433 | install_default(NAT_NODE); |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 434 | install_element(NAT_NODE, &cfg_nat_imsi_allow_cmd); |
| 435 | install_element(NAT_NODE, &cfg_nat_imsi_deny_cmd); |
Holger Hans Peter Freyther | 9226d70 | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 436 | install_element(NAT_NODE, &cfg_nat_msc_ip_cmd); |
Holger Hans Peter Freyther | bace202 | 2010-04-17 07:48:45 +0200 | [diff] [blame] | 437 | install_element(NAT_NODE, &cfg_nat_msc_port_cmd); |
Holger Hans Peter Freyther | acd3078 | 2010-05-05 16:57:38 +0800 | [diff] [blame] | 438 | install_element(NAT_NODE, &cfg_nat_auth_time_cmd); |
| 439 | install_element(NAT_NODE, &cfg_nat_ping_time_cmd); |
| 440 | install_element(NAT_NODE, &cfg_nat_pong_time_cmd); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 441 | |
| 442 | /* BSC subgroups */ |
| 443 | install_element(NAT_NODE, &cfg_bsc_cmd); |
| 444 | install_node(&bsc_node, config_write_bsc); |
| 445 | install_default(BSC_NODE); |
| 446 | install_element(BSC_NODE, &cfg_bsc_token_cmd); |
| 447 | install_element(BSC_NODE, &cfg_bsc_lac_cmd); |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 448 | install_element(BSC_NODE, &cfg_bsc_imsi_allow_cmd); |
| 449 | install_element(BSC_NODE, &cfg_bsc_imsi_deny_cmd); |
Holger Hans Peter Freyther | 7acf462 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 450 | install_element(BSC_NODE, &cfg_bsc_paging_cmd); |
Holger Hans Peter Freyther | 6f00907 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 451 | install_element(BSC_NODE, &cfg_bsc_desc_cmd); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 452 | |
Holger Hans Peter Freyther | 3660e4d | 2010-06-15 18:50:26 +0800 | [diff] [blame] | 453 | mgcp_vty_init(); |
| 454 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | |
| 459 | /* called by the telnet interface... we have our own init above */ |
| 460 | void bsc_vty_init() |
| 461 | {} |