From: Itzanh Date: Sun, 6 Apr 2025 12:13:21 +0000 (+0200) Subject: app_sms.c: Fix sending and receiving SMS messages in protocol 2 X-Git-Tag: 21.10.0-rc1~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d2e05da56c68c2906237c4f216a81446d5a97d0;p=thirdparty%2Fasterisk.git app_sms.c: Fix sending and receiving SMS messages in protocol 2 This fixes bugs in SMS messaging to SMS-capable analog phones that prevented app_sms.c from talking to phones using SMS protocol 2. - Fix MORX message reception (from phone to Asterisk) in SMS protocol 2 - Fix MTTX message transmission (from Asterisk to phone) in SMS protocol 2 One of the bugs caused messages to have random characters and junk appended at the end up to the character limit. Another bug prevented Asterisk from sending messages from Asterisk to the phone at all. A final bug caused the transmission from Asterisk to the phone to take a long time because app_sms.c did not hang up after correctly sending the message, causing the phone to have to time out and hang up in order to complete the message transmission. This was tested with a Linksys PAP2T and with a GrandStream HT814, sending and receiving messages with Telefónica DOMO Mensajes phones from Telefónica Spain. I had to play with both the network jitter buffer and the dB gain to get it to work. One of my phones required the gain to be set to +3dB for it to work, while another required it to be set to +6dB. Only MORX and MTTX were tested, I did not test sending and receiving messages to a TelCo SMSC. (cherry picked from commit 30e72092495da30a9e4cdd1bddd9279a486287bb) --- diff --git a/apps/app_sms.c b/apps/app_sms.c index ed5406d0a5..94b94a53af 100644 --- a/apps/app_sms.c +++ b/apps/app_sms.c @@ -32,6 +32,7 @@ * \author Adrian Kennard (for the original protocol 1 code) * \author Filippo Grassilli (Hyppo) - protocol 2 support * Not fully tested, under development + * \author Itzan Huerta - Testing and debugging for Telefónica DOMO Mensajes (Spain) phones using protocol 2. */ /*** MODULEINFO @@ -100,13 +101,15 @@ SMS handles exchange of SMS data with a call to/from SMS capable phone or SMS PSTN service center. Can send and/or receive SMS messages. Works to ETSI ES 201 912; compatible with BT SMS PSTN service in - UK and Telecom Italia in Italy. + UK and Telecom Italia in Italy. It has also been tested to work with DOMO phones from Telefónica Spain. Typical usage is to use to handle calls from the SMS service centre CLI, or to set up a call using outgoing or manager interface to connect service centre to SMS(). "Messages are processed as per text file message queues. smsq (a separate software) is a command to generate message queues and send messages. The protocol has tight delay bounds. Please use short frames and disable/keep short the - jitter buffer on the ATA to make sure that responses (ACK etc.) are received in time. + jitter buffer on the ATA to make sure that responses (ACK etc.) are received in time. + It is also important to adjust the gain dB of the ATA. Some Telefónica DOMO Mensajes phones may require + the gain to be set to +3dB, and others even up to +6dB, in order to work. ***/ @@ -866,6 +869,7 @@ static void sms_readfile(sms_t * h, char *fn) memcpy(h->udtxt, p, SMSLEN); /* for protocol 2 */ while (*p && o < SMSLEN) { h->ud[o++] = utf8decode(pp); + p++; } h->udl = o; if (*p) { @@ -1474,6 +1478,7 @@ static void sms_nextoutgoing (sms_t * h) if (h->protocol == 2) { h->omsg[0] = 0x17; /* SMS_REL */ h->omsg[1] = 0; + h->sent_rel = 1; } else { h->omsg[0] = 0x94; /* SMS_REL */ h->omsg[1] = 0; @@ -1800,7 +1805,7 @@ static void sms_process(sms_t * h, int samples, signed short *data) } if (bit && h->ibitc == 200) { /* sync, restart message */ /* Protocol 2: empty connection ready (I am master) */ - if (h->framenumber < 0 && h->ibytec >= 160 && !memcmp(h->imsg, "UUUUUUUUUUUUUUUUUUUU", 20)) { + if (h->framenumber <= 0 && h->ibytec >= 160 && !memcmp(h->imsg, "UUUUUUUUUUUUUUUUUUUU", 20)) { h->framenumber = 1; ast_verb(3, "SMS protocol 2 detected\n"); h->protocol = 2;