|
@@ -10,6 +10,8 @@
|
|
|
* Change Logs:
|
|
|
* Date Author Notes
|
|
|
* 2010-07-07 Bernard fix send mail to mailbox issue.
|
|
|
+ * 2011-07-30 mbbill port lwIP 1.4.0 to RT-Thread
|
|
|
+ * 2012-04-10 Bernard add more compatible with RT-Thread.
|
|
|
*/
|
|
|
|
|
|
/*
|
|
@@ -59,60 +61,172 @@
|
|
|
#include "netif/etharp.h"
|
|
|
#include "netif/ethernetif.h"
|
|
|
|
|
|
-/* configurations */
|
|
|
-#ifndef RT_LWIP_ETHTHREAD_PRIORITY
|
|
|
-#define RT_LWIP_ETHTHREAD_PRIORITY 0x90
|
|
|
-#endif
|
|
|
+#define netifapi_netif_set_link_up(n) netifapi_netif_common(n, netif_set_link_up, NULL)
|
|
|
+#define netifapi_netif_set_link_down(n) netifapi_netif_common(n, netif_set_link_down, NULL)
|
|
|
|
|
|
-#ifndef RT_LWIP_ETHTHREAD_MBOX_SIZE
|
|
|
-#define RT_LWIP_ETHTHREAD_MBOX_SIZE 48
|
|
|
-#endif
|
|
|
+/**
|
|
|
+ * Tx message structure for Ethernet interface
|
|
|
+ */
|
|
|
+struct eth_tx_msg
|
|
|
+{
|
|
|
+ struct netif *netif;
|
|
|
+ struct pbuf *buf;
|
|
|
+};
|
|
|
|
|
|
-#ifndef RT_LWIP_ETHTHREAD_STACKSIZE
|
|
|
-#define RT_LWIP_ETHTHREAD_STACKSIZE 1024
|
|
|
+static struct rt_mailbox eth_tx_thread_mb;
|
|
|
+static struct rt_thread eth_tx_thread;
|
|
|
+#ifndef RT_LWIP_ETHTHREAD_PRIORITY
|
|
|
+static char eth_tx_thread_mb_pool[32 * 4];
|
|
|
+static char eth_tx_thread_stack[512];
|
|
|
+#else
|
|
|
+static char eth_tx_thread_mb_pool[RT_LWIP_ETHTHREAD_MBOX_SIZE * 4];
|
|
|
+static char eth_tx_thread_stack[RT_LWIP_ETHTHREAD_STACKSIZE];
|
|
|
#endif
|
|
|
|
|
|
-
|
|
|
-/* eth rx thread */
|
|
|
static struct rt_mailbox eth_rx_thread_mb;
|
|
|
static struct rt_thread eth_rx_thread;
|
|
|
-
|
|
|
+#ifndef RT_LWIP_ETHTHREAD_PRIORITY
|
|
|
+#define RT_ETHERNETIF_THREAD_PREORITY 0x90
|
|
|
+static char eth_rx_thread_mb_pool[48 * 4];
|
|
|
+static char eth_rx_thread_stack[1024];
|
|
|
+#else
|
|
|
+#define RT_ETHERNETIF_THREAD_PREORITY RT_LWIP_ETHTHREAD_PRIORITY
|
|
|
static char eth_rx_thread_mb_pool[RT_LWIP_ETHTHREAD_MBOX_SIZE * 4];
|
|
|
static char eth_rx_thread_stack[RT_LWIP_ETHTHREAD_STACKSIZE];
|
|
|
+#endif
|
|
|
|
|
|
-
|
|
|
-/* Ugly hacks for old drivers compatible */
|
|
|
-/* ===================================== */
|
|
|
-#if 1
|
|
|
-static struct eth_device * ptmpdev;
|
|
|
-struct eth_device * get_eth_dev(void)
|
|
|
+static err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p)
|
|
|
{
|
|
|
- return ptmpdev;
|
|
|
+ struct eth_tx_msg msg;
|
|
|
+ struct eth_device* enetif;
|
|
|
+
|
|
|
+ enetif = (struct eth_device*)netif->state;
|
|
|
+
|
|
|
+ /* send a message to eth tx thread */
|
|
|
+ msg.netif = netif;
|
|
|
+ msg.buf = p;
|
|
|
+ if (rt_mb_send(ð_tx_thread_mb, (rt_uint32_t) &msg) == RT_EOK)
|
|
|
+ {
|
|
|
+ /* waiting for ack */
|
|
|
+ rt_sem_take(&(enetif->tx_ack), RT_WAITING_FOREVER);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ERR_OK;
|
|
|
}
|
|
|
-int eth_device_init(struct eth_device * dev, char *name)
|
|
|
+
|
|
|
+/* Keep old drivers compatible in RT-Thread */
|
|
|
+rt_err_t eth_device_init_with_flag(struct eth_device *dev, char *name, rt_uint8_t flags)
|
|
|
{
|
|
|
- ptmpdev = dev;
|
|
|
+ struct netif* netif;
|
|
|
+
|
|
|
+ netif = (struct netif*) rt_malloc (sizeof(struct netif));
|
|
|
+ if (netif == RT_NULL)
|
|
|
+ {
|
|
|
+ rt_kprintf("malloc netif failed\n");
|
|
|
+ return -RT_ERROR;
|
|
|
+ }
|
|
|
+ rt_memset(netif, 0, sizeof(struct netif));
|
|
|
+
|
|
|
+ /* set netif */
|
|
|
+ dev->netif = netif;
|
|
|
+ /* device flags, which will be set to netif flags when initializing */
|
|
|
+ dev->flags = flags;
|
|
|
+ /* link changed status of device */
|
|
|
+ dev->link_changed = 0x00;
|
|
|
dev->parent.type = RT_Device_Class_NetIf;
|
|
|
- rt_device_register(&(dev->parent), "eth0", RT_DEVICE_FLAG_RDWR);
|
|
|
- return 0;
|
|
|
+ /* register to RT-Thread device manager */
|
|
|
+ rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
|
|
|
+ rt_sem_init(&(dev->tx_ack), name, 0, RT_IPC_FLAG_FIFO);
|
|
|
+
|
|
|
+ /* 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;
|
|
|
+
|
|
|
+ /* get hardware MAC address */
|
|
|
+ rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr);
|
|
|
+
|
|
|
+ /* set output */
|
|
|
+ netif->output = etharp_output;
|
|
|
+ netif->linkoutput = ethernetif_linkoutput;
|
|
|
+
|
|
|
+ return RT_EOK;
|
|
|
}
|
|
|
-void lwip_sys_init(void)
|
|
|
+
|
|
|
+rt_err_t eth_device_init(struct eth_device * dev, char *name)
|
|
|
{
|
|
|
- lwip_enetif_init();
|
|
|
+ rt_uint8_t flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;
|
|
|
+
|
|
|
+#if LWIP_IGMP
|
|
|
+ /* IGMP support */
|
|
|
+ flags |= NETIF_FLAG_IGMP;
|
|
|
+#endif
|
|
|
+
|
|
|
+ return eth_device_init_with_flag(dev, name, flags);
|
|
|
}
|
|
|
-void eth_system_device_init()
|
|
|
+
|
|
|
+rt_err_t eth_device_ready(struct eth_device* dev)
|
|
|
{
|
|
|
+ if (dev->netif)
|
|
|
+ /* post message to Ethernet thread */
|
|
|
+ return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev);
|
|
|
+ else
|
|
|
+ return ERR_OK; /* netif is not initialized yet, just return. */
|
|
|
}
|
|
|
-rt_err_t eth_device_ready(struct eth_device* dev)
|
|
|
+
|
|
|
+rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up)
|
|
|
{
|
|
|
- return eth_rx_ready(dev);
|
|
|
+ rt_uint32_t level;
|
|
|
+
|
|
|
+ RT_ASSERT(dev != RT_NULL);
|
|
|
+
|
|
|
+ level = rt_hw_interrupt_disable();
|
|
|
+ dev->link_changed = 0x01;
|
|
|
+ if (up == RT_TRUE)
|
|
|
+ dev->link_status = 0x01;
|
|
|
+ else
|
|
|
+ dev->link_status = 0x00;
|
|
|
+ rt_hw_interrupt_enable(level);
|
|
|
+
|
|
|
+ /* post message to ethernet thread */
|
|
|
+ return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev);
|
|
|
}
|
|
|
-#endif
|
|
|
-/* ===================================== */
|
|
|
|
|
|
+/* Ethernet Tx Thread */
|
|
|
+static void eth_tx_thread_entry(void* parameter)
|
|
|
+{
|
|
|
+ struct eth_tx_msg* msg;
|
|
|
+
|
|
|
+ while (1)
|
|
|
+ {
|
|
|
+ if (rt_mb_recv(ð_tx_thread_mb, (rt_uint32_t*)&msg, RT_WAITING_FOREVER) == RT_EOK)
|
|
|
+ {
|
|
|
+ struct eth_device* enetif;
|
|
|
+
|
|
|
+ RT_ASSERT(msg->netif != RT_NULL);
|
|
|
+ RT_ASSERT(msg->buf != RT_NULL);
|
|
|
|
|
|
+ enetif = (struct eth_device*)msg->netif->state;
|
|
|
+ if (enetif != RT_NULL)
|
|
|
+ {
|
|
|
+ /* call driver's interface */
|
|
|
+ if (enetif->eth_tx(&(enetif->parent), msg->buf) != RT_EOK)
|
|
|
+ {
|
|
|
+ rt_kprintf("transmit eth packet failed\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /* send ACK */
|
|
|
+ rt_sem_release(&(enetif->tx_ack));
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
-/* ethernet buffer */
|
|
|
+/* Ethernet Rx Thread */
|
|
|
static void eth_rx_thread_entry(void* parameter)
|
|
|
{
|
|
|
struct eth_device* device;
|
|
@@ -123,6 +237,23 @@ static void eth_rx_thread_entry(void* parameter)
|
|
|
{
|
|
|
struct pbuf *p;
|
|
|
|
|
|
+ /* check link status */
|
|
|
+ if (device->link_changed)
|
|
|
+ {
|
|
|
+ int status;
|
|
|
+ rt_uint32_t level;
|
|
|
+
|
|
|
+ level = rt_hw_interrupt_disable();
|
|
|
+ status = device->link_status;
|
|
|
+ device->link_changed = 0x00;
|
|
|
+ rt_hw_interrupt_enable(level);
|
|
|
+
|
|
|
+ if (status)
|
|
|
+ netifapi_netif_set_link_up(device->netif);
|
|
|
+ else
|
|
|
+ netifapi_netif_set_link_down(device->netif);
|
|
|
+ }
|
|
|
+
|
|
|
/* receive all of buffer */
|
|
|
while (1)
|
|
|
{
|
|
@@ -147,25 +278,12 @@ static void eth_rx_thread_entry(void* parameter)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-static err_t enetif_linkoutput(struct netif *pnetif, struct pbuf *p)
|
|
|
-{
|
|
|
- struct eth_device *dev;
|
|
|
-
|
|
|
- dev = (struct eth_device *)(pnetif->state);
|
|
|
- return dev->eth_tx(&(dev->parent), p);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static err_t enetif_init(struct netif *pnetif)
|
|
|
+void eth_system_device_init()
|
|
|
{
|
|
|
rt_err_t result = RT_EOK;
|
|
|
- struct eth_device *dev;
|
|
|
- rt_uint32_t level;
|
|
|
|
|
|
- /* init rx thread.
|
|
|
- * init mailbox and create ethernet thread */
|
|
|
+ /* initialize Rx thread.
|
|
|
+ * initialize mailbox and create Ethernet Rx thread */
|
|
|
result = rt_mb_init(ð_rx_thread_mb, "erxmb",
|
|
|
ð_rx_thread_mb_pool[0], sizeof(eth_rx_thread_mb_pool)/4,
|
|
|
RT_IPC_FLAG_FIFO);
|
|
@@ -175,147 +293,71 @@ static err_t enetif_init(struct netif *pnetif)
|
|
|
ð_rx_thread_stack[0], sizeof(eth_rx_thread_stack),
|
|
|
RT_LWIP_ETHTHREAD_PRIORITY, 16);
|
|
|
RT_ASSERT(result == RT_EOK);
|
|
|
-
|
|
|
result = rt_thread_startup(ð_rx_thread);
|
|
|
RT_ASSERT(result == RT_EOK);
|
|
|
|
|
|
+ /* initialize Tx thread */
|
|
|
+ /* initialize mailbox and create Ethernet Tx thread */
|
|
|
+ result = rt_mb_init(ð_tx_thread_mb, "etxmb",
|
|
|
+ ð_tx_thread_mb_pool[0], sizeof(eth_tx_thread_mb_pool)/4,
|
|
|
+ RT_IPC_FLAG_FIFO);
|
|
|
+ RT_ASSERT(result == RT_EOK);
|
|
|
|
|
|
- dev = (struct eth_device *)(pnetif->state);
|
|
|
-
|
|
|
- pnetif->name[0] = dev->parent.parent.name[0];
|
|
|
- pnetif->name[1] = dev->parent.parent.name[1];
|
|
|
-
|
|
|
- pnetif->hwaddr_len = 6;
|
|
|
- pnetif->mtu = ETHERNET_MTU;
|
|
|
- pnetif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;
|
|
|
-
|
|
|
-#ifdef LWIP_IGMP
|
|
|
- pnetif->flags |= NETIF_FLAG_IGMP;
|
|
|
-#endif
|
|
|
-
|
|
|
-#ifdef LWIP_DHCP
|
|
|
- pnetif->flags |= NETIF_FLAG_DHCP;
|
|
|
-#endif
|
|
|
-
|
|
|
- /* get hardware address */
|
|
|
- rt_device_control(&(dev->parent), NIOCTL_GADDR, pnetif->hwaddr);
|
|
|
-
|
|
|
- /* set output */
|
|
|
- pnetif->output = etharp_output;
|
|
|
- pnetif->linkoutput = enetif_linkoutput;
|
|
|
-
|
|
|
- /* finally, we connect netif and device together.
|
|
|
- * We initialized eth_device first, but ethernetif is still not ready.
|
|
|
- * Although we checked if dev->netif is null but we still must avoid
|
|
|
- * concurrency problem here.*/
|
|
|
- level = rt_hw_interrupt_disable();
|
|
|
- dev->netif = pnetif;
|
|
|
- rt_hw_interrupt_enable(level);
|
|
|
-
|
|
|
- return ERR_OK;
|
|
|
-}
|
|
|
-
|
|
|
-rt_err_t eth_rx_ready(struct eth_device* dev)
|
|
|
-{
|
|
|
- if (dev->netif)
|
|
|
- /* post message to ethernet thread */
|
|
|
- return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev);
|
|
|
- else
|
|
|
- return ERR_OK; /* netif is not initialized yet, just return. */
|
|
|
-}
|
|
|
-
|
|
|
-/* Functions below shouldn't be here because they are application or usage related.
|
|
|
- * I just give an example of a right power-on procedure here. */
|
|
|
-static struct netif ethernetif;
|
|
|
-extern struct eth_device * get_eth_dev(void);
|
|
|
-
|
|
|
-/* This function is called-back in tcpip thread, so we don't need to use msg api
|
|
|
- * to call those netif_xxx functions. But if we use these anywhere else, we must
|
|
|
- * use msg api to avoid concurrent problem.
|
|
|
- */
|
|
|
-static void tcpip_init_done_callback(void *arg)
|
|
|
-{
|
|
|
- ip_addr_t ipaddr, netmask, gw;
|
|
|
-
|
|
|
- LWIP_ASSERT("invalid arg.\n",arg);
|
|
|
-
|
|
|
-#if LWIP_DHCP
|
|
|
- IP4_ADDR(&gw, 0,0,0,0);
|
|
|
- IP4_ADDR(&ipaddr, 0,0,0,0);
|
|
|
- IP4_ADDR(&netmask, 0,0,0,0);
|
|
|
-#else
|
|
|
- IP4_ADDR(&ipaddr, RT_LWIP_IPADDR0, RT_LWIP_IPADDR1, RT_LWIP_IPADDR2, RT_LWIP_IPADDR3);
|
|
|
- IP4_ADDR(&gw, RT_LWIP_GWADDR0, RT_LWIP_GWADDR1, RT_LWIP_GWADDR2, RT_LWIP_GWADDR3);
|
|
|
- IP4_ADDR(&netmask, RT_LWIP_MSKADDR0, RT_LWIP_MSKADDR1, RT_LWIP_MSKADDR2, RT_LWIP_MSKADDR3);
|
|
|
-#endif
|
|
|
-
|
|
|
- netif_add(ðernetif, &ipaddr, &netmask, &gw,
|
|
|
- get_eth_dev(), enetif_init, tcpip_input);
|
|
|
-
|
|
|
- netif_set_default(ðernetif);
|
|
|
-
|
|
|
-#if LWIP_DHCP
|
|
|
- dhcp_start(ðernetif);
|
|
|
-#else
|
|
|
- netif_set_up(ðernetif);
|
|
|
-#endif
|
|
|
-
|
|
|
- netif_set_link_up(ðernetif);
|
|
|
-
|
|
|
- sys_sem_signal((sys_sem_t*)(&arg));
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-/* Make sure the 'dev' has already been initialized before calling this function.
|
|
|
- * This function will initialize the lwip tcpip stack as well as the ethernetif.
|
|
|
- * It will assign the dev->netif and netif->state field to make a connection between
|
|
|
- * eth driver and ethnetif.
|
|
|
- */
|
|
|
-void lwip_enetif_init(void)
|
|
|
-{
|
|
|
- sys_sem_t init_done_sem;
|
|
|
-
|
|
|
- if(sys_sem_new(&init_done_sem, 0) != ERR_OK)
|
|
|
- {
|
|
|
- LWIP_ASSERT("Failed to create semaphore", 0);
|
|
|
- return;
|
|
|
- }
|
|
|
- tcpip_init(tcpip_init_done_callback,(void *)init_done_sem);
|
|
|
-
|
|
|
- sys_sem_wait(&init_done_sem);
|
|
|
- rt_kprintf("TCP/IP initialized.\n");
|
|
|
+ result = rt_thread_init(ð_tx_thread, "etx", eth_tx_thread_entry, RT_NULL,
|
|
|
+ ð_tx_thread_stack[0], sizeof(eth_tx_thread_stack),
|
|
|
+ RT_ETHERNETIF_THREAD_PREORITY, 16);
|
|
|
+ RT_ASSERT(result == RT_EOK);
|
|
|
|
|
|
- sys_sem_free(&init_done_sem);
|
|
|
+ result = rt_thread_startup(ð_tx_thread);
|
|
|
+ RT_ASSERT(result == RT_EOK);
|
|
|
}
|
|
|
|
|
|
-#if 0
|
|
|
#ifdef RT_USING_FINSH
|
|
|
#include <finsh.h>
|
|
|
-#include "ipv4/lwip/inet.h"
|
|
|
-void set_if(char* ip_addr, char* gw_addr, char* nm_addr)
|
|
|
+void set_if(char* netif_name, char* ip_addr, char* gw_addr, char* nm_addr)
|
|
|
{
|
|
|
- struct ip_addr *ip;
|
|
|
- struct in_addr addr;
|
|
|
-
|
|
|
- ip = (struct ip_addr *)&addr;
|
|
|
-
|
|
|
- /* set ip address */
|
|
|
- if ((ip_addr != RT_NULL) && inet_aton(ip_addr, &addr))
|
|
|
- {
|
|
|
- netif_set_ipaddr(netif_default, ip);
|
|
|
- }
|
|
|
-
|
|
|
- /* set gateway address */
|
|
|
- if ((gw_addr != RT_NULL) && inet_aton(gw_addr, &addr))
|
|
|
- {
|
|
|
- netif_set_gw(netif_default, ip);
|
|
|
- }
|
|
|
-
|
|
|
- /* set netmask address */
|
|
|
- if ((nm_addr != RT_NULL) && inet_aton(nm_addr, &addr))
|
|
|
- {
|
|
|
- netif_set_netmask(netif_default, ip);
|
|
|
- }
|
|
|
+ struct ip_addr *ip;
|
|
|
+ struct ip_addr addr;
|
|
|
+ struct netif * netif = netif_list;
|
|
|
+
|
|
|
+ if(strlen(netif_name) > sizeof(netif->name))
|
|
|
+ {
|
|
|
+ rt_kprintf("network interface name too long!\r\n");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ while(netif != RT_NULL)
|
|
|
+ {
|
|
|
+ if(strncmp(netif_name, netif->name, sizeof(netif->name)) == 0)
|
|
|
+ break;
|
|
|
+
|
|
|
+ netif = netif->next;
|
|
|
+ if( netif == RT_NULL )
|
|
|
+ {
|
|
|
+ rt_kprintf("network interface: %s not found!\r\n", netif_name);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ip = (struct ip_addr *)&addr;
|
|
|
+
|
|
|
+ /* set ip address */
|
|
|
+ if ((ip_addr != RT_NULL) && ipaddr_aton(ip_addr, &addr))
|
|
|
+ {
|
|
|
+ netif_set_ipaddr(netif, ip);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* set gateway address */
|
|
|
+ if ((gw_addr != RT_NULL) && ipaddr_aton(gw_addr, &addr))
|
|
|
+ {
|
|
|
+ netif_set_gw(netif, ip);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* set netmask address */
|
|
|
+ if ((nm_addr != RT_NULL) && ipaddr_aton(nm_addr, &addr))
|
|
|
+ {
|
|
|
+ netif_set_netmask(netif, ip);
|
|
|
+ }
|
|
|
}
|
|
|
FINSH_FUNCTION_EXPORT(set_if, set network interface address);
|
|
|
|
|
@@ -323,32 +365,104 @@ FINSH_FUNCTION_EXPORT(set_if, set network interface address);
|
|
|
#include <lwip/dns.h>
|
|
|
void set_dns(char* dns_server)
|
|
|
{
|
|
|
- struct in_addr addr;
|
|
|
+ struct ip_addr addr;
|
|
|
|
|
|
- if ((dns_server != RT_NULL) && inet_aton(dns_server, &addr))
|
|
|
+ if ((dns_server != RT_NULL) && ipaddr_aton(dns_server, &addr))
|
|
|
{
|
|
|
- dns_setserver(0, (struct ip_addr *)&addr);
|
|
|
+ dns_setserver(0, &addr);
|
|
|
}
|
|
|
}
|
|
|
FINSH_FUNCTION_EXPORT(set_dns, set DNS server address);
|
|
|
#endif
|
|
|
|
|
|
-void list_if()
|
|
|
+void list_if(void)
|
|
|
{
|
|
|
- rt_kprintf("Default network interface: %c%c\n", netif_default->name[0], netif_default->name[1]);
|
|
|
- rt_kprintf("ip address: %s\n", inet_ntoa(*((struct in_addr*)&(netif_default->ip_addr))));
|
|
|
- rt_kprintf("gw address: %s\n", inet_ntoa(*((struct in_addr*)&(netif_default->gw))));
|
|
|
- rt_kprintf("net mask : %s\n", inet_ntoa(*((struct in_addr*)&(netif_default->netmask))));
|
|
|
+ rt_ubase_t index;
|
|
|
+ struct netif * netif;
|
|
|
+
|
|
|
+ netif = netif_list;
|
|
|
+
|
|
|
+ while( netif != RT_NULL )
|
|
|
+ {
|
|
|
+ rt_kprintf("network interface: %c%c%s\n", netif->name[0], netif->name[1], (netif == netif_default)?" (Default)":"");
|
|
|
+ rt_kprintf("MTU: %d\n", netif->mtu);
|
|
|
+ rt_kprintf("MAC: ");
|
|
|
+ for (index = 0; index < netif->hwaddr_len; index ++)
|
|
|
+ rt_kprintf("%02x ", netif->hwaddr[index]);
|
|
|
+ rt_kprintf("\nFLAGS:");
|
|
|
+ if (netif->flags & NETIF_FLAG_UP) rt_kprintf(" UP");
|
|
|
+ else rt_kprintf(" DOWN");
|
|
|
+ if (netif->flags & NETIF_FLAG_LINK_UP) rt_kprintf(" LINK_UP");
|
|
|
+ else rt_kprintf(" LINK_DOWN");
|
|
|
+ if (netif->flags & NETIF_FLAG_DHCP) rt_kprintf(" DHCP");
|
|
|
+ if (netif->flags & NETIF_FLAG_POINTTOPOINT) rt_kprintf(" PPP");
|
|
|
+ if (netif->flags & NETIF_FLAG_ETHARP) rt_kprintf(" ETHARP");
|
|
|
+ if (netif->flags & NETIF_FLAG_IGMP) rt_kprintf(" IGMP");
|
|
|
+ rt_kprintf("\n");
|
|
|
+ rt_kprintf("ip address: %s\n", ipaddr_ntoa(&(netif->ip_addr)));
|
|
|
+ rt_kprintf("gw address: %s\n", ipaddr_ntoa(&(netif->gw)));
|
|
|
+ rt_kprintf("net mask : %s\n", ipaddr_ntoa(&(netif->netmask)));
|
|
|
+ rt_kprintf("\r\n");
|
|
|
+
|
|
|
+ netif = netif->next;
|
|
|
+ }
|
|
|
|
|
|
#if LWIP_DNS
|
|
|
- {
|
|
|
- struct ip_addr ip_addr;
|
|
|
-
|
|
|
- ip_addr = dns_getserver(0);
|
|
|
- rt_kprintf("dns server: %s\n", inet_ntoa(*((struct in_addr*)&(ip_addr))));
|
|
|
- }
|
|
|
-#endif
|
|
|
+ {
|
|
|
+ struct ip_addr ip_addr;
|
|
|
+
|
|
|
+ for(index=0; index<DNS_MAX_SERVERS; index++)
|
|
|
+ {
|
|
|
+ ip_addr = dns_getserver(index);
|
|
|
+ rt_kprintf("dns server #%d: %s\n", index, ipaddr_ntoa(&(ip_addr)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+#endif /**< #if LWIP_DNS */
|
|
|
}
|
|
|
FINSH_FUNCTION_EXPORT(list_if, list network interface information);
|
|
|
+
|
|
|
+#if LWIP_TCP
|
|
|
+#include <lwip/tcp.h>
|
|
|
+#include <lwip/tcp_impl.h>
|
|
|
+
|
|
|
+void list_tcps()
|
|
|
+{
|
|
|
+ struct tcp_pcb *pcb;
|
|
|
+ extern struct tcp_pcb *tcp_active_pcbs;
|
|
|
+ extern union tcp_listen_pcbs_t tcp_listen_pcbs;
|
|
|
+ extern struct tcp_pcb *tcp_tw_pcbs;
|
|
|
+ extern const char *tcp_state_str[];
|
|
|
+
|
|
|
+ rt_enter_critical();
|
|
|
+ rt_kprintf("Active PCB states:\n");
|
|
|
+ for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next)
|
|
|
+ {
|
|
|
+ rt_kprintf("%s:%d <==> %s:%d snd_nxt %d rcv_nxt %d ",
|
|
|
+ ipaddr_ntoa(&(pcb->local_ip)), pcb->local_port,
|
|
|
+ ipaddr_ntoa(&(pcb->remote_ip)), pcb->remote_port,
|
|
|
+ pcb->snd_nxt, pcb->rcv_nxt);
|
|
|
+ rt_kprintf("state: %s\n", tcp_state_str[pcb->state]);
|
|
|
+ }
|
|
|
+
|
|
|
+ rt_kprintf("Listen PCB states:\n");
|
|
|
+ for(pcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; pcb != NULL; pcb = pcb->next)
|
|
|
+ {
|
|
|
+ rt_kprintf("local port %d ", pcb->local_port);
|
|
|
+ rt_kprintf("state: %s\n", tcp_state_str[pcb->state]);
|
|
|
+ }
|
|
|
+
|
|
|
+ rt_kprintf("TIME-WAIT PCB states:\n");
|
|
|
+ for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next)
|
|
|
+ {
|
|
|
+ rt_kprintf("%s:%d <==> %s:%d snd_nxt %d rcv_nxt %d ",
|
|
|
+ ipaddr_ntoa(&(pcb->local_ip)), pcb->local_port,
|
|
|
+ ipaddr_ntoa(&(pcb->remote_ip)), pcb->remote_port,
|
|
|
+ pcb->snd_nxt, pcb->rcv_nxt);
|
|
|
+ rt_kprintf("state: %s\n", tcp_state_str[pcb->state]);
|
|
|
+ }
|
|
|
+ rt_exit_critical();
|
|
|
+}
|
|
|
+FINSH_FUNCTION_EXPORT(list_tcps, list all of tcp connections);
|
|
|
#endif
|
|
|
+
|
|
|
#endif
|