Skip to content

Commit 6401faf

Browse files
committed
net: config: Add set/get functions
Add set and get functions that return/set either the default settings or if user has changed them, the user adjusted value. Make these two functions to use settings API. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent a67cd3e commit 6401faf

File tree

4 files changed

+1133
-25
lines changed

4 files changed

+1133
-25
lines changed

include/zephyr/net/net_config.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
#include <zephyr/net/net_if.h>
1717
#include <zephyr/net/ieee802154_mgmt.h>
1818

19+
#if defined(CONFIG_NET_CONFIG_SETTINGS)
20+
#include <net_init_config.inc>
21+
#else
22+
struct net_init_config;
23+
#endif
24+
1925
#ifdef __cplusplus
2026
extern "C" {
2127
#endif
@@ -99,6 +105,37 @@ int net_config_init_by_iface(struct net_if *iface, const char *app_info,
99105
*/
100106
int net_config_init_app(const struct device *dev, const char *app_info);
101107

108+
/* @brief Get network initialization configuration.
109+
*
110+
* @details This network configuration consists of initial read-only
111+
* configuration and read-write configuration when the
112+
* configuration is changed at runtime.
113+
*
114+
* @param cfg Caller supplied pointer to struct net_init_config where
115+
* the configuration will be stored.
116+
*/
117+
int net_config_get(struct net_init_config *cfg);
118+
119+
/* @brief Set network initialization configuration.
120+
*
121+
* @details The user supplied configuration is saved to permanent
122+
* storage. How this works:
123+
* - If the config option in struct net_init_config is different
124+
* than the default one, then change the option and enable the _changed flag.
125+
* - If the config option in struct net_init_config is the same
126+
* as the default one.
127+
*
128+
* @param cfg Caller supplied pointer to struct net_init_config where
129+
* the configuration will be read.
130+
*/
131+
int net_config_set(const struct net_init_config *cfg);
132+
133+
/* @brief Clear all network configuration.
134+
*
135+
* @details This will reset all runtime configuration back to defaults.
136+
*/
137+
int net_config_clear(void);
138+
102139
/**
103140
* @}
104141
*/

subsys/net/lib/config/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ zephyr_library_compile_definitions_ifdef(
77

88
zephyr_library_sources_ifdef(CONFIG_NET_CONFIG_SETTINGS init.c)
99
zephyr_library_include_directories(${ZEPHYR_BASE}/subsys/net/ip)
10+
zephyr_library_include_directories_ifdef(CONFIG_FILE_SYSTEM_LITTLEFS
11+
${ZEPHYR_BASE}/../modules/fs/littlefs
12+
)
1013

1114
if(CONFIG_NET_CONFIG_SETTINGS)
1215
zephyr_library_sources_ifdef(

subsys/net/lib/config/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ menuconfig NET_CONFIG_SETTINGS
2222

2323
if NET_CONFIG_SETTINGS
2424

25+
config HEAP_MEM_POOL_ADD_SIZE_NET_CONFIG
26+
int "Amount of heap needed for storing user configuration data"
27+
default 1024
28+
depends on SETTINGS
29+
2530
config NET_CONFIG_AUTO_INIT
2631
bool "Init networking support automatically during device startup"
2732
default y if !(USB_DEVICE_NETWORK || USBD_CDC_ECM_CLASS || USBD_CDC_NCM_CLASS)

0 commit comments

Comments
 (0)