Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 1 | /* SMPP 3.4 interface, SMSC-side implementation */ |
| 2 | /* (C) 2012 by Harald Welte <laforge@gnumonks.org> |
| 3 | * |
Harald Welte | 995ff35 | 2013-07-13 16:35:32 +0200 | [diff] [blame] | 4 | * All Rights Reserved |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 5 | * |
Harald Welte | 995ff35 | 2013-07-13 16:35:32 +0200 | [diff] [blame] | 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. |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 10 | * |
Harald Welte | 995ff35 | 2013-07-13 16:35:32 +0200 | [diff] [blame] | 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/>. |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <unistd.h> |
| 23 | #include <string.h> |
| 24 | #include <stdint.h> |
| 25 | #include <errno.h> |
Daniel Willmann | 1fc8ec6 | 2014-01-17 15:17:36 +0100 | [diff] [blame] | 26 | #include <limits.h> |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 27 | |
| 28 | #include <sys/socket.h> |
| 29 | #include <netinet/in.h> |
| 30 | |
| 31 | #include <smpp34.h> |
| 32 | #include <smpp34_structs.h> |
| 33 | #include <smpp34_params.h> |
| 34 | |
| 35 | #include <osmocom/core/utils.h> |
| 36 | #include <osmocom/core/socket.h> |
| 37 | #include <osmocom/core/msgb.h> |
| 38 | #include <osmocom/core/logging.h> |
| 39 | #include <osmocom/core/write_queue.h> |
| 40 | #include <osmocom/core/talloc.h> |
| 41 | |
| 42 | #include "smpp_smsc.h" |
| 43 | |
| 44 | #include <openbsc/debug.h> |
Holger Hans Peter Freyther | d7b22c6 | 2013-04-29 09:11:02 +0200 | [diff] [blame] | 45 | #include <openbsc/gsm_data.h> |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 46 | |
Harald Welte | 4dbcdad | 2012-11-08 22:12:45 +0100 | [diff] [blame] | 47 | /*! \brief Ugly wrapper. libsmpp34 should do this itself! */ |
| 48 | #define SMPP34_UNPACK(rc, type, str, data, len) \ |
| 49 | memset(str, 0, sizeof(*str)); \ |
| 50 | rc = smpp34_unpack(type, str, data, len) |
| 51 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 52 | enum emse_bind { |
| 53 | ESME_BIND_RX = 0x01, |
| 54 | ESME_BIND_TX = 0x02, |
| 55 | }; |
| 56 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 57 | const struct value_string smpp_status_strs[] = { |
| 58 | { ESME_ROK, "No Error" }, |
| 59 | { ESME_RINVMSGLEN, "Message Length is invalid" }, |
| 60 | { ESME_RINVCMDLEN, "Command Length is invalid" }, |
| 61 | { ESME_RINVCMDID, "Invalid Command ID" }, |
| 62 | { ESME_RINVBNDSTS, "Incorrect BIND Status for given command" }, |
| 63 | { ESME_RALYBND, "ESME Already in Bound State" }, |
| 64 | { ESME_RINVPRTFLG, "Invalid Priority Flag" }, |
| 65 | { ESME_RINVREGDLVFLG, "Invalid Registered Delivery Flag" }, |
| 66 | { ESME_RSYSERR, "System Error" }, |
| 67 | { ESME_RINVSRCADR, "Invalid Source Address" }, |
| 68 | { ESME_RINVDSTADR, "Invalid Destination Address" }, |
| 69 | { ESME_RINVMSGID, "Message ID is invalid" }, |
| 70 | { ESME_RBINDFAIL, "Bind failed" }, |
| 71 | { ESME_RINVPASWD, "Invalid Password" }, |
| 72 | { ESME_RINVSYSID, "Invalid System ID" }, |
| 73 | { ESME_RCANCELFAIL, "Cancel SM Failed" }, |
| 74 | { ESME_RREPLACEFAIL, "Replace SM Failed" }, |
| 75 | { ESME_RMSGQFUL, "Message Queue Full" }, |
| 76 | { ESME_RINVSERTYP, "Invalid Service Type" }, |
| 77 | { ESME_RINVNUMDESTS, "Invalid number of destinations" }, |
| 78 | { ESME_RINVDLNAME, "Invalid Distribution List name" }, |
| 79 | { ESME_RINVDESTFLAG, "Destination flag is invalid" }, |
| 80 | { ESME_RINVSUBREP, "Invalid submit with replace request" }, |
| 81 | { ESME_RINVESMCLASS, "Invalid esm_class field data" }, |
| 82 | { ESME_RCNTSUBDL, "Cannot Submit to Distribution List" }, |
| 83 | { ESME_RSUBMITFAIL, "submit_sm or submit_multi failed" }, |
| 84 | { ESME_RINVSRCTON, "Invalid Source address TON" }, |
| 85 | { ESME_RINVSRCNPI, "Invalid Sourec address NPI" }, |
| 86 | { ESME_RINVDSTTON, "Invalid Destination address TON" }, |
| 87 | { ESME_RINVDSTNPI, "Invalid Desetination address NPI" }, |
| 88 | { ESME_RINVSYSTYP, "Invalid system_type field" }, |
| 89 | { ESME_RINVREPFLAG, "Invalid replace_if_present field" }, |
| 90 | { ESME_RINVNUMMSGS, "Invalid number of messages" }, |
| 91 | { ESME_RTHROTTLED, "Throttling error (ESME has exceeded message limits)" }, |
| 92 | { ESME_RINVSCHED, "Invalid Scheduled Delivery Time" }, |
| 93 | { ESME_RINVEXPIRY, "Invalid message validity period (Expiry time)" }, |
| 94 | { ESME_RINVDFTMSGID, "Predefined Message Invalid or Not Found" }, |
| 95 | { ESME_RX_T_APPN, "ESME Receiver Temporary App Error Code" }, |
| 96 | { ESME_RX_P_APPN, "ESME Receiver Permanent App Error Code" }, |
| 97 | { ESME_RX_R_APPN, "ESME Receiver Reject Message Error Code" }, |
| 98 | { ESME_RQUERYFAIL, "query_sm request failed" }, |
| 99 | { ESME_RINVOPTPARSTREAM,"Error in the optional part of the PDU Body" }, |
| 100 | { ESME_ROPTPARNOTALLWD, "Optional Parameter not allowed" }, |
| 101 | { ESME_RINVPARLEN, "Invalid Parameter Length" }, |
| 102 | { ESME_RMISSINGOPTPARAM,"Expected Optional Parameter missing" }, |
| 103 | { ESME_RINVOPTPARAMVAL, "Invalid Optional Parameter Value" }, |
| 104 | { ESME_RDELIVERYFAILURE,"Delivery Failure (used for data_sm_resp)" }, |
| 105 | { ESME_RUNKNOWNERR, "Unknown Error" }, |
| 106 | { 0, NULL } |
| 107 | }; |
| 108 | |
| 109 | /*! \brief compare if two SMPP addresses are equal */ |
| 110 | int smpp_addr_eq(const struct osmo_smpp_addr *a, |
| 111 | const struct osmo_smpp_addr *b) |
| 112 | { |
| 113 | if (a->ton == b->ton && |
| 114 | a->npi == b->npi && |
| 115 | !strcmp(a->addr, b->addr)) |
| 116 | return 1; |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 122 | struct osmo_smpp_acl *smpp_acl_by_system_id(struct smsc *smsc, |
| 123 | const char *sys_id) |
| 124 | { |
| 125 | struct osmo_smpp_acl *acl; |
| 126 | |
| 127 | llist_for_each_entry(acl, &smsc->acl_list, list) { |
| 128 | if (!strcmp(acl->system_id, sys_id)) |
| 129 | return acl; |
| 130 | } |
| 131 | |
| 132 | return NULL; |
| 133 | } |
| 134 | |
| 135 | struct osmo_smpp_acl *smpp_acl_alloc(struct smsc *smsc, const char *sys_id) |
| 136 | { |
| 137 | struct osmo_smpp_acl *acl; |
| 138 | |
| 139 | if (strlen(sys_id) > SMPP_SYS_ID_LEN) |
| 140 | return NULL; |
| 141 | |
| 142 | if (smpp_acl_by_system_id(smsc, sys_id)) |
| 143 | return NULL; |
| 144 | |
| 145 | acl = talloc_zero(smsc, struct osmo_smpp_acl); |
| 146 | if (!acl) |
| 147 | return NULL; |
| 148 | |
| 149 | acl->smsc = smsc; |
| 150 | strcpy(acl->system_id, sys_id); |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 151 | INIT_LLIST_HEAD(&acl->route_list); |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 152 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 153 | llist_add_tail(&acl->list, &smsc->acl_list); |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 154 | |
| 155 | return acl; |
| 156 | } |
| 157 | |
| 158 | void smpp_acl_delete(struct osmo_smpp_acl *acl) |
| 159 | { |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 160 | struct osmo_smpp_route *r, *r2; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 161 | |
| 162 | llist_del(&acl->list); |
| 163 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 164 | /* kill any active ESMEs */ |
| 165 | if (acl->esme) { |
| 166 | struct osmo_esme *esme = acl->esme; |
| 167 | osmo_fd_unregister(&esme->wqueue.bfd); |
| 168 | close(esme->wqueue.bfd.fd); |
| 169 | esme->wqueue.bfd.fd = -1; |
| 170 | esme->acl = NULL; |
| 171 | smpp_esme_put(esme); |
| 172 | } |
| 173 | |
| 174 | /* delete all routes for this ACL */ |
| 175 | llist_for_each_entry_safe(r, r2, &acl->route_list, list) { |
| 176 | llist_del(&r->list); |
| 177 | llist_del(&r->global_list); |
| 178 | talloc_free(r); |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | talloc_free(acl); |
| 182 | } |
| 183 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 184 | static struct osmo_smpp_route *route_alloc(struct osmo_smpp_acl *acl) |
| 185 | { |
| 186 | struct osmo_smpp_route *r; |
| 187 | |
| 188 | r = talloc_zero(acl, struct osmo_smpp_route); |
| 189 | if (!r) |
| 190 | return NULL; |
| 191 | |
| 192 | llist_add_tail(&r->list, &acl->route_list); |
| 193 | llist_add_tail(&r->global_list, &acl->smsc->route_list); |
| 194 | |
| 195 | return r; |
| 196 | } |
| 197 | |
| 198 | int smpp_route_pfx_add(struct osmo_smpp_acl *acl, |
| 199 | const struct osmo_smpp_addr *pfx) |
| 200 | { |
| 201 | struct osmo_smpp_route *r; |
| 202 | |
| 203 | llist_for_each_entry(r, &acl->route_list, list) { |
| 204 | if (r->type == SMPP_ROUTE_PREFIX && |
| 205 | smpp_addr_eq(&r->u.prefix, pfx)) |
| 206 | return -EEXIST; |
| 207 | } |
| 208 | |
| 209 | r = route_alloc(acl); |
| 210 | if (!r) |
| 211 | return -ENOMEM; |
| 212 | r->type = SMPP_ROUTE_PREFIX; |
| 213 | r->acl = acl; |
| 214 | memcpy(&r->u.prefix, pfx, sizeof(r->u.prefix)); |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | int smpp_route_pfx_del(struct osmo_smpp_acl *acl, |
| 220 | const struct osmo_smpp_addr *pfx) |
| 221 | { |
| 222 | struct osmo_smpp_route *r, *r2; |
| 223 | |
| 224 | llist_for_each_entry_safe(r, r2, &acl->route_list, list) { |
| 225 | if (r->type == SMPP_ROUTE_PREFIX && |
| 226 | smpp_addr_eq(&r->u.prefix, pfx)) { |
| 227 | llist_del(&r->list); |
| 228 | talloc_free(r); |
| 229 | return 0; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | return -ENODEV; |
| 234 | } |
| 235 | |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 236 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 237 | /*! \brief increaes the use/reference count */ |
| 238 | void smpp_esme_get(struct osmo_esme *esme) |
| 239 | { |
| 240 | esme->use++; |
| 241 | } |
| 242 | |
| 243 | static void esme_destroy(struct osmo_esme *esme) |
| 244 | { |
| 245 | osmo_wqueue_clear(&esme->wqueue); |
| 246 | if (esme->wqueue.bfd.fd >= 0) { |
| 247 | osmo_fd_unregister(&esme->wqueue.bfd); |
| 248 | close(esme->wqueue.bfd.fd); |
| 249 | } |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 250 | smpp_cmd_flush_pending(esme); |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 251 | llist_del(&esme->list); |
| 252 | talloc_free(esme); |
| 253 | } |
| 254 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 255 | static uint32_t esme_inc_seq_nr(struct osmo_esme *esme) |
| 256 | { |
| 257 | esme->own_seq_nr++; |
| 258 | if (esme->own_seq_nr > 0x7fffffff) |
| 259 | esme->own_seq_nr = 1; |
| 260 | |
| 261 | return esme->own_seq_nr; |
| 262 | } |
| 263 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 264 | /*! \brief decrease the use/reference count, free if it is 0 */ |
| 265 | void smpp_esme_put(struct osmo_esme *esme) |
| 266 | { |
| 267 | esme->use--; |
| 268 | if (esme->use <= 0) |
| 269 | esme_destroy(esme); |
| 270 | } |
| 271 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 272 | /*! \brief try to find a SMPP route (ESME) for given destination */ |
Benoit Bolsee | 7535c07 | 2017-07-05 11:46:55 +0200 | [diff] [blame] | 273 | int smpp_route(const struct smsc *smsc, const struct osmo_smpp_addr *dest, struct osmo_esme **pesme) |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 274 | { |
| 275 | struct osmo_smpp_route *r; |
| 276 | struct osmo_smpp_acl *acl = NULL; |
| 277 | |
| 278 | DEBUGP(DSMPP, "Looking up route for (%u/%u/%s)\n", |
| 279 | dest->ton, dest->npi, dest->addr); |
| 280 | |
| 281 | /* search for a specific route */ |
| 282 | llist_for_each_entry(r, &smsc->route_list, global_list) { |
| 283 | switch (r->type) { |
| 284 | case SMPP_ROUTE_PREFIX: |
| 285 | DEBUGP(DSMPP, "Checking prefix route (%u/%u/%s)->%s\n", |
| 286 | r->u.prefix.ton, r->u.prefix.npi, r->u.prefix.addr, |
| 287 | r->acl->system_id); |
| 288 | if (r->u.prefix.ton == dest->ton && |
| 289 | r->u.prefix.npi == dest->npi && |
| 290 | !strncmp(r->u.prefix.addr, dest->addr, |
| 291 | strlen(r->u.prefix.addr))) { |
| 292 | DEBUGP(DSMPP, "Found prefix route ACL\n"); |
| 293 | acl = r->acl; |
| 294 | } |
| 295 | break; |
| 296 | default: |
| 297 | break; |
| 298 | } |
| 299 | |
| 300 | if (acl) |
| 301 | break; |
| 302 | } |
| 303 | |
| 304 | if (!acl) { |
| 305 | /* check for default route */ |
| 306 | if (smsc->def_route) { |
| 307 | DEBUGP(DSMPP, "Using existing default route\n"); |
| 308 | acl = smsc->def_route; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | if (acl && acl->esme) { |
| 313 | struct osmo_esme *esme; |
| 314 | DEBUGP(DSMPP, "ACL even has ESME, we can route to it!\n"); |
| 315 | esme = acl->esme; |
Benoit Bolsee | 7535c07 | 2017-07-05 11:46:55 +0200 | [diff] [blame] | 316 | if (esme->bind_flags & ESME_BIND_RX) { |
| 317 | *pesme = esme; |
| 318 | return 0; |
| 319 | } else |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 320 | LOGP(DSMPP, LOGL_NOTICE, "[%s] is matching route, " |
| 321 | "but not bound for Rx, discarding MO SMS\n", |
| 322 | esme->system_id); |
| 323 | } |
| 324 | |
Benoit Bolsee | 7535c07 | 2017-07-05 11:46:55 +0200 | [diff] [blame] | 325 | *pesme = NULL; |
| 326 | if (acl) |
| 327 | return GSM48_CC_CAUSE_NETWORK_OOO; |
| 328 | else |
| 329 | return GSM48_CC_CAUSE_UNASSIGNED_NR; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 330 | } |
| 331 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 332 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 333 | /*! \brief initialize the libsmpp34 data structure for a response */ |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 334 | #define INIT_RESP(type, resp, req) { \ |
| 335 | memset((resp), 0, sizeof(*(resp))); \ |
| 336 | (resp)->command_length = 0; \ |
| 337 | (resp)->command_id = type; \ |
| 338 | (resp)->command_status = ESME_ROK; \ |
| 339 | (resp)->sequence_number = (req)->sequence_number; \ |
| 340 | } |
| 341 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 342 | /*! \brief pack a libsmpp34 data strcutrure and send it to the ESME */ |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 343 | #define PACK_AND_SEND(esme, ptr) pack_and_send(esme, (ptr)->command_id, ptr) |
| 344 | static int pack_and_send(struct osmo_esme *esme, uint32_t type, void *ptr) |
| 345 | { |
| 346 | struct msgb *msg = msgb_alloc(4096, "SMPP_Tx"); |
| 347 | int rc, rlen; |
| 348 | if (!msg) |
| 349 | return -ENOMEM; |
| 350 | |
| 351 | rc = smpp34_pack(type, msg->tail, msgb_tailroom(msg), &rlen, ptr); |
| 352 | if (rc != 0) { |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 353 | LOGP(DSMPP, LOGL_ERROR, "[%s] Error during smpp34_pack(): %s\n", |
| 354 | esme->system_id, smpp34_strerror); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 355 | msgb_free(msg); |
| 356 | return -EINVAL; |
| 357 | } |
| 358 | msgb_put(msg, rlen); |
| 359 | |
Holger Hans Peter Freyther | fd603ed | 2015-03-28 18:09:31 +0100 | [diff] [blame] | 360 | if (osmo_wqueue_enqueue(&esme->wqueue, msg) != 0) { |
| 361 | LOGP(DSMPP, LOGL_ERROR, "[%s] Write queue full. Dropping message\n", |
| 362 | esme->system_id); |
| 363 | msgb_free(msg); |
| 364 | return -EAGAIN; |
| 365 | } |
| 366 | return 0; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 367 | } |
| 368 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 369 | /*! \brief transmit a generic NACK to a remote ESME */ |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 370 | static int smpp_tx_gen_nack(struct osmo_esme *esme, uint32_t seq, uint32_t status) |
| 371 | { |
| 372 | struct generic_nack_t nack; |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 373 | char buf[SMALL_BUFF]; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 374 | |
| 375 | nack.command_length = 0; |
| 376 | nack.command_id = GENERIC_NACK; |
| 377 | nack.sequence_number = seq; |
| 378 | nack.command_status = status; |
| 379 | |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 380 | LOGP(DSMPP, LOGL_ERROR, "[%s] Tx GENERIC NACK: %s\n", |
| 381 | esme->system_id, str_command_status(status, buf)); |
| 382 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 383 | return PACK_AND_SEND(esme, &nack); |
| 384 | } |
| 385 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 386 | /*! \brief retrieve SMPP command ID from a msgb */ |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 387 | static inline uint32_t smpp_msgb_cmdid(struct msgb *msg) |
| 388 | { |
| 389 | uint8_t *tmp = msgb_data(msg) + 4; |
| 390 | return ntohl(*(uint32_t *)tmp); |
| 391 | } |
| 392 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 393 | /*! \brief retrieve SMPP sequence number from a msgb */ |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 394 | static inline uint32_t smpp_msgb_seq(struct msgb *msg) |
| 395 | { |
| 396 | uint8_t *tmp = msgb_data(msg); |
| 397 | return ntohl(*(uint32_t *)tmp); |
| 398 | } |
| 399 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 400 | /*! \brief handle an incoming SMPP generic NACK */ |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 401 | static int smpp_handle_gen_nack(struct osmo_esme *esme, struct msgb *msg) |
| 402 | { |
| 403 | struct generic_nack_t nack; |
| 404 | char buf[SMALL_BUFF]; |
| 405 | int rc; |
| 406 | |
Harald Welte | 4dbcdad | 2012-11-08 22:12:45 +0100 | [diff] [blame] | 407 | SMPP34_UNPACK(rc, GENERIC_NACK, &nack, msgb_data(msg), |
| 408 | msgb_length(msg)); |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 409 | if (rc < 0) { |
| 410 | LOGP(DSMPP, LOGL_ERROR, "[%s] Error in smpp34_unpack():%s\n", |
| 411 | esme->system_id, smpp34_strerror); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 412 | return rc; |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 413 | } |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 414 | |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 415 | LOGP(DSMPP, LOGL_ERROR, "[%s] Rx GENERIC NACK: %s\n", |
| 416 | esme->system_id, str_command_status(nack.command_status, buf)); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 421 | static int _process_bind(struct osmo_esme *esme, uint8_t if_version, |
| 422 | uint32_t bind_flags, const char *sys_id, |
| 423 | const char *passwd) |
| 424 | { |
| 425 | struct osmo_smpp_acl *acl; |
| 426 | |
| 427 | if (if_version != SMPP_VERSION) |
| 428 | return ESME_RSYSERR; |
| 429 | |
| 430 | if (esme->bind_flags) |
| 431 | return ESME_RALYBND; |
| 432 | |
| 433 | esme->smpp_version = if_version; |
| 434 | snprintf(esme->system_id, sizeof(esme->system_id), "%s", sys_id); |
| 435 | |
| 436 | acl = smpp_acl_by_system_id(esme->smsc, esme->system_id); |
| 437 | if (!esme->smsc->accept_all) { |
| 438 | if (!acl) { |
| 439 | /* This system is unknown */ |
| 440 | return ESME_RINVSYSID; |
| 441 | } else { |
| 442 | if (strlen(acl->passwd) && |
| 443 | strcmp(acl->passwd, passwd)) { |
| 444 | return ESME_RINVPASWD; |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | if (acl) { |
| 449 | esme->acl = acl; |
| 450 | acl->esme = esme; |
| 451 | } |
| 452 | |
| 453 | esme->bind_flags = bind_flags; |
| 454 | |
| 455 | return ESME_ROK; |
| 456 | } |
| 457 | |
| 458 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 459 | /*! \brief handle an incoming SMPP BIND RECEIVER */ |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 460 | static int smpp_handle_bind_rx(struct osmo_esme *esme, struct msgb *msg) |
| 461 | { |
| 462 | struct bind_receiver_t bind; |
| 463 | struct bind_receiver_resp_t bind_r; |
| 464 | int rc; |
| 465 | |
Harald Welte | 4dbcdad | 2012-11-08 22:12:45 +0100 | [diff] [blame] | 466 | SMPP34_UNPACK(rc, BIND_RECEIVER, &bind, msgb_data(msg), |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 467 | msgb_length(msg)); |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 468 | if (rc < 0) { |
| 469 | LOGP(DSMPP, LOGL_ERROR, "[%s] Error in smpp34_unpack():%s\n", |
| 470 | esme->system_id, smpp34_strerror); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 471 | return rc; |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 472 | } |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 473 | |
| 474 | INIT_RESP(BIND_TRANSMITTER_RESP, &bind_r, &bind); |
| 475 | |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 476 | LOGP(DSMPP, LOGL_INFO, "[%s] Rx BIND Rx from (Version %02x)\n", |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 477 | bind.system_id, bind.interface_version); |
| 478 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 479 | rc = _process_bind(esme, bind.interface_version, ESME_BIND_RX, |
| 480 | (const char *)bind.system_id, (const char *)bind.password); |
| 481 | bind_r.command_status = rc; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 482 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 483 | return PACK_AND_SEND(esme, &bind_r); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 484 | } |
| 485 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 486 | /*! \brief handle an incoming SMPP BIND TRANSMITTER */ |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 487 | static int smpp_handle_bind_tx(struct osmo_esme *esme, struct msgb *msg) |
| 488 | { |
| 489 | struct bind_transmitter_t bind; |
| 490 | struct bind_transmitter_resp_t bind_r; |
| 491 | struct tlv_t tlv; |
| 492 | int rc; |
| 493 | |
Harald Welte | 4dbcdad | 2012-11-08 22:12:45 +0100 | [diff] [blame] | 494 | SMPP34_UNPACK(rc, BIND_TRANSMITTER, &bind, msgb_data(msg), |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 495 | msgb_length(msg)); |
| 496 | if (rc < 0) { |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 497 | LOGP(DSMPP, LOGL_ERROR, "[%s] Error in smpp34_unpack():%s\n", |
| 498 | esme->system_id, smpp34_strerror); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 499 | return rc; |
| 500 | } |
| 501 | |
| 502 | INIT_RESP(BIND_TRANSMITTER_RESP, &bind_r, &bind); |
| 503 | |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 504 | LOGP(DSMPP, LOGL_INFO, "[%s] Rx BIND Tx (Version %02x)\n", |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 505 | bind.system_id, bind.interface_version); |
| 506 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 507 | rc = _process_bind(esme, bind.interface_version, ESME_BIND_TX, |
| 508 | (const char *)bind.system_id, (const char *)bind.password); |
| 509 | bind_r.command_status = rc; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 510 | |
| 511 | /* build response */ |
| 512 | snprintf((char *)bind_r.system_id, sizeof(bind_r.system_id), "%s", |
| 513 | esme->smsc->system_id); |
| 514 | |
| 515 | /* add interface version TLV */ |
| 516 | tlv.tag = TLVID_sc_interface_version; |
| 517 | tlv.length = sizeof(uint8_t); |
| 518 | tlv.value.val16 = esme->smpp_version; |
| 519 | build_tlv(&bind_r.tlv, &tlv); |
| 520 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 521 | return PACK_AND_SEND(esme, &bind_r); |
| 522 | } |
| 523 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 524 | /*! \brief handle an incoming SMPP BIND TRANSCEIVER */ |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 525 | static int smpp_handle_bind_trx(struct osmo_esme *esme, struct msgb *msg) |
| 526 | { |
| 527 | struct bind_transceiver_t bind; |
| 528 | struct bind_transceiver_resp_t bind_r; |
| 529 | int rc; |
| 530 | |
Harald Welte | 4dbcdad | 2012-11-08 22:12:45 +0100 | [diff] [blame] | 531 | SMPP34_UNPACK(rc, BIND_TRANSCEIVER, &bind, msgb_data(msg), |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 532 | msgb_length(msg)); |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 533 | if (rc < 0) { |
| 534 | LOGP(DSMPP, LOGL_ERROR, "[%s] Error in smpp34_unpack():%s\n", |
| 535 | esme->system_id, smpp34_strerror); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 536 | return rc; |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 537 | } |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 538 | |
Harald Welte | 61e1935 | 2013-05-26 14:40:14 +0200 | [diff] [blame] | 539 | INIT_RESP(BIND_TRANSCEIVER_RESP, &bind_r, &bind); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 540 | |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 541 | LOGP(DSMPP, LOGL_INFO, "[%s] Rx BIND Trx (Version %02x)\n", |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 542 | bind.system_id, bind.interface_version); |
| 543 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 544 | rc = _process_bind(esme, bind.interface_version, ESME_BIND_RX|ESME_BIND_TX, |
| 545 | (const char *)bind.system_id, (const char *)bind.password); |
| 546 | bind_r.command_status = rc; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 547 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 548 | return PACK_AND_SEND(esme, &bind_r); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 549 | } |
| 550 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 551 | /*! \brief handle an incoming SMPP UNBIND */ |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 552 | static int smpp_handle_unbind(struct osmo_esme *esme, struct msgb *msg) |
| 553 | { |
| 554 | struct unbind_t unbind; |
| 555 | struct unbind_resp_t unbind_r; |
| 556 | int rc; |
| 557 | |
Harald Welte | 4dbcdad | 2012-11-08 22:12:45 +0100 | [diff] [blame] | 558 | SMPP34_UNPACK(rc, UNBIND, &unbind, msgb_data(msg), |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 559 | msgb_length(msg)); |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 560 | if (rc < 0) { |
| 561 | LOGP(DSMPP, LOGL_ERROR, "[%s] Error in smpp34_unpack():%s\n", |
| 562 | esme->system_id, smpp34_strerror); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 563 | return rc; |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 564 | } |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 565 | |
| 566 | INIT_RESP(UNBIND_RESP, &unbind_r, &unbind); |
| 567 | |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 568 | LOGP(DSMPP, LOGL_INFO, "[%s] Rx UNBIND\n", esme->system_id); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 569 | |
| 570 | if (esme->bind_flags == 0) { |
| 571 | unbind_r.command_status = ESME_RINVBNDSTS; |
| 572 | goto err; |
| 573 | } |
| 574 | |
| 575 | esme->bind_flags = 0; |
| 576 | err: |
| 577 | return PACK_AND_SEND(esme, &unbind_r); |
| 578 | } |
| 579 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 580 | /*! \brief handle an incoming SMPP ENQUIRE LINK */ |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 581 | static int smpp_handle_enq_link(struct osmo_esme *esme, struct msgb *msg) |
| 582 | { |
| 583 | struct enquire_link_t enq; |
| 584 | struct enquire_link_resp_t enq_r; |
| 585 | int rc; |
| 586 | |
Harald Welte | 4dbcdad | 2012-11-08 22:12:45 +0100 | [diff] [blame] | 587 | SMPP34_UNPACK(rc, ENQUIRE_LINK, &enq, msgb_data(msg), |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 588 | msgb_length(msg)); |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 589 | if (rc < 0) { |
| 590 | LOGP(DSMPP, LOGL_ERROR, "[%s] Error in smpp34_unpack():%s\n", |
| 591 | esme->system_id, smpp34_strerror); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 592 | return rc; |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 593 | } |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 594 | |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 595 | LOGP(DSMPP, LOGL_DEBUG, "[%s] Rx Enquire Link\n", esme->system_id); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 596 | |
| 597 | INIT_RESP(ENQUIRE_LINK_RESP, &enq_r, &enq); |
| 598 | |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 599 | LOGP(DSMPP, LOGL_DEBUG, "[%s] Tx Enquire Link Response\n", esme->system_id); |
| 600 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 601 | return PACK_AND_SEND(esme, &enq_r); |
| 602 | } |
| 603 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 604 | /*! \brief send a SUBMIT-SM RESPONSE to a remote ESME */ |
Harald Welte | d4bdee7 | 2012-11-08 19:44:08 +0100 | [diff] [blame] | 605 | int smpp_tx_submit_r(struct osmo_esme *esme, uint32_t sequence_nr, |
| 606 | uint32_t command_status, char *msg_id) |
| 607 | { |
| 608 | struct submit_sm_resp_t submit_r; |
| 609 | |
| 610 | memset(&submit_r, 0, sizeof(submit_r)); |
| 611 | submit_r.command_length = 0; |
| 612 | submit_r.command_id = SUBMIT_SM_RESP; |
| 613 | submit_r.command_status = command_status; |
| 614 | submit_r.sequence_number= sequence_nr; |
Harald Welte | 8a1b056 | 2012-11-09 12:51:44 +0100 | [diff] [blame] | 615 | snprintf((char *) submit_r.message_id, sizeof(submit_r.message_id), "%s", msg_id); |
Harald Welte | d4bdee7 | 2012-11-08 19:44:08 +0100 | [diff] [blame] | 616 | |
| 617 | return PACK_AND_SEND(esme, &submit_r); |
| 618 | } |
| 619 | |
Harald Welte | 8a1b056 | 2012-11-09 12:51:44 +0100 | [diff] [blame] | 620 | static const struct value_string smpp_avail_strs[] = { |
| 621 | { 0, "Available" }, |
| 622 | { 1, "Denied" }, |
| 623 | { 2, "Unavailable" }, |
| 624 | { 0, NULL } |
| 625 | }; |
| 626 | |
| 627 | /*! \brief send an ALERT_NOTIFICATION to a remote ESME */ |
| 628 | int smpp_tx_alert(struct osmo_esme *esme, uint8_t ton, uint8_t npi, |
| 629 | const char *addr, uint8_t avail_status) |
| 630 | { |
| 631 | struct alert_notification_t alert; |
| 632 | struct tlv_t tlv; |
| 633 | |
| 634 | memset(&alert, 0, sizeof(alert)); |
| 635 | alert.command_length = 0; |
| 636 | alert.command_id = ALERT_NOTIFICATION; |
| 637 | alert.command_status = ESME_ROK; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 638 | alert.sequence_number = esme_inc_seq_nr(esme); |
Harald Welte | 8a1b056 | 2012-11-09 12:51:44 +0100 | [diff] [blame] | 639 | alert.source_addr_ton = ton; |
| 640 | alert.source_addr_npi = npi; |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 641 | snprintf((char *)alert.source_addr, sizeof(alert.source_addr), "%s", addr); |
Harald Welte | 8a1b056 | 2012-11-09 12:51:44 +0100 | [diff] [blame] | 642 | |
| 643 | tlv.tag = TLVID_ms_availability_status; |
| 644 | tlv.length = sizeof(uint8_t); |
| 645 | tlv.value.val08 = avail_status; |
| 646 | build_tlv(&alert.tlv, &tlv); |
| 647 | |
| 648 | LOGP(DSMPP, LOGL_DEBUG, "[%s] Tx ALERT_NOTIFICATION (%s/%u/%u): %s\n", |
| 649 | esme->system_id, alert.source_addr, alert.source_addr_ton, |
| 650 | alert.source_addr_npi, |
| 651 | get_value_string(smpp_avail_strs, avail_status)); |
| 652 | |
| 653 | return PACK_AND_SEND(esme, &alert); |
| 654 | } |
| 655 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 656 | /* \brief send a DELIVER-SM message to given ESME */ |
| 657 | int smpp_tx_deliver(struct osmo_esme *esme, struct deliver_sm_t *deliver) |
| 658 | { |
| 659 | deliver->sequence_number = esme_inc_seq_nr(esme); |
| 660 | |
Pau Espin Pedrol | 2c1e2b7 | 2017-07-06 13:50:59 +0200 | [diff] [blame] | 661 | LOGP(DSMPP, LOGL_DEBUG, "[%s] Tx DELIVER-SM (from %s)\n", |
| 662 | esme->system_id, deliver->source_addr); |
| 663 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 664 | return PACK_AND_SEND(esme, deliver); |
| 665 | } |
| 666 | |
| 667 | /*! \brief handle an incoming SMPP DELIVER-SM RESPONSE */ |
| 668 | static int smpp_handle_deliver_resp(struct osmo_esme *esme, struct msgb *msg) |
| 669 | { |
| 670 | struct deliver_sm_resp_t deliver_r; |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 671 | struct osmo_smpp_cmd *cmd; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 672 | int rc; |
| 673 | |
| 674 | memset(&deliver_r, 0, sizeof(deliver_r)); |
| 675 | SMPP34_UNPACK(rc, DELIVER_SM_RESP, &deliver_r, msgb_data(msg), |
| 676 | msgb_length(msg)); |
| 677 | if (rc < 0) { |
| 678 | LOGP(DSMPP, LOGL_ERROR, "[%s] Error in smpp34_unpack():%s\n", |
| 679 | esme->system_id, smpp34_strerror); |
| 680 | return rc; |
| 681 | } |
| 682 | |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 683 | cmd = smpp_cmd_find_by_seqnum(esme, deliver_r.sequence_number); |
| 684 | if (!cmd) { |
| 685 | LOGP(DSMPP, LOGL_ERROR, "[%s] Rx DELIVER-SM RESP !? (%s)\n", |
| 686 | esme->system_id, get_value_string(smpp_status_strs, |
| 687 | deliver_r.command_status)); |
| 688 | return -1; |
| 689 | } |
| 690 | |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 691 | if (deliver_r.command_status == ESME_ROK) |
| 692 | smpp_cmd_ack(cmd); |
| 693 | else |
Keith | 320960c | 2017-05-13 23:38:52 +0200 | [diff] [blame] | 694 | smpp_cmd_err(cmd, deliver_r.command_status); |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 695 | |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 696 | LOGP(DSMPP, LOGL_INFO, "[%s] Rx DELIVER-SM RESP (%s)\n", |
| 697 | esme->system_id, get_value_string(smpp_status_strs, |
| 698 | deliver_r.command_status)); |
| 699 | |
| 700 | return 0; |
| 701 | } |
| 702 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 703 | /*! \brief handle an incoming SMPP SUBMIT-SM */ |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 704 | static int smpp_handle_submit(struct osmo_esme *esme, struct msgb *msg) |
| 705 | { |
| 706 | struct submit_sm_t submit; |
| 707 | struct submit_sm_resp_t submit_r; |
| 708 | int rc; |
| 709 | |
Harald Welte | 4dbcdad | 2012-11-08 22:12:45 +0100 | [diff] [blame] | 710 | memset(&submit, 0, sizeof(submit)); |
| 711 | SMPP34_UNPACK(rc, SUBMIT_SM, &submit, msgb_data(msg), |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 712 | msgb_length(msg)); |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 713 | if (rc < 0) { |
| 714 | LOGP(DSMPP, LOGL_ERROR, "[%s] Error in smpp34_unpack():%s\n", |
| 715 | esme->system_id, smpp34_strerror); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 716 | return rc; |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 717 | } |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 718 | |
| 719 | INIT_RESP(SUBMIT_SM_RESP, &submit_r, &submit); |
| 720 | |
| 721 | if (!(esme->bind_flags & ESME_BIND_TX)) { |
| 722 | submit_r.command_status = ESME_RINVBNDSTS; |
| 723 | return PACK_AND_SEND(esme, &submit_r); |
| 724 | } |
| 725 | |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 726 | LOGP(DSMPP, LOGL_INFO, "[%s] Rx SUBMIT-SM (%s/%u/%u)\n", |
| 727 | esme->system_id, submit.destination_addr, |
| 728 | submit.dest_addr_ton, submit.dest_addr_npi); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 729 | |
| 730 | INIT_RESP(SUBMIT_SM_RESP, &submit_r, &submit); |
| 731 | |
| 732 | rc = handle_smpp_submit(esme, &submit, &submit_r); |
| 733 | if (rc == 0) |
| 734 | return PACK_AND_SEND(esme, &submit_r); |
| 735 | |
| 736 | return rc; |
| 737 | } |
| 738 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 739 | /*! \brief one complete SMPP PDU from the ESME has been received */ |
Holger Hans Peter Freyther | d7b22c6 | 2013-04-29 09:11:02 +0200 | [diff] [blame] | 740 | static int smpp_pdu_rx(struct osmo_esme *esme, struct msgb *msg __uses) |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 741 | { |
| 742 | uint32_t cmd_id = smpp_msgb_cmdid(msg); |
| 743 | int rc = 0; |
| 744 | |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 745 | LOGP(DSMPP, LOGL_DEBUG, "[%s] smpp_pdu_rx(%s)\n", esme->system_id, |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 746 | osmo_hexdump(msgb_data(msg), msgb_length(msg))); |
| 747 | |
| 748 | switch (cmd_id) { |
| 749 | case GENERIC_NACK: |
| 750 | rc = smpp_handle_gen_nack(esme, msg); |
| 751 | break; |
| 752 | case BIND_RECEIVER: |
| 753 | rc = smpp_handle_bind_rx(esme, msg); |
| 754 | break; |
| 755 | case BIND_TRANSMITTER: |
| 756 | rc = smpp_handle_bind_tx(esme, msg); |
| 757 | break; |
| 758 | case BIND_TRANSCEIVER: |
| 759 | rc = smpp_handle_bind_trx(esme, msg); |
| 760 | break; |
| 761 | case UNBIND: |
| 762 | rc = smpp_handle_unbind(esme, msg); |
| 763 | break; |
| 764 | case ENQUIRE_LINK: |
| 765 | rc = smpp_handle_enq_link(esme, msg); |
| 766 | break; |
| 767 | case SUBMIT_SM: |
| 768 | rc = smpp_handle_submit(esme, msg); |
| 769 | break; |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 770 | case DELIVER_SM_RESP: |
| 771 | rc = smpp_handle_deliver_resp(esme, msg); |
| 772 | break; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 773 | case DELIVER_SM: |
| 774 | break; |
| 775 | case DATA_SM: |
| 776 | break; |
| 777 | case CANCEL_SM: |
| 778 | case QUERY_SM: |
| 779 | case REPLACE_SM: |
| 780 | case SUBMIT_MULTI: |
Ruben Undheim | 59d57da | 2016-12-20 17:38:31 +0100 | [diff] [blame] | 781 | LOGP(DSMPP, LOGL_NOTICE, "[%s] Unimplemented PDU Command " |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 782 | "0x%08x\n", esme->system_id, cmd_id); |
| 783 | break; |
| 784 | default: |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 785 | LOGP(DSMPP, LOGL_ERROR, "[%s] Unknown PDU Command 0x%08x\n", |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 786 | esme->system_id, cmd_id); |
| 787 | rc = smpp_tx_gen_nack(esme, smpp_msgb_seq(msg), ESME_RINVCMDID); |
| 788 | break; |
| 789 | } |
| 790 | |
| 791 | return rc; |
| 792 | } |
| 793 | |
Daniel Willmann | a4540b2 | 2014-01-17 15:17:36 +0100 | [diff] [blame] | 794 | /* This macro should be called after a call to read() in the read_cb of an |
| 795 | * osmo_fd to properly check for errors. |
| 796 | * rc is the return value of read, err_label is the label to jump to in case of |
| 797 | * an error. The code there should handle closing the connection. |
| 798 | * FIXME: This code should go in libosmocore utils.h so it can be used by other |
| 799 | * projects as well. |
| 800 | * */ |
| 801 | #define OSMO_FD_CHECK_READ(rc, err_label) \ |
| 802 | if (rc < 0) { \ |
| 803 | /* EINTR is a non-fatal error, just try again */ \ |
| 804 | if (errno == EINTR) \ |
| 805 | return 0; \ |
| 806 | goto err_label; \ |
| 807 | } else if (rc == 0) { \ |
| 808 | goto err_label; \ |
| 809 | } |
| 810 | |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 811 | /* !\brief call-back when per-ESME TCP socket has some data to be read */ |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 812 | static int esme_link_read_cb(struct osmo_fd *ofd) |
| 813 | { |
| 814 | struct osmo_esme *esme = ofd->data; |
| 815 | uint32_t len; |
| 816 | uint8_t *lenptr = (uint8_t *) &len; |
| 817 | uint8_t *cur; |
| 818 | struct msgb *msg; |
Daniel Willmann | 1fc8ec6 | 2014-01-17 15:17:36 +0100 | [diff] [blame] | 819 | ssize_t rdlen, rc; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 820 | |
| 821 | switch (esme->read_state) { |
| 822 | case READ_ST_IN_LEN: |
| 823 | rdlen = sizeof(uint32_t) - esme->read_idx; |
| 824 | rc = read(ofd->fd, lenptr + esme->read_idx, rdlen); |
Daniel Willmann | a4540b2 | 2014-01-17 15:17:36 +0100 | [diff] [blame] | 825 | if (rc < 0) |
Daniel Willmann | 1fc8ec6 | 2014-01-17 15:17:36 +0100 | [diff] [blame] | 826 | LOGP(DSMPP, LOGL_ERROR, "[%s] read returned %zd (%s)\n", |
Daniel Willmann | a4540b2 | 2014-01-17 15:17:36 +0100 | [diff] [blame] | 827 | esme->system_id, rc, strerror(errno)); |
| 828 | OSMO_FD_CHECK_READ(rc, dead_socket); |
| 829 | |
| 830 | esme->read_idx += rc; |
| 831 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 832 | if (esme->read_idx >= sizeof(uint32_t)) { |
| 833 | esme->read_len = ntohl(len); |
Daniel Willmann | 1fc8ec6 | 2014-01-17 15:17:36 +0100 | [diff] [blame] | 834 | if (esme->read_len < 8 || esme->read_len > UINT16_MAX) { |
| 835 | LOGP(DSMPP, LOGL_ERROR, "[%s] length invalid %u\n", |
Daniel Willmann | b6f01e7 | 2014-01-17 15:17:36 +0100 | [diff] [blame] | 836 | esme->system_id, esme->read_len); |
| 837 | goto dead_socket; |
| 838 | } |
| 839 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 840 | msg = msgb_alloc(esme->read_len, "SMPP Rx"); |
| 841 | if (!msg) |
| 842 | return -ENOMEM; |
| 843 | esme->read_msg = msg; |
| 844 | cur = msgb_put(msg, sizeof(uint32_t)); |
| 845 | memcpy(cur, lenptr, sizeof(uint32_t)); |
| 846 | esme->read_state = READ_ST_IN_MSG; |
| 847 | esme->read_idx = sizeof(uint32_t); |
| 848 | } |
| 849 | break; |
| 850 | case READ_ST_IN_MSG: |
| 851 | msg = esme->read_msg; |
| 852 | rdlen = esme->read_len - esme->read_idx; |
| 853 | rc = read(ofd->fd, msg->tail, OSMO_MIN(rdlen, msgb_tailroom(msg))); |
Daniel Willmann | a4540b2 | 2014-01-17 15:17:36 +0100 | [diff] [blame] | 854 | if (rc < 0) |
Daniel Willmann | 1fc8ec6 | 2014-01-17 15:17:36 +0100 | [diff] [blame] | 855 | LOGP(DSMPP, LOGL_ERROR, "[%s] read returned %zd (%s)\n", |
Daniel Willmann | a4540b2 | 2014-01-17 15:17:36 +0100 | [diff] [blame] | 856 | esme->system_id, rc, strerror(errno)); |
| 857 | OSMO_FD_CHECK_READ(rc, dead_socket); |
| 858 | |
| 859 | esme->read_idx += rc; |
| 860 | msgb_put(msg, rc); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 861 | |
| 862 | if (esme->read_idx >= esme->read_len) { |
| 863 | rc = smpp_pdu_rx(esme, esme->read_msg); |
Holger Hans Peter Freyther | d7b22c6 | 2013-04-29 09:11:02 +0200 | [diff] [blame] | 864 | msgb_free(esme->read_msg); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 865 | esme->read_msg = NULL; |
| 866 | esme->read_idx = 0; |
| 867 | esme->read_len = 0; |
| 868 | esme->read_state = READ_ST_IN_LEN; |
| 869 | } |
| 870 | break; |
| 871 | } |
| 872 | |
| 873 | return 0; |
| 874 | dead_socket: |
| 875 | msgb_free(esme->read_msg); |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 876 | osmo_fd_unregister(&esme->wqueue.bfd); |
| 877 | close(esme->wqueue.bfd.fd); |
| 878 | esme->wqueue.bfd.fd = -1; |
| 879 | smpp_esme_put(esme); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 880 | |
| 881 | return 0; |
| 882 | } |
| 883 | |
| 884 | /* call-back of write queue once it wishes to write a message to the socket */ |
Holger Hans Peter Freyther | 5ecbc93 | 2013-07-27 18:39:30 +0200 | [diff] [blame] | 885 | static int esme_link_write_cb(struct osmo_fd *ofd, struct msgb *msg) |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 886 | { |
| 887 | struct osmo_esme *esme = ofd->data; |
| 888 | int rc; |
| 889 | |
| 890 | rc = write(ofd->fd, msgb_data(msg), msgb_length(msg)); |
| 891 | if (rc == 0) { |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 892 | osmo_fd_unregister(&esme->wqueue.bfd); |
| 893 | close(esme->wqueue.bfd.fd); |
| 894 | esme->wqueue.bfd.fd = -1; |
| 895 | smpp_esme_put(esme); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 896 | } else if (rc < msgb_length(msg)) { |
Harald Welte | 874f9f1 | 2012-11-09 13:02:49 +0100 | [diff] [blame] | 897 | LOGP(DSMPP, LOGL_ERROR, "[%s] Short write\n", esme->system_id); |
Holger Hans Peter Freyther | 5ecbc93 | 2013-07-27 18:39:30 +0200 | [diff] [blame] | 898 | return -1; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 899 | } |
Holger Hans Peter Freyther | 5ecbc93 | 2013-07-27 18:39:30 +0200 | [diff] [blame] | 900 | |
| 901 | return 0; |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | /* callback for already-accepted new TCP socket */ |
| 905 | static int link_accept_cb(struct smsc *smsc, int fd, |
| 906 | struct sockaddr_storage *s, socklen_t s_len) |
| 907 | { |
| 908 | struct osmo_esme *esme = talloc_zero(smsc, struct osmo_esme); |
Holger Hans Peter Freyther | 1b624ba | 2013-07-14 08:59:32 +0200 | [diff] [blame] | 909 | if (!esme) { |
| 910 | close(fd); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 911 | return -ENOMEM; |
Holger Hans Peter Freyther | 1b624ba | 2013-07-14 08:59:32 +0200 | [diff] [blame] | 912 | } |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 913 | |
Pablo Neira Ayuso | 93ffbd0 | 2017-05-04 18:44:22 +0200 | [diff] [blame] | 914 | INIT_LLIST_HEAD(&esme->smpp_cmd_list); |
Harald Welte | e94db49 | 2012-11-08 20:11:05 +0100 | [diff] [blame] | 915 | smpp_esme_get(esme); |
Harald Welte | 8a1b056 | 2012-11-09 12:51:44 +0100 | [diff] [blame] | 916 | esme->own_seq_nr = rand(); |
Harald Welte | e07b6a7 | 2012-11-23 19:02:37 +0100 | [diff] [blame] | 917 | esme_inc_seq_nr(esme); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 918 | esme->smsc = smsc; |
| 919 | osmo_wqueue_init(&esme->wqueue, 10); |
| 920 | esme->wqueue.bfd.fd = fd; |
| 921 | esme->wqueue.bfd.data = esme; |
| 922 | esme->wqueue.bfd.when = BSC_FD_READ; |
Holger Hans Peter Freyther | c962d45 | 2013-07-14 08:58:15 +0200 | [diff] [blame] | 923 | |
| 924 | if (osmo_fd_register(&esme->wqueue.bfd) != 0) { |
Holger Hans Peter Freyther | 1b624ba | 2013-07-14 08:59:32 +0200 | [diff] [blame] | 925 | close(fd); |
Holger Hans Peter Freyther | c962d45 | 2013-07-14 08:58:15 +0200 | [diff] [blame] | 926 | talloc_free(esme); |
| 927 | return -EIO; |
| 928 | } |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 929 | |
| 930 | esme->wqueue.read_cb = esme_link_read_cb; |
| 931 | esme->wqueue.write_cb = esme_link_write_cb; |
| 932 | |
| 933 | esme->sa_len = OSMO_MIN(sizeof(esme->sa), s_len); |
| 934 | memcpy(&esme->sa, s, esme->sa_len); |
| 935 | |
| 936 | llist_add_tail(&esme->list, &smsc->esme_list); |
| 937 | |
| 938 | return 0; |
| 939 | } |
| 940 | |
| 941 | /* callback of listening TCP socket */ |
| 942 | static int smsc_fd_cb(struct osmo_fd *ofd, unsigned int what) |
| 943 | { |
| 944 | int rc; |
| 945 | struct sockaddr_storage sa; |
| 946 | socklen_t sa_len = sizeof(sa); |
| 947 | |
| 948 | rc = accept(ofd->fd, (struct sockaddr *)&sa, &sa_len); |
| 949 | if (rc < 0) { |
| 950 | LOGP(DSMPP, LOGL_ERROR, "Accept returns %d (%s)\n", |
| 951 | rc, strerror(errno)); |
| 952 | return rc; |
| 953 | } |
| 954 | return link_accept_cb(ofd->data, rc, &sa, sa_len); |
| 955 | } |
| 956 | |
Neels Hofmeyr | 1b0e554 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 957 | /*! \brief allocate and initialize an smsc struct from talloc context ctx. */ |
| 958 | struct smsc *smpp_smsc_alloc_init(void *ctx) |
| 959 | { |
| 960 | struct smsc *smsc = talloc_zero(ctx, struct smsc); |
| 961 | |
| 962 | INIT_LLIST_HEAD(&smsc->esme_list); |
| 963 | INIT_LLIST_HEAD(&smsc->acl_list); |
| 964 | INIT_LLIST_HEAD(&smsc->route_list); |
| 965 | |
| 966 | smsc->listen_ofd.data = smsc; |
| 967 | smsc->listen_ofd.cb = smsc_fd_cb; |
| 968 | |
| 969 | return smsc; |
| 970 | } |
| 971 | |
| 972 | /*! \brief Set the SMPP address and port without binding. */ |
| 973 | int smpp_smsc_conf(struct smsc *smsc, const char *bind_addr, uint16_t port) |
| 974 | { |
| 975 | talloc_free((void*)smsc->bind_addr); |
| 976 | smsc->bind_addr = NULL; |
| 977 | if (bind_addr) { |
| 978 | smsc->bind_addr = talloc_strdup(smsc, bind_addr); |
| 979 | if (!smsc->bind_addr) |
| 980 | return -ENOMEM; |
| 981 | } |
| 982 | smsc->listen_port = port; |
| 983 | return 0; |
| 984 | } |
| 985 | |
| 986 | /*! \brief Bind to given address and port and accept connections. |
| 987 | * \param[in] bind_addr Local IP address, may be NULL for any. |
| 988 | * \param[in] port TCP port number, may be 0 for default SMPP (2775). |
| 989 | */ |
| 990 | int smpp_smsc_start(struct smsc *smsc, const char *bind_addr, uint16_t port) |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 991 | { |
| 992 | int rc; |
| 993 | |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 994 | /* default port for SMPP */ |
Neels Hofmeyr | 1b0e554 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 995 | if (!port) |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 996 | port = 2775; |
| 997 | |
Neels Hofmeyr | 1b0e554 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 998 | smpp_smsc_stop(smsc); |
| 999 | |
| 1000 | LOGP(DSMPP, LOGL_NOTICE, "SMPP at %s %d\n", |
| 1001 | bind_addr? bind_addr : "0.0.0.0", port); |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 1002 | |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 1003 | rc = osmo_sock_init_ofd(&smsc->listen_ofd, AF_UNSPEC, SOCK_STREAM, |
Neels Hofmeyr | 1b0e554 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 1004 | IPPROTO_TCP, bind_addr, port, |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 1005 | OSMO_SOCK_F_BIND); |
Neels Hofmeyr | 1b0e554 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 1006 | if (rc < 0) |
| 1007 | return rc; |
Harald Welte | 338e3b3 | 2012-11-20 22:22:04 +0100 | [diff] [blame] | 1008 | |
Neels Hofmeyr | 1b0e554 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 1009 | /* store new address and port */ |
| 1010 | rc = smpp_smsc_conf(smsc, bind_addr, port); |
| 1011 | if (rc) |
| 1012 | smpp_smsc_stop(smsc); |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 1013 | return rc; |
| 1014 | } |
Neels Hofmeyr | 1b0e554 | 2016-02-24 19:15:39 +0100 | [diff] [blame] | 1015 | |
| 1016 | /*! \brief Change a running connection to a different address/port, and upon |
| 1017 | * error switch back to the running configuration. */ |
| 1018 | int smpp_smsc_restart(struct smsc *smsc, const char *bind_addr, uint16_t port) |
| 1019 | { |
| 1020 | int rc; |
| 1021 | |
| 1022 | rc = smpp_smsc_start(smsc, bind_addr, port); |
| 1023 | if (rc) |
| 1024 | /* if there is an error, try to re-bind to the old port */ |
| 1025 | return smpp_smsc_start(smsc, smsc->bind_addr, smsc->listen_port); |
| 1026 | return 0; |
| 1027 | } |
| 1028 | |
| 1029 | /*! /brief Close SMPP connection. */ |
| 1030 | void smpp_smsc_stop(struct smsc *smsc) |
| 1031 | { |
| 1032 | if (smsc->listen_ofd.fd > 0) { |
| 1033 | close(smsc->listen_ofd.fd); |
| 1034 | smsc->listen_ofd.fd = 0; |
| 1035 | osmo_fd_unregister(&smsc->listen_ofd); |
| 1036 | } |
| 1037 | } |