aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeith Whyte <keith@rhizomatica.org>2022-06-11 02:34:21 +0100
committerKeith Whyte <keith@rhizomatica.org>2022-06-11 02:34:25 +0100
commitf4bbd22912ca4cb8c5e9bc47189cf7508681964b (patch)
tree501e9ab6e6431e12e2172d217cd22a03a8c919ae
parent52d3935d460f432973bc387d1d6280ac3b4202d3 (diff)
Queue the specific SMS, Don't just run the queue on SMS_SUBMITED
Running the queue is not good enough, as only some few SMS for unattached subs will stop the db routine from reaching the new message.
-rw-r--r--include/osmocom/msc/signal.h2
-rw-r--r--src/libmsc/smpp_openbsc.c7
-rw-r--r--src/libmsc/sms_queue.c42
3 files changed, 48 insertions, 3 deletions
diff --git a/include/osmocom/msc/signal.h b/include/osmocom/msc/signal.h
index 915313131..77a9bcf34 100644
--- a/include/osmocom/msc/signal.h
+++ b/include/osmocom/msc/signal.h
@@ -86,4 +86,6 @@ struct sms_signal_data {
struct gsm_sms *sms;
/* true when paging was successful */
bool paging_result;
+ /* the id of the last inserted SMS */
+ unsigned long long id;
};
diff --git a/src/libmsc/smpp_openbsc.c b/src/libmsc/smpp_openbsc.c
index 91666a9ca..32b9b72b2 100644
--- a/src/libmsc/smpp_openbsc.c
+++ b/src/libmsc/smpp_openbsc.c
@@ -301,6 +301,8 @@ int handle_smpp_submit(struct osmo_esme *esme, struct submit_sm_t *submit,
case 1: /* datagram */
case 3: /* store-and-forward */
rc = db_sms_store(sms);
+ memset(&sig, 0, sizeof(sig));
+ sig.id = sms->id;
sms_free(sms);
sms = NULL;
if (rc < 0) {
@@ -312,7 +314,10 @@ int handle_smpp_submit(struct osmo_esme *esme, struct submit_sm_t *submit,
strcpy((char *)submit_r->message_id, "msg_id_not_implemented");
LOGP(DLSMS, LOGL_INFO, "SMPP SUBMIT-SM: Stored in DB\n");
- memset(&sig, 0, sizeof(sig));
+ /* We have stored the new SMS in the db, so now we signal the
+ * queue to run, but this is not good enough, as the queue may well
+ * not pick up this new SMS on the next run, if there are sufficient
+ * older messages in the queue. */
osmo_signal_dispatch(SS_SMS, S_SMS_SUBMITTED, &sig);
rc = 0;
break;
diff --git a/src/libmsc/sms_queue.c b/src/libmsc/sms_queue.c
index 08dffae31..4257837b8 100644
--- a/src/libmsc/sms_queue.c
+++ b/src/libmsc/sms_queue.c
@@ -585,10 +585,48 @@ static int sms_sms_cb(unsigned int subsys, unsigned int signal,
struct sms_signal_data *sig_sms = signal_data;
struct gsm_sms_pending *pending;
struct vlr_subscr *vsub;
+ struct gsm_sms *sms;
/* We got a new SMS and maybe should launch the queue again. */
- if (signal == S_SMS_SUBMITTED || signal == S_SMS_SMMA) {
- /* TODO: For SMMA we might want to re-use the radio connection. */
+ if (signal == S_SMS_SUBMITTED) {
+ if (sig_sms->id) {
+ LOGP(DLSMS, LOGL_INFO, "Got Signal for new Sms Submitted with id [%llu]\n",
+ sig_sms->id);
+ sms = db_sms_get(network, sig_sms->id);
+ if (!sms)
+ return -1;
+ if (!sms->receiver || !sms->receiver->lu_complete) {
+ LOGP(DLSMS, LOGL_DEBUG,
+ "Subscriber %s%s is not attached, skipping SMS.\n",
+ sms->receiver ? "" : "MSISDN-",
+ sms->receiver ? vlr_subscr_msisdn_or_name(sms->receiver) : sms->dst.addr);
+ return -1;
+ }
+
+ /* Check somehow it's not already in the pending list */
+ if (sms_queue_sms_is_pending(smq, sms->id)) {
+ sms_free(sms);
+ return 0;
+ }
+ /* Or that this sub is not already pending */
+ if (sms_subscriber_is_pending(smq, sms->receiver)) {
+ sms_free(sms);
+ return 0;
+ }
+
+ /* Now add this SMS to the Queue for immediate sending. */
+ pending = sms_pending_from(smq, sms);
+ sms_free(sms);
+ /* Schedule the timer to send this SMS */
+ sms_pending_resend(pending);
+ return 0;
+ }
+ }
+
+ if (signal == S_SMS_SMMA) {
+ /* TODO: For SMMA we might want to re-use the radio connection.
+ * Here, also, we really want to queue specifically for this MS, because
+ * just running the queue may not pick up its messages. */
sms_queue_trigger(smq);
return 0;
}