Skip to content

Commit 9cb1058

Browse files
maxd-nordicrlubos
authored andcommitted
net: downloader: add coap proxy-uri support
Add support for Proxy-URI options to downloader. This is defined in RFC7252 and we need it for nRF Cloud. Signed-off-by: Maximilian Deubel <[email protected]>
1 parent c4258e2 commit 9cb1058

File tree

8 files changed

+25
-6
lines changed

8 files changed

+25
-6
lines changed

include/net/downloader.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ struct downloader_host_cfg {
185185
* Set to @c AF_UNSPEC (0) to fallback to @c AF_INET if @c AF_INET6 does not work.
186186
*/
187187
int family;
188+
/**
189+
* CoAP Proxy-URI option.
190+
* This string is used in case you are requesting a proxied file from a CoAP server.
191+
*/
192+
const char *proxy_uri;
188193
};
189194

190195
/**

subsys/net/lib/downloader/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ config DOWNLOADER_SHELL
3232

3333
config DOWNLOADER_TRANSPORT_PARAMS_SIZE
3434
int "Maximum transport parameter size"
35-
default 128
35+
default 256
3636

3737
config DOWNLOADER_TRANSPORT_HTTP
3838
bool "HTTP transport"

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ struct transport_params_coap {
5757
bool new_data_req;
5858
/** Request retransmission */
5959
bool retransmission_req;
60+
/* Proxy-URI option value */
61+
const char *proxy_uri;
6062
};
6163

6264
BUILD_ASSERT(CONFIG_DOWNLOADER_TRANSPORT_PARAMS_SIZE >= sizeof(struct transport_params_coap));
@@ -311,6 +313,15 @@ static int coap_request_send(struct downloader *dl)
311313
return err;
312314
}
313315

316+
if (coap->proxy_uri != NULL) {
317+
err = coap_packet_append_option(&request, COAP_OPTION_PROXY_URI,
318+
coap->proxy_uri, strlen(coap->proxy_uri));
319+
if (err) {
320+
LOG_ERR("Unable to add Proxy-URI option");
321+
return err;
322+
}
323+
}
324+
314325
if (!has_pending(dl)) {
315326
struct coap_transmission_parameters params = coap_get_transmission_parameters();
316327

@@ -408,6 +419,9 @@ static int dl_coap_init(struct downloader *dl, struct downloader_host_cfg *dl_ho
408419
coap->sock.type |= SOCK_NATIVE_TLS;
409420
}
410421

422+
/* Copy proxy-uri to internal struct */
423+
coap->proxy_uri = dl_host_cfg->proxy_uri;
424+
411425
return 0;
412426
}
413427

tests/subsys/net/lib/downloader/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ target_compile_options(app
3636
PRIVATE
3737
-DCONFIG_DOWNLOADER_MAX_HOSTNAME_SIZE=256
3838
-DCONFIG_DOWNLOADER_MAX_FILENAME_SIZE=256
39-
-DCONFIG_DOWNLOADER_TRANSPORT_PARAMS_SIZE=128
39+
-DCONFIG_DOWNLOADER_TRANSPORT_PARAMS_SIZE=256
4040
-DCONFIG_DOWNLOADER_STACK_SIZE=2048
4141
-DCONFIG_NET_SOCKETS_POSIX_NAMES=y
4242
-DCONFIG_NET_IPV6=y

tests/subsys/net/lib/fota_download/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ target_compile_options(app
3434
-DCONFIG_DOWNLOADER_STACK_SIZE=500
3535
-DCONFIG_DOWNLOADER_MAX_FILENAME_SIZE=192
3636
-DCONFIG_DOWNLOADER_MAX_HOSTNAME_SIZE=128
37-
-DCONFIG_DOWNLOADER_TRANSPORT_PARAMS_SIZE=128
37+
-DCONFIG_DOWNLOADER_TRANSPORT_PARAMS_SIZE=256
3838
-DCONFIG_FW_MAGIC_LEN=32
3939
-DABI_INFO_MAGIC=0xdededede
4040
-DCONFIG_FW_FIRMWARE_INFO_OFFSET=0x200

tests/subsys/net/lib/lwm2m_client_utils/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ set(options
3636
-DCONFIG_DOWNLOADER_STACK_SIZE=4096
3737
-DCONFIG_DOWNLOADER_MAX_HOSTNAME_SIZE=128
3838
-DCONFIG_DOWNLOADER_MAX_FILENAME_SIZE=128
39-
-DCONFIG_DOWNLOADER_TRANSPORT_PARAMS_SIZE=128
39+
-DCONFIG_DOWNLOADER_TRANSPORT_PARAMS_SIZE=256
4040
-DCONFIG_LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT
4141
-DCONFIG_LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT
4242
-DCONFIG_DFU_TARGET_MCUBOOT

tests/subsys/net/lib/lwm2m_fota_utils/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ set(options
3535
-DCONFIG_DOWNLOADER_STACK_SIZE=4096
3636
-DCONFIG_DOWNLOADER_MAX_HOSTNAME_SIZE=128
3737
-DCONFIG_DOWNLOADER_MAX_FILENAME_SIZE=128
38-
-DCONFIG_DOWNLOADER_TRANSPORT_PARAMS_SIZE=128
38+
-DCONFIG_DOWNLOADER_TRANSPORT_PARAMS_SIZE=256
3939
-DCONFIG_LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT
4040
-DCONFIG_LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT
4141
-DCONFIG_DFU_TARGET_MCUBOOT=y

tests/subsys/net/lib/mcumgr_smp_client/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ target_compile_options(app
4444
-DCONFIG_FOTA_DOWNLOAD_RESOURCE_LOCATOR_LENGTH=512
4545
-DCONFIG_DOWNLOADER_MAX_HOSTNAME_SIZE=128
4646
-DCONFIG_DOWNLOADER_MAX_FILENAME_SIZE=128
47-
-DCONFIG_DOWNLOADER_TRANSPORT_PARAMS_SIZE=128
47+
-DCONFIG_DOWNLOADER_TRANSPORT_PARAMS_SIZE=256
4848
-DCONFIG_DOWNLOADER_STACK_SIZE=1024
4949
-DCONFIG_DFU_TARGET_SMP=1
5050
)

0 commit comments

Comments
 (0)