forked from xuos/xiuos
1、fix lwip_tcp_demo and lwip_udp_demo error;2、add license for ethernet/netdev;3、add netdev for xiwangtong、ok1052、imxrt1176 board。
This commit is contained in:
@@ -1,3 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file eth_netdev.c
|
||||
* @brief register net dev function for lwip
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023-08-07
|
||||
*/
|
||||
|
||||
#include <connect_ethernet.h>
|
||||
#include <inet.h>
|
||||
|
||||
@@ -61,6 +61,9 @@ int32_t low_level_init(struct netif* netif);
|
||||
err_t low_level_output(struct netif* netif, struct pbuf* p);
|
||||
struct pbuf* low_level_input(struct netif* netif);
|
||||
|
||||
int lwip_netdev_add(struct netif* lwip_netif);
|
||||
void lwip_netdev_del(struct netif* lwip_netif);
|
||||
|
||||
int HwEthInit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c fsl_enet_qos.c
|
||||
SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c fsl_enet_qos.c eth_netdev.c
|
||||
SRC_DIR := phy mdio
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -353,5 +353,11 @@ err_t ethernetif_init(struct netif *netif,
|
||||
}
|
||||
#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
|
||||
|
||||
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Adding netdev.\n", __func__));
|
||||
if (EOK != lwip_netdev_add(netif)) {
|
||||
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] LWIP add netdev failed.\n", __func__));
|
||||
} else {
|
||||
printf("[%s] Add Netdev successful\n", __func__);
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file eth_netdev.c
|
||||
* @brief register net dev function for lwip
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023-08-07
|
||||
*/
|
||||
|
||||
#include <connect_ethernet.h>
|
||||
#include <inet.h>
|
||||
#include <lwip/dhcp.h>
|
||||
#include <lwip/netif.h>
|
||||
#include <netdev.h>
|
||||
#include <xs_kdbg.h>
|
||||
|
||||
static const uint32_t NETIF_NAME_LEN = 2;
|
||||
|
||||
static int lwip_netdev_set_up(struct netdev* netdev)
|
||||
{
|
||||
netif_set_up((struct netif*)netdev->user_data);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static int lwip_netdev_set_down(struct netdev* netif)
|
||||
{
|
||||
netif_set_down((struct netif*)netif->user_data);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
#ifndef ip_2_ip4
|
||||
#define ip_2_ip4(ipaddr) (ipaddr)
|
||||
#endif
|
||||
static int lwip_netdev_set_addr_info(struct netdev* netdev, ip_addr_t* ip_addr, ip_addr_t* netmask, ip_addr_t* gw)
|
||||
{
|
||||
if (ip_addr && netmask && gw) {
|
||||
netif_set_addr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr), ip_2_ip4(netmask), ip_2_ip4(gw));
|
||||
} else {
|
||||
if (ip_addr) {
|
||||
netif_set_ipaddr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr));
|
||||
}
|
||||
if (netmask) {
|
||||
netif_set_netmask((struct netif*)netdev->user_data, ip_2_ip4(netmask));
|
||||
}
|
||||
if (gw) {
|
||||
netif_set_gw((struct netif*)netdev->user_data, ip_2_ip4(gw));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LWIP_DNS
|
||||
static int lwip_netdev_set_dns_server(struct netdev* netdev, uint8_t dns_num, ip_addr_t* dns_server)
|
||||
{
|
||||
#if LWIP_VERSION_MAJOR == 1U /* v1.x */
|
||||
extern void dns_setserver(u8_t numdns, ip_addr_t * dnsserver);
|
||||
#else /* >=2.x */
|
||||
extern void dns_setserver(uint8_t dns_num, const ip_addr_t* dns_server);
|
||||
#endif /* LWIP_VERSION_MAJOR == 1U */
|
||||
|
||||
dns_setserver(dns_num, dns_server);
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LWIP_DHCP
|
||||
static int lwip_netdev_set_dhcp(struct netdev* netdev, bool is_enabled)
|
||||
{
|
||||
netdev_low_level_set_dhcp_status(netdev, is_enabled);
|
||||
|
||||
if (true == is_enabled) {
|
||||
dhcp_start((struct netif*)netdev->user_data);
|
||||
} else {
|
||||
dhcp_stop((struct netif*)netdev->user_data);
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int lwip_netdev_set_default(struct netdev* netdev)
|
||||
{
|
||||
netif_set_default((struct netif*)netdev->user_data);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static const struct netdev_ops lwip_netdev_ops = {
|
||||
.set_up = lwip_netdev_set_up,
|
||||
.set_down = lwip_netdev_set_down,
|
||||
.set_addr_info = lwip_netdev_set_addr_info,
|
||||
#ifdef LWIP_DNS
|
||||
.set_dns_server = lwip_netdev_set_dns_server,
|
||||
#endif
|
||||
#ifdef LWIP_DHCP
|
||||
.set_dhcp = lwip_netdev_set_dhcp,
|
||||
#endif
|
||||
.set_default = lwip_netdev_set_default,
|
||||
};
|
||||
|
||||
static inline int netdev_set_flags(struct netif* lwip_netif)
|
||||
{
|
||||
CHECK(lwip_netif);
|
||||
struct netdev* netdev = netdev_get_by_name(lwip_netif->name);
|
||||
if (netdev == NULL) {
|
||||
return -ERR_IF;
|
||||
}
|
||||
|
||||
netdev->mtu = lwip_netif->mtu;
|
||||
// set flags
|
||||
if (lwip_netif->flags | NETIF_FLAG_BROADCAST) {
|
||||
netdev->flags |= NETDEV_FLAG_BROADCAST;
|
||||
}
|
||||
if (lwip_netif->flags | NETIF_FLAG_ETHARP) {
|
||||
netdev->flags |= NETDEV_FLAG_ETHARP;
|
||||
}
|
||||
if (lwip_netif->flags | NETIF_FLAG_IGMP) {
|
||||
netdev->flags |= NETDEV_FLAG_IGMP;
|
||||
}
|
||||
#if LWIP_VERSION_MAJOR >= 2U /* >= v2.x */
|
||||
if (lwip_netif->flags & NETIF_FLAG_MLD6) {
|
||||
netdev->flags |= NETDEV_FLAG_MLD6;
|
||||
}
|
||||
#endif /* LWIP_VERSION_MAJOR >= 2U */
|
||||
|
||||
#if LWIP_DHCP
|
||||
netdev_low_level_set_dhcp_status(netdev, true);
|
||||
#else
|
||||
netdev_low_level_set_dhcp_status(netdev, false);
|
||||
#endif
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int lwip_netdev_add(struct netif* lwip_netif)
|
||||
{
|
||||
CHECK(lwip_netif);
|
||||
|
||||
struct netdev* netdev = calloc(1, sizeof(struct netdev));
|
||||
if (netdev == NULL) {
|
||||
return -ERR_IF;
|
||||
}
|
||||
|
||||
// init netdev
|
||||
char netif_name[NETIF_NAME_LEN + 1];
|
||||
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Lwip netif name: %s\n", __func__, lwip_netif->name));
|
||||
strncpy(netif_name, lwip_netif->name, NETIF_NAME_LEN);
|
||||
// register netdev
|
||||
int result = netdev_register(netdev, netif_name, (void*)lwip_netif);
|
||||
// set values of netdev
|
||||
netdev_set_flags(lwip_netif);
|
||||
netdev->ops = &lwip_netdev_ops;
|
||||
netdev->hwaddr_len = lwip_netif->hwaddr_len;
|
||||
memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
|
||||
netdev->ip_addr = lwip_netif->ip_addr;
|
||||
netdev->gw = lwip_netif->gw;
|
||||
netdev->netmask = lwip_netif->netmask;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void lwip_netdev_del(struct netif* lwip_netif)
|
||||
{
|
||||
char name[NETIF_NAME_LEN + 1];
|
||||
struct netdev* netdev;
|
||||
|
||||
CHECK(lwip_netif);
|
||||
|
||||
strncpy(name, lwip_netif->name, NETIF_NAME_LEN);
|
||||
netdev = netdev_get_by_name(name);
|
||||
netdev_unregister(netdev);
|
||||
free(netdev);
|
||||
}
|
||||
@@ -33,6 +33,8 @@
|
||||
#define sourceClock CLOCK_GetFreq(kCLOCK_CoreSysClk)
|
||||
#endif
|
||||
|
||||
int lwip_netdev_add(struct netif* lwip_netif);
|
||||
void lwip_netdev_del(struct netif* lwip_netif);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -164,6 +164,9 @@ void ethernetif_input( void *netif_arg);
|
||||
int ETH_BSP_Config(void);
|
||||
void *ethernetif_config_enet_set(uint8_t enet_port);
|
||||
|
||||
int lwip_netdev_add(struct netif* lwip_netif);
|
||||
void lwip_netdev_del(struct netif* lwip_netif);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c
|
||||
SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c eth_netdev.c
|
||||
SRC_DIR := ksz8081
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -68,6 +68,7 @@
|
||||
#include "fsl_gpio.h"
|
||||
#include "fsl_iomuxc.h"
|
||||
|
||||
#include "netdev.h"
|
||||
#include "sys_arch.h"
|
||||
|
||||
/*******************************************************************************
|
||||
@@ -319,6 +320,12 @@ err_t ethernetif_init(struct netif *netif, struct ethernetif *ethernetif,
|
||||
}
|
||||
#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
|
||||
|
||||
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Adding netdev.\n", __func__));
|
||||
if (EOK != lwip_netdev_add(netif)) {
|
||||
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] LWIP add netdev failed.\n", __func__));
|
||||
} else {
|
||||
printf("[%s] Add Netdev successful\n", __func__);
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file eth_netdev.c
|
||||
* @brief register net dev function for lwip
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023-08-07
|
||||
*/
|
||||
|
||||
#include <connect_ethernet.h>
|
||||
#include <inet.h>
|
||||
#include <lwip/dhcp.h>
|
||||
#include <lwip/netif.h>
|
||||
#include <netdev.h>
|
||||
#include <xs_kdbg.h>
|
||||
|
||||
static const uint32_t NETIF_NAME_LEN = 2;
|
||||
|
||||
static int lwip_netdev_set_up(struct netdev* netdev)
|
||||
{
|
||||
netif_set_up((struct netif*)netdev->user_data);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static int lwip_netdev_set_down(struct netdev* netif)
|
||||
{
|
||||
netif_set_down((struct netif*)netif->user_data);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
#ifndef ip_2_ip4
|
||||
#define ip_2_ip4(ipaddr) (ipaddr)
|
||||
#endif
|
||||
static int lwip_netdev_set_addr_info(struct netdev* netdev, ip_addr_t* ip_addr, ip_addr_t* netmask, ip_addr_t* gw)
|
||||
{
|
||||
if (ip_addr && netmask && gw) {
|
||||
netif_set_addr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr), ip_2_ip4(netmask), ip_2_ip4(gw));
|
||||
} else {
|
||||
if (ip_addr) {
|
||||
netif_set_ipaddr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr));
|
||||
}
|
||||
if (netmask) {
|
||||
netif_set_netmask((struct netif*)netdev->user_data, ip_2_ip4(netmask));
|
||||
}
|
||||
if (gw) {
|
||||
netif_set_gw((struct netif*)netdev->user_data, ip_2_ip4(gw));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LWIP_DNS
|
||||
static int lwip_netdev_set_dns_server(struct netdev* netdev, uint8_t dns_num, ip_addr_t* dns_server)
|
||||
{
|
||||
#if LWIP_VERSION_MAJOR == 1U /* v1.x */
|
||||
extern void dns_setserver(u8_t numdns, ip_addr_t * dnsserver);
|
||||
#else /* >=2.x */
|
||||
extern void dns_setserver(uint8_t dns_num, const ip_addr_t* dns_server);
|
||||
#endif /* LWIP_VERSION_MAJOR == 1U */
|
||||
|
||||
dns_setserver(dns_num, dns_server);
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LWIP_DHCP
|
||||
static int lwip_netdev_set_dhcp(struct netdev* netdev, bool is_enabled)
|
||||
{
|
||||
netdev_low_level_set_dhcp_status(netdev, is_enabled);
|
||||
|
||||
if (true == is_enabled) {
|
||||
dhcp_start((struct netif*)netdev->user_data);
|
||||
} else {
|
||||
dhcp_stop((struct netif*)netdev->user_data);
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int lwip_netdev_set_default(struct netdev* netdev)
|
||||
{
|
||||
netif_set_default((struct netif*)netdev->user_data);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static const struct netdev_ops lwip_netdev_ops = {
|
||||
.set_up = lwip_netdev_set_up,
|
||||
.set_down = lwip_netdev_set_down,
|
||||
.set_addr_info = lwip_netdev_set_addr_info,
|
||||
#ifdef LWIP_DNS
|
||||
.set_dns_server = lwip_netdev_set_dns_server,
|
||||
#endif
|
||||
#ifdef LWIP_DHCP
|
||||
.set_dhcp = lwip_netdev_set_dhcp,
|
||||
#endif
|
||||
.set_default = lwip_netdev_set_default,
|
||||
};
|
||||
|
||||
static inline int netdev_set_flags(struct netif* lwip_netif)
|
||||
{
|
||||
CHECK(lwip_netif);
|
||||
struct netdev* netdev = netdev_get_by_name(lwip_netif->name);
|
||||
if (netdev == NULL) {
|
||||
return -ERR_IF;
|
||||
}
|
||||
|
||||
netdev->mtu = lwip_netif->mtu;
|
||||
// set flags
|
||||
if (lwip_netif->flags | NETIF_FLAG_BROADCAST) {
|
||||
netdev->flags |= NETDEV_FLAG_BROADCAST;
|
||||
}
|
||||
if (lwip_netif->flags | NETIF_FLAG_ETHARP) {
|
||||
netdev->flags |= NETDEV_FLAG_ETHARP;
|
||||
}
|
||||
if (lwip_netif->flags | NETIF_FLAG_IGMP) {
|
||||
netdev->flags |= NETDEV_FLAG_IGMP;
|
||||
}
|
||||
#if LWIP_VERSION_MAJOR >= 2U /* >= v2.x */
|
||||
if (lwip_netif->flags & NETIF_FLAG_MLD6) {
|
||||
netdev->flags |= NETDEV_FLAG_MLD6;
|
||||
}
|
||||
#endif /* LWIP_VERSION_MAJOR >= 2U */
|
||||
|
||||
#if LWIP_DHCP
|
||||
netdev_low_level_set_dhcp_status(netdev, true);
|
||||
#else
|
||||
netdev_low_level_set_dhcp_status(netdev, false);
|
||||
#endif
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int lwip_netdev_add(struct netif* lwip_netif)
|
||||
{
|
||||
CHECK(lwip_netif);
|
||||
|
||||
struct netdev* netdev = calloc(1, sizeof(struct netdev));
|
||||
if (netdev == NULL) {
|
||||
return -ERR_IF;
|
||||
}
|
||||
|
||||
// init netdev
|
||||
char netif_name[NETIF_NAME_LEN + 1];
|
||||
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Lwip netif name: %s\n", __func__, lwip_netif->name));
|
||||
strncpy(netif_name, lwip_netif->name, NETIF_NAME_LEN);
|
||||
// register netdev
|
||||
int result = netdev_register(netdev, netif_name, (void*)lwip_netif);
|
||||
// set values of netdev
|
||||
netdev_set_flags(lwip_netif);
|
||||
netdev->ops = &lwip_netdev_ops;
|
||||
netdev->hwaddr_len = lwip_netif->hwaddr_len;
|
||||
memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
|
||||
netdev->ip_addr = lwip_netif->ip_addr;
|
||||
netdev->gw = lwip_netif->gw;
|
||||
netdev->netmask = lwip_netif->netmask;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void lwip_netdev_del(struct netif* lwip_netif)
|
||||
{
|
||||
char name[NETIF_NAME_LEN + 1];
|
||||
struct netdev* netdev;
|
||||
|
||||
CHECK(lwip_netif);
|
||||
|
||||
strncpy(name, lwip_netif->name, NETIF_NAME_LEN);
|
||||
netdev = netdev_get_by_name(name);
|
||||
netdev_unregister(netdev);
|
||||
free(netdev);
|
||||
}
|
||||
@@ -33,6 +33,8 @@
|
||||
#define sourceClock CLOCK_GetFreq(kCLOCK_CoreSysClk)
|
||||
#endif
|
||||
|
||||
int lwip_netdev_add(struct netif* lwip_netif);
|
||||
void lwip_netdev_del(struct netif* lwip_netif);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -181,11 +181,14 @@ err_t ethernetif1_init(struct netif *netif);
|
||||
*/
|
||||
void ethernetif_input( void *netif_arg);
|
||||
|
||||
void ETH_BSP_Config(void);
|
||||
int ETH_BSP_Config(void);
|
||||
void *ethernetif_config_enet_set(uint8_t enet_port);
|
||||
|
||||
int32 lwip_obtain_semaphore(struct netif *netif);
|
||||
|
||||
int lwip_netdev_add(struct netif* lwip_netif);
|
||||
void lwip_netdev_del(struct netif* lwip_netif);
|
||||
|
||||
#define NETIF_ENET0_INIT_FUNC ethernetif0_init
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
@@ -1,3 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file eth_netdev.c
|
||||
* @brief register net dev function for lwip
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023-08-07
|
||||
*/
|
||||
|
||||
#include <connect_ethernet.h>
|
||||
#include <inet.h>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c
|
||||
SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c eth_netdev.c
|
||||
SRC_DIR := lan8720
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -68,6 +68,7 @@
|
||||
#include "fsl_gpio.h"
|
||||
#include "fsl_iomuxc.h"
|
||||
|
||||
#include "netdev.h"
|
||||
#include "sys_arch.h"
|
||||
|
||||
/*******************************************************************************
|
||||
@@ -319,6 +320,12 @@ err_t ethernetif_init(struct netif *netif, struct ethernetif *ethernetif,
|
||||
}
|
||||
#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
|
||||
|
||||
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Adding netdev.\n", __func__));
|
||||
if (EOK != lwip_netdev_add(netif)) {
|
||||
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] LWIP add netdev failed.\n", __func__));
|
||||
} else {
|
||||
printf("[%s] Add Netdev successful\n", __func__);
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file eth_netdev.c
|
||||
* @brief register net dev function for lwip
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023-08-07
|
||||
*/
|
||||
|
||||
#include <connect_ethernet.h>
|
||||
#include <inet.h>
|
||||
#include <lwip/dhcp.h>
|
||||
#include <lwip/netif.h>
|
||||
#include <netdev.h>
|
||||
#include <xs_kdbg.h>
|
||||
|
||||
static const uint32_t NETIF_NAME_LEN = 2;
|
||||
|
||||
static int lwip_netdev_set_up(struct netdev* netdev)
|
||||
{
|
||||
netif_set_up((struct netif*)netdev->user_data);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static int lwip_netdev_set_down(struct netdev* netif)
|
||||
{
|
||||
netif_set_down((struct netif*)netif->user_data);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
#ifndef ip_2_ip4
|
||||
#define ip_2_ip4(ipaddr) (ipaddr)
|
||||
#endif
|
||||
static int lwip_netdev_set_addr_info(struct netdev* netdev, ip_addr_t* ip_addr, ip_addr_t* netmask, ip_addr_t* gw)
|
||||
{
|
||||
if (ip_addr && netmask && gw) {
|
||||
netif_set_addr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr), ip_2_ip4(netmask), ip_2_ip4(gw));
|
||||
} else {
|
||||
if (ip_addr) {
|
||||
netif_set_ipaddr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr));
|
||||
}
|
||||
if (netmask) {
|
||||
netif_set_netmask((struct netif*)netdev->user_data, ip_2_ip4(netmask));
|
||||
}
|
||||
if (gw) {
|
||||
netif_set_gw((struct netif*)netdev->user_data, ip_2_ip4(gw));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LWIP_DNS
|
||||
static int lwip_netdev_set_dns_server(struct netdev* netdev, uint8_t dns_num, ip_addr_t* dns_server)
|
||||
{
|
||||
#if LWIP_VERSION_MAJOR == 1U /* v1.x */
|
||||
extern void dns_setserver(u8_t numdns, ip_addr_t * dnsserver);
|
||||
#else /* >=2.x */
|
||||
extern void dns_setserver(uint8_t dns_num, const ip_addr_t* dns_server);
|
||||
#endif /* LWIP_VERSION_MAJOR == 1U */
|
||||
|
||||
dns_setserver(dns_num, dns_server);
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LWIP_DHCP
|
||||
static int lwip_netdev_set_dhcp(struct netdev* netdev, bool is_enabled)
|
||||
{
|
||||
netdev_low_level_set_dhcp_status(netdev, is_enabled);
|
||||
|
||||
if (true == is_enabled) {
|
||||
dhcp_start((struct netif*)netdev->user_data);
|
||||
} else {
|
||||
dhcp_stop((struct netif*)netdev->user_data);
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int lwip_netdev_set_default(struct netdev* netdev)
|
||||
{
|
||||
netif_set_default((struct netif*)netdev->user_data);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static const struct netdev_ops lwip_netdev_ops = {
|
||||
.set_up = lwip_netdev_set_up,
|
||||
.set_down = lwip_netdev_set_down,
|
||||
.set_addr_info = lwip_netdev_set_addr_info,
|
||||
#ifdef LWIP_DNS
|
||||
.set_dns_server = lwip_netdev_set_dns_server,
|
||||
#endif
|
||||
#ifdef LWIP_DHCP
|
||||
.set_dhcp = lwip_netdev_set_dhcp,
|
||||
#endif
|
||||
.set_default = lwip_netdev_set_default,
|
||||
};
|
||||
|
||||
static inline int netdev_set_flags(struct netif* lwip_netif)
|
||||
{
|
||||
CHECK(lwip_netif);
|
||||
struct netdev* netdev = netdev_get_by_name(lwip_netif->name);
|
||||
if (netdev == NULL) {
|
||||
return -ERR_IF;
|
||||
}
|
||||
|
||||
netdev->mtu = lwip_netif->mtu;
|
||||
// set flags
|
||||
if (lwip_netif->flags | NETIF_FLAG_BROADCAST) {
|
||||
netdev->flags |= NETDEV_FLAG_BROADCAST;
|
||||
}
|
||||
if (lwip_netif->flags | NETIF_FLAG_ETHARP) {
|
||||
netdev->flags |= NETDEV_FLAG_ETHARP;
|
||||
}
|
||||
if (lwip_netif->flags | NETIF_FLAG_IGMP) {
|
||||
netdev->flags |= NETDEV_FLAG_IGMP;
|
||||
}
|
||||
#if LWIP_VERSION_MAJOR >= 2U /* >= v2.x */
|
||||
if (lwip_netif->flags & NETIF_FLAG_MLD6) {
|
||||
netdev->flags |= NETDEV_FLAG_MLD6;
|
||||
}
|
||||
#endif /* LWIP_VERSION_MAJOR >= 2U */
|
||||
|
||||
#if LWIP_DHCP
|
||||
netdev_low_level_set_dhcp_status(netdev, true);
|
||||
#else
|
||||
netdev_low_level_set_dhcp_status(netdev, false);
|
||||
#endif
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int lwip_netdev_add(struct netif* lwip_netif)
|
||||
{
|
||||
CHECK(lwip_netif);
|
||||
|
||||
struct netdev* netdev = calloc(1, sizeof(struct netdev));
|
||||
if (netdev == NULL) {
|
||||
return -ERR_IF;
|
||||
}
|
||||
|
||||
// init netdev
|
||||
char netif_name[NETIF_NAME_LEN + 1];
|
||||
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Lwip netif name: %s\n", __func__, lwip_netif->name));
|
||||
strncpy(netif_name, lwip_netif->name, NETIF_NAME_LEN);
|
||||
// register netdev
|
||||
int result = netdev_register(netdev, netif_name, (void*)lwip_netif);
|
||||
// set values of netdev
|
||||
netdev_set_flags(lwip_netif);
|
||||
netdev->ops = &lwip_netdev_ops;
|
||||
netdev->hwaddr_len = lwip_netif->hwaddr_len;
|
||||
memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
|
||||
netdev->ip_addr = lwip_netif->ip_addr;
|
||||
netdev->gw = lwip_netif->gw;
|
||||
netdev->netmask = lwip_netif->netmask;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void lwip_netdev_del(struct netif* lwip_netif)
|
||||
{
|
||||
char name[NETIF_NAME_LEN + 1];
|
||||
struct netdev* netdev;
|
||||
|
||||
CHECK(lwip_netif);
|
||||
|
||||
strncpy(name, lwip_netif->name, NETIF_NAME_LEN);
|
||||
netdev = netdev_get_by_name(name);
|
||||
netdev_unregister(netdev);
|
||||
free(netdev);
|
||||
}
|
||||
@@ -32,6 +32,9 @@ extern "C" {
|
||||
#define sourceClock CLOCK_GetFreq(kCLOCK_CoreSysClk)
|
||||
#endif
|
||||
|
||||
int lwip_netdev_add(struct netif* lwip_netif);
|
||||
void lwip_netdev_del(struct netif* lwip_netif);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -185,6 +185,9 @@ int ETH_BSP_Config(void);
|
||||
void *ethernetif_config_enet_set(uint8_t enet_port);
|
||||
int32 lwip_obtain_semaphore(struct netif *netif);
|
||||
|
||||
int lwip_netdev_add(struct netif* lwip_netif);
|
||||
void lwip_netdev_del(struct netif* lwip_netif);
|
||||
|
||||
#define NETIF_ENET0_INIT_FUNC ethernetif0_init
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
Reference in New Issue
Block a user