Skip to content

Commit c18c062

Browse files
committed
feat(net_connect): introduce unified network connectivity component
Key features: - Port network connection logic from protocol_examples_common into a standalone net_connect component. - Provide unified APIs for WiFi, Ethernet, Thread, and PPP connectivity. - Add comprehensive Kconfig options and example usage. - Introduce programmatic WiFi STA configuration APIs: - net_configure_wifi_sta() - net_connect_wifi() - net_disconnect_wifi() - Simplify WiFi connection flow and remove redundant config prefixes. - Add backward-compatibility mappings via sdkconfig.rename. Ethernet migration & cleanup: - Migrate Ethernet setup to the new ethernet_init component. - Simplify Kconfig by delegating Ethernet options to the main config. - Add interface init/deinit logging. - Fix missing Thread/PPP shutdown handlers. - Remove obsolete net_get_eth_handle() API. Misc: - Update component structure, CMake files, and general cleanup.
1 parent 858f67c commit c18c062

25 files changed

+2871
-2
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ repos:
5757
- repo: local
5858
hooks:
5959
- id: commit message scopes
60-
name: "commit message must be scoped with: mdns, dns, modem, websocket, asio, mqtt_cxx, console, common, eppp, tls_cxx, mosq, sockutls, lws, modem_sim"
61-
entry: '\A(?!(feat|fix|ci|bump|test|docs|chore)\((mdns|dns|modem|common|console|websocket|asio|mqtt_cxx|examples|eppp|tls_cxx|mosq|sockutls|lws|modem_sim)\)\:)'
60+
name: "commit message must be scoped with: mdns, dns, modem, websocket, asio, mqtt_cxx, console, common, eppp, tls_cxx, mosq, sockutls, lws, modem_sim, net_connect"
61+
entry: '\A(?!(feat|fix|ci|bump|test|docs|chore)\((mdns|dns|modem|common|console|websocket|asio|mqtt_cxx|examples|eppp|tls_cxx|mosq|sockutls|lws|modem_sim|net_connect)\)\:)'
6262
language: pygrep
6363
args: [--multiline]
6464
stages: [commit-msg]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
idf_build_get_property(target IDF_TARGET)
2+
3+
if(${target} STREQUAL "linux")
4+
# Header only library for linux
5+
6+
idf_component_register(INCLUDE_DIRS include
7+
SRCS protocol_examples_utils.c)
8+
return()
9+
endif()
10+
11+
set(srcs "stdin_out.c"
12+
"addr_from_stdin.c"
13+
"connect.c"
14+
"wifi_connect.c"
15+
"protocol_examples_utils.c")
16+
17+
if(CONFIG_NET_CONNECT_PROVIDE_WIFI_CONSOLE_CMD)
18+
list(APPEND srcs "console_cmd.c")
19+
endif()
20+
21+
if(CONFIG_NET_CONNECT_ETHERNET)
22+
list(APPEND srcs "eth_connect.c")
23+
endif()
24+
25+
if(CONFIG_NET_CONNECT_THREAD)
26+
list(APPEND srcs "thread_connect.c")
27+
endif()
28+
29+
if(CONFIG_NET_CONNECT_PPP)
30+
list(APPEND srcs "ppp_connect.c")
31+
endif()
32+
33+
34+
idf_component_register(SRCS "${srcs}"
35+
INCLUDE_DIRS "include"
36+
PRIV_REQUIRES esp_netif esp_driver_gpio esp_driver_uart esp_wifi vfs console openthread)
37+
38+
if(CONFIG_NET_CONNECT_PROVIDE_WIFI_CONSOLE_CMD)
39+
idf_component_optional_requires(PRIVATE console)
40+
endif()
41+
42+
if(CONFIG_NET_CONNECT_ETHERNET)
43+
idf_component_optional_requires(PRIVATE esp_eth)
44+
endif()
45+
46+
if(CONFIG_NET_CONNECT_THREAD)
47+
idf_component_optional_requires(PRIVATE openthread)
48+
endif()
49+
50+
if(CONFIG_NET_CONNECT_PPP)
51+
idf_component_optional_requires(PRIVATE esp_tinyusb espressif__esp_tinyusb)
52+
endif()
Lines changed: 316 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,316 @@
1+
menu "Net Connect Configuration"
2+
3+
orsource "$IDF_PATH/examples/common_components/env_caps/$IDF_TARGET/Kconfig.env_caps"
4+
5+
config NET_CONNECT_WIFI
6+
bool "connect using WiFi interface"
7+
depends on !IDF_TARGET_LINUX && (SOC_WIFI_SUPPORTED || ESP_WIFI_REMOTE_ENABLED || ESP_HOST_WIFI_ENABLED)
8+
default y if SOC_WIFI_SUPPORTED
9+
help
10+
Protocol examples can use Wi-Fi, Ethernet and/or Thread to connect to the network.
11+
Choose this option to connect with WiFi
12+
13+
if NET_CONNECT_WIFI
14+
config NET_CONNECT_WIFI_SSID_PWD_FROM_STDIN
15+
bool "Get ssid and password from stdin"
16+
default n
17+
help
18+
Give the WiFi SSID and password from stdin.
19+
20+
config NET_CONNECT_PROVIDE_WIFI_CONSOLE_CMD
21+
depends on !NET_CONNECT_WIFI_SSID_PWD_FROM_STDIN
22+
bool "Provide wifi connect commands"
23+
default y
24+
help
25+
Provide wifi connect commands for esp_console.
26+
Please use `example_register_wifi_connect_commands` to register them.
27+
28+
config NET_CONNECT_WIFI_SSID
29+
depends on !NET_CONNECT_WIFI_SSID_PWD_FROM_STDIN
30+
string "WiFi SSID"
31+
default "myssid"
32+
help
33+
SSID (network name) for the example to connect to.
34+
35+
config NET_CONNECT_WIFI_PASSWORD
36+
depends on !NET_CONNECT_WIFI_SSID_PWD_FROM_STDIN
37+
string "WiFi Password"
38+
default "mypassword"
39+
help
40+
WiFi password (WPA or WPA2) for the example to use.
41+
Can be left blank if the network has no security set.
42+
43+
config NET_CONNECT_WIFI_CONN_MAX_RETRY
44+
int "Maximum retry"
45+
default 6
46+
help
47+
Set the Maximum retry to avoid station reconnecting to the AP unlimited,
48+
in case the AP is really inexistent.
49+
50+
choice NET_CONNECT_WIFI_SCAN_METHOD
51+
prompt "WiFi Scan Method"
52+
default NET_CONNECT_WIFI_SCAN_METHOD_ALL_CHANNEL
53+
help
54+
WiFi scan method:
55+
56+
If "Fast" is selected, scan will end after find SSID match AP.
57+
58+
If "All Channel" is selected, scan will end after scan all the channel.
59+
60+
config NET_CONNECT_WIFI_SCAN_METHOD_FAST
61+
bool "Fast"
62+
config NET_CONNECT_WIFI_SCAN_METHOD_ALL_CHANNEL
63+
bool "All Channel"
64+
endchoice
65+
66+
menu "WiFi Scan threshold"
67+
config NET_CONNECT_WIFI_SCAN_RSSI_THRESHOLD
68+
int "WiFi minimum rssi"
69+
range -127 0
70+
71+
default -127
72+
help
73+
The minimum rssi to accept in the scan mode.
74+
75+
choice NET_CONNECT_WIFI_SCAN_AUTH_MODE_THRESHOLD
76+
prompt "WiFi Scan auth mode threshold"
77+
default NET_CONNECT_WIFI_AUTH_OPEN
78+
help
79+
The weakest authmode to accept in the scan mode.
80+
81+
config NET_CONNECT_WIFI_AUTH_OPEN
82+
bool "OPEN"
83+
config NET_CONNECT_WIFI_AUTH_WEP
84+
bool "WEP"
85+
config NET_CONNECT_WIFI_AUTH_WPA_PSK
86+
bool "WPA PSK"
87+
config NET_CONNECT_WIFI_AUTH_WPA2_PSK
88+
bool "WPA2 PSK"
89+
config NET_CONNECT_WIFI_AUTH_WPA_WPA2_PSK
90+
bool "WPA WPA2 PSK"
91+
config NET_CONNECT_WIFI_AUTH_WPA2_ENTERPRISE
92+
bool "WPA2 ENTERPRISE"
93+
config NET_CONNECT_WIFI_AUTH_WPA3_PSK
94+
bool "WPA3 PSK"
95+
config NET_CONNECT_WIFI_AUTH_WPA2_WPA3_PSK
96+
bool "WPA2 WPA3 PSK"
97+
config NET_CONNECT_WIFI_AUTH_WAPI_PSK
98+
bool "WAPI PSK"
99+
endchoice
100+
endmenu
101+
102+
choice NET_CONNECT_WIFI_CONNECT_AP_SORT_METHOD
103+
prompt "WiFi Connect AP Sort Method"
104+
default NET_CONNECT_WIFI_CONNECT_AP_BY_SIGNAL
105+
help
106+
WiFi connect AP sort method:
107+
108+
If "Signal" is selected, Sort matched APs in scan list by RSSI.
109+
110+
If "Security" is selected, Sort matched APs in scan list by security mode.
111+
112+
config NET_CONNECT_WIFI_CONNECT_AP_BY_SIGNAL
113+
bool "Signal"
114+
config NET_CONNECT_WIFI_CONNECT_AP_BY_SECURITY
115+
bool "Security"
116+
endchoice
117+
endif
118+
119+
config NET_CONNECT_ETHERNET
120+
bool "connect using Ethernet interface"
121+
depends on !IDF_TARGET_LINUX
122+
default y if !NET_CONNECT_WIFI && !NET_CONNECT_THREAD
123+
help
124+
Protocol examples can use Wi-Fi, Ethernet and/or Thread to connect to the network.
125+
Choose this option to enable connection with Ethernet.
126+
Go to `Top -> Ethernet Configuration` to configure the Ethernet interface.
127+
128+
config NET_CONNECT_DISABLE_ETHERNET_CONFIG
129+
bool
130+
select ETHERNET_INIT_OVERRIDE_DISABLE
131+
default y if !NET_CONNECT_ETHERNET
132+
133+
config NET_CONNECT_PPP
134+
bool "connect using Point to Point interface"
135+
select LWIP_PPP_SUPPORT
136+
help
137+
Protocol examples can use PPP connection over serial line.
138+
Choose this option to connect to the ppp server running
139+
on your laptop over a serial line (either UART or USB ACM)
140+
141+
if NET_CONNECT_PPP
142+
choice NET_CONNECT_PPP_DEVICE
143+
prompt "Choose PPP device"
144+
default NET_CONNECT_PPP_DEVICE_USB
145+
help
146+
Select which peripheral to use to connect to the PPP server.
147+
148+
config NET_CONNECT_PPP_DEVICE_USB
149+
bool "USB"
150+
depends on SOC_USB_OTG_SUPPORTED
151+
select TINYUSB_CDC_ENABLED
152+
help
153+
Use USB ACM device.
154+
155+
config NET_CONNECT_PPP_DEVICE_UART
156+
bool "UART"
157+
help
158+
Use UART.
159+
160+
endchoice
161+
162+
menu "UART Configuration"
163+
depends on NET_CONNECT_PPP_DEVICE_UART
164+
config NET_CONNECT_UART_TX_PIN
165+
int "TXD Pin Number"
166+
default 4
167+
range 0 31
168+
help
169+
Pin number of UART TX.
170+
171+
config NET_CONNECT_UART_RX_PIN
172+
int "RXD Pin Number"
173+
default 5
174+
range 0 31
175+
help
176+
Pin number of UART RX.
177+
178+
config NET_CONNECT_UART_BAUDRATE
179+
int "UART Baudrate"
180+
default 115200
181+
range 9600 3000000
182+
help
183+
Baudrate of the UART device
184+
185+
endmenu
186+
187+
config NET_CONNECT_PPP_CONN_MAX_RETRY
188+
int "Maximum retry"
189+
default 6
190+
help
191+
Set the Maximum retry to avoid station reconnecting if the pppd
192+
is not available
193+
194+
endif # NET_CONNECT_PPP
195+
196+
config NET_CONNECT_THREAD
197+
bool "Connect using Thread interface"
198+
depends on !IDF_TARGET_LINUX && OPENTHREAD_ENABLED
199+
default y if SOC_IEEE802154_SUPPORTED
200+
select NET_CONNECT_IPV6
201+
help
202+
Protocol examples can use Wi-Fi, Ethernet and/or Thread to connect to the network.
203+
Choose this option to connect with Thread.
204+
The operational active dataset of the Thread network can be configured in openthread
205+
component at '->Components->OpenThread->Thread Core Features->Thread Operational Dataset'
206+
207+
if NET_CONNECT_THREAD
208+
config NET_CONNECT_THREAD_TASK_STACK_SIZE
209+
int "Example Thread task stack size"
210+
default 8192
211+
help
212+
Thread task stack size
213+
214+
menu "Radio Spinel Options"
215+
depends on OPENTHREAD_RADIO_SPINEL_UART || OPENTHREAD_RADIO_SPINEL_SPI
216+
217+
config NET_CONNECT_THREAD_UART_RX_PIN
218+
depends on OPENTHREAD_RADIO_SPINEL_UART
219+
int "Uart Rx Pin"
220+
default 17
221+
222+
config NET_CONNECT_THREAD_UART_TX_PIN
223+
depends on OPENTHREAD_RADIO_SPINEL_UART
224+
int "Uart Tx pin"
225+
default 18
226+
227+
config NET_CONNECT_THREAD_UART_BAUD
228+
depends on OPENTHREAD_RADIO_SPINEL_UART
229+
int "Uart baud rate"
230+
default 460800
231+
232+
config NET_CONNECT_THREAD_UART_PORT
233+
depends on OPENTHREAD_RADIO_SPINEL_UART
234+
int "Uart port"
235+
default 1
236+
237+
config NET_CONNECT_THREAD_SPI_CS_PIN
238+
depends on OPENTHREAD_RADIO_SPINEL_SPI
239+
int "SPI CS Pin"
240+
default 10
241+
242+
config NET_CONNECT_THREAD_SPI_SCLK_PIN
243+
depends on OPENTHREAD_RADIO_SPINEL_SPI
244+
int "SPI SCLK Pin"
245+
default 12
246+
247+
config NET_CONNECT_THREAD_SPI_MISO_PIN
248+
depends on OPENTHREAD_RADIO_SPINEL_SPI
249+
int "SPI MISO Pin"
250+
default 13
251+
252+
config NET_CONNECT_THREAD_SPI_MOSI_PIN
253+
depends on OPENTHREAD_RADIO_SPINEL_SPI
254+
int "SPI MOSI Pin"
255+
default 11
256+
257+
config NET_CONNECT_THREAD_SPI_INTR_PIN
258+
depends on OPENTHREAD_RADIO_SPINEL_SPI
259+
int "SPI Interrupt Pin"
260+
default 8
261+
endmenu
262+
263+
endif
264+
265+
config NET_CONNECT_IPV4
266+
bool
267+
depends on LWIP_IPV4
268+
default n if NET_CONNECT_THREAD
269+
default y
270+
271+
config NET_CONNECT_IPV6
272+
depends on NET_CONNECT_WIFI || NET_CONNECT_ETHERNET || NET_CONNECT_PPP || NET_CONNECT_THREAD
273+
bool "Obtain IPv6 address"
274+
default y
275+
select LWIP_IPV6
276+
select LWIP_PPP_ENABLE_IPV6 if NET_CONNECT_PPP
277+
help
278+
By default, examples will wait until IPv4 and IPv6 local link addresses are obtained.
279+
Disable this option if the network does not support IPv6.
280+
Choose the preferred IPv6 address type if the connection code should wait until other than
281+
the local link address gets assigned.
282+
Consider enabling IPv6 stateless address autoconfiguration (SLAAC) in the LWIP component.
283+
284+
if NET_CONNECT_IPV6
285+
choice NET_CONNECT_PREFERRED_IPV6
286+
prompt "Preferred IPv6 Type"
287+
default NET_CONNECT_IPV6_PREF_LOCAL_LINK
288+
help
289+
Select which kind of IPv6 address the connect logic waits for.
290+
291+
config NET_CONNECT_IPV6_PREF_LOCAL_LINK
292+
bool "Local Link Address"
293+
help
294+
Blocks until Local link address assigned.
295+
296+
config NET_CONNECT_IPV6_PREF_GLOBAL
297+
bool "Global Address"
298+
help
299+
Blocks until Global address assigned.
300+
301+
config NET_CONNECT_IPV6_PREF_SITE_LOCAL
302+
bool "Site Local Address"
303+
help
304+
Blocks until Site link address assigned.
305+
306+
config NET_CONNECT_IPV6_PREF_UNIQUE_LOCAL
307+
bool "Unique Local Link Address"
308+
help
309+
Blocks until Unique local address assigned.
310+
311+
endchoice
312+
313+
endif
314+
315+
316+
endmenu

0 commit comments

Comments
 (0)