samples: net: dsa: Enable DHCPv4 and start it when interface is up
Enable DHCPv4 when network interface goes up. This makes it easier to test IP connectivity with DSA. Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no> Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
This commit is contained in:
parent
4eb1669ac6
commit
c09ec58f01
2 changed files with 41 additions and 2 deletions
|
@ -2,7 +2,7 @@ CONFIG_NETWORKING=y
|
||||||
CONFIG_NET_LOG=y
|
CONFIG_NET_LOG=y
|
||||||
CONFIG_NET_IPV6=y
|
CONFIG_NET_IPV6=y
|
||||||
CONFIG_NET_IPV4=y
|
CONFIG_NET_IPV4=y
|
||||||
CONFIG_NET_DHCPV4=n
|
CONFIG_NET_DHCPV4=y
|
||||||
CONFIG_NET_UDP=y
|
CONFIG_NET_UDP=y
|
||||||
CONFIG_NET_TCP=y
|
CONFIG_NET_TCP=y
|
||||||
CONFIG_NET_STATISTICS=y
|
CONFIG_NET_STATISTICS=y
|
||||||
|
@ -18,6 +18,9 @@ CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=5
|
||||||
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=5
|
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=5
|
||||||
CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=1
|
CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=1
|
||||||
CONFIG_NET_MAX_CONTEXTS=4
|
CONFIG_NET_MAX_CONTEXTS=4
|
||||||
|
CONFIG_ZVFS_OPEN_MAX=4
|
||||||
|
CONFIG_ZVFS_POLL_MAX=4
|
||||||
|
CONFIG_NET_MAX_CONN=4
|
||||||
|
|
||||||
CONFIG_INIT_STACKS=y
|
CONFIG_INIT_STACKS=y
|
||||||
CONFIG_PRINTK=y
|
CONFIG_PRINTK=y
|
||||||
|
@ -46,3 +49,10 @@ CONFIG_REQUIRES_FULL_LIBC=y
|
||||||
|
|
||||||
CONFIG_NET_IF_MAX_IPV4_COUNT=4
|
CONFIG_NET_IF_MAX_IPV4_COUNT=4
|
||||||
CONFIG_NET_IF_MAX_IPV6_COUNT=4
|
CONFIG_NET_IF_MAX_IPV6_COUNT=4
|
||||||
|
|
||||||
|
CONFIG_NET_MGMT=y
|
||||||
|
CONFIG_NET_MGMT_EVENT=y
|
||||||
|
CONFIG_NET_MGMT_EVENT_STACK_SIZE=2048
|
||||||
|
|
||||||
|
CONFIG_NET_HOSTNAME_ENABLE=y
|
||||||
|
CONFIG_NET_HOSTNAME="dsa"
|
||||||
|
|
|
@ -39,7 +39,8 @@ static void dsa_iface_find_cb(struct net_if *iface, void *user_data)
|
||||||
if (user == NULL) {
|
if (user == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
LOG_INF("User interface %d found.", i);
|
LOG_INF("[%d] User interface %d found.", i,
|
||||||
|
net_if_get_by_iface(user));
|
||||||
|
|
||||||
ifaces->lan[i] = user;
|
ifaces->lan[i] = user;
|
||||||
}
|
}
|
||||||
|
@ -48,12 +49,40 @@ static void dsa_iface_find_cb(struct net_if *iface, void *user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_MGMT_EVENT)
|
||||||
|
#define EVENT_MASK (NET_EVENT_IF_UP)
|
||||||
|
static struct net_mgmt_event_callback mgmt_cb;
|
||||||
|
|
||||||
|
static void event_handler(struct net_mgmt_event_callback *cb,
|
||||||
|
uint32_t mgmt_event, struct net_if *iface)
|
||||||
|
{
|
||||||
|
ARG_UNUSED(iface);
|
||||||
|
ARG_UNUSED(cb);
|
||||||
|
|
||||||
|
if (mgmt_event == NET_EVENT_IF_UP) {
|
||||||
|
LOG_INF("Port %d is up", net_if_get_by_iface(iface));
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_DHCPV4)
|
||||||
|
net_dhcpv4_start(iface);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_NET_MGMT_EVENT */
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
/* Initialize interfaces - read them to user_data */
|
/* Initialize interfaces - read them to user_data */
|
||||||
(void)memset(&user_data, 0, sizeof(user_data));
|
(void)memset(&user_data, 0, sizeof(user_data));
|
||||||
net_if_foreach(dsa_iface_find_cb, &user_data);
|
net_if_foreach(dsa_iface_find_cb, &user_data);
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_MGMT_EVENT)
|
||||||
|
net_mgmt_init_event_callback(&mgmt_cb,
|
||||||
|
event_handler, EVENT_MASK);
|
||||||
|
net_mgmt_add_event_callback(&mgmt_cb);
|
||||||
|
#endif /* CONFIG_NET_MGMT_EVENT */
|
||||||
|
|
||||||
#if defined(CONFIG_NET_SAMPLE_DSA_LLDP)
|
#if defined(CONFIG_NET_SAMPLE_DSA_LLDP)
|
||||||
dsa_lldp(&user_data);
|
dsa_lldp(&user_data);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue