Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 1 | /* Osmo BSC VTY Configuration */ |
| 2 | /* (C) 2009-2010 by Holger Hans Peter Freyther |
Holger Hans Peter Freyther | 85531cc | 2010-10-06 20:37:09 +0800 | [diff] [blame] | 3 | * (C) 2009-2010 by On-Waves |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 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 |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 14 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 15 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 21 | #include <openbsc/gsm_data.h> |
| 22 | #include <openbsc/osmo_msc_data.h> |
| 23 | #include <openbsc/vty.h> |
| 24 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 25 | #include <osmocom/core/talloc.h> |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 26 | |
Holger Hans Peter Freyther | fe16622 | 2010-11-03 13:32:48 +0100 | [diff] [blame] | 27 | |
| 28 | #define IPA_STR "IP.ACCESS specific\n" |
| 29 | |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 30 | extern struct gsm_network *bsc_gsmnet; |
| 31 | |
| 32 | static struct osmo_msc_data *osmo_msc_data(struct vty *vty) |
| 33 | { |
| 34 | return bsc_gsmnet->msc_data; |
| 35 | } |
| 36 | |
| 37 | static struct cmd_node msc_node = { |
| 38 | MSC_NODE, |
| 39 | "%s(msc)#", |
| 40 | 1, |
| 41 | }; |
| 42 | |
| 43 | DEFUN(cfg_net_msc, cfg_net_msc_cmd, |
| 44 | "msc", "Configure MSC details") |
| 45 | { |
| 46 | vty->index = bsc_gsmnet; |
| 47 | vty->node = MSC_NODE; |
| 48 | |
| 49 | return CMD_SUCCESS; |
| 50 | } |
| 51 | |
| 52 | static int config_write_msc(struct vty *vty) |
| 53 | { |
| 54 | struct osmo_msc_data *data = osmo_msc_data(vty); |
| 55 | |
| 56 | vty_out(vty, " msc%s", VTY_NEWLINE); |
| 57 | if (data->bsc_token) |
| 58 | vty_out(vty, " token %s%s", data->bsc_token, VTY_NEWLINE); |
Holger Hans Peter Freyther | 4de1116 | 2010-11-03 13:12:18 +0100 | [diff] [blame] | 59 | if (data->core_ncc != -1) |
| 60 | vty_out(vty, " core-mobile-network-code %d%s", |
| 61 | data->core_ncc, VTY_NEWLINE); |
Holger Hans Peter Freyther | 2a8675e | 2010-11-05 19:43:07 +0100 | [diff] [blame] | 62 | if (data->core_mcc != -1) |
| 63 | vty_out(vty, " core-mobile-country-code %d%s", |
| 64 | data->core_mcc, VTY_NEWLINE); |
Holger Hans Peter Freyther | fe16622 | 2010-11-03 13:32:48 +0100 | [diff] [blame] | 65 | vty_out(vty, " ip.access rtp-base %d%s", data->rtp_base, VTY_NEWLINE); |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 66 | vty_out(vty, " ip %s%s", data->msc_ip, VTY_NEWLINE); |
| 67 | vty_out(vty, " port %d%s", data->msc_port, VTY_NEWLINE); |
| 68 | vty_out(vty, " ip-dscp %d%s", data->msc_ip_dscp, VTY_NEWLINE); |
| 69 | vty_out(vty, " timeout-ping %d%s", data->ping_timeout, VTY_NEWLINE); |
| 70 | vty_out(vty, " timeout-pong %d%s", data->pong_timeout, VTY_NEWLINE); |
Holger Hans Peter Freyther | bb62b3f | 2010-11-22 18:30:21 +0100 | [diff] [blame] | 71 | if (data->mid_call_txt) |
Holger Hans Peter Freyther | fcac291 | 2011-03-29 17:08:27 +0200 | [diff] [blame^] | 72 | vty_out(vty, " mid-call-text %s%s", data->mid_call_txt, VTY_NEWLINE); |
| 73 | vty_out(vty, " mid-call-timeout %d%s", data->mid_call_timeout, VTY_NEWLINE); |
Holger Hans Peter Freyther | fbceea4 | 2010-11-26 00:11:34 +0100 | [diff] [blame] | 74 | if (data->ussd_welcome_txt) |
Holger Hans Peter Freyther | fcac291 | 2011-03-29 17:08:27 +0200 | [diff] [blame^] | 75 | vty_out(vty, " bsc-welcome-text %s%s", data->ussd_welcome_txt, VTY_NEWLINE); |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 76 | |
Holger Hans Peter Freyther | 7bf66c5 | 2010-11-03 13:55:49 +0100 | [diff] [blame] | 77 | if (data->audio_length != 0) { |
| 78 | int i; |
| 79 | |
Holger Hans Peter Freyther | fcac291 | 2011-03-29 17:08:27 +0200 | [diff] [blame^] | 80 | vty_out(vty, " codec-list "); |
Holger Hans Peter Freyther | 7bf66c5 | 2010-11-03 13:55:49 +0100 | [diff] [blame] | 81 | for (i = 0; i < data->audio_length; ++i) { |
| 82 | if (i != 0) |
| 83 | vty_out(vty, ", "); |
| 84 | |
| 85 | if (data->audio_support[i]->hr) |
| 86 | vty_out(vty, "hr%.1u", data->audio_support[i]->ver); |
| 87 | else |
| 88 | vty_out(vty, "fr%.1u", data->audio_support[i]->ver); |
| 89 | } |
| 90 | vty_out(vty, "%s", VTY_NEWLINE); |
| 91 | |
| 92 | } |
| 93 | |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 94 | return CMD_SUCCESS; |
| 95 | } |
| 96 | |
Holger Hans Peter Freyther | 5b848f3 | 2010-11-03 13:11:14 +0100 | [diff] [blame] | 97 | DEFUN(cfg_net_bsc_token, |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 98 | cfg_net_bsc_token_cmd, |
| 99 | "token TOKEN", |
| 100 | "A token for the BSC to be sent to the MSC") |
| 101 | { |
| 102 | struct osmo_msc_data *data = osmo_msc_data(vty); |
| 103 | |
Holger Hans Peter Freyther | 3e9a7f8 | 2010-10-12 23:21:54 +0200 | [diff] [blame] | 104 | bsc_replace_string(data, &data->bsc_token, argv[0]); |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 105 | return CMD_SUCCESS; |
| 106 | } |
| 107 | |
Holger Hans Peter Freyther | 4de1116 | 2010-11-03 13:12:18 +0100 | [diff] [blame] | 108 | DEFUN(cfg_net_bsc_ncc, |
| 109 | cfg_net_bsc_ncc_cmd, |
Holger Hans Peter Freyther | 6e1a676 | 2011-02-10 11:37:13 +0100 | [diff] [blame] | 110 | "core-mobile-network-code <1-999>", |
Holger Hans Peter Freyther | 4de1116 | 2010-11-03 13:12:18 +0100 | [diff] [blame] | 111 | "Use this network code for the backbone\n" "NCC value\n") |
| 112 | { |
| 113 | struct osmo_msc_data *data = osmo_msc_data(vty); |
| 114 | data->core_ncc = atoi(argv[0]); |
| 115 | return CMD_SUCCESS; |
| 116 | } |
| 117 | |
Holger Hans Peter Freyther | 2a8675e | 2010-11-05 19:43:07 +0100 | [diff] [blame] | 118 | DEFUN(cfg_net_bsc_mcc, |
| 119 | cfg_net_bsc_mcc_cmd, |
Holger Hans Peter Freyther | 6e1a676 | 2011-02-10 11:37:13 +0100 | [diff] [blame] | 120 | "core-mobile-country-code <1-999>", |
Holger Hans Peter Freyther | 2a8675e | 2010-11-05 19:43:07 +0100 | [diff] [blame] | 121 | "Use this country code for the backbone\n" "MCC value\n") |
| 122 | { |
| 123 | struct osmo_msc_data *data = osmo_msc_data(vty); |
| 124 | data->core_mcc = atoi(argv[0]); |
| 125 | return CMD_SUCCESS; |
| 126 | } |
| 127 | |
Holger Hans Peter Freyther | fe16622 | 2010-11-03 13:32:48 +0100 | [diff] [blame] | 128 | DEFUN(cfg_net_bsc_rtp_base, |
| 129 | cfg_net_bsc_rtp_base_cmd, |
| 130 | "ip.access rtp-base <1-65000>", |
| 131 | IPA_STR |
| 132 | "Set the rtp-base port for the RTP stream\n" |
| 133 | "Port number\n") |
| 134 | { |
| 135 | struct osmo_msc_data *data = osmo_msc_data(vty); |
| 136 | data->rtp_base = atoi(argv[0]); |
| 137 | return CMD_SUCCESS; |
| 138 | } |
| 139 | |
Holger Hans Peter Freyther | 7bf66c5 | 2010-11-03 13:55:49 +0100 | [diff] [blame] | 140 | DEFUN(cfg_net_bsc_codec_list, |
| 141 | cfg_net_bsc_codec_list_cmd, |
| 142 | "codec-list .LIST", |
| 143 | "Set the allowed audio codecs\n" |
| 144 | "List of audio codecs\n") |
| 145 | { |
| 146 | struct osmo_msc_data *data = osmo_msc_data(vty); |
| 147 | int saw_fr, saw_hr; |
| 148 | int i; |
| 149 | |
| 150 | saw_fr = saw_hr = 0; |
| 151 | |
| 152 | /* free the old list... if it exists */ |
| 153 | if (data->audio_support) { |
| 154 | talloc_free(data->audio_support); |
| 155 | data->audio_support = NULL; |
| 156 | data->audio_length = 0; |
| 157 | } |
| 158 | |
| 159 | /* create a new array */ |
| 160 | data->audio_support = |
| 161 | talloc_zero_array(data, struct gsm_audio_support *, argc); |
| 162 | data->audio_length = argc; |
| 163 | |
| 164 | for (i = 0; i < argc; ++i) { |
| 165 | /* check for hrX or frX */ |
| 166 | if (strlen(argv[i]) != 3 |
| 167 | || argv[i][1] != 'r' |
| 168 | || (argv[i][0] != 'h' && argv[i][0] != 'f') |
| 169 | || argv[i][2] < 0x30 |
| 170 | || argv[i][2] > 0x39) |
| 171 | goto error; |
| 172 | |
| 173 | data->audio_support[i] = talloc_zero(data->audio_support, |
| 174 | struct gsm_audio_support); |
| 175 | data->audio_support[i]->ver = atoi(argv[i] + 2); |
| 176 | |
| 177 | if (strncmp("hr", argv[i], 2) == 0) { |
| 178 | data->audio_support[i]->hr = 1; |
| 179 | saw_hr = 1; |
| 180 | } else if (strncmp("fr", argv[i], 2) == 0) { |
| 181 | data->audio_support[i]->hr = 0; |
| 182 | saw_fr = 1; |
| 183 | } |
| 184 | |
| 185 | if (saw_hr && saw_fr) { |
| 186 | vty_out(vty, "Can not have full-rate and half-rate codec.%s", |
| 187 | VTY_NEWLINE); |
| 188 | return CMD_ERR_INCOMPLETE; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | return CMD_SUCCESS; |
| 193 | |
| 194 | error: |
| 195 | vty_out(vty, "Codec name must be hrX or frX. Was '%s'%s", |
| 196 | argv[i], VTY_NEWLINE); |
| 197 | return CMD_ERR_INCOMPLETE; |
| 198 | } |
| 199 | |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 200 | DEFUN(cfg_net_msc_ip, |
| 201 | cfg_net_msc_ip_cmd, |
| 202 | "ip A.B.C.D", "Set the MSC/MUX IP address.") |
| 203 | { |
| 204 | struct osmo_msc_data *data = osmo_msc_data(vty); |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 205 | |
Holger Hans Peter Freyther | 3e9a7f8 | 2010-10-12 23:21:54 +0200 | [diff] [blame] | 206 | bsc_replace_string(data, &data->msc_ip, argv[0]); |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 207 | return CMD_SUCCESS; |
| 208 | } |
| 209 | |
| 210 | DEFUN(cfg_net_msc_port, |
| 211 | cfg_net_msc_port_cmd, |
| 212 | "port <1-65000>", |
| 213 | "Set the MSC/MUX port.") |
| 214 | { |
| 215 | struct osmo_msc_data *data = osmo_msc_data(vty); |
| 216 | data->msc_port = atoi(argv[0]); |
| 217 | return CMD_SUCCESS; |
| 218 | } |
| 219 | |
| 220 | |
| 221 | DEFUN(cfg_net_msc_prio, |
| 222 | cfg_net_msc_prio_cmd, |
| 223 | "ip-dscp <0-255>", |
| 224 | "Set the IP_TOS socket attribite") |
| 225 | { |
| 226 | struct osmo_msc_data *data = osmo_msc_data(vty); |
| 227 | data->msc_ip_dscp = atoi(argv[0]); |
| 228 | return CMD_SUCCESS; |
| 229 | } |
| 230 | |
| 231 | DEFUN(cfg_net_msc_ping_time, |
| 232 | cfg_net_msc_ping_time_cmd, |
| 233 | "timeout-ping NR", |
| 234 | "Set the PING interval, negative for not sending PING") |
| 235 | { |
| 236 | struct osmo_msc_data *data = osmo_msc_data(vty); |
| 237 | data->ping_timeout = atoi(argv[0]); |
| 238 | return CMD_SUCCESS; |
| 239 | } |
| 240 | |
| 241 | DEFUN(cfg_net_msc_pong_time, |
| 242 | cfg_net_msc_pong_time_cmd, |
| 243 | "timeout-pong NR", |
| 244 | "Set the time to wait for a PONG.") |
| 245 | { |
| 246 | struct osmo_msc_data *data = osmo_msc_data(vty); |
| 247 | data->pong_timeout = atoi(argv[0]); |
| 248 | return CMD_SUCCESS; |
| 249 | } |
| 250 | |
Holger Hans Peter Freyther | bb62b3f | 2010-11-22 18:30:21 +0100 | [diff] [blame] | 251 | DEFUN(cfg_net_msc_mid_call_text, |
| 252 | cfg_net_msc_mid_call_text_cmd, |
| 253 | "mid-call-text .TEXT", |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 254 | "Set the USSD notifcation to be send.\n" "Text to be sent\n") |
| 255 | { |
| 256 | struct osmo_msc_data *data = osmo_msc_data(vty); |
Holger Hans Peter Freyther | 414bc4a | 2010-11-22 22:27:39 +0100 | [diff] [blame] | 257 | char *txt = argv_concat(argv, argc, 0); |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 258 | if (!txt) |
| 259 | return CMD_WARNING; |
| 260 | |
Holger Hans Peter Freyther | bb62b3f | 2010-11-22 18:30:21 +0100 | [diff] [blame] | 261 | bsc_replace_string(data, &data->mid_call_txt, txt); |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 262 | talloc_free(txt); |
| 263 | return CMD_SUCCESS; |
| 264 | } |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 265 | |
Holger Hans Peter Freyther | bb62b3f | 2010-11-22 18:30:21 +0100 | [diff] [blame] | 266 | DEFUN(cfg_net_msc_mid_call_timeout, |
| 267 | cfg_net_msc_mid_call_timeout_cmd, |
| 268 | "mid-call-timeout NR", |
Holger Hans Peter Freyther | 625b6e4 | 2010-11-22 18:25:02 +0100 | [diff] [blame] | 269 | "Switch from Grace to Off in NR seconds.\n" "Timeout in seconds\n") |
| 270 | { |
| 271 | struct osmo_msc_data *data = osmo_msc_data(vty); |
Holger Hans Peter Freyther | bb62b3f | 2010-11-22 18:30:21 +0100 | [diff] [blame] | 272 | data->mid_call_timeout = atoi(argv[0]); |
Holger Hans Peter Freyther | 625b6e4 | 2010-11-22 18:25:02 +0100 | [diff] [blame] | 273 | return CMD_SUCCESS; |
| 274 | } |
| 275 | |
Holger Hans Peter Freyther | fbceea4 | 2010-11-26 00:11:34 +0100 | [diff] [blame] | 276 | DEFUN(cfg_net_msc_welcome_ussd, |
| 277 | cfg_net_msc_welcome_ussd_cmd, |
| 278 | "bsc-welcome-text .TEXT", |
| 279 | "Set the USSD notification to be sent.\n" "Text to be sent\n") |
| 280 | { |
| 281 | struct osmo_msc_data *data = osmo_msc_data(vty); |
| 282 | char *str = argv_concat(argv, argc, 0); |
| 283 | if (!str) |
| 284 | return CMD_WARNING; |
| 285 | |
| 286 | bsc_replace_string(data, &data->ussd_welcome_txt, str); |
| 287 | talloc_free(str); |
| 288 | return CMD_SUCCESS; |
| 289 | } |
Holger Hans Peter Freyther | 625b6e4 | 2010-11-22 18:25:02 +0100 | [diff] [blame] | 290 | |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 291 | int bsc_vty_init_extra(void) |
| 292 | { |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 293 | install_element(GSMNET_NODE, &cfg_net_msc_cmd); |
| 294 | install_node(&msc_node, config_write_msc); |
| 295 | install_default(MSC_NODE); |
| 296 | install_element(MSC_NODE, &cfg_net_bsc_token_cmd); |
Holger Hans Peter Freyther | 4de1116 | 2010-11-03 13:12:18 +0100 | [diff] [blame] | 297 | install_element(MSC_NODE, &cfg_net_bsc_ncc_cmd); |
Holger Hans Peter Freyther | 2a8675e | 2010-11-05 19:43:07 +0100 | [diff] [blame] | 298 | install_element(MSC_NODE, &cfg_net_bsc_mcc_cmd); |
Holger Hans Peter Freyther | fe16622 | 2010-11-03 13:32:48 +0100 | [diff] [blame] | 299 | install_element(MSC_NODE, &cfg_net_bsc_rtp_base_cmd); |
Holger Hans Peter Freyther | 7bf66c5 | 2010-11-03 13:55:49 +0100 | [diff] [blame] | 300 | install_element(MSC_NODE, &cfg_net_bsc_codec_list_cmd); |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 301 | install_element(MSC_NODE, &cfg_net_msc_ip_cmd); |
| 302 | install_element(MSC_NODE, &cfg_net_msc_port_cmd); |
| 303 | install_element(MSC_NODE, &cfg_net_msc_prio_cmd); |
| 304 | install_element(MSC_NODE, &cfg_net_msc_ping_time_cmd); |
| 305 | install_element(MSC_NODE, &cfg_net_msc_pong_time_cmd); |
Holger Hans Peter Freyther | bb62b3f | 2010-11-22 18:30:21 +0100 | [diff] [blame] | 306 | install_element(MSC_NODE, &cfg_net_msc_mid_call_text_cmd); |
| 307 | install_element(MSC_NODE, &cfg_net_msc_mid_call_timeout_cmd); |
Holger Hans Peter Freyther | fbceea4 | 2010-11-26 00:11:34 +0100 | [diff] [blame] | 308 | install_element(MSC_NODE, &cfg_net_msc_welcome_ussd_cmd); |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 309 | |
Holger Hans Peter Freyther | cacbc73 | 2010-06-30 14:59:23 +0800 | [diff] [blame] | 310 | return 0; |
| 311 | } |