Skip to content

Commit ff98db7

Browse files
committed
app: coap, http: Prevent URC interleaving in multi-part responses
Wrap the entire send sequence in sm_at_host_lock()/sm_at_host_unlock() to prevent URCs from being injected between parts. Use rsp_send_to() for the response header. Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
1 parent cad23be commit ff98db7

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

app/src/sm_at_coap.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ static void coap_send_data(struct coap_request *req, const uint8_t *payload, siz
168168
return;
169169
}
170170

171-
urc_send_to(req->pipe, "\r\n#XCOAPCDATA: %d,%d,%d\r\n", req->fd,
171+
/* Lock the AT host to prevent URCs from being injected between the notification
172+
* header, the data bytes, and the trailing CRLF.
173+
*/
174+
sm_at_host_lock(req->pipe);
175+
rsp_send_to(req->pipe, "\r\n#XCOAPCDATA: %d,%d,%d\r\n", req->fd,
172176
(int)req->bytes_sent, (int)payload_len);
173177
req->bytes_sent += payload_len;
174178
if (req->hex_rx) {
@@ -178,6 +182,7 @@ static void coap_send_data(struct coap_request *req, const uint8_t *payload, siz
178182
}
179183
/* CRLF after the data chunk, consistent with socket auto-receive behaviour. */
180184
rsp_send_to(req->pipe, "\r\n");
185+
sm_at_host_unlock(req->pipe);
181186
}
182187

183188
/* Notify host that a response block is ready to pull in manual receive mode. */

app/src/sm_at_httpc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,11 @@ static void http_send_data(struct http_request *req, const uint8_t *data, int le
504504
return;
505505
}
506506

507-
urc_send_to(req->pipe, "\r\n#XHTTPCDATA: %d,%d,%d\r\n", req->fd, req->bytes_sent, len);
507+
/* Lock the AT host to prevent URCs from being injected between the notification
508+
* header, the data bytes, and the trailing CRLF.
509+
*/
510+
sm_at_host_lock(req->pipe);
511+
rsp_send_to(req->pipe, "\r\n#XHTTPCDATA: %d,%d,%d\r\n", req->fd, req->bytes_sent, len);
508512
req->bytes_sent += len;
509513
if (req->hex_rx) {
510514
http_data_send_hex(req->pipe, data, (size_t)len);
@@ -513,6 +517,7 @@ static void http_send_data(struct http_request *req, const uint8_t *data, int le
513517
}
514518
/* CRLF after the data chunk, consistent with socket auto-receive behaviour. */
515519
rsp_send_to(req->pipe, "\r\n");
520+
sm_at_host_unlock(req->pipe);
516521
}
517522

518523
/*

0 commit comments

Comments
 (0)