From c60df131101a4cd288a6b16e419f9d3abe4e3198 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 18 Jun 2018 20:57:23 +0300 Subject: [PATCH] net: app: Split code for configuring network to a separate lib, "config" net_app library consisted of 2 disjoint parts: a) library to setup/configure networking on the application startup; b) library to setup client and server connections. As the configuration library is universally useful and is a generic Zephyr networking component, split it out to a seperate top-level networking library under net/lib/config/. Fixes: #7658 Signed-off-by: Paul Sokolovsky --- subsys/net/lib/CMakeLists.txt | 3 +- subsys/net/lib/Kconfig | 4 +- subsys/net/lib/app/CMakeLists.txt | 10 - subsys/net/lib/app/Kconfig | 185 ---------------- subsys/net/lib/config/CMakeLists.txt | 18 ++ subsys/net/lib/config/Kconfig | 201 ++++++++++++++++++ subsys/net/lib/{app => config}/bt_settings.c | 0 subsys/net/lib/{app => config}/bt_settings.h | 0 .../lib/{app => config}/ieee802154_settings.c | 0 .../lib/{app => config}/ieee802154_settings.h | 0 subsys/net/lib/{app => config}/init.c | 0 11 files changed, 224 insertions(+), 197 deletions(-) create mode 100644 subsys/net/lib/config/CMakeLists.txt create mode 100644 subsys/net/lib/config/Kconfig rename subsys/net/lib/{app => config}/bt_settings.c (100%) rename subsys/net/lib/{app => config}/bt_settings.h (100%) rename subsys/net/lib/{app => config}/ieee802154_settings.c (100%) rename subsys/net/lib/{app => config}/ieee802154_settings.h (100%) rename subsys/net/lib/{app => config}/init.c (100%) diff --git a/subsys/net/lib/CMakeLists.txt b/subsys/net/lib/CMakeLists.txt index 5296b3aa08e..f201fb3ed72 100644 --- a/subsys/net/lib/CMakeLists.txt +++ b/subsys/net/lib/CMakeLists.txt @@ -3,7 +3,8 @@ add_subdirectory_if_kconfig(lwm2m) add_subdirectory_if_kconfig(sntp) add_subdirectory_ifdef(CONFIG_DNS_RESOLVER dns) add_subdirectory_ifdef(CONFIG_MQTT_LIB mqtt) -add_subdirectory_ifdef(CONFIG_NET_APP_SETTINGS app) +add_subdirectory_ifdef(CONFIG_NET_APP app) +add_subdirectory_ifdef(CONFIG_NET_APP_SETTINGS config) add_subdirectory_ifdef(CONFIG_NET_SOCKETS sockets) add_subdirectory_ifdef(CONFIG_WEBSOCKET websocket) diff --git a/subsys/net/lib/Kconfig b/subsys/net/lib/Kconfig index 8bd37062d9a..908959db471 100644 --- a/subsys/net/lib/Kconfig +++ b/subsys/net/lib/Kconfig @@ -22,7 +22,9 @@ source "subsys/net/lib/websocket/Kconfig" endmenu -menu "Network Application Support" +menu "Network Libraries" + +source "subsys/net/lib/config/Kconfig" source "subsys/net/lib/app/Kconfig" diff --git a/subsys/net/lib/app/CMakeLists.txt b/subsys/net/lib/app/CMakeLists.txt index 3286906341e..06635da4bb0 100644 --- a/subsys/net/lib/app/CMakeLists.txt +++ b/subsys/net/lib/app/CMakeLists.txt @@ -3,18 +3,8 @@ zephyr_library_compile_definitions_ifdef( CONFIG_NEWLIB_LIBC __LINUX_ERRNO_EXTENSIONS__ ) -zephyr_library_sources_ifdef(CONFIG_NET_APP init.c) zephyr_library_sources_ifdef(CONFIG_NET_APP_SERVER net_app.c server.c) zephyr_library_sources_ifdef(CONFIG_NET_APP_CLIENT net_app.c client.c) -if(CONFIG_NET_APP_SETTINGS) - zephyr_library_sources_ifdef( - CONFIG_NET_L2_IEEE802154 - ieee802154_settings.c - ) - - zephyr_library_sources_ifdef(CONFIG_NET_L2_BT bt_settings.c) -endif() - zephyr_link_interface_ifdef(CONFIG_MBEDTLS mbedTLS) zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS) diff --git a/subsys/net/lib/app/Kconfig b/subsys/net/lib/app/Kconfig index 57cb1e05d73..3e6a5871bf0 100644 --- a/subsys/net/lib/app/Kconfig +++ b/subsys/net/lib/app/Kconfig @@ -17,55 +17,6 @@ menuconfig NET_APP if NET_APP -config NET_APP_AUTO_INIT - bool "Init networking support automatically during device startup" - default y - help - If this option is set, then the net_app API is automatically - initialized when the device is started. If you do not wish to do - this, then disable this and call net_app_init() in your application. - -config NET_APP_INIT_PRIO - int "Startup priority for the network application init" - default 95 - depends on NET_APP_AUTO_INIT - -config NET_APP_INIT_TIMEOUT - int "How long to wait for networking to be ready and available" - default 30 - depends on NET_APP_AUTO_INIT - help - The value is in seconds. If for example IPv4 address from DHCPv4 is not - received within this limit, then the net_app_init() call will fail - during the device startup. - -config NET_APP_NEED_IPV6 - bool "This application wants IPv6 support" - depends on NET_APP_AUTO_INIT - select NET_IPV6 - help - The network application needs IPv6 support to function properly. - This option makes sure the network application is initialized properly - in order to use IPv6. - -config NET_APP_NEED_IPV6_ROUTER - bool "This application wants IPv6 router to exists" - depends on NET_APP_AUTO_INIT - depends on NET_IPV6 - help - The network application needs IPv6 router to exists before continuing. - What this means that the application wants to wait until it receives - IPv6 router advertisement message before continuing. - -config NET_APP_NEED_IPV4 - bool "This application wants IPv4 support" - depends on NET_APP_AUTO_INIT - select NET_IPV4 - help - The network application needs IPv4 support to function properly. - This option makes sure the network application is initialized properly - in order to use IPv4. - config NET_DEBUG_APP bool "Debug net app library" default n @@ -127,139 +78,3 @@ config NET_APP_TLS_STACK_SIZE thus it is by default very large. endif # NET_APP - -menuconfig NET_APP_SETTINGS - bool "Set network settings for applications" - default n - depends on NET_APP - help - Allow IP addresses to be set in config file for - networking client/server sample applications, or - some link-layer dedicated settings like the channel. - Beware this is not meant to be used for proper - provisioning but quick sampling/testing. - -if NET_APP_SETTINGS - -if NET_IPV6 - -config NET_APP_MY_IPV6_ADDR - string "My IPv6 address" - help - Use 2001:db8::1 here if uncertain. - -config NET_APP_PEER_IPV6_ADDR - string "Peer IPv6 address" - help - This is only applicable in client side applications that try - to establish a connection to peer host. - Use 2001:db8::2 here if uncertain. - -endif # NET_IPV6 - -if NET_IPV4 - -config NET_APP_MY_IPV4_ADDR - string "My IPv4 address" - help - Use 192.0.2.1 here if uncertain. - -config NET_APP_MY_IPV4_NETMASK - string "My IPv4 netmask" - default "255.255.255.0" - help - Static netmask to use if not overridden by DHCP. Use empty value to - skip setting static value. - -config NET_APP_MY_IPV4_GW - string "My IPv4 gateway" - help - Static gateway to use if not overridden by DHCP. Use empty value to - skip setting static value. - -config NET_APP_PEER_IPV4_ADDR - string "Peer IPv4 address" - help - This is only applicable in client side applications that try - to establish a connection to peer host. - Use 192.0.2.2 here if uncertain. - -endif # NET_IPV4 - -if NET_L2_IEEE802154 || IEEE802154_RAW_MODE || NET_L2_OPENTHREAD - -config NET_APP_IEEE802154_DEV_NAME - string "IEEE 802.15.4 device name" - help - The device name to get bindings from in the sample application. - -endif # NET_L2_IEEE802154 || IEEE802154_RAW_MODE || NET_L2_OPENTHREAD - -if NET_L2_IEEE802154 || IEEE802154_RAW_MODE - -config NET_APP_IEEE802154_PAN_ID - hex "IEEE 802.15.4 PAN ID" - default 0xabcd - help - The PAN ID to use by default in the sample. - -config NET_APP_IEEE802154_CHANNEL - int "IEEE 802.15.4 channel" - default 26 - help - The channel to use by default in the sample application. - -config NET_APP_IEEE802154_RADIO_TX_POWER - int "IEEE 802.15.4 TX power in dbm" - default 0 - help - The TX power to use by default in the sample application. - See NET_L2_IEEE802154_RADIO_DFLT_TX_POWER for more info. - -config NET_APP_IEEE802154_SECURITY_KEY - string "IEEE 802.15.4 security key" - default "moooh!" - depends on NET_L2_IEEE802154_SECURITY - help - The key string to use for the link-layer security part. - -config NET_APP_IEEE802154_SECURITY_KEY_MODE - int "IEEE 802.15.4 security key mode" - default 0 - range 0 0 - depends on NET_L2_IEEE802154_SECURITY - help - The key mode to use for the link-layer security part. - Only implicit mode is supported, thus 0. - -config NET_APP_IEEE802154_SECURITY_LEVEL - int "IEEE 802.15.4 security level (0-7)" - default 0 - range 0 7 - depends on NET_L2_IEEE802154_SECURITY - help - The security level to use for the link-layer security part. - 0 means no security - 1 authentication only with a 4 bytes length tag - 2 authentication only with a 8 bytes length tag - 3 authentication only with a 16 bytes length tag - 4 encryption only - 5 encryption/authentication with a 4 bytes length tag - 6 encryption/authentication with a 8 bytes length tag - 7 encryption/authentication with a 16 bytes length tag - -endif # NET_L2_IEEE802154 || IEEE802154_RAW_MODE - -if NET_L2_BT - -config NET_APP_BT_NODE - bool "Enable Bluetooth node support" - default n - select NET_L2_BT_MGMT - help - Enables application to operate in node mode which requires GATT - service to be registered and start advertising as peripheral. - -endif # NET_L2_BT - -endif # NET_APP_SETTINGS diff --git a/subsys/net/lib/config/CMakeLists.txt b/subsys/net/lib/config/CMakeLists.txt new file mode 100644 index 00000000000..778b5af644e --- /dev/null +++ b/subsys/net/lib/config/CMakeLists.txt @@ -0,0 +1,18 @@ +zephyr_library() +zephyr_library_compile_definitions_ifdef( + CONFIG_NEWLIB_LIBC __LINUX_ERRNO_EXTENSIONS__ + ) + +zephyr_library_sources_ifdef(CONFIG_NET_APP_SETTINGS init.c) + +if(CONFIG_NET_APP_SETTINGS) + zephyr_library_sources_ifdef( + CONFIG_NET_L2_IEEE802154 + ieee802154_settings.c + ) + + zephyr_library_sources_ifdef( + CONFIG_NET_L2_BT + bt_settings.c + ) +endif() diff --git a/subsys/net/lib/config/Kconfig b/subsys/net/lib/config/Kconfig new file mode 100644 index 00000000000..6e4cf3bf64d --- /dev/null +++ b/subsys/net/lib/config/Kconfig @@ -0,0 +1,201 @@ +# Kconfig - Options for networking configuration + +# +# Copyright (c) 2017 Intel Corporation. +# +# SPDX-License-Identifier: Apache-2.0 +# + +config NET_APP_AUTO_INIT + bool "Init networking support automatically during device startup" + default y + help + If this option is set, then the net_app API is automatically + initialized when the device is started. If you do not wish to do + this, then disable this and call net_app_init() in your application. + +config NET_APP_INIT_PRIO + int "Startup priority for the network application init" + default 95 + depends on NET_APP_AUTO_INIT + +config NET_APP_INIT_TIMEOUT + int "How long to wait for networking to be ready and available" + default 30 + depends on NET_APP_AUTO_INIT + help + The value is in seconds. If for example IPv4 address from DHCPv4 is not + received within this limit, then the net_app_init() call will fail + during the device startup. + +config NET_APP_NEED_IPV6 + bool "This application wants IPv6 support" + depends on NET_APP_AUTO_INIT + select NET_IPV6 + help + The network application needs IPv6 support to function properly. + This option makes sure the network application is initialized properly + in order to use IPv6. + +config NET_APP_NEED_IPV6_ROUTER + bool "This application wants IPv6 router to exists" + depends on NET_APP_AUTO_INIT + depends on NET_IPV6 + help + The network application needs IPv6 router to exists before continuing. + What this means that the application wants to wait until it receives + IPv6 router advertisement message before continuing. + +config NET_APP_NEED_IPV4 + bool "This application wants IPv4 support" + depends on NET_APP_AUTO_INIT + select NET_IPV4 + help + The network application needs IPv4 support to function properly. + This option makes sure the network application is initialized properly + in order to use IPv4. + +config NET_DEBUG_CONFIG + bool "Debug net config library" + default n + default y if NET_LOG_GLOBAL + help + Enables net config library to output debug messages + +menuconfig NET_APP_SETTINGS + bool "Set network settings for applications" + default n + depends on NET_APP + select NET_MGMT + select NET_MGMT_EVENT + help + Allow IP addresses to be set in config file for + networking client/server sample applications, or + some link-layer dedicated settings like the channel. + Beware this is not meant to be used for proper + provisioning but quick sampling/testing. + +if NET_APP_SETTINGS + +if NET_IPV6 + +config NET_APP_MY_IPV6_ADDR + string "My IPv6 address" + help + Use 2001:db8::1 here if uncertain. + +config NET_APP_PEER_IPV6_ADDR + string "Peer IPv6 address" + help + This is only applicable in client side applications that try + to establish a connection to peer host. + Use 2001:db8::2 here if uncertain. + +endif # NET_IPV6 + +if NET_IPV4 + +config NET_APP_MY_IPV4_ADDR + string "My IPv4 address" + help + Use 192.0.2.1 here if uncertain. + +config NET_APP_MY_IPV4_NETMASK + string "My IPv4 netmask" + default "255.255.255.0" + help + Static netmask to use if not overridden by DHCP. Use empty value to + skip setting static value. + +config NET_APP_MY_IPV4_GW + string "My IPv4 gateway" + help + Static gateway to use if not overridden by DHCP. Use empty value to + skip setting static value. + +config NET_APP_PEER_IPV4_ADDR + string "Peer IPv4 address" + help + This is only applicable in client side applications that try + to establish a connection to peer host. + Use 192.0.2.2 here if uncertain. + +endif # NET_IPV4 + +if NET_L2_IEEE802154 || IEEE802154_RAW_MODE || NET_L2_OPENTHREAD + +config NET_APP_IEEE802154_DEV_NAME + string "IEEE 802.15.4 device name" + help + The device name to get bindings from in the sample application. + +endif # NET_L2_IEEE802154 || IEEE802154_RAW_MODE || NET_L2_OPENTHREAD + +if NET_L2_IEEE802154 || IEEE802154_RAW_MODE + +config NET_APP_IEEE802154_PAN_ID + hex "IEEE 802.15.4 PAN ID" + default 0xabcd + help + The PAN ID to use by default in the sample. + +config NET_APP_IEEE802154_CHANNEL + int "IEEE 802.15.4 channel" + default 26 + help + The channel to use by default in the sample application. + +config NET_APP_IEEE802154_RADIO_TX_POWER + int "IEEE 802.15.4 TX power in dbm" + default 0 + help + The TX power to use by default in the sample application. + See NET_L2_IEEE802154_RADIO_DFLT_TX_POWER for more info. + +config NET_APP_IEEE802154_SECURITY_KEY + string "IEEE 802.15.4 security key" + default "moooh!" + depends on NET_L2_IEEE802154_SECURITY + help + The key string to use for the link-layer security part. + +config NET_APP_IEEE802154_SECURITY_KEY_MODE + int "IEEE 802.15.4 security key mode" + default 0 + range 0 0 + depends on NET_L2_IEEE802154_SECURITY + help + The key mode to use for the link-layer security part. + Only implicit mode is supported, thus 0. + +config NET_APP_IEEE802154_SECURITY_LEVEL + int "IEEE 802.15.4 security level (0-7)" + default 0 + range 0 7 + depends on NET_L2_IEEE802154_SECURITY + help + The security level to use for the link-layer security part. + 0 means no security + 1 authentication only with a 4 bytes length tag + 2 authentication only with a 8 bytes length tag + 3 authentication only with a 16 bytes length tag + 4 encryption only + 5 encryption/authentication with a 4 bytes length tag + 6 encryption/authentication with a 8 bytes length tag + 7 encryption/authentication with a 16 bytes length tag + +endif # NET_L2_IEEE802154 || IEEE802154_RAW_MODE + +if NET_L2_BT + +config NET_APP_BT_NODE + bool "Enable Bluetooth node support" + default n + select NET_L2_BT_MGMT + help + Enables application to operate in node mode which requires GATT + service to be registered and start advertising as peripheral. + +endif # NET_L2_BT + +endif # NET_APP_SETTINGS diff --git a/subsys/net/lib/app/bt_settings.c b/subsys/net/lib/config/bt_settings.c similarity index 100% rename from subsys/net/lib/app/bt_settings.c rename to subsys/net/lib/config/bt_settings.c diff --git a/subsys/net/lib/app/bt_settings.h b/subsys/net/lib/config/bt_settings.h similarity index 100% rename from subsys/net/lib/app/bt_settings.h rename to subsys/net/lib/config/bt_settings.h diff --git a/subsys/net/lib/app/ieee802154_settings.c b/subsys/net/lib/config/ieee802154_settings.c similarity index 100% rename from subsys/net/lib/app/ieee802154_settings.c rename to subsys/net/lib/config/ieee802154_settings.c diff --git a/subsys/net/lib/app/ieee802154_settings.h b/subsys/net/lib/config/ieee802154_settings.h similarity index 100% rename from subsys/net/lib/app/ieee802154_settings.h rename to subsys/net/lib/config/ieee802154_settings.h diff --git a/subsys/net/lib/app/init.c b/subsys/net/lib/config/init.c similarity index 100% rename from subsys/net/lib/app/init.c rename to subsys/net/lib/config/init.c