Merge pull request #2826 from Lawlieta/develop

[net][netdev] Add RT_USING_FINSH control for netdev network commands
This commit is contained in:
Bernard Xiong 2019-07-03 19:50:44 +08:00 committed by GitHub
commit 6da69f6556
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 29 deletions

View File

@ -146,8 +146,8 @@ static int lwip_netdev_set_addr_info(struct netdev *netif, ip_addr_t *ip_addr, i
#ifdef RT_LWIP_DNS
static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_addr_t *dns_server)
{
extern void set_dns(uint8_t dns_num, char* dns_server);
set_dns(dns_num, ipaddr_ntoa(dns_server));
extern void dns_setserver(uint8_t dns_num, ip_addr_t *dns_server);
dns_setserver(dns_num, dns_server);
return ERR_OK;
}
#endif /* RT_LWIP_DNS */
@ -160,6 +160,7 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled)
}
#endif /* RT_LWIP_DHCP */
#ifdef RT_USING_FINSH
#ifdef RT_LWIP_USING_PING
extern int lwip_ping_recv(int s, int *ttl);
extern err_t lwip_ping_send(int s, ip_addr_t *addr, int size);
@ -250,6 +251,7 @@ void lwip_netdev_netstat(struct netdev *netif)
#endif
}
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
#endif /* RT_USING_FINSH */
const struct netdev_ops lwip_netdev_ops =
{
@ -269,6 +271,7 @@ const struct netdev_ops lwip_netdev_ops =
NULL,
#endif /* RT_LWIP_DHCP */
#ifdef RT_USING_FINSH
#ifdef RT_LWIP_USING_PING
lwip_netdev_ping,
#else
@ -278,6 +281,7 @@ const struct netdev_ops lwip_netdev_ops =
#if defined (RT_LWIP_TCP) || defined (RT_LWIP_UDP)
lwip_netdev_netstat,
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
#endif /* RT_USING_FINSH */
};
static int netdev_add(struct netif *lwip_netif)

View File

@ -154,8 +154,8 @@ static int lwip_netdev_set_addr_info(struct netdev *netif, ip_addr_t *ip_addr, i
#ifdef RT_LWIP_DNS
static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_addr_t *dns_server)
{
extern void set_dns(uint8_t dns_num, char* dns_server);
set_dns(dns_num, ipaddr_ntoa(dns_server));
extern void dns_setserver(uint8_t dns_num, const ip_addr_t *dns_server);
dns_setserver(dns_num, dns_server);
return ERR_OK;
}
#endif /* RT_LWIP_DNS */
@ -168,6 +168,7 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled)
}
#endif /* RT_LWIP_DHCP */
#ifdef RT_USING_FINSH
#ifdef RT_LWIP_USING_PING
extern int lwip_ping_recv(int s, int *ttl);
extern err_t lwip_ping_send(int s, ip_addr_t *addr, int size);
@ -258,6 +259,7 @@ void lwip_netdev_netstat(struct netdev *netif)
#endif
}
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
#endif /* RT_USING_FINSH */
const struct netdev_ops lwip_netdev_ops =
{
@ -277,6 +279,7 @@ const struct netdev_ops lwip_netdev_ops =
NULL,
#endif /* RT_LWIP_DHCP */
#ifdef RT_USING_FINSH
#ifdef RT_LWIP_USING_PING
lwip_netdev_ping,
#else
@ -286,6 +289,7 @@ const struct netdev_ops lwip_netdev_ops =
#if defined (RT_LWIP_TCP) || defined (RT_LWIP_UDP)
lwip_netdev_netstat,
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
#endif /* RT_USING_FINSH */
};
static int netdev_add(struct netif *lwip_netif)

View File

@ -155,8 +155,8 @@ static int lwip_netdev_set_addr_info(struct netdev *netif, ip_addr_t *ip_addr, i
#ifdef RT_LWIP_DNS
static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_addr_t *dns_server)
{
extern void set_dns(uint8_t dns_num, char* dns_server);
set_dns(dns_num, ipaddr_ntoa(dns_server));
extern void dns_setserver(uint8_t dns_num, const ip_addr_t *dns_server);
dns_setserver(dns_num, dns_server);
return ERR_OK;
}
#endif /* RT_LWIP_DNS */
@ -169,6 +169,7 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled)
}
#endif /* RT_LWIP_DHCP */
#ifdef RT_USING_FINSH
#ifdef RT_LWIP_USING_PING
extern int lwip_ping_recv(int s, int *ttl);
extern err_t lwip_ping_send(int s, ip_addr_t *addr, int size);
@ -259,6 +260,7 @@ void lwip_netdev_netstat(struct netdev *netif)
#endif
}
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
#endif /* RT_USING_FINSH */
const struct netdev_ops lwip_netdev_ops =
{
@ -278,6 +280,7 @@ const struct netdev_ops lwip_netdev_ops =
NULL,
#endif /* RT_LWIP_DHCP */
#ifdef RT_USING_FINSH
#ifdef RT_LWIP_USING_PING
lwip_netdev_ping,
#else
@ -287,6 +290,7 @@ const struct netdev_ops lwip_netdev_ops =
#if defined (RT_LWIP_TCP) || defined (RT_LWIP_UDP)
lwip_netdev_netstat,
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
#endif /* RT_USING_FINSH */
};
static int netdev_add(struct netif *lwip_netif)

