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