Skip to content

Commit ab80a43

Browse files
eivindj-nordicrlubos
authored andcommitted
net: lib: downloader: Leave room for header when using TLS with nRF91
Using range requests of 2048 bytes leaves no room for the header when using TLS with nRF91 devices. Reduce the range requests if recv return -EMSGSIZE. The range_override can be configured in the host configuration to improve performance. Signed-off-by: Eivind Jølsgard <[email protected]>
1 parent d41acf4 commit ab80a43

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

doc/nrf/libraries/networking/downloader.rst

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,32 @@ The following snippet shows how to download a file using HTTPS:
187187
Limitations
188188
***********
189189

190-
The library requires the host server to provide a Content-Range field in the HTTP GET response header when using HTTPS with the nRF91 Series devices.
191-
If this header field is missing, the library logs the following error::
190+
The following limitations apply to this library:
192191

193-
<err> downloader: Server did not send "Content-Range" in response
192+
nRF91 Series TLS limitation
193+
===========================
194194

195-
Due to internal limitations, maximum CoAP block size is 512 bytes.
195+
The nRF91 Series modem has a size limit for receiving TLS packages.
196+
The size limit depends on modem internals and is around 2 kB.
197+
See modem firmware release notes for details.
198+
The library asks the server for a content-range which must be supported by the host server when using HTTPS with the nRF91 Series devices.
199+
200+
The content range is set by the :c:member:`downloader_host_cfg.range_override` configuration in the download client configuration.
201+
If the configuration is not set, a default value will be used for the nRF91 Series devices when using HTTPS.
202+
203+
The fragment size must be set so that the TLS package does not exceed the modem limit.
204+
The TLS package size is dependent on the HTTP header and payload size.
205+
The HTTP header size is dependent on the server in use.
206+
When meeting this limitation, the downloader attempts to reduce the content-range in order to fill the TLS size requirements.
207+
If the requirements cannot be met, the downloader fails with error ``-EMSSIZE``.
208+
209+
.. note::
210+
If you are experiencing this issue on a deployed product, reducing the HTTP header size responded by the server can also resolve this issue.
211+
212+
CoaP block size
213+
===============
214+
215+
Due to internal limitations, the maximum CoAP block size is 512 bytes.
196216

197217
API documentation
198218
*****************

include/net/downloader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ enum downloader_evt_id {
5555
* - -EINVAL: Invalid configuration.
5656
* - -EAFNOSUPPORT: Unsupported address family (IPv4/IPv6).
5757
* - -EHOSTUNREACH: Failed to resolve the target address.
58+
* - -EMSGSIZE: TLS packet is larger than the nRF91 Modem can handle.
5859
*
5960
* In case of @c ECONNRESET errors, returning zero from the callback will let the
6061
* library attempt to reconnect to the server and download the last fragment again.

subsys/net/lib/downloader/src/transports/http.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919

2020
LOG_MODULE_DECLARE(downloader, CONFIG_DOWNLOADER_LOG_LEVEL);
2121

22-
/* nRF91 modem TLS secure socket buffer limited to 2kB including header */
22+
/* In the nRF91 Series modem, the TLS secure socket buffer is limited to around 2 kB.
23+
* If the header and data is too large, the downloader will reduce the range requests until
24+
* the requirements are satisfied. The application can also set the range_override in
25+
* struct downloader_host_cfg to utilize the size better.
26+
*/
2327
#define TLS_RANGE_MAX 2048
2428

2529
#define DEFAULT_PORT_TLS 443
@@ -431,9 +435,7 @@ static int http_parse(struct downloader *dl, size_t len)
431435
if (dl->progress + len != dl->file_size) {
432436
if (http->ranged) {
433437
http->ranged_progress += len;
434-
if (http->ranged_progress < (dl->host_cfg.range_override
435-
? dl->host_cfg.range_override
436-
: TLS_RANGE_MAX - 1)) {
438+
if (http->ranged_progress < dl->host_cfg.range_override) {
437439
/* Ranged query: read until a full fragment */
438440
return len;
439441
}
@@ -610,6 +612,19 @@ static int dl_http_download(struct downloader *dl)
610612
dl->cfg.buf_size - dl->buf_offset);
611613

612614
if (len < 0) {
615+
if (len == -EMSGSIZE && dl->host_cfg.range_override) {
616+
/* We do not have enough space for the http header and requested data,
617+
* reattempt with shorter range request.
618+
*/
619+
dl->host_cfg.range_override -=
620+
((dl->host_cfg.range_override > 256) ? 128 : 8);
621+
if (dl->host_cfg.range_override <= 8) {
622+
return -EMSGSIZE;
623+
}
624+
LOG_DBG("Message size too big, reattempting with range size %d",
625+
dl->host_cfg.range_override);
626+
return -ECONNRESET;
627+
}
613628
if (http->connection_close) {
614629
return -ECONNRESET;
615630
}

0 commit comments

Comments
 (0)