Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync from master #6981

Merged
merged 23 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
feed84b
fix rt_kprint 64bit error
zhkag Feb 20, 2023
ff58949
update rtdevice.h add lcd
XYZ-20240101 Feb 18, 2023
aaba21c
[fix]避免字符设备特殊控制指令和通用控制指令冲突
JonasWen Feb 21, 2023
1533b88
[arduino][lpc55s69] : 对接RTduino
Z8MAN8 Feb 22, 2023
b3b8c23
[spi] rt_spi_configure 增加对cs_pin处理
liYony Feb 23, 2023
52cb2f0
[lwIP] apply AF_UNIX feature (#6954)
Guozhanxin Feb 23, 2023
6d4764a
serial_v2 rt_device_write/read return data type as rt_ssize_t
JonasWen Feb 23, 2023
96a636f
[Renesas]Add tft-lcd lvgl support
Rbb666 Feb 22, 2023
08c2a65
[rtduino][lpc55s69] 修正RTduino框架下的引脚错误 (#6963)
kurisaW Feb 23, 2023
382e9bc
[rt-smart] handling kernel from accessing unmapped user stack (#6957)
polarvid Feb 24, 2023
7bf6648
[serial]增加at32的serial_v2驱动
JonasWen Feb 23, 2023
a5c62b9
[bsp/at32] add support usb driver (#6968)
sheltonyu Feb 25, 2023
022760c
[Infineon]Fix scb5 can't use bug
Rbb666 Feb 24, 2023
faddfec
[rtduino][lpc55s69] update (#6972)
Z8MAN8 Feb 25, 2023
7763183
[rtduino][lpc55s69] 纠正uart引脚错误并使能相关依赖项 (#6976)
kurisaW Feb 25, 2023
e50a7e3
🐞 fix(components/drivers/tty/pty.c): fix ptmx not init (#6970)
xqyjlj Feb 25, 2023
4c1c6ef
解决关中断时进行了调度操作
zhkag Feb 24, 2023
d3553e7
fixed fstat/stat/readlink syscall.
geniusgogo Feb 24, 2023
53afeda
fix inet_ioctlsocket set O_LARGEFILE flag by musl.
geniusgogo Feb 24, 2023
a53367a
fixed O_LARGEFILE not defined ci build error.
geniusgogo Feb 25, 2023
fef2607
[lwp] save virtual addr in shm structure
polarvid Feb 25, 2023
12f0df9
[libcpu/aarch64] stop when no page is free
polarvid Feb 25, 2023
e63e33a
[ch32][bsp] fix warning: rt_size_t to rt_ssize_t
linshire Feb 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[lwIP] apply AF_UNIX feature (#6954)
  • Loading branch information
Guozhanxin committed Feb 23, 2023
commit 52cb2f0b7efb29176bf4011adfe4d44c4b085f21
163 changes: 163 additions & 0 deletions components/net/lwip/port/ethernetif.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,169 @@ void eth_device_deinit(struct eth_device *dev)
rt_free(netif);
}

#ifdef SAL_USING_AF_UNIX /* create loopback netdev */
static err_t af_unix_eth_netif_device_init(struct netif *netif)
{
struct eth_device *ethif;

ethif = (struct eth_device*)netif->state;
if (ethif != RT_NULL)
{
rt_device_t device;

#ifdef RT_USING_NETDEV
/* network interface device register */
netdev_add(netif);
#endif /* RT_USING_NETDEV */

/* get device object */
device = (rt_device_t) ethif;
if (rt_device_init(device) != RT_EOK)
{
return ERR_IF;
}
if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK)
{
return ERR_IF;
}

/* copy device flags to netif flags */
netif->flags = (ethif->flags & 0xff);
netif->mtu = ETHERNET_MTU;

/* set output */
netif->output = etharp_output;

#if LWIP_IPV6
netif->output_ip6 = ethip6_output;
netif->ip6_autoconfig_enabled = 1;
netif_create_ip6_linklocal_address(netif, 1);

#if LWIP_IPV6_MLD
netif->flags |= NETIF_FLAG_MLD6;

/*
* For hardware/netifs that implement MAC filtering.
* All-nodes link-local is handled by default, so we must let the hardware know
* to allow multicast packets in.
* Should set mld_mac_filter previously. */
if (netif->mld_mac_filter != NULL)
{
ip6_addr_t ip6_allnodes_ll;
ip6_addr_set_allnodes_linklocal(&ip6_allnodes_ll);
netif->mld_mac_filter(netif, &ip6_allnodes_ll, NETIF_ADD_MAC_FILTER);
}
#endif /* LWIP_IPV6_MLD */

#endif /* LWIP_IPV6 */

/* set default netif */
if (netif_default == RT_NULL)
netif_set_default(ethif->netif);

/* set interface up */
netif_set_up(ethif->netif);


if (ethif->flags & ETHIF_LINK_PHYUP)
{
/* set link_up for this netif */
netif_set_link_up(ethif->netif);
}

#ifdef RT_USING_NETDEV
/* network interface device flags synchronize */
netdev_flags_sync(netif);
#endif /* RT_USING_NETDEV */

return ERR_OK;
}

return ERR_IF;
}

/* Keep old drivers compatible in RT-Thread */
rt_err_t af_unix_eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_uint16_t flags)
{
struct netif* netif;
#if LWIP_NETIF_HOSTNAME
#define LWIP_HOSTNAME_LEN 16
char *hostname = RT_NULL;
netif = (struct netif*) rt_calloc (1, sizeof(struct netif) + LWIP_HOSTNAME_LEN);
#else
netif = (struct netif*) rt_calloc (1, sizeof(struct netif));
#endif
if (netif == RT_NULL)
{
rt_kprintf("malloc netif failed\n");
return -RT_ERROR;
}

/* set netif */
dev->netif = netif;
dev->flags = flags;
/* link changed status of device */
dev->link_changed = 0x00;
/* avoid send the same mail to mailbox */
dev->rx_notice = 0x00;
dev->parent.type = RT_Device_Class_NetIf;
/* register to RT-Thread device manager */
rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);

/* set name */
netif->name[0] = name[0];
netif->name[1] = name[1];

/* set hw address to 6 */
netif->hwaddr_len = 6;
/* maximum transfer unit */
netif->mtu = ETHERNET_MTU;

/* set linkoutput */
netif->linkoutput = ethernetif_linkoutput;

/* get hardware MAC address */
rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr);

#if LWIP_NETIF_HOSTNAME
/* Initialize interface hostname */
hostname = (char *)netif + sizeof(struct netif);
rt_sprintf(hostname, "rtthread_%02x%02x", name[0], name[1]);
netif->hostname = hostname;
#endif /* LWIP_NETIF_HOSTNAME */

/* if tcp thread has been started up, we add this netif to the system */
if (rt_thread_find("tcpip") != RT_NULL)
{
#if LWIP_VERSION_MAJOR == 1U /* v1.x */
struct ip_addr ipaddr, netmask, gw;
#else /* >= v2.x */
ip4_addr_t ipaddr, netmask, gw;
#endif /* LWIP_VERSION_MAJOR == 1U */

ipaddr.addr = inet_addr("127.0.0.1");
gw.addr = inet_addr("255.0.0.0");
netmask.addr = inet_addr("127.0.0.1");

netifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, af_unix_eth_netif_device_init, tcpip_input);
}

return RT_EOK;
}

rt_err_t af_unix_eth_device_init(struct eth_device * dev, const char *name)
{
rt_uint16_t flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;

#if LWIP_IGMP
/* IGMP support */
flags |= NETIF_FLAG_IGMP;
#endif

return af_unix_eth_device_init_with_flag(dev, name, flags);
}
#endif /* SAL_USING_AF_UNIX */

#ifndef LWIP_NO_RX_THREAD
rt_err_t eth_device_ready(struct eth_device* dev)
{
Expand Down
5 changes: 5 additions & 0 deletions components/net/sal/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ if RT_USING_SAL
Enable BSD socket operated by file system API
Let BSD socket operated by file system API, such as read/write and involveed in select/poll POSIX APIs.

config SAL_USING_AF_UNIX
bool "Enable support AF_UNIX socket"
default n
default y if RT_USING_SMART

config SAL_SOCKETS_NUM
int "the maximum number of sockets"
depends on !SAL_USING_POSIX
Expand Down