View File

@ -132,10 +132,11 @@ struct netdev_ops
int (*set_dns_server)(struct netdev *netdev, uint8_t dns_num, ip_addr_t *dns_server);
int (*set_dhcp)(struct netdev *netdev, rt_bool_t is_enabled);
#ifdef RT_USING_FINSH
/* set network interface device common network interface device operations */
int (*ping)(struct netdev *netdev, const char *host, size_t data_len, uint32_t timeout, struct netdev_ping_resp *ping_resp);
void (*netstat)(struct netdev *netdev);
#endif
};
/* The network interface device registered and unregistered*/

View File

@ -821,7 +821,7 @@ void netdev_low_level_set_dhcp_status(struct netdev *netdev, rt_bool_t is_enable
}
}
#ifdef FINSH_USING_MSH
#ifdef RT_USING_FINSH
#include <finsh.h>
@ -832,7 +832,6 @@ static void netdev_list_if(void)
#define NETDEV_IFCONFIG_IEMI_MAX_LEN 8
rt_ubase_t index;
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *netdev = RT_NULL;
struct netdev *cur_netdev_list = netdev_list;
@ -843,14 +842,12 @@ static void netdev_list_if(void)
return;
}
level = rt_hw_interrupt_disable();
for (node = &(cur_netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_list_entry(node, struct netdev, list);
rt_kprintf("network interface device: %s%s\n",
netdev->name,
rt_kprintf("network interface device: %.*s%s\n",
RT_NAME_MAX, netdev->name,
(netdev == netdev_default) ? " (Default)" : "");
rt_kprintf("MTU: %d\n", netdev->mtu);
@ -925,8 +922,6 @@ static void netdev_list_if(void)
rt_kprintf("\n");
}
}
rt_hw_interrupt_enable(level);
}
static void netdev_set_if(char* netdev_name, char* ip_addr, char* gw_addr, char* nm_addr)
@ -985,7 +980,7 @@ FINSH_FUNCTION_EXPORT_ALIAS(netdev_ifconfig, __cmd_ifconfig, list the informatio
#endif /* NETDEV_USING_IFCONFIG */
#ifdef NETDEV_USING_PING
static int netdev_cmd_ping(char* target_name, rt_uint32_t times, rt_size_t size)
int netdev_cmd_ping(char* target_name, rt_uint32_t times, rt_size_t size)
{
#define NETDEV_PING_DATA_SIZE 32
/** ping receive timeout - in milliseconds */
@ -1075,19 +1070,16 @@ FINSH_FUNCTION_EXPORT_ALIAS(netdev_ping, __cmd_ping, ping network host);
static void netdev_list_dns(void)
{
rt_base_t level;
int index = 0;
struct netdev *netdev = RT_NULL;
rt_slist_t *node = RT_NULL;
level = rt_hw_interrupt_disable();
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_list_entry(node, struct netdev, list);
rt_kprintf("network interface device: %s%s\n",
netdev->name,
rt_kprintf("network interface device: %.*s%s\n",
RT_NAME_MAX, netdev->name,
(netdev == netdev_default)?" (Default)":"");
for(index = 0; index < NETDEV_DNS_SERVERS_NUM; index++)
@ -1100,8 +1092,6 @@ static void netdev_list_dns(void)
rt_kprintf("\n");
}
}
rt_hw_interrupt_enable(level);
}
static void netdev_set_dns(char *netdev_name, uint8_t dns_num, char *dns_server)
@ -1149,7 +1139,6 @@ FINSH_FUNCTION_EXPORT_ALIAS(netdev_dns, __cmd_dns, list and set the information
#ifdef NETDEV_USING_NETSTAT
static void netdev_cmd_netstat(void)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *netdev = RT_NULL;
struct netdev *cur_netdev_list = netdev_list;
@ -1160,8 +1149,6 @@ static void netdev_cmd_netstat(void)
return;
}
level = rt_hw_interrupt_disable();
for (node = &(cur_netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_list_entry(node, struct netdev, list);
@ -1172,8 +1159,6 @@ static void netdev_cmd_netstat(void)
}
}
rt_hw_interrupt_enable(level);
netdev->ops->netstat(netdev);
}
@ -1193,4 +1178,4 @@ int netdev_netstat(int argc, char **argv)
FINSH_FUNCTION_EXPORT_ALIAS(netdev_netstat, __cmd_netstat, list the information of TCP / IP);
#endif /* NETDEV_USING_NETSTAT */
#endif /* FINSH_USING_MSH */
#endif /* RT_USING_FINSH */