Skip to content

Conversation

@Devika-Raju-Z
Copy link

Updating the SiWx917 device's firmware including NWP, M4, and the combined M4 + TA images using an HTTP or HTTPS server. It supports both secure and non-secure firmware updates for all three types: NWP, M4, and the combined image.

@Devika-Raju-Z Devika-Raju-Z force-pushed the https_otaf branch 24 times, most recently from 569c7b4 to dd7f3de Compare September 25, 2025 17:03
@jhedberg jhedberg changed the title http/s otaf application samples: siwx917_ota: http/s OTAF application Sep 26, 2025
@jhedberg
Copy link
Contributor

Please rebase this on the latest main branch to see if the Compliance failure gets resolved

char *full_url = CONFIG_OTA_UPDATE_URL;
size_t data_len;

memset(&parser, 0, sizeof(parser));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant with http_parser_url_init().

int ret = http_parser_parse_url(full_url, strlen(full_url), 0, &parser);
if (ret) {
printf("Failed to parse URL: %s\n", full_url);
return -EINVAL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering:

  • this is a fatal error you can't recover
  • this is sample (pedagogic) code

You can use __ASSERT(). Same comment in case host, path or schema is not specified.

BTW, you need to retrieve the schema to know if TLS is enabled or not.
You also need to set a default value for the port if it is not specified.

return -errno;
}

if (IS_ENABLED(CONFIG_OTA_HTTPS_SUPPORT)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONFIG_OTA_HTTPS_SUPPORT is not required, you can look at the schema of the URL. You may __ASSERT(IS_ENABLED(CONFIG_NET_SOCKETS_SOCKOPT_TLS), "Application was built without support for TLS");.

addr_ptr = &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr;
}
zsock_inet_ntop(res->ai_family, addr_ptr, addr_str, sizeof(addr_str));
printf("Connected to %s:%s\n", addr_str, http_parse_data_st.port);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just print http_parse_data_st.host. So you won't have to do the conversion above.

void *addr_ptr;
struct zsock_addrinfo hints = {
.ai_family = (CONFIG_OTA_IP_PROTOCOL_SELECTION == 0) ? AF_INET : AF_INET6,
.ai_socktype = SOCK_STREAM};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hints is not really required. Zephyr will already automatically selects the right IP version.

Copy link
Author

@Devika-Raju-Z Devika-Raju-Z Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In one of your earlier comments, you mentioned that we can have dual stack configuration. I would like to clarify whether such an approach would be viable in this particular scenario.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A very relevant question. TL;DR: the selection IPv4/IPv6 is out of the scope of the sample.

Theoretically, Zephyr should choose IPv4/IPv6 depending of the IP addresses configured on the system [1]. In practice, Zephyr relies on compile time configuration and favorise IPv4. I don't think we should try to workaround this behavior.

In order to get a proper out of the box behavior, I suggest to also prioritize IPv4:

	// Prioritize IPv4
	if (IS_ENABLED(CONFIG_NET_IPV4)) {
		ret = k_event_wait_safe(&ctx->event, OTA_EVENT_GET_IPV4, false, K_SECONDS(60));
	} else {
		ret = k_event_wait_safe(&ctx->event, OTA_EVENT_GET_IPV6, false, K_SECONDS(60));
	}

If user configure IPV4 + IPV6 and try to connect to an IPv6 only network, the application won't work. I believe we can live with this limitation. The proper way to fix it would be to fix getaddrinfo().

[1]: See AI_ADDRCONFIG in https://man7.org/linux/man-pages/man3/getaddrinfo.3.html

printf("Failed to set TLS_HOSTNAME option (%d)\n", -errno);
zsock_close(*sock_ptr);
zsock_freeaddrinfo(res);
return -errno;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to manage the errors of this function using a label and goto.

BTW, "Connection failed is definitely something we want to report. But, the others (Failed to create TLS socket, Failed to set TLS secure option, etc...) should really not happen. Since it is a pedagogic code, I am not sure it make sense to clutter the code with such debug traces.

{
int ret = 0;
char range_header[64];
const char *headers[2] = {range_header, NULL};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add space after { and before }.

@Devika-Raju-Z Devika-Raju-Z force-pushed the https_otaf branch 8 times, most recently from 6025ad2 to 8cc35e9 Compare October 1, 2025 09:07
/* Message for HTTP data */
typedef struct {
uint32_t length;
uint8_t buffer[RECV_BUFFER_SIZE];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RECV_BUFFER_SIZE is an arbitrary value and used only once. Drop the symbols and replace it the value.

if (app_ctx_st->http_response_error) {
printf("Error occurred during HTTP download, skipping processing\n");
return -EPROTO;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably handled by the caller.

@Devika-Raju-Z Devika-Raju-Z requested a review from a team as a code owner October 8, 2025 04:59
@Devika-Raju-Z Devika-Raju-Z force-pushed the https_otaf branch 6 times, most recently from 9c620ad to 7fe97ff Compare October 14, 2025 09:48
@Devika-Raju-Z Devika-Raju-Z force-pushed the https_otaf branch 5 times, most recently from c3b2473 to 4bf41dc Compare October 21, 2025 09:50
Copy link
Contributor

@jerome-pouiller jerome-pouiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stop here for today.


config OTA_UPDATE_URL
string "OTA update URL"
default "http://example.com:8080/firmware.rps"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation talks about HTTPS, but the default value doesn't use it.


Application demonstrates how to perform HTTP/HTTPS OTA firmware updates on the
SiWx917 platform using Zephyr RTOS. It connects to a Wi-Fi network, establishes
a secure HTTPS connection using a CA certificate, and downloads firmware
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a secure HTTPS connection using a CA certificate

In simple words: an HTTPS connection.

This application demonstrates the support for OTA
firmware upgrade.

Signed-off-by: Devika Raju <Devika.Raju@silabs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants