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