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