Skip to content

Commit

Permalink
net: Add Wi-Fi provision library and sample
Browse files Browse the repository at this point in the history
Add Wi-Fi provision library and sample

Signed-off-by: Simen S. Røstad <[email protected]>
  • Loading branch information
simensrostad committed Apr 10, 2024
1 parent f176353 commit 2fea720
Show file tree
Hide file tree
Showing 16 changed files with 1,714 additions and 0 deletions.
77 changes: 77 additions & 0 deletions include/net/wifi_provision.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/**
* @file
* @brief
*/

#ifndef WIFI_PROVISION_H__
#define WIFI_PROVISION_H__

/**
* @defgroup
* @{
* @brief
*/

#ifdef __cplusplus
extern "C" {
#endif

enum wifi_provision_evt_type {
/** The provisioning process has started. */
WIFI_PROVISION_EVT_STARTED,
/** A client has connected to the provisioning network. */
WIFI_PROVISION_EVT_CLIENT_CONNECTED,
/** A client has disconnected from the provisioning network. */
WIFI_PROVISION_EVT_CLIENT_DISCONNECTED,
/** Wi-Fi credentials received. */
WIFI_PROVISION_EVT_CREDENTIALS_RECEIVED,
/** The provisioning process has completed. */
WIFI_PROVISION_EVT_COMPLETED,
/** Wi-Fi credentials deleted, reboot required to enter a known unprovisioned state. */
WIFI_PROVISION_EVT_RESET_REBOOT_REQUEST,
/** The provisioning process has failed, irrecoverable error. */
WIFI_PROVISION_EVT_FATAL_ERROR,
};

/** @brief Struct with data received from the library. */
struct wifi_provision_evt {
/** Type of event. */
enum wifi_provision_evt_type type;
};

/** @brief Asynchronous event handler.
*
* @param[in] evt The event and any associated parameters.
*/
typedef void (*wifi_provision_evt_handler_t)(const struct wifi_provision_evt *evt);

/** @brief Initialize and start the Wi-Fi provisioning library.
* This function blocks until provisioning has completed.
*
* @param[in] handler Event handler to be called for asynchronous notifications from the library.
*
* @retval 0 If the operation was successful.
* Otherwise, a (negative) error code is returned.
*/
int wifi_provision_start(const wifi_provision_evt_handler_t handler);

/** @brief Reset the library and restart the provisioning process.
*
* @retval 0 If the operation was successful.
* Otherwise, a (negative) error code is returned.
*/
int wifi_provision_reset(void);

#ifdef __cplusplus
}
#endif

/** @} */

#endif /* WIFI_PROVISION_H__ */
12 changes: 12 additions & 0 deletions samples/wifi/wifi_provision/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(wifi_provision)

target_sources(app PRIVATE src/main.c)
24 changes: 24 additions & 0 deletions samples/wifi/wifi_provision/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menu "Wi-Fi provision"

config WIFI_PROVISION_SAMPLE_POWER_SAVING_MODE
bool "Enable Wi-Fi power saving mode"
help
Power saving mode is default off.
Disabling Power Saving mode is needed to make the device discoverable reliably via
mDNS. Service Discovery has proven to be unstabile in power saving mode. (DTIM)

menu "Zephyr Kernel"
source "Kconfig.zephyr"
endmenu

module = WIFI_PROVISION_SAMPLE
module-str = Wi-Fi provision sample
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"

endmenu
68 changes: 68 additions & 0 deletions samples/wifi/wifi_provision/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
.. _wifi_provision:

Wi-Fi Provision
###############

.. contents::
:local:
:depth: 2

.. |wifi| replace:: Wi-Fi

.. include:: /includes/net_connection_manager.txt

Requirements
************

The sample supports the following development kits:

.. table-from-sample-yaml::

.. include:: /includes/tfm.txt

Overview
********

Configuration
*************

|config|

Configuration options
=====================

.. include:: /includes/wifi_credentials_shell.txt

.. include:: /includes/wifi_credentials_static.txt

Configuration files
===================

The sample includes pre-configured configuration files for the development kits that are supported:

* :file:`prj.conf` - For all devices.

Building and running
********************

.. include:: /includes/build_and_run_ns.txt

Testing
=======

|test_sample|

Sample output
=============

Troubleshooting
***************

