mirror of
https://github.com/ep00ch/lwip-contrib-mac.git
synced 2024-07-07 20:29:04 +00:00
Minor changes (do functions for NO_SYS=1 case, use ethernet_input)
This commit is contained in:
parent
5a43133b6a
commit
d5ac707a3d
@ -32,58 +32,58 @@
|
||||
#ifndef __LWIPOPTS_H__
|
||||
#define __LWIPOPTS_H__
|
||||
|
||||
#define NO_SYS 0
|
||||
#define LWIP_SOCKET 1
|
||||
#define LWIP_NETCONN 1
|
||||
#define NO_SYS 1
|
||||
#define LWIP_SOCKET (NO_SYS==0)
|
||||
#define LWIP_NETCONN (NO_SYS==0)
|
||||
|
||||
#define LWIP_IGMP 1
|
||||
#define LWIP_ICMP 1
|
||||
#define LWIP_SNMP 1
|
||||
#define LWIP_IGMP 1
|
||||
#define LWIP_ICMP 1
|
||||
#define LWIP_SNMP 1
|
||||
|
||||
#define LWIP_HAVE_LOOPIF 1
|
||||
#define LWIP_HAVE_LOOPIF 1
|
||||
|
||||
#define LWIP_COMPAT_SOCKETS 1
|
||||
#define LWIP_COMPAT_SOCKETS 1
|
||||
|
||||
#define LWIP_TCPIP_CORE_LOCKING 0
|
||||
#define LWIP_TCPIP_CORE_LOCKING 0
|
||||
|
||||
#define LWIP_NETIF_LINK_CALLBACK 1
|
||||
#define LWIP_NETIF_LINK_CALLBACK 1
|
||||
#define LWIP_NETIF_STATUS_CALLBACK 1
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
|
||||
#define LWIP_DBG_MIN_LEVEL 0
|
||||
#define TAPIF_DEBUG LWIP_DBG_OFF
|
||||
#define TUNIF_DEBUG LWIP_DBG_OFF
|
||||
#define UNIXIF_DEBUG LWIP_DBG_OFF
|
||||
#define DELIF_DEBUG LWIP_DBG_OFF
|
||||
#define SIO_FIFO_DEBUG LWIP_DBG_OFF
|
||||
#define TCPDUMP_DEBUG LWIP_DBG_OFF
|
||||
#define PPP_DEBUG LWIP_DBG_OFF
|
||||
#define MEM_DEBUG LWIP_DBG_OFF
|
||||
#define MEMP_DEBUG LWIP_DBG_OFF
|
||||
#define PBUF_DEBUG LWIP_DBG_OFF
|
||||
#define API_LIB_DEBUG LWIP_DBG_OFF
|
||||
#define API_MSG_DEBUG LWIP_DBG_OFF
|
||||
#define TCPIP_DEBUG LWIP_DBG_OFF
|
||||
#define NETIF_DEBUG LWIP_DBG_OFF
|
||||
#define SOCKETS_DEBUG LWIP_DBG_OFF
|
||||
#define DEMO_DEBUG LWIP_DBG_OFF
|
||||
#define IP_DEBUG LWIP_DBG_OFF
|
||||
#define IP_REASS_DEBUG LWIP_DBG_OFF
|
||||
#define ICMP_DEBUG LWIP_DBG_OFF
|
||||
#define UDP_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_RTO_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_CWND_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_WND_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_FR_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_RST_DEBUG LWIP_DBG_OFF
|
||||
#define LWIP_DBG_MIN_LEVEL 0
|
||||
#define TAPIF_DEBUG LWIP_DBG_OFF
|
||||
#define TUNIF_DEBUG LWIP_DBG_OFF
|
||||
#define UNIXIF_DEBUG LWIP_DBG_OFF
|
||||
#define DELIF_DEBUG LWIP_DBG_OFF
|
||||
#define SIO_FIFO_DEBUG LWIP_DBG_OFF
|
||||
#define TCPDUMP_DEBUG LWIP_DBG_OFF
|
||||
#define PPP_DEBUG LWIP_DBG_OFF
|
||||
#define MEM_DEBUG LWIP_DBG_OFF
|
||||
#define MEMP_DEBUG LWIP_DBG_OFF
|
||||
#define PBUF_DEBUG LWIP_DBG_OFF
|
||||
#define API_LIB_DEBUG LWIP_DBG_OFF
|
||||
#define API_MSG_DEBUG LWIP_DBG_OFF
|
||||
#define TCPIP_DEBUG LWIP_DBG_OFF
|
||||
#define NETIF_DEBUG LWIP_DBG_OFF
|
||||
#define SOCKETS_DEBUG LWIP_DBG_OFF
|
||||
#define DEMO_DEBUG LWIP_DBG_OFF
|
||||
#define IP_DEBUG LWIP_DBG_OFF
|
||||
#define IP_REASS_DEBUG LWIP_DBG_OFF
|
||||
#define ICMP_DEBUG LWIP_DBG_OFF
|
||||
#define UDP_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_RTO_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_CWND_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_WND_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_FR_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_RST_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT)
|
||||
#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT)
|
||||
|
||||
/* ---------- Memory options ---------- */
|
||||
/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
|
||||
|
@ -59,22 +59,125 @@
|
||||
#include "lwip/igmp.h"
|
||||
#include "lwip/dhcp.h"
|
||||
#include "lwip/autoip.h"
|
||||
#endif
|
||||
#endif /* NO_SYS */
|
||||
|
||||
/* include the port-dependent configuration */
|
||||
#include "lwipcfg_msvc.h"
|
||||
|
||||
|
||||
/* some forward function definitions... */
|
||||
err_t ethernetif_init(struct netif *netif);
|
||||
void shutdown_adapter(void);
|
||||
void update_adapter(void);
|
||||
|
||||
#if NO_SYS
|
||||
/* functions used for timer execution */
|
||||
void sys_init_timing();
|
||||
u32_t sys_get_ms();
|
||||
#endif
|
||||
|
||||
/* globales variables for timer execution */
|
||||
int last_time;
|
||||
int timerTcpFast, timerTcpSlow, timerArp;
|
||||
int timerDhcpFine, timerDhcpCoarse, timerIpReass;
|
||||
int timerAutoIP, timerIgmp;
|
||||
|
||||
void timers_init()
|
||||
{
|
||||
last_time = clock();
|
||||
timerTcpFast = 0;
|
||||
timerTcpSlow = 0;
|
||||
timerArp = 0;
|
||||
timerDhcpFine = 0;
|
||||
timerDhcpCoarse = 0;
|
||||
timerIpReass = 0;
|
||||
timerAutoIP = 0;
|
||||
timerIgmp = 0;
|
||||
}
|
||||
|
||||
void timers_update()
|
||||
{
|
||||
int cur_time;
|
||||
int time_diff;
|
||||
|
||||
cur_time = sys_get_ms();
|
||||
time_diff = cur_time - last_time;
|
||||
/* the '> 0' is an easy wrap-around check: the big gap at
|
||||
* the wraparound step is simply ignored... */
|
||||
if (time_diff > 0) {
|
||||
last_time = cur_time;
|
||||
timerTcpFast += time_diff;
|
||||
timerTcpSlow += time_diff;
|
||||
timerArp += time_diff;
|
||||
timerDhcpFine += time_diff;
|
||||
timerDhcpCoarse += time_diff;
|
||||
timerIpReass += time_diff;
|
||||
timerAutoIP += time_diff;
|
||||
timerIgmp += time_diff;
|
||||
}
|
||||
#if LWIP_TCP
|
||||
/* execute TCP fast timer every 250 ms */
|
||||
if (timerTcpFast > TCP_TMR_INTERVAL) {
|
||||
tcp_fasttmr();
|
||||
timerTcpFast -= TCP_TMR_INTERVAL;
|
||||
}
|
||||
/* execute TCP slow timer every 500 ms */
|
||||
if (timerTcpSlow > ((TCP_TMR_INTERVAL)*2)) {
|
||||
tcp_slowtmr();
|
||||
timerTcpSlow -= (TCP_TMR_INTERVAL)*2;
|
||||
}
|
||||
#endif /* LWIP_TCP */
|
||||
#if LWIP_ARP
|
||||
/* execute ARP timer */
|
||||
if (timerArp > ARP_TMR_INTERVAL) {
|
||||
etharp_tmr();
|
||||
timerArp -= ARP_TMR_INTERVAL;
|
||||
}
|
||||
#endif /* LWIP_ARP */
|
||||
#if LWIP_DHCP
|
||||
/* execute DHCP fine timer */
|
||||
if (timerDhcpFine > DHCP_FINE_TIMER_MSECS) {
|
||||
dhcp_fine_tmr();
|
||||
timerDhcpFine -= DHCP_FINE_TIMER_MSECS;
|
||||
}
|
||||
/* execute DHCP coarse timer */
|
||||
if (timerDhcpCoarse > ((DHCP_COARSE_TIMER_SECS)*1000)) {
|
||||
dhcp_coarse_tmr();
|
||||
timerDhcpCoarse -= DHCP_COARSE_TIMER_SECS*1000;
|
||||
}
|
||||
#endif /* LWIP_DHCP */
|
||||
#if IP_REASSEMBLY
|
||||
/* execute IP reassembly timer */
|
||||
if (timerIpReass > IP_TMR_INTERVAL) {
|
||||
ip_reass_tmr();
|
||||
timerIpReass -= IP_TMR_INTERVAL;
|
||||
}
|
||||
#endif /* IP_REASSEMBLY*/
|
||||
#if LWIP_AUTOIP
|
||||
/* execute AUTOIP timer */
|
||||
if (timerAutoIP > AUTOIP_TMR_INTERVAL) {
|
||||
autoip_tmr();
|
||||
timerAutoIP -= AUTOIP_TMR_INTERVAL;
|
||||
}
|
||||
#endif /* LWIP_AUTOIP */
|
||||
#if LWIP_IGMP
|
||||
/* execute IGP timer */
|
||||
if (timerIgmp > IGMP_TMR_INTERVAL) {
|
||||
igmp_tmr();
|
||||
timerIgmp -= IGMP_TMR_INTERVAL;
|
||||
}
|
||||
#endif /* LWIP_IGMP */
|
||||
}
|
||||
|
||||
void nosys_init()
|
||||
{
|
||||
lwip_init();
|
||||
sys_init_timing();
|
||||
timers_init();
|
||||
}
|
||||
#else /* NO_SYS */
|
||||
#define timers_init()
|
||||
#define timers_update()
|
||||
#define nosys_init()
|
||||
#endif /* NO_SYS */
|
||||
|
||||
/* THE ethernet interface */
|
||||
struct netif netif;
|
||||
@ -83,62 +186,7 @@ struct netif netif;
|
||||
struct netif loop_netif;
|
||||
#endif /* LWIP_HAVE_LOOPIF */
|
||||
|
||||
|
||||
/* my own input filtering function if using NO_SYS:
|
||||
* this is 'stolen' from tcpip.c and might be used from there... */
|
||||
#if LWIP_ARP
|
||||
err_t
|
||||
my_ethernet_input(struct pbuf *p, struct netif *netif)
|
||||
{
|
||||
struct eth_hdr* ethhdr;
|
||||
|
||||
/* points to packet payload, which starts with an Ethernet header */
|
||||
ethhdr = p->payload;
|
||||
|
||||
switch (htons(ethhdr->type)) {
|
||||
/* IP packet? */
|
||||
case ETHTYPE_IP:
|
||||
#if ETHARP_TRUST_IP_MAC
|
||||
/* update ARP table */
|
||||
etharp_ip_input( netif, p);
|
||||
#endif /* ETHARP_TRUST_IP_MAC */
|
||||
/* skip Ethernet header */
|
||||
if(pbuf_header(p, -(s16_t)sizeof(struct eth_hdr))) {
|
||||
LWIP_ASSERT("Can't move over header in packet", 0);
|
||||
pbuf_free(p);
|
||||
p = NULL;
|
||||
} else {
|
||||
/* pass to IP layer */
|
||||
ip_input(p, netif);
|
||||
}
|
||||
break;
|
||||
|
||||
case ETHTYPE_ARP:
|
||||
/* pass p to ARP module */
|
||||
etharp_arp_input(netif, (struct eth_addr*)(netif->hwaddr), p);
|
||||
break;
|
||||
|
||||
#if PPPOE_SUPPORT
|
||||
case ETHTYPE_PPPOEDISC: /* PPP Over Ethernet Discovery Stage */
|
||||
pppoe_disc_input(netif, p);
|
||||
break;
|
||||
|
||||
case ETHTYPE_PPPOE: /* PPP Over Ethernet Session Stage */
|
||||
pppoe_data_input(netif, p);
|
||||
break;
|
||||
#endif /* PPPOE_SUPPORT */
|
||||
|
||||
default:
|
||||
pbuf_free(p);
|
||||
p = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
return ERR_OK; /* return value ignored */
|
||||
}
|
||||
#endif /* LWIP_ARP */
|
||||
|
||||
/* a sipmle multicast test */
|
||||
/* a simple multicast test */
|
||||
#if LWIP_UDP && LWIP_IGMP
|
||||
void mcast_init(void)
|
||||
{
|
||||
@ -150,9 +198,9 @@ void mcast_init(void)
|
||||
err_t err;
|
||||
|
||||
pcb = udp_new();
|
||||
udp_bind(pcb, IP_ADDR_ANY, 10000);
|
||||
udp_bind(pcb, IP_ADDR_ANY, 0);
|
||||
|
||||
pcb->multicast_ip.addr = inet_addr("192.168.5.5");
|
||||
LWIP_PORT_INIT_IPADDR(&pcb->multicast_ip);
|
||||
|
||||
p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
|
||||
if (p == NULL) {
|
||||
@ -169,8 +217,6 @@ void mcast_init(void)
|
||||
}
|
||||
udp_remove(pcb);
|
||||
}
|
||||
#else
|
||||
#define mcast_init()
|
||||
#endif /* LWIP_UDP && LWIP_IGMP*/
|
||||
|
||||
/* This function initializes all network interfaces */
|
||||
@ -188,7 +234,7 @@ void my_netif_init()
|
||||
|
||||
#if NO_SYS
|
||||
#if LWIP_ARP
|
||||
netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, my_ethernet_input));
|
||||
netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, ethernet_input));
|
||||
#else /* LWIP_ARP */
|
||||
netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, ip_input));
|
||||
#endif /* LWIP_ARP */
|
||||
@ -219,119 +265,25 @@ void my_netif_init()
|
||||
void main_loop()
|
||||
{
|
||||
#if NO_SYS
|
||||
int last_time;
|
||||
int timerTcpFast, timerTcpSlow, timerArp;
|
||||
int timerDhcpFine, timerDhcpCoarse, timerIpReass;
|
||||
int timerAutoIP, timerIgmp;
|
||||
#endif /* NO_SYS */
|
||||
int done;
|
||||
|
||||
#if NO_SYS
|
||||
lwip_init();
|
||||
sys_init_timing();
|
||||
nosys_init();
|
||||
#else /* NO_SYS */
|
||||
tcpip_init(0,0);
|
||||
#endif /* NO_SYS */
|
||||
|
||||
my_netif_init();
|
||||
|
||||
#if LWIP_UDP
|
||||
#if LWIP_UDP && LWIP_IGMP
|
||||
mcast_init();
|
||||
#endif /* LWIP_UDP */
|
||||
#endif /* LWIP_UDP && LWIP_IGMP */
|
||||
|
||||
#if LWIP_TCP
|
||||
httpd_init();
|
||||
netio_init();
|
||||
#endif /* LWIP_TCP */
|
||||
|
||||
|
||||
#if NO_SYS
|
||||
last_time = clock();
|
||||
timerTcpFast = 0;
|
||||
timerTcpSlow = 0;
|
||||
timerArp = 0;
|
||||
timerDhcpFine = 0;
|
||||
timerDhcpCoarse = 0;
|
||||
timerIpReass = 0;
|
||||
timerAutoIP = 0;
|
||||
timerIgmp = 0;
|
||||
#endif /* NO_SYS */
|
||||
done = 0;
|
||||
|
||||
while (!done) {
|
||||
#if NO_SYS
|
||||
int cur_time;
|
||||
int time_diff;
|
||||
|
||||
cur_time = sys_get_ms();
|
||||
time_diff = cur_time - last_time;
|
||||
/* the '> 0' is an easy wrap-around check: the big gap at
|
||||
* the wraparound step is simply ignored... */
|
||||
if (time_diff > 0) {
|
||||
last_time = cur_time;
|
||||
timerTcpFast += time_diff;
|
||||
timerTcpSlow += time_diff;
|
||||
timerArp += time_diff;
|
||||
timerDhcpFine += time_diff;
|
||||
timerDhcpCoarse += time_diff;
|
||||
timerIpReass += time_diff;
|
||||
timerAutoIP += time_diff;
|
||||
timerIgmp += time_diff;
|
||||
}
|
||||
#if LWIP_TCP
|
||||
/* execute TCP fast timer every 250 ms */
|
||||
if (timerTcpFast > TCP_TMR_INTERVAL) {
|
||||
tcp_fasttmr();
|
||||
timerTcpFast -= TCP_TMR_INTERVAL;
|
||||
}
|
||||
/* execute TCP slow timer every 500 ms */
|
||||
if (timerTcpSlow > ((TCP_TMR_INTERVAL)*2)) {
|
||||
tcp_slowtmr();
|
||||
timerTcpSlow -= (TCP_TMR_INTERVAL)*2;
|
||||
done = _kbhit();
|
||||
}
|
||||
#endif /* LWIP_TCP */
|
||||
#if LWIP_ARP
|
||||
/* execute ARP timer */
|
||||
if (timerArp > ARP_TMR_INTERVAL) {
|
||||
etharp_tmr();
|
||||
timerArp -= ARP_TMR_INTERVAL;
|
||||
}
|
||||
#endif /* LWIP_ARP */
|
||||
#if LWIP_DHCP
|
||||
/* execute DHCP fine timer */
|
||||
if (timerDhcpFine > DHCP_FINE_TIMER_MSECS) {
|
||||
dhcp_fine_tmr();
|
||||
timerDhcpFine -= DHCP_FINE_TIMER_MSECS;
|
||||
}
|
||||
/* execute DHCP coarse timer */
|
||||
if (timerDhcpCoarse > ((DHCP_COARSE_TIMER_SECS)*1000)) {
|
||||
dhcp_coarse_tmr();
|
||||
timerDhcpCoarse -= DHCP_COARSE_TIMER_SECS*1000;
|
||||
}
|
||||
#endif /* LWIP_DHCP */
|
||||
#if IP_REASSEMBLY
|
||||
/* execute IP reassembly timer */
|
||||
if (timerIpReass > IP_TMR_INTERVAL) {
|
||||
ip_reass_tmr();
|
||||
timerIpReass -= IP_TMR_INTERVAL;
|
||||
}
|
||||
#endif /* IP_REASSEMBLY*/
|
||||
#if LWIP_AUTOIP
|
||||
/* execute AUTOIP timer */
|
||||
if (timerAutoIP > AUTOIP_TMR_INTERVAL) {
|
||||
autoip_tmr();
|
||||
timerAutoIP -= AUTOIP_TMR_INTERVAL;
|
||||
}
|
||||
#endif /* LWIP_AUTOIP */
|
||||
#if LWIP_IGMP
|
||||
/* execute IGP timer */
|
||||
if (timerIgmp > IGMP_TMR_INTERVAL) {
|
||||
igmp_tmr();
|
||||
timerIgmp -= IGMP_TMR_INTERVAL;
|
||||
}
|
||||
#endif /* LWIP_IGMP */
|
||||
|
||||
#endif /* NO_SYS */
|
||||
while (!_kbhit()) {
|
||||
/* handle timers with NO_SYS=1 */
|
||||
timers_update();
|
||||
|
||||
/* check for packets */
|
||||
update_adapter();
|
||||
|
Loading…
Reference in New Issue
Block a user