Skip to content

Commit 5722b2a

Browse files
committed
tom_modem: fix sms extraction for huawei modem
1 parent 6320016 commit 5722b2a

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

application/tom_modem/src/operations.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,20 @@ int sms_read(PROFILE_T *profile, void *transport_ptr)
100100
{
101101
char *line = strtok(response_text, "\n");
102102
int sms_count = 0;
103+
char *pdu;
103104

104-
while (line != NULL || line == "\n")
105+
while (line != NULL)
105106
{
106107
if (strncmp(line, "+CMGL:", 6) == 0)
107108
{
108109
sms = (SMS_T *)malloc(sizeof(SMS_T));
109110
memset(sms, 0, sizeof(SMS_T));
110-
char *pdu = strtok(NULL, "\n");
111+
112+
pdu = strtok(NULL, "\n");
113+
if (pdu == NULL || strlen(pdu) < 3) {
114+
dbg_msg("No PDU found for line: %s", line);
115+
pdu = strtok(NULL, "\n");
116+
}
111117
sms->sms_pdu = (char *)malloc(strlen(pdu));
112118
sms->sender = (char *)malloc(PHONE_NUMBER_SIZE);
113119
sms->sms_text = (char *)malloc(SMS_TEXT_SIZE);
@@ -126,6 +132,7 @@ int sms_read(PROFILE_T *profile, void *transport_ptr)
126132
}
127133
}
128134
line = strtok(NULL, "\n");
135+
129136
}
130137

131138
display_sms_in_json(sms_list, sms_count);
@@ -215,14 +222,18 @@ int sms_read_unread(PROFILE_T *profile, void *transport_ptr)
215222
{
216223
char *line = strtok(response_text, "\n");
217224
int sms_count = 0;
218-
219-
while (line != NULL || line == "\n")
225+
char *pdu;
226+
while (line != NULL)
220227
{
221228
if (strncmp(line, "+CMGL:", 6) == 0)
222229
{
223230
sms = (SMS_T *)malloc(sizeof(SMS_T));
224231
memset(sms, 0, sizeof(SMS_T));
225-
char *pdu = strtok(NULL, "\n");
232+
pdu = strtok(NULL, "\n");
233+
if (pdu == NULL || strlen(pdu) < 3) {
234+
dbg_msg("No PDU found for line: %s", line);
235+
pdu = strtok(NULL, "\n");
236+
}
226237
sms->sms_pdu = (char *)malloc(strlen(pdu));
227238
sms->sender = (char *)malloc(PHONE_NUMBER_SIZE);
228239
sms->sms_text = (char *)malloc(SMS_TEXT_SIZE);

0 commit comments

Comments
 (0)