Dependencies
************

This sample uses the following Zephyr libraries:

* :ref:`net_if_interface`
* :ref:`net_mgmt_interface`
* :ref:`Connection Manager <zephyr:conn_mgr_overview>`
95 changes: 95 additions & 0 deletions samples/wifi/wifi_provision/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# Optimize TF-M
CONFIG_TFM_PROFILE_TYPE_SMALL=y
CONFIG_PM_PARTITION_SIZE_TFM_SRAM=0xc000
CONFIG_PM_PARTITION_SIZE_TFM=0x20000

# Optimize Wi-Fi stack to save some memory
CONFIG_HEAP_MEM_POOL_SIZE=81920
CONFIG_NRF700X_RX_NUM_BUFS=16
CONFIG_NRF700X_MAX_TX_AGGREGATION=4

# Wi-Fi
CONFIG_WIFI=y
CONFIG_WIFI_NRF700X=y
CONFIG_NRF700X_AP_MODE=y
CONFIG_WPA_SUPP=y
CONFIG_WPA_SUPP_AP=y
CONFIG_NET_L2_ETHERNET=y
CONFIG_WIFI_CREDENTIALS=y

# General
CONFIG_LOG=y
CONFIG_LOG_BUFFER_SIZE=4096
CONFIG_ASSERT=y
CONFIG_ASSERT_VERBOSE=n

## Temporarily enable FS support so that linking succeeds
CONFIG_FILE_SYSTEM=y
CONFIG_MAIN_STACK_SIZE=16384
CONFIG_NANOPB=y
CONFIG_SMF=y

# HTTP parser
CONFIG_HTTP_PARSER=y
CONFIG_HTTP_PARSER_URL=y

# DK Butons and LEDs
CONFIG_DK_LIBRARY=y

# Link time optimization
CONFIG_LTO=y
CONFIG_ISR_TABLES_LOCAL_DECLARATION=y

# Networking config
CONFIG_NETWORKING=y
CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_NET_IPV4=y
# Disable IPv6 to save memory
CONFIG_NET_IPV6=n
CONFIG_NET_TCP=y
CONFIG_NET_UDP=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_MAX_CONN=6
CONFIG_POSIX_MAX_FDS=20
CONFIG_NET_SOCKETS_TLS_MAX_CONTEXTS=2
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y

# Zephyr NET Connection Manager connectivity layer
CONFIG_L2_WIFI_CONNECTIVITY=y
CONFIG_L2_WIFI_CONNECTIVITY_AUTO_CONNECT=n
CONFIG_L2_WIFI_CONNECTIVITY_AUTO_DOWN=n

# Wi-Fi Provisioning
CONFIG_WIFI_PROVISION=y
CONFIG_WIFI_PROVISION_LOG_LEVEL_DBG=y

# (M)DNS
CONFIG_MDNS_RESPONDER=y
CONFIG_DNS_SD=y
CONFIG_MDNS_RESPONDER_DNS_SD=y
CONFIG_NET_HOSTNAME_ENABLE=y
CONFIG_NET_HOSTNAME="wifiprov"
## Disable POSIX uname support to suppress build warning that hostname is too long
CONFIG_POSIX_UNAME=n

# DHCPv4 client and server
CONFIG_NET_DHCPV4=y
CONFIG_NET_DHCPV4_SERVER=y

# MBed TLS heap size, required by WPA supplicant and MBed TLS
CONFIG_MBEDTLS_HEAP_SIZE=81920
CONFIG_MBEDTLS_RSA_C=y

# Store TLS credentials to protected storage
CONFIG_TLS_CREDENTIALS=y
CONFIG_TLS_CREDENTIALS_BACKEND_PROTECTED_STORAGE=y

# Disable auto init of NET config as the Wi-Fi provisioning library will manually set its
# own IP configuration.
CONFIG_NET_CONFIG_AUTO_INIT=n
9 changes: 9 additions & 0 deletions samples/wifi/wifi_provision/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sample:
name: Wi-Fi Provision
tests:
sample.wifi.wifi_provision:
build_only: true
integration_platforms:
- nrf7002dk_nrf5340_cpuapp_ns
platform_allow: nrf7002dk_nrf5340_cpuapp_ns
tags: ci_build
Loading

0 comments on commit 2fea720

Please sign in to comment.