Skip to content

Commit 2bfa4e9

Browse files
author
Marcin Radomski
committed
AT_CellularSMS: set "international" flag in PDU when applicable
Currently, create_pdu receives a destination address without '+' prefix, and always sets the "type of address" to "unknown". That means, the number needs to contain appropriate international number prefix (00/011) if necessary - which is not the case if the leading + is simply stripped. This changes send_sms behavior so that when a SMS is sent to an international number (indicated by leading +): - AT+CMGS command receives the number with + prefix, - created PDU has the "international" flag set.
1 parent 033fffe commit 2bfa4e9

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

features/cellular/framework/AT/AT_CellularSMS.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ char *AT_CellularSMS::create_pdu(const char *phone_number, const char *message,
274274
uint8_t msg_part_number, uint8_t &header_size)
275275
{
276276
int totalPDULength = 0;
277+
const bool is_number_international = (phone_number[0] == '+');
278+
if (is_number_international) {
279+
++phone_number;
280+
}
277281
int number_len = strlen(phone_number);
278282

279283
totalPDULength += number_len;
@@ -313,7 +317,11 @@ char *AT_CellularSMS::create_pdu(const char *phone_number, const char *message,
313317
int_to_hex_str(number_len, pdu + x);
314318
x += 2;
315319
// Type of the Destination Phone Number
316-
pdu[x++] = '8';
320+
if (is_number_international) {
321+
pdu[x++] = '9'; // international
322+
} else {
323+
pdu[x++] = '8'; // unknown
324+
}
317325
pdu[x++] = '1';
318326

319327
// phone number as reverse nibble encoded
@@ -405,12 +413,11 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
405413
_at.lock();
406414

407415
int write_size = 0;
408-
int remove_plus_sign = (phone_number[0] == '+') ? 1 : 0;
409416

410417
ThisThread::sleep_for(_sim_wait_time);
411418

412419
if (_mode == CellularSMSMmodeText) {
413-
_at.cmd_start_stop("+CMGS", "=", "%s", phone_number + remove_plus_sign);
420+
_at.cmd_start_stop("+CMGS", "=", "%s", phone_number);
414421

415422
ThisThread::sleep_for(_sim_wait_time);
416423
_at.resp_start("> ", true);
@@ -463,7 +470,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
463470
pdu_len = remaining_len > concatenated_sms_length ? concatenated_sms_length : remaining_len;
464471
}
465472

466-
pdu_str = create_pdu(phone_number + remove_plus_sign, message + i * concatenated_sms_length, pdu_len,
473+
pdu_str = create_pdu(phone_number, message + i * concatenated_sms_length, pdu_len,
467474
sms_count, i + 1, header_len);
468475
if (!pdu_str) {
469476
_at.unlock();

0 commit comments

Comments
 (0)