Skip to content

Commit da3f9a2

Browse files
committed
[nrf fromtree] samples: net: Add Wi-Fi snippet support for networking samples
Make use of wifi-ipv4 snippet in several networking samples. Signed-off-by: Robert Lubos <[email protected]> (cherry picked from commit fd2fa54)
1 parent e652c24 commit da3f9a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+259
-26
lines changed

samples/net/common/common.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
# Common routines used in net samples
4+
5+
target_include_directories(app PRIVATE ${ZEPHYR_BASE}/samples/net/common/)
6+
target_sources(app PRIVATE $ENV{ZEPHYR_BASE}/samples/net/common/net_sample_common.c)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/logging/log.h>
8+
LOG_MODULE_REGISTER(net_samples_common, LOG_LEVEL_DBG);
9+
10+
#include <zephyr/net/conn_mgr_connectivity.h>
11+
12+
#if defined(CONFIG_NET_CONNECTION_MANAGER)
13+
#define L4_EVENT_MASK (NET_EVENT_L4_CONNECTED | NET_EVENT_L4_DISCONNECTED)
14+
15+
static struct net_mgmt_event_callback l4_cb;
16+
static K_SEM_DEFINE(network_connected, 0, 1);
17+
18+
static void l4_event_handler(struct net_mgmt_event_callback *cb, uint32_t event,
19+
struct net_if *iface)
20+
{
21+
switch (event) {
22+
case NET_EVENT_L4_CONNECTED:
23+
LOG_INF("Network connectivity established and IP address assigned");
24+
k_sem_give(&network_connected);
25+
break;
26+
case NET_EVENT_L4_DISCONNECTED:
27+
break;
28+
default:
29+
break;
30+
}
31+
}
32+
33+
void wait_for_network(void)
34+
{
35+
net_mgmt_init_event_callback(&l4_cb, l4_event_handler, L4_EVENT_MASK);
36+
net_mgmt_add_event_callback(&l4_cb);
37+
38+
LOG_INF("Waiting for network...");
39+
40+
k_sem_take(&network_connected, K_FOREVER);
41+
}
42+
#endif /* CONFIG_NET_CONNECTION_MANAGER */
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#if defined(CONFIG_NET_CONNECTION_MANAGER)
8+
void wait_for_network(void);
9+
#else
10+
static inline void wait_for_network(void) { }
11+
#endif /* CONFIG_NET_CONNECTION_MANAGER */

samples/net/dns_resolve/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ project(dns_resolve)
66

77
FILE(GLOB app_sources src/*.c)
88
target_sources(app PRIVATE ${app_sources})
9+
10+
include(${ZEPHYR_BASE}/samples/net/common/common.cmake)

samples/net/dns_resolve/README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,9 @@ Open a terminal window and type:
155155
Use 'dmesg' to find the right USB device.
156156

157157
Once the binary is loaded into the FRDM board, press the RESET button.
158+
159+
Wi-Fi
160+
=====
161+
162+
The IPv4 Wi-Fi support can be enabled in the sample with
163+
:ref:`Wi-Fi snippet <snippet-wifi-ipv4>`.

samples/net/dns_resolve/sample.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ tests:
2323
- CONFIG_LLMNR_RESOLVER=y
2424
- CONFIG_NET_DHCPV4=y
2525
tags: llmnr
26+
sample.net.dns_resolve.wifi.nrf70dk:
27+
extra_args:
28+
- SNIPPET=wifi-ipv4
29+
- CONFIG_NRF_WIFI_BUILD_ONLY_MODE=y
30+
platform_allow:
31+
- nrf7002dk/nrf5340/cpuapp

samples/net/dns_resolve/src/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ LOG_MODULE_REGISTER(net_dns_resolve_client_sample, LOG_LEVEL_DBG);
1717
#include <zephyr/net/net_mgmt.h>
1818
#include <zephyr/net/dns_resolve.h>
1919

20+
#include "net_sample_common.h"
21+
2022
#if defined(CONFIG_MDNS_RESOLVER)
2123
#if defined(CONFIG_NET_IPV4)
2224
static struct k_work_delayable mdns_ipv4_timer;
@@ -395,6 +397,8 @@ int main(void)
395397

396398
LOG_INF("Starting DNS resolve sample");
397399

400+
wait_for_network();
401+
398402
setup_ipv4(iface);
399403

400404
setup_dhcpv4(iface);

samples/net/ipv4_autoconf/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ project(ipv4_autoconf)
66

77
FILE(GLOB app_sources src/*.c)
88
target_sources(app PRIVATE ${app_sources})
9+
10+
include(${ZEPHYR_BASE}/samples/net/common/common.cmake)

samples/net/ipv4_autoconf/README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@ type:
6969
.. code-block:: console
7070
7171
$ ping -I eth1 169.254.218.128
72+
73+
Wi-Fi
74+
=====
75+
76+
The IPv4 Wi-Fi support can be enabled in the sample with
77+
:ref:`Wi-Fi snippet <snippet-wifi-ipv4>`.
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
common:
22
harness: net
3+
depends_on: netif
34
tags:
45
- net
56
- ipv4_autoconf
6-
platform_allow:
7-
- qemu_x86
8-
- native_sim
9-
- native_sim/native/64
10-
integration_platforms:
11-
- native_sim
127
sample:
138
description: Test IPv4 autoconf functionality
149
name: IPv4 autoconf sample app
1510
tests:
1611
sample.net.ipv4_autoconf:
17-
depends_on: netif
12+
platform_allow:
13+
- qemu_x86
14+
- native_sim
15+
- native_sim/native/64
16+
integration_platforms:
17+
- native_sim
18+
sample.net.ipv4_autoconf.wifi.nrf70dk:
19+
extra_args:
20+
- SNIPPET=wifi-ipv4
21+
- CONFIG_NRF_WIFI_BUILD_ONLY_MODE=y
22+
platform_allow:
23+
- nrf7002dk/nrf5340/cpuapp

0 commit comments

Comments
 (0)