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