summaryrefslogtreecommitdiff
path: root/components/net/netdev/src
diff options
context:
space:
mode:
authorWBI\nxf44444 <[email protected]>2022-01-26 01:43:05 +0800
committerWBI\nxf44444 <[email protected]>2022-01-26 01:43:05 +0800
commit8b0f50b7e211ee32ab08ba085ecd74588c3a3c63 (patch)
tree75440be5ecd30cc1403a9387851c0530ed057981 /components/net/netdev/src
parent3be35fecae513b07c35bd6f3992bf7824434bdd6 (diff)
parent32a5668593c578b85560338c29d76f3a252c8dbc (diff)
Update i2c driver, add read ACK and BUS status check
Diffstat (limited to 'components/net/netdev/src')
-rw-r--r--components/net/netdev/src/netdev.c72
-rw-r--r--components/net/netdev/src/netdev_ipaddr.c4
2 files changed, 63 insertions, 13 deletions
diff --git a/components/net/netdev/src/netdev.c b/components/net/netdev/src/netdev.c
index 76a937cc75..f121f52c19 100644
--- a/components/net/netdev/src/netdev.c
+++ b/components/net/netdev/src/netdev.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2019, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -10,6 +10,7 @@
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
#include <rtthread.h>
#include <rthw.h>
@@ -77,6 +78,14 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
netdev->status_callback = RT_NULL;
netdev->addr_callback = RT_NULL;
+ if(rt_strlen(name) > RT_NAME_MAX)
+ {
+ char netdev_name[RT_NAME_MAX + 1] = {0};
+
+ rt_strncpy(netdev_name, name, RT_NAME_MAX);
+ LOG_E("netdev name[%s] length is so long that have been cut into [%s].", name, netdev_name);
+ }
+
/* fill network interface device */
rt_strncpy(netdev->name, name, RT_NAME_MAX);
netdev->user_data = user_data;
@@ -260,7 +269,7 @@ struct netdev *netdev_get_by_name(const char *name)
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_slist_entry(node, struct netdev, list);
- if (netdev && (rt_strncmp(netdev->name, name, RT_NAME_MAX) == 0))
+ if (netdev && (rt_strncmp(netdev->name, name, rt_strlen(netdev->name) < RT_NAME_MAX ? rt_strlen(netdev->name) : RT_NAME_MAX) == 0))
{
rt_hw_interrupt_enable(level);
return netdev;
@@ -821,6 +830,34 @@ void netdev_low_level_set_link_status(struct netdev *netdev, rt_bool_t is_up)
}
/**
+ * This function will set network interface device active internet status.
+ * @NOTE it can only be called in the network interface device driver.
+ *
+ * @param netdev the network interface device to change
+ * @param is_up the new internet status
+ */
+void netdev_low_level_set_internet_status(struct netdev *netdev, rt_bool_t is_up)
+{
+ if (netdev && netdev_is_internet_up(netdev) != is_up)
+ {
+ if (is_up)
+ {
+ netdev->flags |= NETDEV_FLAG_INTERNET_UP;
+ }
+ else
+ {
+ netdev->flags &= ~NETDEV_FLAG_INTERNET_UP;
+ }
+
+ /* execute network interface device status change callback function */
+ if (netdev->status_callback)
+ {
+ netdev->status_callback(netdev, is_up ? NETDEV_CB_STATUS_INTERNET_UP : NETDEV_CB_STATUS_INTERNET_DOWN);
+ }
+ }
+}
+
+/**
* This function will set network interface device DHCP status.
* @NOTE it can only be called in the network interface device driver.
*
@@ -1011,11 +1048,11 @@ int netdev_ifconfig(int argc, char **argv)
return 0;
}
-FINSH_FUNCTION_EXPORT_ALIAS(netdev_ifconfig, __cmd_ifconfig, list the information of all network interfaces);
+MSH_CMD_EXPORT_ALIAS(netdev_ifconfig, ifconfig, list the information of all network interfaces);
#endif /* NETDEV_USING_IFCONFIG */
#ifdef NETDEV_USING_PING
-int netdev_cmd_ping(char* target_name, rt_uint32_t times, rt_size_t size)
+int netdev_cmd_ping(char* target_name, char *netdev_name, rt_uint32_t times, rt_size_t size)
{
#define NETDEV_PING_DATA_SIZE 32
/** ping receive timeout - in milliseconds */
@@ -1036,6 +1073,16 @@ int netdev_cmd_ping(char* target_name, rt_uint32_t times, rt_size_t size)
size = NETDEV_PING_DATA_SIZE;
}
+ if (netdev_name != RT_NULL)
+ {
+ netdev = netdev_get_by_name(netdev_name);
+ if (netdev == RT_NULL)
+ {
+ netdev = netdev_default;
+ rt_kprintf("ping: not found specified netif, using default netdev %s.\n", netdev->name);
+ }
+ }
+
if (NETDEV_PING_IS_COMMONICABLE(netdev_default))
{
/* using default network interface device for ping */
@@ -1107,16 +1154,20 @@ int netdev_ping(int argc, char **argv)
{
if (argc == 1)
{
- rt_kprintf("Please input: ping <host address>\n");
+ rt_kprintf("Please input: ping [netdev name] <host address>\n");
}
- else
+ else if (argc == 2)
{
- netdev_cmd_ping(argv[1], 4, 0);
+ netdev_cmd_ping(argv[1], RT_NULL, 4, 0);
+ }
+ else if (argc == 3)
+ {
+ netdev_cmd_ping(argv[1], argv[2], 4, 0);
}
return 0;
}
-FINSH_FUNCTION_EXPORT_ALIAS(netdev_ping, __cmd_ping, ping network host);
+MSH_CMD_EXPORT_ALIAS(netdev_ping, ping, ping network host);
#endif /* NETDEV_USING_IFCONFIG */
static void netdev_list_dns(void)
@@ -1186,8 +1237,7 @@ int netdev_dns(int argc, char **argv)
return 0;
}
-FINSH_FUNCTION_EXPORT_ALIAS(netdev_dns, __cmd_dns, list and set the information of dns);
-
+MSH_CMD_EXPORT_ALIAS(netdev_dns, dns, list and set the information of dns);
#ifdef NETDEV_USING_NETSTAT
static void netdev_cmd_netstat(void)
{
@@ -1234,7 +1284,7 @@ int netdev_netstat(int argc, char **argv)
return 0;
}
-FINSH_FUNCTION_EXPORT_ALIAS(netdev_netstat, __cmd_netstat, list the information of TCP / IP);
+MSH_CMD_EXPORT_ALIAS(netdev_netstat, netstat, list the information of TCP / IP);
#endif /* NETDEV_USING_NETSTAT */
#endif /* RT_USING_FINSH */
diff --git a/components/net/netdev/src/netdev_ipaddr.c b/components/net/netdev/src/netdev_ipaddr.c
index a70a90bb75..afb6d1d962 100644
--- a/components/net/netdev/src/netdev_ipaddr.c
+++ b/components/net/netdev/src/netdev_ipaddr.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -7,7 +7,7 @@
* Date Author Notes
* 2018-05-18 ChenYong First version
*/
-
+#include <stdlib.h>
#include <rtthread.h>
#include <netdev_ipaddr.h>