Neels Hofmeyr | 5e5a8bb | 2016-05-10 12:50:31 +0200 | [diff] [blame] | 1 | /* Code used by both libbsc and libmsc (common_cs means "BSC or MSC"). |
| 2 | * |
| 3 | * (C) 2016 by sysmocom s.m.f.c. <info@sysmocom.de> |
Neels Hofmeyr | 191933d | 2016-05-11 18:48:39 +0200 | [diff] [blame] | 4 | * (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
Neels Hofmeyr | 5e5a8bb | 2016-05-10 12:50:31 +0200 | [diff] [blame] | 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 Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 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 Affero General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
Neels Hofmeyr | 191933d | 2016-05-11 18:48:39 +0200 | [diff] [blame] | 21 | |
Neels Hofmeyr | bfe2727 | 2016-05-12 01:16:58 +0200 | [diff] [blame] | 22 | #include <osmocom/core/utils.h> |
| 23 | |
| 24 | #include <osmocom/vty/command.h> |
| 25 | #include <osmocom/vty/logging.h> |
| 26 | #include <osmocom/vty/stats.h> |
| 27 | |
| 28 | #include <openbsc/vty.h> |
| 29 | |
Neels Hofmeyr | 191933d | 2016-05-11 18:48:39 +0200 | [diff] [blame] | 30 | #include <openbsc/gsm_data.h> |
Neels Hofmeyr | bfe2727 | 2016-05-12 01:16:58 +0200 | [diff] [blame] | 31 | #include <openbsc/gsm_subscriber.h> |
| 32 | |
| 33 | struct cmd_node net_node = { |
| 34 | GSMNET_NODE, |
| 35 | "%s(config-net)# ", |
| 36 | 1, |
| 37 | }; |
| 38 | |
| 39 | #define NETWORK_STR "Configure the GSM network\n" |
| 40 | #define CODE_CMD_STR "Code commands\n" |
| 41 | #define NAME_CMD_STR "Name Commands\n" |
| 42 | #define NAME_STR "Name to use\n" |
| 43 | |
| 44 | DEFUN(cfg_net, |
| 45 | cfg_net_cmd, |
| 46 | "network", NETWORK_STR) |
| 47 | { |
| 48 | vty->index = gsmnet_from_vty(vty); |
| 49 | vty->node = GSMNET_NODE; |
| 50 | |
| 51 | return CMD_SUCCESS; |
| 52 | } |
| 53 | |
| 54 | DEFUN(cfg_net_ncc, |
| 55 | cfg_net_ncc_cmd, |
| 56 | "network country code <1-999>", |
| 57 | "Set the GSM network country code\n" |
| 58 | "Country commands\n" |
| 59 | CODE_CMD_STR |
| 60 | "Network Country Code to use\n") |
| 61 | { |
| 62 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 63 | |
| 64 | gsmnet->country_code = atoi(argv[0]); |
| 65 | |
| 66 | return CMD_SUCCESS; |
| 67 | } |
| 68 | |
| 69 | DEFUN(cfg_net_mnc, |
| 70 | cfg_net_mnc_cmd, |
| 71 | "mobile network code <0-999>", |
| 72 | "Set the GSM mobile network code\n" |
| 73 | "Network Commands\n" |
| 74 | CODE_CMD_STR |
| 75 | "Mobile Network Code to use\n") |
| 76 | { |
| 77 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 78 | |
| 79 | gsmnet->network_code = atoi(argv[0]); |
| 80 | |
| 81 | return CMD_SUCCESS; |
| 82 | } |
| 83 | |
| 84 | DEFUN(cfg_net_name_short, |
| 85 | cfg_net_name_short_cmd, |
| 86 | "short name NAME", |
| 87 | "Set the short GSM network name\n" NAME_CMD_STR NAME_STR) |
| 88 | { |
| 89 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 90 | |
| 91 | bsc_replace_string(gsmnet, &gsmnet->name_short, argv[0]); |
| 92 | return CMD_SUCCESS; |
| 93 | } |
| 94 | |
| 95 | DEFUN(cfg_net_name_long, |
| 96 | cfg_net_name_long_cmd, |
| 97 | "long name NAME", |
| 98 | "Set the long GSM network name\n" NAME_CMD_STR NAME_STR) |
| 99 | { |
| 100 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 101 | |
| 102 | bsc_replace_string(gsmnet, &gsmnet->name_long, argv[0]); |
| 103 | return CMD_SUCCESS; |
| 104 | } |
| 105 | |
| 106 | DEFUN(cfg_net_auth_policy, |
| 107 | cfg_net_auth_policy_cmd, |
| 108 | "auth policy (closed|accept-all|regexp|token)", |
| 109 | "Authentication (not cryptographic)\n" |
| 110 | "Set the GSM network authentication policy\n" |
| 111 | "Require the MS to be activated in HLR\n" |
| 112 | "Accept all MS, whether in HLR or not\n" |
| 113 | "Use regular expression for IMSI authorization decision\n" |
| 114 | "Use SMS-token based authentication\n") |
| 115 | { |
| 116 | enum gsm_auth_policy policy = gsm_auth_policy_parse(argv[0]); |
| 117 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 118 | |
| 119 | gsmnet->auth_policy = policy; |
| 120 | |
| 121 | return CMD_SUCCESS; |
| 122 | } |
| 123 | |
| 124 | DEFUN(cfg_net_authorize_regexp, cfg_net_authorize_regexp_cmd, |
| 125 | "authorized-regexp REGEXP", |
| 126 | "Set regexp for IMSI which will be used for authorization decision\n" |
| 127 | "Regular expression, IMSIs matching it are allowed to use the network\n") |
| 128 | { |
| 129 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 130 | if (gsm_parse_reg(gsmnet, &gsmnet->authorized_regexp, |
| 131 | &gsmnet->authorized_reg_str, argc, argv) != 0) { |
| 132 | vty_out(vty, "%%Failed to parse the authorized-regexp: '%s'%s", |
| 133 | argv[0], VTY_NEWLINE); |
| 134 | return CMD_WARNING; |
| 135 | } |
| 136 | |
| 137 | return CMD_SUCCESS; |
| 138 | } |
| 139 | |
| 140 | DEFUN(cfg_net_reject_cause, |
| 141 | cfg_net_reject_cause_cmd, |
| 142 | "location updating reject cause <2-111>", |
| 143 | "Set the reject cause of location updating reject\n" |
| 144 | "Set the reject cause of location updating reject\n" |
| 145 | "Set the reject cause of location updating reject\n" |
| 146 | "Set the reject cause of location updating reject\n" |
| 147 | "Cause Value as Per GSM TS 04.08\n") |
| 148 | { |
| 149 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 150 | |
| 151 | gsmnet->reject_cause = atoi(argv[0]); |
| 152 | |
| 153 | return CMD_SUCCESS; |
| 154 | } |
| 155 | |
| 156 | DEFUN(cfg_net_encryption, |
| 157 | cfg_net_encryption_cmd, |
| 158 | "encryption a5 (0|1|2|3)", |
| 159 | "Encryption options\n" |
| 160 | "A5 encryption\n" "A5/0: No encryption\n" |
| 161 | "A5/1: Encryption\n" "A5/2: Export-grade Encryption\n" |
| 162 | "A5/3: 'New' Secure Encryption\n") |
| 163 | { |
| 164 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 165 | |
| 166 | gsmnet->a5_encryption= atoi(argv[0]); |
| 167 | |
| 168 | return CMD_SUCCESS; |
| 169 | } |
| 170 | |
| 171 | DEFUN(cfg_net_rrlp_mode, cfg_net_rrlp_mode_cmd, |
| 172 | "rrlp mode (none|ms-based|ms-preferred|ass-preferred)", |
| 173 | "Radio Resource Location Protocol\n" |
| 174 | "Set the Radio Resource Location Protocol Mode\n" |
| 175 | "Don't send RRLP request\n" |
| 176 | "Request MS-based location\n" |
| 177 | "Request any location, prefer MS-based\n" |
| 178 | "Request any location, prefer MS-assisted\n") |
| 179 | { |
| 180 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 181 | |
| 182 | gsmnet->rrlp.mode = rrlp_mode_parse(argv[0]); |
| 183 | |
| 184 | return CMD_SUCCESS; |
| 185 | } |
| 186 | |
| 187 | DEFUN(cfg_net_mm_info, cfg_net_mm_info_cmd, |
| 188 | "mm info (0|1)", |
| 189 | "Mobility Management\n" |
| 190 | "Send MM INFO after LOC UPD ACCEPT\n" |
| 191 | "Disable\n" "Enable\n") |
| 192 | { |
| 193 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 194 | |
| 195 | gsmnet->send_mm_info = atoi(argv[0]); |
| 196 | |
| 197 | return CMD_SUCCESS; |
| 198 | } |
| 199 | |
| 200 | DEFUN(cfg_net_subscr_keep, |
| 201 | cfg_net_subscr_keep_cmd, |
| 202 | "subscriber-keep-in-ram (0|1)", |
| 203 | "Keep unused subscribers in RAM.\n" |
| 204 | "Delete unused subscribers\n" "Keep unused subscribers\n") |
| 205 | { |
| 206 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 207 | gsmnet->subscr_group->keep_subscr = atoi(argv[0]); |
| 208 | return CMD_SUCCESS; |
| 209 | } |
Neels Hofmeyr | 191933d | 2016-05-11 18:48:39 +0200 | [diff] [blame] | 210 | |
Neels Hofmeyr | 093d8f8 | 2016-05-14 03:24:41 +0200 | [diff] [blame^] | 211 | DEFUN(cfg_net_timezone, |
| 212 | cfg_net_timezone_cmd, |
| 213 | "timezone <-19-19> (0|15|30|45)", |
| 214 | "Set the Timezone Offset of the network\n" |
| 215 | "Timezone offset (hours)\n" |
| 216 | "Timezone offset (00 minutes)\n" |
| 217 | "Timezone offset (15 minutes)\n" |
| 218 | "Timezone offset (30 minutes)\n" |
| 219 | "Timezone offset (45 minutes)\n" |
| 220 | ) |
| 221 | { |
| 222 | struct gsm_network *net = vty->index; |
| 223 | int tzhr = atoi(argv[0]); |
| 224 | int tzmn = atoi(argv[1]); |
| 225 | |
| 226 | net->tz.hr = tzhr; |
| 227 | net->tz.mn = tzmn; |
| 228 | net->tz.dst = 0; |
| 229 | net->tz.override = 1; |
| 230 | |
| 231 | return CMD_SUCCESS; |
| 232 | } |
| 233 | |
| 234 | DEFUN(cfg_net_timezone_dst, |
| 235 | cfg_net_timezone_dst_cmd, |
| 236 | "timezone <-19-19> (0|15|30|45) <0-2>", |
| 237 | "Set the Timezone Offset of the network\n" |
| 238 | "Timezone offset (hours)\n" |
| 239 | "Timezone offset (00 minutes)\n" |
| 240 | "Timezone offset (15 minutes)\n" |
| 241 | "Timezone offset (30 minutes)\n" |
| 242 | "Timezone offset (45 minutes)\n" |
| 243 | "DST offset (hours)\n" |
| 244 | ) |
| 245 | { |
| 246 | struct gsm_network *net = vty->index; |
| 247 | int tzhr = atoi(argv[0]); |
| 248 | int tzmn = atoi(argv[1]); |
| 249 | int tzdst = atoi(argv[2]); |
| 250 | |
| 251 | net->tz.hr = tzhr; |
| 252 | net->tz.mn = tzmn; |
| 253 | net->tz.dst = tzdst; |
| 254 | net->tz.override = 1; |
| 255 | |
| 256 | return CMD_SUCCESS; |
| 257 | } |
| 258 | |
| 259 | DEFUN(cfg_net_no_timezone, |
| 260 | cfg_net_no_timezone_cmd, |
| 261 | "no timezone", |
| 262 | NO_STR |
| 263 | "Disable network timezone override, use system tz\n") |
| 264 | { |
| 265 | struct gsm_network *net = vty->index; |
| 266 | |
| 267 | net->tz.override = 0; |
| 268 | |
| 269 | return CMD_SUCCESS; |
| 270 | } |
| 271 | |
Neels Hofmeyr | 191933d | 2016-05-11 18:48:39 +0200 | [diff] [blame] | 272 | static struct gsm_network *vty_global_gsm_network = NULL; |
| 273 | |
| 274 | /* initialize VTY elements used in both BSC and MSC */ |
Neels Hofmeyr | bfe2727 | 2016-05-12 01:16:58 +0200 | [diff] [blame] | 275 | int common_cs_vty_init(struct gsm_network *network, |
| 276 | int (* config_write_net )(struct vty *)) |
Neels Hofmeyr | 191933d | 2016-05-11 18:48:39 +0200 | [diff] [blame] | 277 | { |
| 278 | OSMO_ASSERT(vty_global_gsm_network == NULL); |
| 279 | vty_global_gsm_network = network; |
Neels Hofmeyr | bfe2727 | 2016-05-12 01:16:58 +0200 | [diff] [blame] | 280 | |
| 281 | install_element(CONFIG_NODE, &cfg_net_cmd); |
| 282 | install_node(&net_node, config_write_net); |
| 283 | vty_install_default(GSMNET_NODE); |
| 284 | install_element(GSMNET_NODE, &cfg_net_ncc_cmd); |
| 285 | install_element(GSMNET_NODE, &cfg_net_mnc_cmd); |
| 286 | install_element(GSMNET_NODE, &cfg_net_name_short_cmd); |
| 287 | install_element(GSMNET_NODE, &cfg_net_name_long_cmd); |
| 288 | install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd); |
| 289 | install_element(GSMNET_NODE, &cfg_net_authorize_regexp_cmd); |
| 290 | install_element(GSMNET_NODE, &cfg_net_reject_cause_cmd); |
| 291 | install_element(GSMNET_NODE, &cfg_net_encryption_cmd); |
| 292 | install_element(GSMNET_NODE, &cfg_net_rrlp_mode_cmd); |
| 293 | install_element(GSMNET_NODE, &cfg_net_mm_info_cmd); |
| 294 | install_element(GSMNET_NODE, &cfg_net_subscr_keep_cmd); |
Neels Hofmeyr | 093d8f8 | 2016-05-14 03:24:41 +0200 | [diff] [blame^] | 295 | install_element(GSMNET_NODE, &cfg_net_timezone_cmd); |
| 296 | install_element(GSMNET_NODE, &cfg_net_timezone_dst_cmd); |
| 297 | install_element(GSMNET_NODE, &cfg_net_no_timezone_cmd); |
Neels Hofmeyr | bfe2727 | 2016-05-12 01:16:58 +0200 | [diff] [blame] | 298 | |
| 299 | return CMD_SUCCESS; |
Neels Hofmeyr | 191933d | 2016-05-11 18:48:39 +0200 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | struct gsm_network *gsmnet_from_vty(struct vty *v) |
| 303 | { |
| 304 | /* It can't hurt to force callers to continue to pass the vty instance |
| 305 | * to this function, in case we'd like to retrieve the global |
| 306 | * gsm_network instance from the vty at some point in the future. But |
| 307 | * until then, just return the global pointer, which should have been |
| 308 | * initialized by common_cs_vty_init(). |
| 309 | */ |
| 310 | OSMO_ASSERT(vty_global_gsm_network); |
| 311 | return vty_global_gsm_network; |
| 312 | } |