Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 1 | /* OpenBSC SMPP 3.4 interface, SMSC-side implementation */ |
| 2 | |
Harald Welte | e6f1160 | 2022-05-17 18:25:14 +0200 | [diff] [blame] | 3 | /* (C) 2012-2022 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 4 | * |
Harald Welte | 995ff35 | 2013-07-13 16:35:32 +0200 | [diff] [blame] | 5 | * All Rights Reserved |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 6 | * |
Harald Welte | 995ff35 | 2013-07-13 16:35:32 +0200 | [diff] [blame] | 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. |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 11 | * |
Harald Welte | 995ff35 | 2013-07-13 16:35:32 +0200 | [diff] [blame] | 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/>. |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | #include <unistd.h> |
| 24 | #include <string.h> |
| 25 | #include <stdint.h> |
| 26 | #include <errno.h> |
Harald Welte | e6f1160 | 2022-05-17 18:25:14 +0200 | [diff] [blame] | 27 | #include <time.h> |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 28 | |
| 29 | #include <smpp34.h> |
| 30 | #include <smpp34_structs.h> |
| 31 | #include <smpp34_params.h> |
Harald Welte | e39f6cd | 2019-04-10 00:33:46 +0200 | [diff] [blame] | 32 | #include <smpp34_heap.h> |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 33 | |
| 34 | #include <osmocom/core/utils.h> |
| 35 | #include <osmocom/core/msgb.h> |
| 36 | #include <osmocom/core/logging.h> |
| 37 | #include <osmocom/core/talloc.h> |
| 38 | #include <osmocom/gsm/protocol/gsm_04_11.h> |
Harald Welte | 3f78600 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 39 | #include <osmocom/gsm/protocol/smpp34_osmocom.h> |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 40 | |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 41 | #include <osmocom/msc/gsm_subscriber.h> |
| 42 | #include <osmocom/msc/debug.h> |
| 43 | #include <osmocom/msc/db.h> |
| 44 | #include <osmocom/msc/gsm_04_11.h> |
| 45 | #include <osmocom/msc/gsm_data.h> |
| 46 | #include <osmocom/msc/signal.h> |
| 47 | #include <osmocom/msc/transaction.h> |
| 48 | #include <osmocom/msc/gsm_subscriber.h> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 49 | #include <osmocom/msc/vlr.h> |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 50 | #include <osmocom/msc/msc_a.h> |
Max | 5346f69 | 2022-07-28 14:19:22 +0700 | [diff] [blame] | 51 | #include <osmocom/smpp/smpp_smsc.h> |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 52 | |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 53 | #define VSUB_USE_SMPP "SMPP" |
| 54 | #define VSUB_USE_SMPP_CMD "SMPP-cmd" |
| 55 | |
Harald Welte | e39f6cd | 2019-04-10 00:33:46 +0200 | [diff] [blame] | 56 | /* talloc integration for libsmpp34 */ |
| 57 | |
| 58 | static struct smsc *g_smsc; |
| 59 | |
| 60 | static void *smpp34_talloc_malloc(size_t sz) |
| 61 | { |
| 62 | return talloc_size(g_smsc, sz); |
| 63 | } |
| 64 | |
| 65 | static void *smpp34_talloc_realloc(void *ptr, size_t sz) |
| 66 | { |
| 67 | return talloc_realloc_size(g_smsc, ptr, sz); |
| 68 | } |
| 69 | |
| 70 | static void smpp34_talloc_free(void *ptr) |
| 71 | { |
| 72 | talloc_free(ptr); |
| 73 | } |
| 74 | |
| 75 | static const struct smpp34_memory_functions smpp34_talloc = { |
| 76 | .malloc_fun = smpp34_talloc_malloc, |
| 77 | .realloc_fun = smpp34_talloc_realloc, |
| 78 | .free_fun = smpp34_talloc_free, |
| 79 | }; |
| 80 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 81 | /*! \brief find vlr_subscr for a given SMPP NPI/TON/Address */ |
| 82 | static struct vlr_subscr *subscr_by_dst(struct gsm_network *net, |
| 83 | uint8_t npi, uint8_t ton, |
| 84 | const char *addr) |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 85 | { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 86 | struct vlr_subscr *vsub = NULL; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 87 | |
| 88 | switch (npi) { |
| 89 | case NPI_Land_Mobile_E212: |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 90 | vsub = vlr_subscr_find_by_imsi(net->vlr, addr, VSUB_USE_SMPP); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 91 | break; |
| 92 | case NPI_ISDN_E163_E164: |
| 93 | case NPI_Private: |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 94 | vsub = vlr_subscr_find_by_msisdn(net->vlr, addr, VSUB_USE_SMPP); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 95 | break; |
| 96 | default: |
| 97 | LOGP(DSMPP, LOGL_NOTICE, "Unsupported NPI: %u\n", npi); |
| 98 | break; |
| 99 | } |
| 100 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 101 | log_set_context(LOG_CTX_VLR_SUBSCR, vsub); |
| 102 | return vsub; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 103 | } |
| 104 | |
Pablo Neira Ayuso | 9a3ed85 | 2017-08-11 12:02:12 +0200 | [diff] [blame] | 105 | static int smpp34_submit_tlv_msg_payload(const struct tlv_t *t, |
| 106 | const struct submit_sm_t *submit, |
| 107 | const uint8_t **sms_msg, |
| 108 | unsigned int *sms_msg_len) |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 109 | { |
Pablo Neira Ayuso | 9a3ed85 | 2017-08-11 12:02:12 +0200 | [diff] [blame] | 110 | if (submit->sm_length) { |
| 111 | LOGP(DLSMS, LOGL_ERROR, |
| 112 | "SMPP cannot have payload in TLV _and_ in the header\n"); |
| 113 | return -1; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 114 | } |
Pablo Neira Ayuso | 9a3ed85 | 2017-08-11 12:02:12 +0200 | [diff] [blame] | 115 | *sms_msg = t->value.octet; |
| 116 | *sms_msg_len = t->length; |
| 117 | |
| 118 | return 0; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 119 | } |
| 120 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 121 | /*! \brief convert from submit_sm_t to gsm_sms */ |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 122 | static int submit_to_sms(struct gsm_sms **psms, struct gsm_network *net, |
| 123 | const struct submit_sm_t *submit) |
| 124 | { |
Harald Welte | e6f1160 | 2022-05-17 18:25:14 +0200 | [diff] [blame] | 125 | time_t t_now = time(NULL); |
| 126 | time_t t_validity_absolute; |
Pablo Neira Ayuso | 9a3ed85 | 2017-08-11 12:02:12 +0200 | [diff] [blame] | 127 | const uint8_t *sms_msg = NULL; |
Pau Espin Pedrol | 7e16e72 | 2017-08-14 21:18:41 +0200 | [diff] [blame] | 128 | unsigned int sms_msg_len = 0; |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 129 | struct vlr_subscr *dest; |
Pablo Neira Ayuso | 9a3ed85 | 2017-08-11 12:02:12 +0200 | [diff] [blame] | 130 | uint16_t msg_ref = 0; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 131 | struct gsm_sms *sms; |
| 132 | struct tlv_t *t; |
Harald Welte | 27d5e65 | 2013-05-28 20:37:07 +0200 | [diff] [blame] | 133 | int mode; |
Stefan Sperling | 6d28981 | 2018-01-30 12:15:40 +0100 | [diff] [blame] | 134 | int can_store_sms = ((submit->esm_class & SMPP34_MSG_MODE_MASK) != 2); /* != forward mode */ |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 135 | |
| 136 | dest = subscr_by_dst(net, submit->dest_addr_npi, |
| 137 | submit->dest_addr_ton, |
| 138 | (const char *)submit->destination_addr); |
Stefan Sperling | 6d28981 | 2018-01-30 12:15:40 +0100 | [diff] [blame] | 139 | if (!dest && !can_store_sms) { |
Harald Welte | 0d0c9ec | 2012-11-24 11:13:19 +0100 | [diff] [blame] | 140 | LOGP(DLSMS, LOGL_NOTICE, "SMPP SUBMIT-SM for unknown subscriber: " |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 141 | "%s (NPI=%u)\n", submit->destination_addr, |
| 142 | submit->dest_addr_npi); |
| 143 | return ESME_RINVDSTADR; |
| 144 | } |
| 145 | |
Pablo Neira Ayuso | 9a3ed85 | 2017-08-11 12:02:12 +0200 | [diff] [blame] | 146 | smpp34_tlv_for_each(t, submit->tlv) { |
| 147 | switch (t->tag) { |
| 148 | case TLVID_message_payload: |
| 149 | if (smpp34_submit_tlv_msg_payload(t, submit, &sms_msg, |
| 150 | &sms_msg_len) < 0) { |
Stefan Sperling | 6d28981 | 2018-01-30 12:15:40 +0100 | [diff] [blame] | 151 | if (dest) |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 152 | vlr_subscr_put(dest, VSUB_USE_SMPP); |
Pablo Neira Ayuso | 9a3ed85 | 2017-08-11 12:02:12 +0200 | [diff] [blame] | 153 | return ESME_ROPTPARNOTALLWD; |
| 154 | } |
| 155 | break; |
| 156 | case TLVID_user_message_reference: |
Pau Espin Pedrol | d5c4339 | 2017-08-18 12:26:23 +0200 | [diff] [blame] | 157 | msg_ref = t->value.val16; |
Pablo Neira Ayuso | 9a3ed85 | 2017-08-11 12:02:12 +0200 | [diff] [blame] | 158 | break; |
| 159 | default: |
| 160 | break; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 161 | } |
Pablo Neira Ayuso | 9a3ed85 | 2017-08-11 12:02:12 +0200 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | if (!sms_msg) { |
| 165 | if (submit->sm_length > 0 && submit->sm_length < 255) { |
| 166 | sms_msg = submit->short_message; |
| 167 | sms_msg_len = submit->sm_length; |
| 168 | } else { |
| 169 | LOGP(DLSMS, LOGL_ERROR, |
| 170 | "SMPP neither message payload nor valid sm_length.\n"); |
Neels Hofmeyr | 0714002 | 2019-04-15 13:46:44 +0200 | [diff] [blame] | 171 | if (dest) |
| 172 | vlr_subscr_put(dest, VSUB_USE_SMPP); |
Pablo Neira Ayuso | 9a3ed85 | 2017-08-11 12:02:12 +0200 | [diff] [blame] | 173 | return ESME_RINVPARLEN; |
| 174 | } |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | sms = sms_alloc(); |
Harald Welte | d4bdee7 | 2012-11-08 19:44:08 +0100 | [diff] [blame] | 178 | sms->source = SMS_SOURCE_SMPP; |
| 179 | sms->smpp.sequence_nr = submit->sequence_number; |
Pablo Neira Ayuso | 791bdf7 | 2017-08-07 14:01:18 +0100 | [diff] [blame] | 180 | sms->status_rep_req = submit->registered_delivery; |
Pablo Neira Ayuso | 9a3ed85 | 2017-08-11 12:02:12 +0200 | [diff] [blame] | 181 | sms->msg_ref = msg_ref; |
Harald Welte | c0de14d | 2012-11-23 23:35:01 +0100 | [diff] [blame] | 182 | |
| 183 | /* fill in the destination address */ |
Harald Welte | 1a2993a | 2012-11-09 19:48:48 +0100 | [diff] [blame] | 184 | sms->receiver = dest; |
Neels Hofmeyr | 0714002 | 2019-04-15 13:46:44 +0200 | [diff] [blame] | 185 | if (dest) { |
| 186 | /* Replace use count from above subscr_by_dst (VSUB_USE_SMPP) by the sms->receiver use count |
| 187 | * (VSUB_USE_SMS_RECEIVER) */ |
| 188 | vlr_subscr_get(sms->receiver, VSUB_USE_SMS_RECEIVER); |
| 189 | vlr_subscr_put(dest, VSUB_USE_SMPP); |
| 190 | } |
Harald Welte | c0de14d | 2012-11-23 23:35:01 +0100 | [diff] [blame] | 191 | sms->dst.ton = submit->dest_addr_ton; |
| 192 | sms->dst.npi = submit->dest_addr_npi; |
Stefan Sperling | 6d28981 | 2018-01-30 12:15:40 +0100 | [diff] [blame] | 193 | if (dest) |
Max | 98f7467 | 2018-02-05 12:57:06 +0100 | [diff] [blame] | 194 | OSMO_STRLCPY_ARRAY(sms->dst.addr, dest->msisdn); |
Stefan Sperling | 6d28981 | 2018-01-30 12:15:40 +0100 | [diff] [blame] | 195 | else |
Max | 98f7467 | 2018-02-05 12:57:06 +0100 | [diff] [blame] | 196 | OSMO_STRLCPY_ARRAY(sms->dst.addr, |
| 197 | (const char *)submit->destination_addr); |
Harald Welte | c0de14d | 2012-11-23 23:35:01 +0100 | [diff] [blame] | 198 | |
| 199 | /* fill in the source address */ |
Harald Welte | c0de14d | 2012-11-23 23:35:01 +0100 | [diff] [blame] | 200 | sms->src.ton = submit->source_addr_ton; |
| 201 | sms->src.npi = submit->source_addr_npi; |
Max | 98f7467 | 2018-02-05 12:57:06 +0100 | [diff] [blame] | 202 | OSMO_STRLCPY_ARRAY(sms->src.addr, (char *)submit->source_addr); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 203 | |
Pablo Neira Ayuso | d7e14da | 2017-08-11 13:10:48 +0200 | [diff] [blame] | 204 | if (submit->esm_class == SMPP34_DELIVERY_ACK) |
Pablo Neira Ayuso | bd71d32 | 2017-08-07 14:01:40 +0100 | [diff] [blame] | 205 | sms->is_report = true; |
| 206 | |
Pablo Neira Ayuso | d7e14da | 2017-08-11 13:10:48 +0200 | [diff] [blame] | 207 | if (submit->esm_class & SMPP34_UDHI_IND) |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 208 | sms->ud_hdr_ind = 1; |
| 209 | |
Pablo Neira Ayuso | d7e14da | 2017-08-11 13:10:48 +0200 | [diff] [blame] | 210 | if (submit->esm_class & SMPP34_REPLY_PATH) { |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 211 | sms->reply_path_req = 1; |
| 212 | #warning Implement reply path |
| 213 | } |
| 214 | |
Harald Welte | 9ad0362 | 2012-11-08 22:15:04 +0100 | [diff] [blame] | 215 | if (submit->data_coding == 0x00 || /* SMSC default */ |
Harald Welte | 27d5e65 | 2013-05-28 20:37:07 +0200 | [diff] [blame] | 216 | submit->data_coding == 0x01) { /* GSM default alphabet */ |
| 217 | sms->data_coding_scheme = GSM338_DCS_1111_7BIT; |
| 218 | mode = MODE_7BIT; |
| 219 | } else if ((submit->data_coding & 0xFC) == 0xF0) { /* 03.38 DCS default */ |
| 220 | /* pass DCS 1:1 through from SMPP to GSM */ |
| 221 | sms->data_coding_scheme = submit->data_coding; |
| 222 | mode = MODE_7BIT; |
| 223 | } else if (submit->data_coding == 0x02 || |
| 224 | submit->data_coding == 0x04) { |
| 225 | /* 8-bit binary */ |
| 226 | sms->data_coding_scheme = GSM338_DCS_1111_8BIT_DATA; |
| 227 | mode = MODE_8BIT; |
| 228 | } else if ((submit->data_coding & 0xFC) == 0xF4) { /* 03.38 DCS 8bit */ |
| 229 | /* pass DCS 1:1 through from SMPP to GSM */ |
| 230 | sms->data_coding_scheme = submit->data_coding; |
| 231 | mode = MODE_8BIT; |
Harald Welte | 7e40be3 | 2014-02-21 13:21:03 +0100 | [diff] [blame] | 232 | } else if (submit->data_coding == 0x08) { |
Harald Welte | 27d5e65 | 2013-05-28 20:37:07 +0200 | [diff] [blame] | 233 | /* UCS-2 */ |
| 234 | sms->data_coding_scheme = (2 << 2); |
| 235 | mode = MODE_8BIT; |
| 236 | } else { |
| 237 | sms_free(sms); |
| 238 | LOGP(DLSMS, LOGL_ERROR, "SMPP Unknown Data Coding 0x%02x\n", |
| 239 | submit->data_coding); |
| 240 | return ESME_RUNKNOWNERR; |
| 241 | } |
| 242 | |
Harald Welte | c75ed6d | 2013-05-28 20:58:02 +0200 | [diff] [blame] | 243 | if (mode == MODE_7BIT) { |
Harald Welte | b8a1f96 | 2012-11-24 01:37:39 +0100 | [diff] [blame] | 244 | uint8_t ud_len = 0, padbits = 0; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 245 | sms->data_coding_scheme = GSM338_DCS_1111_7BIT; |
Harald Welte | 9122c13 | 2012-11-09 19:43:50 +0100 | [diff] [blame] | 246 | if (sms->ud_hdr_ind) { |
| 247 | ud_len = *sms_msg + 1; |
Oliver Smith | 6a8dae6 | 2023-06-22 12:15:15 +0200 | [diff] [blame] | 248 | if (ud_len > sms_msg_len) { |
| 249 | sms_free(sms); |
| 250 | LOGP(DLSMS, LOGL_ERROR, "invalid ud_len=%u > sms_msg_len=%u\n", ud_len, |
| 251 | sms_msg_len); |
| 252 | return ESME_RINVPARLEN; |
| 253 | } |
Harald Welte | 9122c13 | 2012-11-09 19:43:50 +0100 | [diff] [blame] | 254 | printf("copying %u bytes user data...\n", ud_len); |
| 255 | memcpy(sms->user_data, sms_msg, |
| 256 | OSMO_MIN(ud_len, sizeof(sms->user_data))); |
| 257 | sms_msg += ud_len; |
| 258 | sms_msg_len -= ud_len; |
Harald Welte | b8a1f96 | 2012-11-24 01:37:39 +0100 | [diff] [blame] | 259 | padbits = 7 - (ud_len % 7); |
Harald Welte | 9122c13 | 2012-11-09 19:43:50 +0100 | [diff] [blame] | 260 | } |
Vadim Yanitskiy | 566ce11 | 2021-02-05 20:08:00 +0100 | [diff] [blame] | 261 | gsm_septet_pack(sms->user_data+ud_len, sms_msg, sms_msg_len, padbits); |
Harald Welte | b8a1f96 | 2012-11-24 01:37:39 +0100 | [diff] [blame] | 262 | sms->user_data_len = (ud_len*8 + padbits)/7 + sms_msg_len;/* SEPTETS */ |
| 263 | /* FIXME: sms->text */ |
Harald Welte | 27d5e65 | 2013-05-28 20:37:07 +0200 | [diff] [blame] | 264 | } else { |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 265 | memcpy(sms->user_data, sms_msg, sms_msg_len); |
| 266 | sms->user_data_len = sms_msg_len; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 267 | } |
| 268 | |
Harald Welte | e6f1160 | 2022-05-17 18:25:14 +0200 | [diff] [blame] | 269 | t_validity_absolute = smpp_parse_time_format((const char *) submit->validity_period, &t_now); |
| 270 | if (!t_validity_absolute) |
Harald Welte | 2765a18 | 2022-05-17 18:56:55 +0200 | [diff] [blame] | 271 | sms->validity_minutes = net->sms_queue_cfg->default_validity_mins; |
Harald Welte | e6f1160 | 2022-05-17 18:25:14 +0200 | [diff] [blame] | 272 | else |
| 273 | sms->validity_minutes = (t_validity_absolute - t_now) / 60; |
| 274 | |
Harald Welte | a3c639f | 2022-05-17 19:01:43 +0200 | [diff] [blame] | 275 | if (sms->validity_minutes < net->sms_queue_cfg->minimum_validity_mins) { |
| 276 | LOGP(DLSMS, LOGL_INFO, "SMS to %s: Overriding ESME-provided validity period (%lu) " |
| 277 | "with minimum SMSC validity period (%u) minutes\n", submit->destination_addr, |
| 278 | sms->validity_minutes, net->sms_queue_cfg->minimum_validity_mins); |
| 279 | sms->validity_minutes = net->sms_queue_cfg->minimum_validity_mins; |
| 280 | } |
| 281 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 282 | *psms = sms; |
| 283 | return ESME_ROK; |
| 284 | } |
| 285 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 286 | /*! \brief handle incoming libsmpp34 ssubmit_sm_t from remote ESME */ |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 287 | int handle_smpp_submit(struct smpp_esme *esme, struct submit_sm_t *submit, |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 288 | struct submit_sm_resp_t *submit_r) |
| 289 | { |
| 290 | struct gsm_sms *sms; |
Holger Hans Peter Freyther | b5a4edd | 2013-01-20 17:43:50 +0100 | [diff] [blame] | 291 | struct gsm_network *net = esme->smsc->priv; |
| 292 | struct sms_signal_data sig; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 293 | int rc = -1; |
| 294 | |
Holger Hans Peter Freyther | b5a4edd | 2013-01-20 17:43:50 +0100 | [diff] [blame] | 295 | rc = submit_to_sms(&sms, net, submit); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 296 | if (rc != ESME_ROK) { |
| 297 | submit_r->command_status = rc; |
| 298 | return 0; |
| 299 | } |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 300 | smpp_esme_get(esme); |
Harald Welte | d4bdee7 | 2012-11-08 19:44:08 +0100 | [diff] [blame] | 301 | sms->smpp.esme = esme; |
Harald Welte | 9ad0362 | 2012-11-08 22:15:04 +0100 | [diff] [blame] | 302 | sms->protocol_id = submit->protocol_id; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 303 | |
Pablo Neira Ayuso | d7e14da | 2017-08-11 13:10:48 +0200 | [diff] [blame] | 304 | switch (submit->esm_class & SMPP34_MSG_MODE_MASK) { |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 305 | case 0: /* default */ |
| 306 | case 1: /* datagram */ |
| 307 | case 3: /* store-and-forward */ |
| 308 | rc = db_sms_store(sms); |
Holger Hans Peter Freyther | 6a85c15 | 2013-01-20 17:21:31 +0100 | [diff] [blame] | 309 | sms_free(sms); |
| 310 | sms = NULL; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 311 | if (rc < 0) { |
Harald Welte | 0d0c9ec | 2012-11-24 11:13:19 +0100 | [diff] [blame] | 312 | LOGP(DLSMS, LOGL_ERROR, "SMPP SUBMIT-SM: Unable to " |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 313 | "store SMS in database\n"); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 314 | submit_r->command_status = ESME_RSYSERR; |
| 315 | return 0; |
| 316 | } |
| 317 | strcpy((char *)submit_r->message_id, "msg_id_not_implemented"); |
Harald Welte | 0d0c9ec | 2012-11-24 11:13:19 +0100 | [diff] [blame] | 318 | LOGP(DLSMS, LOGL_INFO, "SMPP SUBMIT-SM: Stored in DB\n"); |
Holger Hans Peter Freyther | b5a4edd | 2013-01-20 17:43:50 +0100 | [diff] [blame] | 319 | |
| 320 | memset(&sig, 0, sizeof(sig)); |
| 321 | osmo_signal_dispatch(SS_SMS, S_SMS_SUBMITTED, &sig); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 322 | rc = 0; |
| 323 | break; |
| 324 | case 2: /* forward (i.e. transaction) mode */ |
Harald Welte | 0d0c9ec | 2012-11-24 11:13:19 +0100 | [diff] [blame] | 325 | LOGP(DLSMS, LOGL_DEBUG, "SMPP SUBMIT-SM: Forwarding in " |
Harald Welte | 9122c13 | 2012-11-09 19:43:50 +0100 | [diff] [blame] | 326 | "real time (Transaction/Forward mode)\n"); |
Harald Welte | d4bdee7 | 2012-11-08 19:44:08 +0100 | [diff] [blame] | 327 | sms->smpp.transaction_mode = 1; |
Vadim Yanitskiy | 24e025e | 2018-11-22 15:42:39 +0700 | [diff] [blame] | 328 | gsm411_send_sms(net, sms->receiver, sms); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 329 | rc = 1; /* don't send any response yet */ |
| 330 | break; |
| 331 | } |
| 332 | return rc; |
| 333 | } |
| 334 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 335 | static void alert_all_esme(struct smsc *smsc, struct vlr_subscr *vsub, |
Harald Welte | 045f402 | 2013-07-30 23:45:01 +0800 | [diff] [blame] | 336 | uint8_t smpp_avail_status) |
| 337 | { |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 338 | struct smpp_esme *esme; |
Harald Welte | 045f402 | 2013-07-30 23:45:01 +0800 | [diff] [blame] | 339 | |
| 340 | llist_for_each_entry(esme, &smsc->esme_list, list) { |
| 341 | /* we currently send an alert notification to each ESME that is |
Martin Hauke | 3f07dac | 2019-11-14 17:49:08 +0100 | [diff] [blame] | 342 | * connected, and do not require a (non-existent) delivery |
Keith | c6d219c | 2019-01-17 01:01:59 +0100 | [diff] [blame] | 343 | * pending flag to be set before. */ |
Keith | a3a8821 | 2019-01-17 01:07:53 +0100 | [diff] [blame] | 344 | if (!esme->bind_flags) { |
| 345 | LOGP(DSMPP, LOGL_DEBUG, |
| 346 | "ESME is not (yet) bound, skipping alert\n"); |
| 347 | continue; |
| 348 | } |
Alexander Couzens | 4aeb4ec | 2019-08-23 23:30:12 +0200 | [diff] [blame] | 349 | if (esme->acl && !esme->acl->alert_notifications) { |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 350 | LOGPESME(esme->esme, LOGL_DEBUG, "is not set to receive Alert Notifications\n"); |
Keith | c6d219c | 2019-01-17 01:01:59 +0100 | [diff] [blame] | 351 | continue; |
| 352 | } |
Harald Welte | 045f402 | 2013-07-30 23:45:01 +0800 | [diff] [blame] | 353 | if (esme->acl && esme->acl->deliver_src_imsi) { |
| 354 | smpp_tx_alert(esme, TON_Subscriber_Number, |
| 355 | NPI_Land_Mobile_E212, |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 356 | vsub->imsi, smpp_avail_status); |
Harald Welte | 045f402 | 2013-07-30 23:45:01 +0800 | [diff] [blame] | 357 | } else { |
| 358 | smpp_tx_alert(esme, TON_Network_Specific, |
| 359 | NPI_ISDN_E163_E164, |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 360 | vsub->msisdn, smpp_avail_status); |
Harald Welte | 045f402 | 2013-07-30 23:45:01 +0800 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 366 | /*! \brief signal handler for status of attempted SMS deliveries */ |
Harald Welte | d4bdee7 | 2012-11-08 19:44:08 +0100 | [diff] [blame] | 367 | static int smpp_sms_cb(unsigned int subsys, unsigned int signal, |
| 368 | void *handler_data, void *signal_data) |
| 369 | { |
Harald Welte | d4bdee7 | 2012-11-08 19:44:08 +0100 | [diff] [blame] | 370 | struct sms_signal_data *sig_sms = signal_data; |
| 371 | struct gsm_sms *sms = sig_sms->sms; |
Harald Welte | 99e273d | 2013-07-30 23:39:18 +0800 | [diff] [blame] | 372 | struct smsc *smsc = handler_data; |
Harald Welte | d4bdee7 | 2012-11-08 19:44:08 +0100 | [diff] [blame] | 373 | int rc = 0; |
| 374 | |
| 375 | if (!sms) |
| 376 | return 0; |
| 377 | |
| 378 | if (sms->source != SMS_SOURCE_SMPP) |
| 379 | return 0; |
| 380 | |
| 381 | switch (signal) { |
Harald Welte | 1aeb2af | 2013-07-30 22:30:24 +0800 | [diff] [blame] | 382 | case S_SMS_MEM_EXCEEDED: |
| 383 | /* fall-through: There is no ESME_Rxxx result code to |
| 384 | * indicate a MEMORY EXCEEDED in transaction mode back |
| 385 | * to the ESME */ |
Harald Welte | d4bdee7 | 2012-11-08 19:44:08 +0100 | [diff] [blame] | 386 | case S_SMS_UNKNOWN_ERROR: |
| 387 | if (sms->smpp.transaction_mode) { |
Martin Hauke | 3f07dac | 2019-11-14 17:49:08 +0100 | [diff] [blame] | 388 | /* Send back the SUBMIT-SM response with appropriate error */ |
Harald Welte | 0d0c9ec | 2012-11-24 11:13:19 +0100 | [diff] [blame] | 389 | LOGP(DLSMS, LOGL_INFO, "SMPP SUBMIT-SM: Error\n"); |
Harald Welte | d4bdee7 | 2012-11-08 19:44:08 +0100 | [diff] [blame] | 390 | rc = smpp_tx_submit_r(sms->smpp.esme, |
| 391 | sms->smpp.sequence_nr, |
| 392 | ESME_RDELIVERYFAILURE, |
| 393 | sms->smpp.msg_id); |
| 394 | } |
| 395 | break; |
| 396 | case S_SMS_DELIVERED: |
| 397 | /* SMS layer tells us the delivery has been completed */ |
| 398 | if (sms->smpp.transaction_mode) { |
| 399 | /* Send back the SUBMIT-SM response */ |
Harald Welte | 0d0c9ec | 2012-11-24 11:13:19 +0100 | [diff] [blame] | 400 | LOGP(DLSMS, LOGL_INFO, "SMPP SUBMIT-SM: Success\n"); |
Harald Welte | d4bdee7 | 2012-11-08 19:44:08 +0100 | [diff] [blame] | 401 | rc = smpp_tx_submit_r(sms->smpp.esme, |
| 402 | sms->smpp.sequence_nr, |
| 403 | ESME_ROK, sms->smpp.msg_id); |
| 404 | } |
| 405 | break; |
Harald Welte | 99e273d | 2013-07-30 23:39:18 +0800 | [diff] [blame] | 406 | case S_SMS_SMMA: |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 407 | if (!sig_sms->trans || !sig_sms->trans->vsub) { |
Harald Welte | 99e273d | 2013-07-30 23:39:18 +0800 | [diff] [blame] | 408 | /* SMMA without a subscriber? strange... */ |
| 409 | LOGP(DLSMS, LOGL_NOTICE, "SMMA without subscriber?\n"); |
| 410 | break; |
| 411 | } |
| 412 | |
Harald Welte | 99e273d | 2013-07-30 23:39:18 +0800 | [diff] [blame] | 413 | /* There's no real 1:1 match for SMMA in SMPP. However, |
| 414 | * an ALERT NOTIFICATION seems to be the most logical |
| 415 | * choice */ |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 416 | alert_all_esme(smsc, sig_sms->trans->vsub, 0); |
Harald Welte | 99e273d | 2013-07-30 23:39:18 +0800 | [diff] [blame] | 417 | break; |
Harald Welte | d4bdee7 | 2012-11-08 19:44:08 +0100 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | return rc; |
| 421 | } |
| 422 | |
Harald Welte | 8a1b056 | 2012-11-09 12:51:44 +0100 | [diff] [blame] | 423 | /*! \brief signal handler for subscriber related signals */ |
| 424 | static int smpp_subscr_cb(unsigned int subsys, unsigned int signal, |
| 425 | void *handler_data, void *signal_data) |
| 426 | { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 427 | struct vlr_subscr *vsub = signal_data; |
Harald Welte | 8a1b056 | 2012-11-09 12:51:44 +0100 | [diff] [blame] | 428 | struct smsc *smsc = handler_data; |
Harald Welte | 8a1b056 | 2012-11-09 12:51:44 +0100 | [diff] [blame] | 429 | uint8_t smpp_avail_status; |
| 430 | |
| 431 | /* determine the smpp_avail_status depending on attach/detach */ |
| 432 | switch (signal) { |
| 433 | case S_SUBSCR_ATTACHED: |
| 434 | smpp_avail_status = 0; |
| 435 | break; |
| 436 | case S_SUBSCR_DETACHED: |
| 437 | smpp_avail_status = 2; |
| 438 | break; |
| 439 | default: |
| 440 | return 0; |
| 441 | } |
| 442 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 443 | alert_all_esme(smsc, vsub, smpp_avail_status); |
Harald Welte | 8a1b056 | 2012-11-09 12:51:44 +0100 | [diff] [blame] | 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
Harald Welte | b8a1f96 | 2012-11-24 01:37:39 +0100 | [diff] [blame] | 448 | /* GSM 03.38 6.2.1 Character expanding (no decode!) */ |
| 449 | static int gsm_7bit_expand(char *text, const uint8_t *user_data, uint8_t septet_l, uint8_t ud_hdr_ind) |
| 450 | { |
| 451 | int i = 0; |
| 452 | int shift = 0; |
| 453 | uint8_t c; |
| 454 | |
| 455 | /* skip the user data header */ |
| 456 | if (ud_hdr_ind) { |
| 457 | /* get user data header length + 1 (for the 'user data header length'-field) */ |
| 458 | shift = ((user_data[0] + 1) * 8) / 7; |
| 459 | if ((((user_data[0] + 1) * 8) % 7) != 0) |
| 460 | shift++; |
| 461 | septet_l = septet_l - shift; |
| 462 | } |
| 463 | |
| 464 | for (i = 0; i < septet_l; i++) { |
| 465 | c = |
| 466 | ((user_data[((i + shift) * 7 + 7) >> 3] << |
| 467 | (7 - (((i + shift) * 7 + 7) & 7))) | |
| 468 | (user_data[((i + shift) * 7) >> 3] >> |
| 469 | (((i + shift) * 7) & 7))) & 0x7f; |
| 470 | |
| 471 | *(text++) = c; |
| 472 | } |
| 473 | |
| 474 | *text = '\0'; |
| 475 | |
| 476 | return i; |
| 477 | } |
| 478 | |
| 479 | |
Harald Welte | 3f78600 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 480 | /* FIXME: libsmpp34 helpers, they should be part of libsmpp34! */ |
| 481 | void append_tlv(tlv_t **req_tlv, uint16_t tag, |
| 482 | const uint8_t *data, uint16_t len) |
| 483 | { |
| 484 | tlv_t tlv; |
| 485 | |
| 486 | memset(&tlv, 0, sizeof(tlv)); |
| 487 | tlv.tag = tag; |
| 488 | tlv.length = len; |
| 489 | memcpy(tlv.value.octet, data, tlv.length); |
| 490 | build_tlv(req_tlv, &tlv); |
| 491 | } |
| 492 | void append_tlv_u8(tlv_t **req_tlv, uint16_t tag, uint8_t val) |
| 493 | { |
| 494 | tlv_t tlv; |
| 495 | |
| 496 | memset(&tlv, 0, sizeof(tlv)); |
| 497 | tlv.tag = tag; |
| 498 | tlv.length = 1; |
| 499 | tlv.value.val08 = val; |
| 500 | build_tlv(req_tlv, &tlv); |
| 501 | } |
| 502 | void append_tlv_u16(tlv_t **req_tlv, uint16_t tag, uint16_t val) |
| 503 | { |
| 504 | tlv_t tlv; |
| 505 | |
| 506 | memset(&tlv, 0, sizeof(tlv)); |
| 507 | tlv.tag = tag; |
| 508 | tlv.length = 2; |
Pau Espin Pedrol | d5c4339 | 2017-08-18 12:26:23 +0200 | [diff] [blame] | 509 | tlv.value.val16 = val; |
Harald Welte | 3f78600 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 510 | build_tlv(req_tlv, &tlv); |
| 511 | } |
| 512 | |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 513 | #if BEFORE_MSCSPLIT |
| 514 | /* We currently have no lchan information. Re-add after A-interface, see OS#2390. */ |
Harald Welte | 3f78600 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 515 | /* Append the Osmocom vendor-specific additional TLVs to a SMPP msg */ |
| 516 | static void append_osmo_tlvs(tlv_t **req_tlv, const struct gsm_lchan *lchan) |
| 517 | { |
| 518 | int idx = calc_initial_idx(ARRAY_SIZE(lchan->meas_rep), |
| 519 | lchan->meas_rep_idx, 1); |
| 520 | const struct gsm_meas_rep *mr = &lchan->meas_rep[idx]; |
| 521 | const struct gsm_meas_rep_unidir *ul_meas = &mr->ul; |
| 522 | const struct gsm_meas_rep_unidir *dl_meas = &mr->dl; |
| 523 | |
| 524 | /* Osmocom vendor-specific SMPP34 extensions */ |
| 525 | append_tlv_u16(req_tlv, TLVID_osmo_arfcn, lchan->ts->trx->arfcn); |
| 526 | if (mr->flags & MEAS_REP_F_MS_L1) { |
| 527 | uint8_t ms_dbm; |
| 528 | append_tlv_u8(req_tlv, TLVID_osmo_ta, mr->ms_l1.ta); |
| 529 | ms_dbm = ms_pwr_dbm(lchan->ts->trx->bts->band, mr->ms_l1.pwr); |
| 530 | append_tlv_u8(req_tlv, TLVID_osmo_ms_l1_txpwr, ms_dbm); |
Max | 11e4e41 | 2017-04-20 13:07:58 +0200 | [diff] [blame] | 531 | } else if (mr->flags & MEAS_REP_F_MS_TO) /* Save Timing Offset field = MS Timing Offset + 63 */ |
| 532 | append_tlv_u8(req_tlv, TLVID_osmo_ta, mr->ms_timing_offset + 63); |
Harald Welte | 3f78600 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 533 | |
| 534 | append_tlv_u16(req_tlv, TLVID_osmo_rxlev_ul, |
| 535 | rxlev2dbm(ul_meas->full.rx_lev)); |
| 536 | append_tlv_u8(req_tlv, TLVID_osmo_rxqual_ul, ul_meas->full.rx_qual); |
| 537 | |
| 538 | if (mr->flags & MEAS_REP_F_DL_VALID) { |
| 539 | append_tlv_u16(req_tlv, TLVID_osmo_rxlev_dl, |
| 540 | rxlev2dbm(dl_meas->full.rx_lev)); |
| 541 | append_tlv_u8(req_tlv, TLVID_osmo_rxqual_dl, |
| 542 | dl_meas->full.rx_qual); |
| 543 | } |
| 544 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 545 | if (lchan->conn && lchan->conn->vsub) { |
| 546 | struct vlr_subscr *vsub = lchan->conn->vsub; |
| 547 | size_t imei_len = strlen(vsub->imei); |
Harald Welte | 3f78600 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 548 | if (imei_len) |
| 549 | append_tlv(req_tlv, TLVID_osmo_imei, |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 550 | (uint8_t *)vsub->imei, imei_len+1); |
Harald Welte | 3f78600 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 551 | } |
| 552 | } |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 553 | #endif |
Harald Welte | 3f78600 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 554 | |
Keith | 320960c | 2017-05-13 23:38:52 +0200 | [diff] [blame] | 555 | struct { |
| 556 | uint32_t smpp_status_code; |
| 557 | uint8_t gsm411_cause; |
| 558 | } smpp_to_gsm411_err_array[] = { |
| 559 | |
| 560 | /* Seems like most phones don't care about the failure cause, |
| 561 | * although some will display a different notification for |
| 562 | * GSM411_RP_CAUSE_MO_NUM_UNASSIGNED |
| 563 | * Some provoke a display of "Try again later" |
| 564 | * while others a more definitive "Message sending failed" |
| 565 | */ |
| 566 | |
| 567 | { ESME_RSYSERR, GSM411_RP_CAUSE_MO_DEST_OUT_OF_ORDER }, |
| 568 | { ESME_RINVDSTADR, GSM411_RP_CAUSE_MO_NUM_UNASSIGNED }, |
| 569 | { ESME_RMSGQFUL, GSM411_RP_CAUSE_MO_CONGESTION }, |
| 570 | { ESME_RINVSRCADR, GSM411_RP_CAUSE_MO_SMS_REJECTED }, |
| 571 | { ESME_RINVMSGID, GSM411_RP_CAUSE_INV_TRANS_REF } |
| 572 | }; |
| 573 | |
| 574 | static int smpp_to_gsm411_err(uint32_t smpp_status_code, int *gsm411_cause) |
| 575 | { |
| 576 | int i; |
| 577 | for (i = 0; i < ARRAY_SIZE(smpp_to_gsm411_err_array); i++) { |
| 578 | if (smpp_to_gsm411_err_array[i].smpp_status_code != smpp_status_code) |
| 579 | continue; |
| 580 | *gsm411_cause = smpp_to_gsm411_err_array[i].gsm411_cause; |
| 581 | return 0; |
| 582 | } |
| 583 | return -1; |
| 584 | } |
| 585 | |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 586 | static void smpp_cmd_free(struct osmo_smpp_cmd *cmd) |
| 587 | { |
| 588 | osmo_timer_del(&cmd->response_timer); |
| 589 | llist_del(&cmd->list); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 590 | vlr_subscr_put(cmd->vsub, VSUB_USE_SMPP_CMD); |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 591 | talloc_free(cmd); |
| 592 | } |
| 593 | |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 594 | void smpp_cmd_flush_pending(struct smpp_esme *esme) |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 595 | { |
| 596 | struct osmo_smpp_cmd *cmd, *next; |
| 597 | |
| 598 | llist_for_each_entry_safe(cmd, next, &esme->smpp_cmd_list, list) |
| 599 | smpp_cmd_free(cmd); |
| 600 | } |
| 601 | |
| 602 | void smpp_cmd_ack(struct osmo_smpp_cmd *cmd) |
| 603 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 604 | struct msc_a *msc_a; |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 605 | struct gsm_trans *trans; |
| 606 | |
Pablo Neira Ayuso | adae859 | 2017-08-07 14:01:30 +0100 | [diff] [blame] | 607 | if (cmd->is_report) |
| 608 | goto out; |
| 609 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 610 | msc_a = msc_a_for_vsub(cmd->vsub, true); |
| 611 | if (!msc_a) { |
| 612 | LOGP(DSMPP, LOGL_ERROR, "No connection to subscriber %s\n", vlr_subscr_name(cmd->vsub)); |
Pablo Neira Ayuso | f00d810 | 2017-08-07 14:01:01 +0100 | [diff] [blame] | 613 | goto out; |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 614 | } |
| 615 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 616 | trans = trans_find_by_id(msc_a, TRANS_SMS, cmd->gsm411_trans_id); |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 617 | if (!trans) { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 618 | LOG_MSC_A_CAT(msc_a, DSMPP, LOGL_ERROR, "GSM transaction %u is gone\n", cmd->gsm411_trans_id); |
Pablo Neira Ayuso | f00d810 | 2017-08-07 14:01:01 +0100 | [diff] [blame] | 619 | goto out; |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 620 | } |
| 621 | |
Pablo Neira Ayuso | fdc9966 | 2017-08-07 14:01:10 +0100 | [diff] [blame] | 622 | gsm411_send_rp_ack(trans, cmd->gsm411_msg_ref); |
Pablo Neira Ayuso | f00d810 | 2017-08-07 14:01:01 +0100 | [diff] [blame] | 623 | out: |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 624 | smpp_cmd_free(cmd); |
| 625 | } |
| 626 | |
Keith | 320960c | 2017-05-13 23:38:52 +0200 | [diff] [blame] | 627 | void smpp_cmd_err(struct osmo_smpp_cmd *cmd, uint32_t status) |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 628 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 629 | struct msc_a *msc_a; |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 630 | struct gsm_trans *trans; |
Keith | 320960c | 2017-05-13 23:38:52 +0200 | [diff] [blame] | 631 | int gsm411_cause; |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 632 | |
Pablo Neira Ayuso | adae859 | 2017-08-07 14:01:30 +0100 | [diff] [blame] | 633 | if (cmd->is_report) |
| 634 | goto out; |
| 635 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 636 | msc_a = msc_a_for_vsub(cmd->vsub, true); |
| 637 | if (!msc_a) { |
| 638 | LOGP(DSMPP, LOGL_ERROR, "No connection to subscriber %s\n", vlr_subscr_name(cmd->vsub)); |
Pablo Neira Ayuso | f00d810 | 2017-08-07 14:01:01 +0100 | [diff] [blame] | 639 | goto out; |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 640 | } |
| 641 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 642 | trans = trans_find_by_id(msc_a, TRANS_SMS, cmd->gsm411_trans_id); |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 643 | if (!trans) { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 644 | LOG_MSC_A_CAT(msc_a, DSMPP, LOGL_ERROR, "GSM transaction %u is gone\n", |
| 645 | cmd->gsm411_trans_id); |
Pablo Neira Ayuso | f00d810 | 2017-08-07 14:01:01 +0100 | [diff] [blame] | 646 | goto out; |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 647 | } |
| 648 | |
Keith | 320960c | 2017-05-13 23:38:52 +0200 | [diff] [blame] | 649 | if (smpp_to_gsm411_err(status, &gsm411_cause) < 0) |
| 650 | gsm411_cause = GSM411_RP_CAUSE_MO_NET_OUT_OF_ORDER; |
| 651 | |
Pablo Neira Ayuso | fdc9966 | 2017-08-07 14:01:10 +0100 | [diff] [blame] | 652 | gsm411_send_rp_error(trans, cmd->gsm411_msg_ref, gsm411_cause); |
Pablo Neira Ayuso | f00d810 | 2017-08-07 14:01:01 +0100 | [diff] [blame] | 653 | out: |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 654 | smpp_cmd_free(cmd); |
| 655 | } |
| 656 | |
| 657 | static void smpp_deliver_sm_cb(void *data) |
| 658 | { |
Keith | 320960c | 2017-05-13 23:38:52 +0200 | [diff] [blame] | 659 | smpp_cmd_err(data, ESME_RSYSERR); |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 660 | } |
| 661 | |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 662 | static int smpp_cmd_enqueue(struct smpp_esme *esme, |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 663 | struct vlr_subscr *vsub, struct gsm_sms *sms, |
Pablo Neira Ayuso | fdc9966 | 2017-08-07 14:01:10 +0100 | [diff] [blame] | 664 | uint32_t sequence_number) |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 665 | { |
| 666 | struct osmo_smpp_cmd *cmd; |
| 667 | |
| 668 | cmd = talloc_zero(esme, struct osmo_smpp_cmd); |
| 669 | if (!cmd) |
| 670 | return -1; |
| 671 | |
| 672 | cmd->sequence_nr = sequence_number; |
Pablo Neira Ayuso | adae859 | 2017-08-07 14:01:30 +0100 | [diff] [blame] | 673 | cmd->is_report = sms->is_report; |
Pablo Neira Ayuso | fdc9966 | 2017-08-07 14:01:10 +0100 | [diff] [blame] | 674 | cmd->gsm411_msg_ref = sms->gsm411.msg_ref; |
| 675 | cmd->gsm411_trans_id = sms->gsm411.transaction_id; |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 676 | vlr_subscr_get(vsub, VSUB_USE_SMPP_CMD); |
| 677 | cmd->vsub = vsub; |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 678 | |
| 679 | /* FIXME: No predefined value for this response_timer as specified by |
| 680 | * SMPP 3.4 specs, section 7.2. Make this configurable? Don't forget |
| 681 | * lchan keeps busy until we get a reply to this SMPP command. Too high |
| 682 | * value may exhaust resources. |
| 683 | */ |
Pablo Neira Ayuso | 5121576 | 2017-05-08 20:57:52 +0200 | [diff] [blame] | 684 | osmo_timer_setup(&cmd->response_timer, smpp_deliver_sm_cb, cmd); |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 685 | osmo_timer_schedule(&cmd->response_timer, 5, 0); |
| 686 | llist_add_tail(&cmd->list, &esme->smpp_cmd_list); |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 687 | |
| 688 | return 0; |
| 689 | } |
| 690 | |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 691 | struct osmo_smpp_cmd *smpp_cmd_find_by_seqnum(struct smpp_esme *esme, |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 692 | uint32_t sequence_nr) |
| 693 | { |
| 694 | struct osmo_smpp_cmd *cmd; |
| 695 | |
| 696 | llist_for_each_entry(cmd, &esme->smpp_cmd_list, list) { |
| 697 | if (cmd->sequence_nr == sequence_nr) |
| 698 | return cmd; |
| 699 | } |
| 700 | return NULL; |
| 701 | } |
| 702 | |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 703 | static int deliver_to_esme(struct smpp_esme *esme, struct gsm_sms *sms, |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 704 | struct msc_a *msc_a) |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 705 | { |
| 706 | struct deliver_sm_t deliver; |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 707 | int mode, ret; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 708 | uint8_t dcs; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 709 | struct vlr_subscr *vsub = msc_a_vsub(msc_a); |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 710 | |
| 711 | memset(&deliver, 0, sizeof(deliver)); |
| 712 | deliver.command_length = 0; |
| 713 | deliver.command_id = DELIVER_SM; |
| 714 | deliver.command_status = ESME_ROK; |
| 715 | |
| 716 | strcpy((char *)deliver.service_type, "CMT"); |
| 717 | if (esme->acl && esme->acl->deliver_src_imsi) { |
| 718 | deliver.source_addr_ton = TON_Subscriber_Number; |
| 719 | deliver.source_addr_npi = NPI_Land_Mobile_E212; |
| 720 | snprintf((char *)deliver.source_addr, |
| 721 | sizeof(deliver.source_addr), "%s", |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 722 | vsub->imsi); |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 723 | } else { |
| 724 | deliver.source_addr_ton = TON_Network_Specific; |
| 725 | deliver.source_addr_npi = NPI_ISDN_E163_E164; |
| 726 | snprintf((char *)deliver.source_addr, |
| 727 | sizeof(deliver.source_addr), "%s", |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 728 | vsub->msisdn); |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 729 | } |
| 730 | |
Harald Welte | c0de14d | 2012-11-23 23:35:01 +0100 | [diff] [blame] | 731 | deliver.dest_addr_ton = sms->dst.ton; |
| 732 | deliver.dest_addr_npi = sms->dst.npi; |
| 733 | memcpy(deliver.destination_addr, sms->dst.addr, |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 734 | sizeof(deliver.destination_addr)); |
| 735 | |
Pablo Neira Ayuso | adae859 | 2017-08-07 14:01:30 +0100 | [diff] [blame] | 736 | if (sms->is_report) |
Pablo Neira Ayuso | d7e14da | 2017-08-11 13:10:48 +0200 | [diff] [blame] | 737 | deliver.esm_class = SMPP34_DELIVERY_RECEIPT; |
Pablo Neira Ayuso | adae859 | 2017-08-07 14:01:30 +0100 | [diff] [blame] | 738 | else |
Pablo Neira Ayuso | d7e14da | 2017-08-11 13:10:48 +0200 | [diff] [blame] | 739 | deliver.esm_class = SMPP34_DATAGRAM_MODE; |
Pablo Neira Ayuso | adae859 | 2017-08-07 14:01:30 +0100 | [diff] [blame] | 740 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 741 | if (sms->ud_hdr_ind) |
Pablo Neira Ayuso | d7e14da | 2017-08-11 13:10:48 +0200 | [diff] [blame] | 742 | deliver.esm_class |= SMPP34_UDHI_IND; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 743 | if (sms->reply_path_req) |
Pablo Neira Ayuso | d7e14da | 2017-08-11 13:10:48 +0200 | [diff] [blame] | 744 | deliver.esm_class |= SMPP34_REPLY_PATH; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 745 | |
| 746 | deliver.protocol_id = sms->protocol_id; |
| 747 | deliver.priority_flag = 0; |
Pablo Neira Ayuso | 6ceac7c | 2017-08-07 14:01:15 +0100 | [diff] [blame] | 748 | if (sms->status_rep_req) |
Pablo Neira Ayuso | 4f03b47 | 2017-08-11 14:36:01 +0200 | [diff] [blame] | 749 | deliver.registered_delivery = SMPP34_DELIVERY_RECEIPT_ON; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 750 | |
Harald Welte | c75ed6d | 2013-05-28 20:58:02 +0200 | [diff] [blame] | 751 | /* Figure out SMPP DCS from TP-DCS */ |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 752 | dcs = sms->data_coding_scheme; |
Holger Hans Peter Freyther | a7328a5 | 2013-07-13 17:09:56 +0200 | [diff] [blame] | 753 | if (smpp_determine_scheme(dcs, &deliver.data_coding, &mode) == -1) |
Harald Welte | c75ed6d | 2013-05-28 20:58:02 +0200 | [diff] [blame] | 754 | return -1; |
Harald Welte | c75ed6d | 2013-05-28 20:58:02 +0200 | [diff] [blame] | 755 | |
| 756 | /* Transparently pass on DCS via SMPP if requested */ |
Holger Hans Peter Freyther | 921b227 | 2013-07-14 08:54:07 +0200 | [diff] [blame] | 757 | if (esme->acl && esme->acl->dcs_transparent) |
Harald Welte | c75ed6d | 2013-05-28 20:58:02 +0200 | [diff] [blame] | 758 | deliver.data_coding = dcs; |
| 759 | |
| 760 | if (mode == MODE_7BIT) { |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 761 | uint8_t *dst = deliver.short_message; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 762 | |
| 763 | /* SMPP has this strange notion of putting 7bit SMS in |
| 764 | * an octet-aligned mode */ |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 765 | if (sms->ud_hdr_ind) { |
Harald Welte | b8a1f96 | 2012-11-24 01:37:39 +0100 | [diff] [blame] | 766 | /* length (bytes) of UDH inside UD */ |
| 767 | uint8_t udh_len = sms->user_data[0] + 1; |
| 768 | |
| 769 | /* copy over the UDH */ |
| 770 | memcpy(dst, sms->user_data, udh_len); |
| 771 | dst += udh_len; |
| 772 | deliver.sm_length = udh_len; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 773 | } |
Harald Welte | b8a1f96 | 2012-11-24 01:37:39 +0100 | [diff] [blame] | 774 | /* add decoded text */ |
| 775 | deliver.sm_length += gsm_7bit_expand((char *)dst, sms->user_data, sms->user_data_len, sms->ud_hdr_ind); |
Harald Welte | c75ed6d | 2013-05-28 20:58:02 +0200 | [diff] [blame] | 776 | } else { |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 777 | deliver.sm_length = sms->user_data_len; |
| 778 | memcpy(deliver.short_message, sms->user_data, deliver.sm_length); |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 779 | } |
| 780 | |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 781 | #if BEFORE_MSCSPLIT |
| 782 | /* We currently have no lchan information. Re-add after A-interface, see OS#2390. */ |
Holger Hans Peter Freyther | 019851a | 2015-02-08 09:21:04 +0100 | [diff] [blame] | 783 | if (esme->acl && esme->acl->osmocom_ext && conn->lchan) |
Harald Welte | 3f78600 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 784 | append_osmo_tlvs(&deliver.tlv, conn->lchan); |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 785 | #endif |
Harald Welte | 3f78600 | 2013-03-13 15:29:27 +0100 | [diff] [blame] | 786 | |
Pablo Neira Ayuso | adae859 | 2017-08-07 14:01:30 +0100 | [diff] [blame] | 787 | append_tlv_u16(&deliver.tlv, TLVID_user_message_reference, |
| 788 | sms->msg_ref); |
| 789 | |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 790 | ret = smpp_tx_deliver(esme, &deliver); |
Keith Whyte | c54ce6a | 2023-07-21 20:09:08 +0100 | [diff] [blame] | 791 | destroy_tlv(deliver.tlv); |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 792 | if (ret < 0) |
| 793 | return ret; |
| 794 | |
Pablo Neira Ayuso | 83616a8 | 2020-01-15 10:00:24 +0100 | [diff] [blame] | 795 | OSMO_ASSERT(!sms->smpp.esme); |
| 796 | smpp_esme_get(esme); |
| 797 | sms->smpp.esme = esme; |
| 798 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 799 | return smpp_cmd_enqueue(esme, vsub, sms, |
Pablo Neira Ayuso | fdc9966 | 2017-08-07 14:01:10 +0100 | [diff] [blame] | 800 | deliver.sequence_number); |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 801 | } |
| 802 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 803 | bool smpp_route_smpp_first() |
Holger Hans Peter Freyther | 42cf2e0 | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 804 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 805 | return (bool)(g_smsc->smpp_first); |
Holger Hans Peter Freyther | 42cf2e0 | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 806 | } |
| 807 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 808 | int smpp_try_deliver(struct gsm_sms *sms, struct msc_a *msc_a) |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 809 | { |
Max | 366a340 | 2022-08-01 23:01:24 +0700 | [diff] [blame] | 810 | struct smpp_esme *esme; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 811 | struct osmo_smpp_addr dst; |
Benoit Bolsee | d34ed57 | 2017-07-05 11:46:55 +0200 | [diff] [blame] | 812 | int rc; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 813 | |
| 814 | memset(&dst, 0, sizeof(dst)); |
Harald Welte | c0de14d | 2012-11-23 23:35:01 +0100 | [diff] [blame] | 815 | dst.ton = sms->dst.ton; |
| 816 | dst.npi = sms->dst.npi; |
| 817 | memcpy(dst.addr, sms->dst.addr, sizeof(dst.addr)); |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 818 | |
Benoit Bolsee | d34ed57 | 2017-07-05 11:46:55 +0200 | [diff] [blame] | 819 | rc = smpp_route(g_smsc, &dst, &esme); |
| 820 | if (!rc) |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 821 | rc = deliver_to_esme(esme, sms, msc_a); |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 822 | |
Benoit Bolsee | d34ed57 | 2017-07-05 11:46:55 +0200 | [diff] [blame] | 823 | return rc; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 824 | } |
| 825 | |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 826 | struct smsc *smsc_from_vty(struct vty *v) |
| 827 | { |
| 828 | /* FIXME: this is ugly */ |
| 829 | return g_smsc; |
| 830 | } |
| 831 | |
Max | dfb1cb8 | 2022-08-01 23:47:20 +0700 | [diff] [blame] | 832 | /*! \brief Allocate the OsmoMSC SMPP interface struct and init VTY. */ |
| 833 | int smpp_msc_alloc_init(void *ctx) |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 834 | { |
Neels Hofmeyr | 1b0e554 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 835 | g_smsc = smpp_smsc_alloc_init(ctx); |
| 836 | if (!g_smsc) { |
| 837 | LOGP(DSMPP, LOGL_FATAL, "Cannot allocate smsc struct\n"); |
| 838 | return -1; |
| 839 | } |
Harald Welte | e39f6cd | 2019-04-10 00:33:46 +0200 | [diff] [blame] | 840 | smpp34_set_memory_functions(&smpp34_talloc); |
Neels Hofmeyr | 1b0e554 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 841 | return smpp_vty_init(); |
| 842 | } |
| 843 | |
Max | dfb1cb8 | 2022-08-01 23:47:20 +0700 | [diff] [blame] | 844 | /*! \brief Launch the OsmoMSC SMPP interface with the parameters set from VTY. |
Neels Hofmeyr | 1b0e554 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 845 | */ |
Max | dfb1cb8 | 2022-08-01 23:47:20 +0700 | [diff] [blame] | 846 | int smpp_msc_start(struct gsm_network *net) |
Neels Hofmeyr | 1b0e554 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 847 | { |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 848 | int rc; |
Harald Welte | 76afa16 | 2013-03-13 15:05:26 +0100 | [diff] [blame] | 849 | g_smsc->priv = net; |
Neels Hofmeyr | 1b0e554 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 850 | |
| 851 | /* If a VTY configuration has taken place, the values have been stored |
| 852 | * in the smsc struct. Otherwise, use the defaults (NULL -> any, 0 -> |
| 853 | * default SMPP port, see smpp_smsc_bind()). */ |
| 854 | rc = smpp_smsc_start(g_smsc, g_smsc->bind_addr, g_smsc->listen_port); |
| 855 | if (rc < 0) |
| 856 | return rc; |
| 857 | |
| 858 | rc = osmo_signal_register_handler(SS_SMS, smpp_sms_cb, g_smsc); |
| 859 | if (rc < 0) |
| 860 | return rc; |
| 861 | rc = osmo_signal_register_handler(SS_SUBSCR, smpp_subscr_cb, g_smsc); |
| 862 | if (rc < 0) |
| 863 | return rc; |
| 864 | |
| 865 | return 0; |
Harald Welte | 76afa16 | 2013-03-13 15:05:26 +0100 | [diff] [blame] | 866 | } |