Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 1 | /* SMPP vty interface */ |
| 2 | |
| 3 | /* (C) 2012 by Harald Welte <laforge@gnumonks.org> |
| 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 Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 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 Affero General Public License for more details. |
| 15 | * |
| 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/>. |
| 18 | * |
| 19 | */ |
| 20 | |
Harald Welte | 691ce33 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 21 | #include <ctype.h> |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 22 | #include <string.h> |
Harald Welte | 691ce33 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 23 | #include <errno.h> |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 24 | #include <netdb.h> |
| 25 | #include <sys/socket.h> |
| 26 | |
| 27 | #include <osmocom/vty/command.h> |
| 28 | #include <osmocom/vty/buffer.h> |
| 29 | #include <osmocom/vty/vty.h> |
| 30 | |
| 31 | #include <osmocom/core/linuxlist.h> |
| 32 | #include <osmocom/core/utils.h> |
| 33 | #include <osmocom/core/talloc.h> |
| 34 | |
| 35 | #include <openbsc/vty.h> |
| 36 | |
| 37 | #include "smpp_smsc.h" |
| 38 | |
| 39 | struct smsc *smsc_from_vty(struct vty *v); |
| 40 | |
| 41 | static struct cmd_node smpp_node = { |
| 42 | SMPP_NODE, |
| 43 | "%s(config-smpp)# ", |
| 44 | 1, |
| 45 | }; |
| 46 | |
| 47 | static struct cmd_node esme_node = { |
| 48 | SMPP_ESME_NODE, |
| 49 | "%s(config-smpp-esme)# ", |
| 50 | 1, |
| 51 | }; |
| 52 | |
| 53 | DEFUN(cfg_smpp, cfg_smpp_cmd, |
| 54 | "smpp", "Configure SMPP SMS Interface") |
| 55 | { |
| 56 | vty->node = SMPP_NODE; |
| 57 | |
| 58 | return CMD_SUCCESS; |
| 59 | } |
| 60 | |
Holger Hans Peter Freyther | 3c64e2d | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 61 | DEFUN(cfg_smpp_first, cfg_smpp_first_cmd, |
| 62 | "smpp-first", |
| 63 | "Try SMPP routes before the subscriber DB\n") |
| 64 | { |
| 65 | struct smsc *smsc = smsc_from_vty(vty); |
| 66 | smsc->smpp_first = 1; |
| 67 | return CMD_SUCCESS; |
| 68 | } |
| 69 | |
| 70 | DEFUN(cfg_no_smpp_first, cfg_no_smpp_first_cmd, |
| 71 | "no smpp-first", |
| 72 | NO_STR "Try SMPP before routes before the subscriber DB\n") |
| 73 | { |
| 74 | struct smsc *smsc = smsc_from_vty(vty); |
| 75 | smsc->smpp_first = 0; |
| 76 | return CMD_SUCCESS; |
| 77 | } |
| 78 | |
Neels Hofmeyr | abc6465 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 79 | static int smpp_local_tcp(struct vty *vty, |
| 80 | const char *bind_addr, uint16_t port) |
| 81 | { |
| 82 | struct smsc *smsc = smsc_from_vty(vty); |
| 83 | int is_running = smsc->listen_ofd.fd > 0; |
| 84 | int same_bind_addr; |
| 85 | int rc; |
| 86 | |
| 87 | /* If it is not up yet, don't rebind, just set values. */ |
| 88 | if (!is_running) { |
| 89 | rc = smpp_smsc_conf(smsc, bind_addr, port); |
| 90 | if (rc < 0) { |
| 91 | vty_out(vty, "%% Cannot configure new address:port%s", |
| 92 | VTY_NEWLINE); |
| 93 | return CMD_WARNING; |
| 94 | } |
| 95 | return CMD_SUCCESS; |
| 96 | } |
| 97 | |
| 98 | rc = smpp_smsc_restart(smsc, bind_addr, port); |
| 99 | if (rc < 0) { |
| 100 | vty_out(vty, "%% Cannot bind to new port %s:%u nor to" |
| 101 | " old port %s:%u%s", |
| 102 | bind_addr? bind_addr : "0.0.0.0", |
| 103 | port, |
| 104 | smsc->bind_addr? smsc->bind_addr : "0.0.0.0", |
| 105 | smsc->listen_port, |
| 106 | VTY_NEWLINE); |
| 107 | return CMD_WARNING; |
| 108 | } |
| 109 | |
| 110 | same_bind_addr = (bind_addr == smsc->bind_addr) |
| 111 | || (bind_addr && smsc->bind_addr |
| 112 | && (strcmp(bind_addr, smsc->bind_addr) == 0)); |
| 113 | |
| 114 | if (!same_bind_addr || port != smsc->listen_port) { |
| 115 | vty_out(vty, "%% Cannot bind to new port %s:%u, staying on" |
| 116 | " old port %s:%u%s", |
| 117 | bind_addr? bind_addr : "0.0.0.0", |
| 118 | port, |
| 119 | smsc->bind_addr? smsc->bind_addr : "0.0.0.0", |
| 120 | smsc->listen_port, |
| 121 | VTY_NEWLINE); |
| 122 | return CMD_WARNING; |
| 123 | } |
| 124 | |
| 125 | return CMD_SUCCESS; |
| 126 | } |
| 127 | |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 128 | DEFUN(cfg_smpp_port, cfg_smpp_port_cmd, |
| 129 | "local-tcp-port <1-65535>", |
| 130 | "Set the local TCP port on which we listen for SMPP\n" |
| 131 | "TCP port number") |
| 132 | { |
| 133 | struct smsc *smsc = smsc_from_vty(vty); |
| 134 | uint16_t port = atoi(argv[0]); |
Neels Hofmeyr | abc6465 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 135 | return smpp_local_tcp(vty, smsc->bind_addr, port); |
| 136 | } |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 137 | |
Neels Hofmeyr | abc6465 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 138 | DEFUN(cfg_smpp_addr_port, cfg_smpp_addr_port_cmd, |
| 139 | "local-tcp-ip A.B.C.D <1-65535>", |
| 140 | "Set the local IP address and TCP port on which we listen for SMPP\n" |
| 141 | "Local IP address\n" |
| 142 | "TCP port number") |
| 143 | { |
| 144 | const char *bind_addr = argv[0]; |
| 145 | uint16_t port = atoi(argv[1]); |
| 146 | return smpp_local_tcp(vty, bind_addr, port); |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | DEFUN(cfg_smpp_sys_id, cfg_smpp_sys_id_cmd, |
Harald Welte | 1e0c722 | 2013-07-21 16:00:28 +0800 | [diff] [blame] | 150 | "system-id ID", |
| 151 | "Set the System ID of this SMSC\n" |
| 152 | "Alphanumeric SMSC System ID\n") |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 153 | { |
| 154 | struct smsc *smsc = smsc_from_vty(vty); |
| 155 | |
| 156 | if (strlen(argv[0])+1 > sizeof(smsc->system_id)) |
| 157 | return CMD_WARNING; |
| 158 | |
| 159 | strcpy(smsc->system_id, argv[0]); |
| 160 | |
| 161 | return CMD_SUCCESS; |
| 162 | } |
| 163 | |
| 164 | DEFUN(cfg_smpp_policy, cfg_smpp_policy_cmd, |
| 165 | "policy (accept-all|closed)", |
| 166 | "Set the authentication policy of this SMSC\n" |
| 167 | "Accept all SMPP connections independeint of system ID / passwd\n" |
| 168 | "Accept only SMPP connections from ESMEs explicitly configured") |
| 169 | { |
| 170 | struct smsc *smsc = smsc_from_vty(vty); |
| 171 | |
| 172 | if (!strcmp(argv[0], "accept-all")) |
| 173 | smsc->accept_all = 1; |
| 174 | else |
| 175 | smsc->accept_all = 0; |
| 176 | |
| 177 | return CMD_SUCCESS; |
| 178 | } |
| 179 | |
| 180 | |
| 181 | static int config_write_smpp(struct vty *vty) |
| 182 | { |
| 183 | struct smsc *smsc = smsc_from_vty(vty); |
| 184 | |
| 185 | vty_out(vty, "smpp%s", VTY_NEWLINE); |
Neels Hofmeyr | abc6465 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 186 | if (smsc->bind_addr) |
| 187 | vty_out(vty, " local-tcp-ip %s %u%s", smsc->bind_addr, |
| 188 | smsc->listen_port, VTY_NEWLINE); |
| 189 | else |
| 190 | vty_out(vty, " local-tcp-port %u%s", smsc->listen_port, |
| 191 | VTY_NEWLINE); |
Holger Hans Peter Freyther | 7832d2e | 2013-07-14 08:50:57 +0200 | [diff] [blame] | 192 | if (strlen(smsc->system_id) > 0) |
Harald Welte | 20c366a | 2013-01-24 09:54:04 +0100 | [diff] [blame] | 193 | vty_out(vty, " system-id %s%s", smsc->system_id, VTY_NEWLINE); |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 194 | vty_out(vty, " policy %s%s", |
| 195 | smsc->accept_all ? "accept-all" : "closed", VTY_NEWLINE); |
Holger Hans Peter Freyther | 3c64e2d | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 196 | vty_out(vty, " %ssmpp-first%s", |
| 197 | smsc->smpp_first ? "" : "no ", VTY_NEWLINE); |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 198 | |
| 199 | return CMD_SUCCESS; |
| 200 | } |
| 201 | |
| 202 | DEFUN(cfg_esme, cfg_esme_cmd, |
Harald Welte | 1e0c722 | 2013-07-21 16:00:28 +0800 | [diff] [blame] | 203 | "esme NAME", |
| 204 | "Configure a particular ESME\n" |
| 205 | "Alphanumeric System ID of the ESME to be configured\n") |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 206 | { |
| 207 | struct smsc *smsc = smsc_from_vty(vty); |
| 208 | struct osmo_smpp_acl *acl; |
| 209 | const char *id = argv[0]; |
| 210 | |
| 211 | if (strlen(id) > 16) { |
| 212 | vty_out(vty, "%% System ID cannot be more than 16 " |
| 213 | "characters long%s", VTY_NEWLINE); |
| 214 | return CMD_WARNING; |
| 215 | } |
| 216 | acl = smpp_acl_by_system_id(smsc, id); |
| 217 | if (!acl) { |
| 218 | acl = smpp_acl_alloc(smsc, id); |
| 219 | if (!acl) |
| 220 | return CMD_WARNING; |
| 221 | } |
| 222 | |
| 223 | vty->index = acl; |
| 224 | vty->index_sub = &acl->description; |
| 225 | vty->node = SMPP_ESME_NODE; |
| 226 | |
| 227 | return CMD_SUCCESS; |
| 228 | } |
| 229 | |
| 230 | DEFUN(cfg_no_esme, cfg_no_esme_cmd, |
Harald Welte | 1e0c722 | 2013-07-21 16:00:28 +0800 | [diff] [blame] | 231 | "no esme NAME", |
| 232 | NO_STR "Remove ESME configuration\n" |
| 233 | "Alphanumeric System ID of the ESME to be removed\n") |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 234 | { |
| 235 | struct smsc *smsc = smsc_from_vty(vty); |
| 236 | struct osmo_smpp_acl *acl; |
| 237 | const char *id = argv[0]; |
| 238 | |
| 239 | acl = smpp_acl_by_system_id(smsc, id); |
| 240 | if (!acl) { |
| 241 | vty_out(vty, "%% ESME with system id '%s' unknown%s", |
| 242 | id, VTY_NEWLINE); |
| 243 | return CMD_WARNING; |
| 244 | } |
| 245 | |
| 246 | /* FIXME: close the connection, free data structure, etc. */ |
| 247 | |
| 248 | smpp_acl_delete(acl); |
| 249 | |
| 250 | return CMD_SUCCESS; |
| 251 | } |
| 252 | |
| 253 | |
| 254 | DEFUN(cfg_esme_passwd, cfg_esme_passwd_cmd, |
Harald Welte | 1e0c722 | 2013-07-21 16:00:28 +0800 | [diff] [blame] | 255 | "password PASSWORD", |
| 256 | "Set the password for this ESME\n" |
| 257 | "Alphanumeric password string\n") |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 258 | { |
| 259 | struct osmo_smpp_acl *acl = vty->index; |
| 260 | |
| 261 | if (strlen(argv[0])+1 > sizeof(acl->passwd)) |
| 262 | return CMD_WARNING; |
| 263 | |
| 264 | strcpy(acl->passwd, argv[0]); |
| 265 | |
| 266 | return CMD_SUCCESS; |
| 267 | } |
| 268 | |
| 269 | DEFUN(cfg_esme_no_passwd, cfg_esme_no_passwd_cmd, |
Harald Welte | 1e0c722 | 2013-07-21 16:00:28 +0800 | [diff] [blame] | 270 | "no password", |
| 271 | NO_STR "Remove the password for this ESME\n") |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 272 | { |
| 273 | struct osmo_smpp_acl *acl = vty->index; |
| 274 | |
| 275 | memset(acl->passwd, 0, sizeof(acl->passwd)); |
| 276 | |
| 277 | return CMD_SUCCESS; |
| 278 | } |
| 279 | |
Harald Welte | 691ce33 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 280 | static int osmo_is_digits(const char *str) |
| 281 | { |
| 282 | int i; |
| 283 | for (i = 0; i < strlen(str); i++) { |
| 284 | if (!isdigit(str[i])) |
| 285 | return 0; |
| 286 | } |
| 287 | return 1; |
| 288 | } |
| 289 | |
| 290 | static const struct value_string route_errstr[] = { |
| 291 | { -EEXIST, "Route already exists" }, |
| 292 | { -ENODEV, "Route does not exist" }, |
| 293 | { -ENOMEM, "No memory" }, |
| 294 | { -EINVAL, "Invalid" }, |
| 295 | { 0, NULL } |
| 296 | }; |
| 297 | |
| 298 | static const struct value_string smpp_ton_str_short[] = { |
| 299 | { TON_Unknown, "unknown" }, |
| 300 | { TON_International, "international" }, |
| 301 | { TON_National, "national" }, |
| 302 | { TON_Network_Specific, "network" }, |
| 303 | { TON_Subscriber_Number,"subscriber" }, |
| 304 | { TON_Alphanumeric, "alpha" }, |
| 305 | { TON_Abbreviated, "abbrev" }, |
| 306 | { 0, NULL } |
| 307 | }; |
| 308 | |
| 309 | static const struct value_string smpp_npi_str_short[] = { |
| 310 | { NPI_Unknown, "unknown" }, |
| 311 | { NPI_ISDN_E163_E164, "isdn" }, |
| 312 | { NPI_Data_X121, "x121" }, |
| 313 | { NPI_Telex_F69, "f69" }, |
| 314 | { NPI_Land_Mobile_E212, "e212" }, |
| 315 | { NPI_National, "national" }, |
| 316 | { NPI_Private, "private" }, |
| 317 | { NPI_ERMES, "ermes" }, |
| 318 | { NPI_Internet_IP, "ip" }, |
| 319 | { NPI_WAP_Client_Id, "wap" }, |
| 320 | { 0, NULL } |
| 321 | }; |
| 322 | |
| 323 | |
| 324 | #define SMPP_ROUTE_STR "Configure a route for MO-SMS to be sent to this ESME\n" |
Harald Welte | 1e0c722 | 2013-07-21 16:00:28 +0800 | [diff] [blame] | 325 | #define SMPP_ROUTE_P_STR SMPP_ROUTE_STR "Prefix-match route\n" |
Harald Welte | 691ce33 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 326 | #define SMPP_PREFIX_STR "Destination number prefix\n" |
| 327 | |
| 328 | #define TON_CMD "(unknown|international|national|network|subscriber|alpha|abbrev)" |
| 329 | #define NPI_CMD "(unknown|isdn|x121|f69|e212|national|private|ermes|ip|wap)" |
Harald Welte | 1e0c722 | 2013-07-21 16:00:28 +0800 | [diff] [blame] | 330 | #define TON_STR "Unknown type-of-number\n" \ |
| 331 | "International type-of-number\n" \ |
| 332 | "National type-of-number\n" \ |
| 333 | "Network specific type-of-number\n" \ |
| 334 | "Subscriber type-of-number\n" \ |
| 335 | "Alphanumeric type-of-number\n" \ |
| 336 | "Abbreviated type-of-number\n" |
| 337 | #define NPI_STR "Unknown numbering plan\n" \ |
| 338 | "ISDN (E.164) numbering plan\n" \ |
| 339 | "X.121 numbering plan\n" \ |
| 340 | "F.69 numbering plan\n" \ |
| 341 | "E.212 numbering plan\n" \ |
| 342 | "National numbering plan\n" \ |
| 343 | "Private numbering plan\n" \ |
| 344 | "ERMES numbering plan\n" \ |
| 345 | "IP numbering plan\n" \ |
| 346 | "WAP numbeing plan\n" |
Harald Welte | 691ce33 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 347 | |
| 348 | DEFUN(cfg_esme_route_pfx, cfg_esme_route_pfx_cmd, |
| 349 | "route prefix " TON_CMD " " NPI_CMD " PREFIX", |
| 350 | SMPP_ROUTE_P_STR TON_STR NPI_STR SMPP_PREFIX_STR) |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 351 | { |
| 352 | struct osmo_smpp_acl *acl = vty->index; |
Harald Welte | 691ce33 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 353 | struct osmo_smpp_addr pfx; |
| 354 | int rc; |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 355 | |
Harald Welte | 691ce33 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 356 | /* check if DESTINATION is all-digits */ |
| 357 | if (!osmo_is_digits(argv[2])) { |
| 358 | vty_out(vty, "%% PREFIX has to be numeric%s", VTY_NEWLINE); |
| 359 | return CMD_WARNING; |
| 360 | } |
| 361 | |
| 362 | pfx.ton = get_string_value(smpp_ton_str_short, argv[0]); |
| 363 | pfx.npi = get_string_value(smpp_npi_str_short, argv[1]); |
| 364 | snprintf(pfx.addr, sizeof(pfx.addr), "%s", argv[2]); |
| 365 | |
| 366 | rc = smpp_route_pfx_add(acl, &pfx); |
| 367 | if (rc < 0) { |
| 368 | vty_out(vty, "%% error adding prefix route: %s%s", |
| 369 | get_value_string(route_errstr, rc), VTY_NEWLINE); |
| 370 | return CMD_WARNING; |
| 371 | } |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 372 | |
| 373 | return CMD_SUCCESS; |
| 374 | } |
| 375 | |
Harald Welte | 691ce33 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 376 | DEFUN(cfg_esme_no_route_pfx, cfg_esme_no_route_pfx_cmd, |
| 377 | "no route prefix " TON_CMD " " NPI_CMD " PREFIX", |
| 378 | NO_STR SMPP_ROUTE_P_STR TON_STR NPI_STR SMPP_PREFIX_STR) |
| 379 | { |
| 380 | struct osmo_smpp_acl *acl = vty->index; |
| 381 | struct osmo_smpp_addr pfx; |
| 382 | int rc; |
| 383 | |
| 384 | /* check if DESTINATION is all-digits */ |
| 385 | if (!osmo_is_digits(argv[2])) { |
| 386 | vty_out(vty, "%% PREFIX has to be numeric%s", VTY_NEWLINE); |
| 387 | return CMD_WARNING; |
| 388 | } |
| 389 | |
| 390 | pfx.ton = get_string_value(smpp_ton_str_short, argv[0]); |
| 391 | pfx.npi = get_string_value(smpp_npi_str_short, argv[1]); |
| 392 | snprintf(pfx.addr, sizeof(pfx.addr), "%s", argv[2]); |
| 393 | |
| 394 | rc = smpp_route_pfx_del(acl, &pfx); |
| 395 | if (rc < 0) { |
| 396 | vty_out(vty, "%% error removing prefix route: %s%s", |
| 397 | get_value_string(route_errstr, rc), VTY_NEWLINE); |
| 398 | return CMD_WARNING; |
| 399 | } |
| 400 | |
| 401 | return CMD_SUCCESS; |
| 402 | |
| 403 | } |
| 404 | |
| 405 | |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 406 | DEFUN(cfg_esme_defaultroute, cfg_esme_defaultroute_cmd, |
| 407 | "default-route", |
| 408 | "Set this ESME as default-route for all SMS to unknown destinations") |
| 409 | { |
| 410 | struct osmo_smpp_acl *acl = vty->index; |
| 411 | |
| 412 | acl->default_route = 1; |
| 413 | |
Harald Welte | 691ce33 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 414 | if (!acl->smsc->def_route) |
| 415 | acl->smsc->def_route = acl; |
| 416 | |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 417 | return CMD_SUCCESS; |
| 418 | } |
| 419 | |
| 420 | DEFUN(cfg_no_esme_defaultroute, cfg_esme_no_defaultroute_cmd, |
| 421 | "no default-route", NO_STR |
Harald Welte | 1e0c722 | 2013-07-21 16:00:28 +0800 | [diff] [blame] | 422 | "Remove this ESME as default-route for all SMS to unknown destinations") |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 423 | { |
| 424 | struct osmo_smpp_acl *acl = vty->index; |
| 425 | |
| 426 | acl->default_route = 0; |
| 427 | |
| 428 | /* remove currently active default route, if it was created by |
| 429 | * this ACL */ |
Harald Welte | 691ce33 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 430 | if (acl->smsc->def_route && acl->smsc->def_route == acl) |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 431 | acl->smsc->def_route = NULL; |
| 432 | |
| 433 | return CMD_SUCCESS; |
| 434 | } |
| 435 | |
Harald Welte | 602b5d9 | 2013-09-02 16:41:00 +0200 | [diff] [blame] | 436 | DEFUN(cfg_esme_del_src_imsi, cfg_esme_del_src_imsi_cmd, |
| 437 | "deliver-src-imsi", |
| 438 | "Enable the use of IMSI as source addres in DELIVER") |
| 439 | { |
| 440 | struct osmo_smpp_acl *acl = vty->index; |
| 441 | |
| 442 | acl->deliver_src_imsi = 1; |
| 443 | |
| 444 | return CMD_SUCCESS; |
| 445 | } |
| 446 | |
| 447 | DEFUN(cfg_esme_no_del_src_imsi, cfg_esme_no_del_src_imsi_cmd, |
| 448 | "no deliver-src-imsi", NO_STR |
| 449 | "Disable the use of IMSI as source addres in DELIVER") |
| 450 | { |
| 451 | struct osmo_smpp_acl *acl = vty->index; |
| 452 | |
| 453 | acl->deliver_src_imsi = 0; |
| 454 | |
| 455 | return CMD_SUCCESS; |
| 456 | } |
| 457 | |
Harald Welte | f243cb9 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 458 | DEFUN(cfg_esme_osmo_ext, cfg_esme_osmo_ext_cmd, |
| 459 | "osmocom-extensions", |
| 460 | "Enable the use of Osmocom SMPP Extensions for this ESME") |
| 461 | { |
| 462 | struct osmo_smpp_acl *acl = vty->index; |
| 463 | |
| 464 | acl->osmocom_ext = 1; |
| 465 | |
| 466 | return CMD_SUCCESS; |
| 467 | } |
| 468 | |
| 469 | DEFUN(cfg_esme_no_osmo_ext, cfg_esme_no_osmo_ext_cmd, |
| 470 | "no osmocom-extensions", NO_STR |
| 471 | "Disable the use of Osmocom SMPP Extensions for this ESME") |
| 472 | { |
| 473 | struct osmo_smpp_acl *acl = vty->index; |
| 474 | |
| 475 | acl->osmocom_ext = 0; |
| 476 | |
| 477 | return CMD_SUCCESS; |
| 478 | } |
| 479 | |
Harald Welte | af16c81 | 2013-05-28 20:58:02 +0200 | [diff] [blame] | 480 | DEFUN(cfg_esme_dcs_transp, cfg_esme_dcs_transp_cmd, |
| 481 | "dcs-transparent", |
| 482 | "Enable the transparent pass-through of TP-DCS to SMPP DataCoding") |
| 483 | { |
| 484 | struct osmo_smpp_acl *acl = vty->index; |
| 485 | |
| 486 | acl->dcs_transparent = 1; |
| 487 | |
| 488 | return CMD_SUCCESS; |
| 489 | } |
| 490 | |
| 491 | DEFUN(cfg_esme_no_dcs_transp, cfg_esme_no_dcs_transp_cmd, |
| 492 | "no dcs-transparent", NO_STR |
| 493 | "Disable the transparent pass-through of TP-DCS to SMPP DataCoding") |
| 494 | { |
| 495 | struct osmo_smpp_acl *acl = vty->index; |
| 496 | |
| 497 | acl->dcs_transparent = 0; |
| 498 | |
| 499 | return CMD_SUCCESS; |
| 500 | } |
| 501 | |
| 502 | |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 503 | static void dump_one_esme(struct vty *vty, struct osmo_esme *esme) |
| 504 | { |
| 505 | char host[128], serv[128]; |
| 506 | |
| 507 | host[0] = 0; |
| 508 | serv[0] = 0; |
| 509 | getnameinfo((const struct sockaddr *) &esme->sa, esme->sa_len, |
| 510 | host, sizeof(host), serv, sizeof(serv), NI_NUMERICSERV); |
| 511 | |
| 512 | vty_out(vty, "ESME System ID: %s, Password: %s, SMPP Version %02x%s", |
Harald Welte | 691ce33 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 513 | esme->system_id, esme->acl ? esme->acl->passwd : "", |
| 514 | esme->smpp_version, VTY_NEWLINE); |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 515 | vty_out(vty, " Connected from: %s:%s%s", host, serv, VTY_NEWLINE); |
Harald Welte | 691ce33 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 516 | if (esme->smsc->def_route == esme->acl) |
| 517 | vty_out(vty, " Is current default route%s", VTY_NEWLINE); |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | DEFUN(show_esme, show_esme_cmd, |
| 521 | "show smpp esme", |
| 522 | SHOW_STR "SMPP Interface\n" "SMPP Extrenal SMS Entity\n") |
| 523 | { |
| 524 | struct smsc *smsc = smsc_from_vty(vty); |
| 525 | struct osmo_esme *esme; |
| 526 | |
| 527 | llist_for_each_entry(esme, &smsc->esme_list, list) |
| 528 | dump_one_esme(vty, esme); |
| 529 | |
| 530 | return CMD_SUCCESS; |
| 531 | } |
| 532 | |
Harald Welte | 691ce33 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 533 | static void write_esme_route_single(struct vty *vty, struct osmo_smpp_route *r) |
| 534 | { |
| 535 | switch (r->type) { |
| 536 | case SMPP_ROUTE_PREFIX: |
| 537 | vty_out(vty, " route prefix %s ", |
| 538 | get_value_string(smpp_ton_str_short, r->u.prefix.ton)); |
| 539 | vty_out(vty, "%s %s%s", |
| 540 | get_value_string(smpp_npi_str_short, r->u.prefix.npi), |
| 541 | r->u.prefix.addr, VTY_NEWLINE); |
| 542 | break; |
| 543 | case SMPP_ROUTE_NONE: |
| 544 | break; |
| 545 | } |
| 546 | } |
| 547 | |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 548 | static void config_write_esme_single(struct vty *vty, struct osmo_smpp_acl *acl) |
| 549 | { |
Harald Welte | 691ce33 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 550 | struct osmo_smpp_route *r; |
| 551 | |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 552 | vty_out(vty, " esme %s%s", acl->system_id, VTY_NEWLINE); |
| 553 | if (strlen(acl->passwd)) |
| 554 | vty_out(vty, " password %s%s", acl->passwd, VTY_NEWLINE); |
| 555 | if (acl->default_route) |
| 556 | vty_out(vty, " default-route%s", VTY_NEWLINE); |
Harald Welte | 691ce33 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 557 | if (acl->deliver_src_imsi) |
| 558 | vty_out(vty, " deliver-src-imsi%s", VTY_NEWLINE); |
Harald Welte | f243cb9 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 559 | if (acl->osmocom_ext) |
| 560 | vty_out(vty, " osmocom-extensions%s", VTY_NEWLINE); |
Harald Welte | af16c81 | 2013-05-28 20:58:02 +0200 | [diff] [blame] | 561 | if (acl->dcs_transparent) |
| 562 | vty_out(vty, " dcs-transparent%s", VTY_NEWLINE); |
Harald Welte | 691ce33 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 563 | |
| 564 | llist_for_each_entry(r, &acl->route_list, list) |
| 565 | write_esme_route_single(vty, r); |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | static int config_write_esme(struct vty *v) |
| 569 | { |
| 570 | struct smsc *smsc = smsc_from_vty(v); |
| 571 | struct osmo_smpp_acl *acl; |
| 572 | |
| 573 | llist_for_each_entry(acl, &smsc->acl_list, list) |
| 574 | config_write_esme_single(v, acl); |
| 575 | |
| 576 | return CMD_SUCCESS; |
| 577 | } |
| 578 | |
| 579 | int smpp_vty_init(void) |
| 580 | { |
| 581 | install_node(&smpp_node, config_write_smpp); |
Jacob Erlbeck | f414e85 | 2013-10-29 09:30:30 +0100 | [diff] [blame] | 582 | vty_install_default(SMPP_NODE); |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 583 | install_element(CONFIG_NODE, &cfg_smpp_cmd); |
| 584 | |
Holger Hans Peter Freyther | 3c64e2d | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 585 | install_element(SMPP_NODE, &cfg_smpp_first_cmd); |
| 586 | install_element(SMPP_NODE, &cfg_no_smpp_first_cmd); |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 587 | install_element(SMPP_NODE, &cfg_smpp_port_cmd); |
Neels Hofmeyr | abc6465 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 588 | install_element(SMPP_NODE, &cfg_smpp_addr_port_cmd); |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 589 | install_element(SMPP_NODE, &cfg_smpp_sys_id_cmd); |
| 590 | install_element(SMPP_NODE, &cfg_smpp_policy_cmd); |
| 591 | install_element(SMPP_NODE, &cfg_esme_cmd); |
| 592 | install_element(SMPP_NODE, &cfg_no_esme_cmd); |
| 593 | |
| 594 | install_node(&esme_node, config_write_esme); |
Jacob Erlbeck | f414e85 | 2013-10-29 09:30:30 +0100 | [diff] [blame] | 595 | vty_install_default(SMPP_ESME_NODE); |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 596 | install_element(SMPP_ESME_NODE, &cfg_esme_passwd_cmd); |
| 597 | install_element(SMPP_ESME_NODE, &cfg_esme_no_passwd_cmd); |
Harald Welte | 691ce33 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 598 | install_element(SMPP_ESME_NODE, &cfg_esme_route_pfx_cmd); |
| 599 | install_element(SMPP_ESME_NODE, &cfg_esme_no_route_pfx_cmd); |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 600 | install_element(SMPP_ESME_NODE, &cfg_esme_defaultroute_cmd); |
| 601 | install_element(SMPP_ESME_NODE, &cfg_esme_no_defaultroute_cmd); |
Harald Welte | 602b5d9 | 2013-09-02 16:41:00 +0200 | [diff] [blame] | 602 | install_element(SMPP_ESME_NODE, &cfg_esme_del_src_imsi_cmd); |
| 603 | install_element(SMPP_ESME_NODE, &cfg_esme_no_del_src_imsi_cmd); |
Harald Welte | f243cb9 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 604 | install_element(SMPP_ESME_NODE, &cfg_esme_osmo_ext_cmd); |
| 605 | install_element(SMPP_ESME_NODE, &cfg_esme_no_osmo_ext_cmd); |
Harald Welte | af16c81 | 2013-05-28 20:58:02 +0200 | [diff] [blame] | 606 | install_element(SMPP_ESME_NODE, &cfg_esme_dcs_transp_cmd); |
| 607 | install_element(SMPP_ESME_NODE, &cfg_esme_no_dcs_transp_cmd); |
Harald Welte | b7dd661 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 608 | |
| 609 | install_element_ve(&show_esme_cmd); |
| 610 | |
| 611 | return 0; |
| 612 | } |