net: wifi: Introduce Wi-Fi network managers

This introduces support for Wi-Fi network managers in Zephyr. The
motivation is for the Wi-Fi management layer to work with both
Network managers and offloaded Wi-Fi drivers. The device driver
decides which one to use.

network manager : Apps -> Wi-Fi Mgmt -> Network Manager -> Wi-Fi
interface

offloaded       : Apps -> Wi-Fi Mgmt -> Wi-Fi offloaded interface

Support for multiple network managers has been added, each device can
choose its own network manager and there can be mix and match:

  wlan0 - Offloaded
  wlan1 - Network manager 1
  wlan2 - Network manager 2

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
This commit is contained in:
Chaitanya Tata 2023-06-14 02:20:54 +05:30 committed by Carles Cufí
parent a132487fec
commit 38fc560f21
5 changed files with 211 additions and 0 deletions

View file

@ -0,0 +1,100 @@
/** @file
* @brief Wi-Fi Network manager API
*
* This file contains the Wi-Fi network manager API. These APIs are used by the
* any network management application to register as a Wi-Fi network manager.
*/
/*
* Copyright (c) 2023 Nordic Semiconductor ASA.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_ZEPHYR_NET_WIFI_NM_H_
#define ZEPHYR_INCLUDE_ZEPHYR_NET_WIFI_NM_H_
#include <zephyr/kernel.h>
#include <zephyr/types.h>
#include <zephyr/sys/iterable_sections.h>
#include <zephyr/net/net_if.h>
#include <zephyr/net/wifi_mgmt.h>
/**
* @brief Wi-Fi Network manager API
* @defgroup wifi_nm Wi-Fi Network Manager API
* @ingroup networking
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief WiFi Network manager instance
*/
struct wifi_nm_instance {
/** Name of the Network manager instance */
const char *name;
/** Wi-Fi Management operations */
const struct wifi_mgmt_ops *ops;
/** List of Managed interfaces */
struct net_if *mgd_ifaces[CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES];
};
#define WIFI_NM_NAME(name) wifi_nm_##name
#define DEFINE_WIFI_NM_INSTANCE(_name, _ops) \
static STRUCT_SECTION_ITERABLE(wifi_nm_instance, WIFI_NM_NAME(_name)) = { \
.name = STRINGIFY(_name), \
.ops = _ops, \
.mgd_ifaces = { NULL }, \
}
/**
* @brief Get a Network manager instance for a given name
*
* @param name Name of the Network manager instance
*
*/
struct wifi_nm_instance *wifi_nm_get_instance(const char *name);
/**
* @brief Get a Network manager instance for a given interface
*
* @param iface Interface
*
*/
struct wifi_nm_instance *wifi_nm_get_instance_iface(struct net_if *iface);
/**
* @brief Register a managed interface
*
* @param nm Pointer to Network manager instance
* @param iface Managed interface
*
* @retval 0 If successful.
* @retval -EINVAL If invalid parameters were passed.
* @retval -ENOTSUP If the interface is not a Wi-Fi interface.
* @retval -ENOMEM If the maximum number of managed interfaces has been reached.
*/
int wifi_nm_register_mgd_iface(struct wifi_nm_instance *nm, struct net_if *iface);
/**
* @brief Unregister managed interface
*
* @param nm Pointer to Network manager instance
* @param iface Interface
* @return int 0 for OK; -EINVAL for invalid parameters; -ENOENT if interface is not registered
* with the Network manager.
*/
int wifi_nm_unregister_mgd_iface(struct wifi_nm_instance *nm, struct net_if *iface);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_INCLUDE_ZEPHYR_NET_WIFI_NM_H_ */

View file

@ -8,3 +8,10 @@ zephyr_library_compile_definitions_ifdef(
zephyr_library_sources_ifdef(CONFIG_NET_L2_WIFI_MGMT wifi_mgmt.c)
zephyr_library_sources_ifdef(CONFIG_NET_L2_WIFI_SHELL wifi_shell.c)
zephyr_library_sources_ifdef(CONFIG_WIFI_NM wifi_nm.c)
# Linker section placement for wifi_nm_instance iterable structure
zephyr_linker_sources_ifdef(CONFIG_WIFI_NM DATA_SECTIONS wifi_nm.ld)
if (CONFIG_WIFI_NM)
zephyr_iterable_section(NAME wifi_nm_instance GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4)
endif()

View file

@ -46,3 +46,25 @@ config WIFI_MGMT_FORCED_PASSIVE_SCAN
the scan type is always sent as passive.
This doesn't guarantee that passive scan will be used, it depends
on the underlying chip implementation to support and honour scan type.
config WIFI_NM
bool "Wi-Fi Network manager support"
help
This option enables using the Wi-Fi Network managers (e.g. wpa_supplicant) to
manage the Wi-Fi network interfaces.
if WIFI_NM
config WIFI_NM_MAX_MANAGED_INTERFACES
int "Maximum number of managed interfaces per Wi-Fi network manager"
default 1
help
This option defines the maximum number of managed interfaces per Wi-Fi
network manager instance that can be used simultaneously.
module = WIFI_NM
module-dep = NET_LOG
module-str = Log level for Wi-Fi Network manager module
module-help = Enables using the Wi-Fi Network managers to manage the Wi-Fi network interfaces.
source "subsys/net/Kconfig.template.log_config.net"
endif # WIFI_NM

View file

@ -0,0 +1,75 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(wifi_nm, CONFIG_WIFI_NM_LOG_LEVEL);
#include <zephyr/kernel.h>
#include <zephyr/net/wifi_nm.h>
struct wifi_nm_instance *wifi_nm_get_instance(const char *name)
{
STRUCT_SECTION_FOREACH(wifi_nm_instance, nm) {
if (!strcmp(nm->name, name)) {
return nm;
}
}
return NULL;
}
struct wifi_nm_instance *wifi_nm_get_instance_iface(struct net_if *iface)
{
if (!iface || !net_if_is_wifi(iface)) {
return false;
}
STRUCT_SECTION_FOREACH(wifi_nm_instance, nm) {
for (int i = 0; i < CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES; i++) {
if (nm->mgd_ifaces[i] == iface) {
return nm;
}
}
}
return NULL;
}
int wifi_nm_register_mgd_iface(struct wifi_nm_instance *nm, struct net_if *iface)
{
if (!nm || !iface) {
return -EINVAL;
}
if (!net_if_is_wifi(iface)) {
return -ENOTSUP;
}
for (int i = 0; i < CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES; i++) {
if (!nm->mgd_ifaces[i]) {
nm->mgd_ifaces[i] = iface;
return 0;
}
}
return -ENOMEM;
}
int wifi_nm_unregister_mgd_iface(struct wifi_nm_instance *nm, struct net_if *iface)
{
if (!nm || !iface) {
return -EINVAL;
}
for (int i = 0; i < CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES; i++) {
if (nm->mgd_ifaces[i] == iface) {
nm->mgd_ifaces[i] = NULL;
return 0;
}
}
return -ENOENT;
}

View file

@ -0,0 +1,7 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
ITERABLE_SECTION_RAM(wifi_nm_instance, 4)