mgmt: hawkbit: samples: use net config settings

use net config setting and `CONFIG_NET_CONFIG_NEED_IPV4`
to get dhcpv4  address.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
This commit is contained in:
Fin Maaß 2024-04-29 12:24:06 +02:00 committed by Alberto Escolar
parent cbd9b37ef5
commit 5176324e2f
5 changed files with 4 additions and 73 deletions

View file

@ -10,9 +10,7 @@ set(KCONFIG_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/Kconfig)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(hawkbit) project(hawkbit)
FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE src/main.c)
target_sources(app PRIVATE ${app_sources})
target_sources_ifdef(CONFIG_NET_DHCPV4 app PRIVATE src/dhcp.c)
include(${ZEPHYR_BASE}/samples/net/common/common.cmake) include(${ZEPHYR_BASE}/samples/net/common/common.cmake)

View file

@ -23,6 +23,9 @@ CONFIG_MAIN_STACK_SIZE=4096
CONFIG_HEAP_MEM_POOL_SIZE=4096 CONFIG_HEAP_MEM_POOL_SIZE=4096
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096 CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_NEED_IPV4=y
CONFIG_NET_IPV4=y CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=n CONFIG_NET_IPV6=n

View file

@ -1,54 +0,0 @@
/*
* Copyright (c) 2020 Linumiz
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/logging/log.h>
#include <zephyr/kernel.h>
#include <zephyr/net/net_if.h>
#include <zephyr/net/net_core.h>
#include <zephyr/net/net_context.h>
#include <zephyr/net/net_mgmt.h>
static struct net_mgmt_event_callback mgmt_cb;
/* Semaphore to indicate a lease has been acquired */
static K_SEM_DEFINE(got_address, 0, 1);
static void handler(struct net_mgmt_event_callback *cb,
uint32_t mgmt_event,
struct net_if *iface)
{
bool notified = false;
if (mgmt_event != NET_EVENT_IPV4_DHCP_BOUND) {
return;
}
if (!notified) {
k_sem_give(&got_address);
notified = true;
}
}
/**
* Start a DHCP client, and wait for a lease to be acquired.
*/
void app_dhcpv4_startup(void)
{
struct net_if *iface;
net_mgmt_init_event_callback(&mgmt_cb, handler,
NET_EVENT_IPV4_DHCP_BOUND);
net_mgmt_add_event_callback(&mgmt_cb);
iface = net_if_get_default();
net_dhcpv4_start(iface);
/* Wait for a lease */
k_sem_take(&got_address, K_FOREVER);
}

View file

@ -1,12 +0,0 @@
/*
* Copyright (c) 2020 Linumiz
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __DHCP_H__
#define __DHCP_H__
void app_dhcpv4_startup(void);
#endif

View file

@ -12,8 +12,6 @@
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>
#include <zephyr/data/json.h> #include <zephyr/data/json.h>
#include "dhcp.h"
#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS) #if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
#include <zephyr/net/tls_credentials.h> #include <zephyr/net/tls_credentials.h>
#include "ca_certificate.h" #include "ca_certificate.h"
@ -62,8 +60,6 @@ int main(void)
LOG_INF("hawkBit sample app started"); LOG_INF("hawkBit sample app started");
LOG_INF("Image build time: " __DATE__ " " __TIME__); LOG_INF("Image build time: " __DATE__ " " __TIME__);
app_dhcpv4_startup();
#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS) #if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
tls_credential_add(CA_CERTIFICATE_TAG, TLS_CREDENTIAL_CA_CERTIFICATE, tls_credential_add(CA_CERTIFICATE_TAG, TLS_CREDENTIAL_CA_CERTIFICATE,
ca_certificate, sizeof(ca_certificate)); ca_certificate, sizeof(ca_certificate));