Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 82 additions & 20 deletions app/src/sm_at_sms.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

LOG_MODULE_REGISTER(sm_sms, CONFIG_SM_LOG_LEVEL);

#define MAX_CONCATENATED_MESSAGE 3
#define MAX_CONCATENATED_MESSAGE 10
#define SM_SMS_AT_HEADER_INFO_MAX_LEN 64
#define MAX_CONCATENATED_MESSAGE_AGE 3000

/**@brief SMS operations. */
enum sm_sms_operation {
Expand All @@ -29,8 +31,10 @@
static uint16_t ref_number;
static uint8_t total_msgs;
static uint8_t count;
static char messages[MAX_CONCATENATED_MESSAGE - 1][SMS_MAX_PAYLOAD_LEN_CHARS + 1];
static char rsp_buf[MAX_CONCATENATED_MESSAGE * SMS_MAX_PAYLOAD_LEN_CHARS + 64] = {0};
static int64_t last_received_uptime;
static char rsp_buf[SMS_MAX_PAYLOAD_LEN_CHARS + SM_SMS_AT_HEADER_INFO_MAX_LEN] = {0};
static char *concat_rsp_buf = NULL;

Check failure on line 36 in app/src/sm_at_sms.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

INITIALISED_STATIC

app/src/sm_at_sms.c:36 do not initialise statics to NULL
int64_t uptime = k_uptime_get();

ARG_UNUSED(context);

Expand All @@ -54,14 +58,65 @@
strcat(rsp_buf, data->payload);
strcat(rsp_buf, "\"\r\n");
rsp_send("%s", rsp_buf);
if (concat_rsp_buf != NULL && uptime - last_received_uptime > MAX_CONCATENATED_MESSAGE_AGE) {

Check warning on line 61 in app/src/sm_at_sms.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

app/src/sm_at_sms.c:61 line length of 117 exceeds 100 columns
LOG_WRN("Cleaned SMS ref number %d, last_received_uptime=%lld, uptime=%lld",

Check warning on line 62 in app/src/sm_at_sms.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE_STRING

app/src/sm_at_sms.c:62 line length of 108 exceeds 100 columns
ref_number, last_received_uptime, uptime);
ref_number = 0;
total_msgs = 0;
count = 0;
if (concat_rsp_buf != NULL) {
free(concat_rsp_buf);
concat_rsp_buf = NULL;
}
last_received_uptime = 0;
}
} else {
LOG_DBG("concatenated message %d, %d, %d",
header->concatenated.ref_number,
total_msgs = header->concatenated.total_msgs,
header->concatenated.total_msgs,
header->concatenated.seq_number);

if (last_received_uptime != 0 &&
ref_number != header->concatenated.ref_number &&
uptime - last_received_uptime > MAX_CONCATENATED_MESSAGE_AGE) {
LOG_WRN("Cleaned SMS ref number %d, last_received_uptime=%lld, uptime=%lld",

Check warning on line 82 in app/src/sm_at_sms.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE_STRING

app/src/sm_at_sms.c:82 line length of 108 exceeds 100 columns
ref_number, last_received_uptime, uptime);
ref_number = 0;
total_msgs = 0;
count = 0;
if (concat_rsp_buf != NULL) {
free(concat_rsp_buf);
concat_rsp_buf = NULL;
}
last_received_uptime = 0;
}

/* ref_number and total_msgs should remain unchanged */
if (ref_number == 0) {
ref_number = header->concatenated.ref_number;

Check failure on line 97 in app/src/sm_at_sms.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

app/src/sm_at_sms.c:97 trailing whitespace
if (header->concatenated.total_msgs > MAX_CONCATENATED_MESSAGE) {
LOG_ERR("SMS concatenated message limited to %d, received: %d",

Check warning on line 99 in app/src/sm_at_sms.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE_STRING

app/src/sm_at_sms.c:99 line length of 103 exceeds 100 columns
MAX_CONCATENATED_MESSAGE, header->concatenated.total_msgs);

Check warning on line 100 in app/src/sm_at_sms.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

app/src/sm_at_sms.c:100 line length of 107 exceeds 100 columns
goto done;
}

Check failure on line 103 in app/src/sm_at_sms.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

app/src/sm_at_sms.c:103 trailing whitespace
/* Allocate buffer for concatenated message. The allocation
* size is an upper boundary as headers and last message part
* are slightly less in practice.
*/
uint16_t concat_msg_len =
SM_SMS_AT_HEADER_INFO_MAX_LEN +
SMS_MAX_PAYLOAD_LEN_CHARS * header->concatenated.total_msgs;
concat_rsp_buf = malloc(concat_msg_len);
if (concat_rsp_buf == NULL) {
LOG_ERR("SMS concatenated message no memory for "
"%d bytes, %d messages",
concat_msg_len,
header->concatenated.total_msgs);
goto done;
}
memset(concat_rsp_buf, 0, concat_msg_len);
}
if (ref_number != header->concatenated.ref_number) {
LOG_ERR("SMS concatenated message ref_number error: %d, %d",
Expand All @@ -76,10 +131,7 @@
total_msgs, header->concatenated.total_msgs);
goto done;
}
if (total_msgs > MAX_CONCATENATED_MESSAGE) {
LOG_ERR("SMS concatenated message no memory: %d", total_msgs);
goto done;
}
last_received_uptime = uptime;
/* seq_number should start with 1 but could arrive in random order */
if (header->concatenated.seq_number == 0 ||
header->concatenated.seq_number > total_msgs) {
Expand All @@ -88,32 +140,42 @@
goto done;
}
if (header->concatenated.seq_number == 1) {
sprintf(rsp_buf, "\r\n#XSMS: \"%02d-%02d-%02d %02d:%02d:%02d\",\"",
sprintf(concat_rsp_buf,
"\r\n#XSMS: \"%02d-%02d-%02d %02d:%02d:%02d\",\"",
header->time.year, header->time.month, header->time.day,
header->time.hour, header->time.minute,
header->time.second);
strcat(rsp_buf, header->originating_address.address_str);
strcat(rsp_buf, "\",\"");
strcat(rsp_buf, data->payload);
count++;
strcat(concat_rsp_buf, header->originating_address.address_str);
strcat(concat_rsp_buf, "\",\"");
strcat(concat_rsp_buf, data->payload);
//LOG_WRN("concat_rsp_buf (seq_number=1): %s", concat_rsp_buf);

Check failure on line 151 in app/src/sm_at_sms.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

app/src/sm_at_sms.c:151 do not use C99 // comments
} else {
strcpy(messages[header->concatenated.seq_number - 2],
data->payload);
count++;
strcpy(concat_rsp_buf + SM_SMS_AT_HEADER_INFO_MAX_LEN + (header->concatenated.seq_number - 1) * SMS_MAX_PAYLOAD_LEN_CHARS,

Check warning on line 153 in app/src/sm_at_sms.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

app/src/sm_at_sms.c:153 line length of 154 exceeds 100 columns
data->payload);
//LOG_WRN("concat_rsp_buf (seq_number=%d): %s", header->concatenated.seq_number,

Check failure on line 155 in app/src/sm_at_sms.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

app/src/sm_at_sms.c:155 do not use C99 // comments

Check warning on line 155 in app/src/sm_at_sms.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE_COMMENT

app/src/sm_at_sms.c:155 line length of 112 exceeds 100 columns
// data->payload);

Check failure on line 156 in app/src/sm_at_sms.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

app/src/sm_at_sms.c:156 do not use C99 // comments
}
count++;
if (count == total_msgs) {
for (int i = 0; i < (total_msgs - 1); i++) {
strcat(rsp_buf, messages[i]);
for (int i = 1; i < (total_msgs); i++) {
//LOG_DBG("concat_rsp_buf (%d): %s", i, concat_rsp_buf + SM_SMS_AT_HEADER_INFO_MAX_LEN + i * SMS_MAX_PAYLOAD_LEN_CHARS);

Check failure on line 161 in app/src/sm_at_sms.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

app/src/sm_at_sms.c:161 do not use C99 // comments

Check warning on line 161 in app/src/sm_at_sms.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE_COMMENT

app/src/sm_at_sms.c:161 line length of 160 exceeds 100 columns
strncat(concat_rsp_buf, concat_rsp_buf + SM_SMS_AT_HEADER_INFO_MAX_LEN + i * SMS_MAX_PAYLOAD_LEN_CHARS, SMS_MAX_PAYLOAD_LEN_CHARS);

Check warning on line 162 in app/src/sm_at_sms.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

app/src/sm_at_sms.c:162 line length of 171 exceeds 100 columns
}
strcat(rsp_buf, "\"\r\n");
rsp_send("%s", rsp_buf);
strcat(concat_rsp_buf, "\"\r\n");
//LOG_WRN("concat_rsp_buf: %s", concat_rsp_buf);

Check failure on line 165 in app/src/sm_at_sms.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

app/src/sm_at_sms.c:165 do not use C99 // comments
rsp_send("%s", concat_rsp_buf);
} else {
return;
}
done:
ref_number = 0;
total_msgs = 0;
count = 0;
if (concat_rsp_buf != NULL) {
free(concat_rsp_buf);
concat_rsp_buf = NULL;
}
last_received_uptime = 0;
}
} else if (data->type == SMS_TYPE_STATUS_REPORT) {
LOG_INF("Status report received");
Expand Down
Loading