mirror of
https://github.com/ep00ch/lwip-contrib-mac.git
synced 2024-07-17 08:28:56 +00:00
Minor changes (do functions for NO_SYS=1 case, use ethernet_input)
This commit is contained in:
parent
5a43133b6a
commit
d5ac707a3d
@ -32,9 +32,9 @@
|
|||||||
#ifndef __LWIPOPTS_H__
|
#ifndef __LWIPOPTS_H__
|
||||||
#define __LWIPOPTS_H__
|
#define __LWIPOPTS_H__
|
||||||
|
|
||||||
#define NO_SYS 0
|
#define NO_SYS 1
|
||||||
#define LWIP_SOCKET 1
|
#define LWIP_SOCKET (NO_SYS==0)
|
||||||
#define LWIP_NETCONN 1
|
#define LWIP_NETCONN (NO_SYS==0)
|
||||||
|
|
||||||
#define LWIP_IGMP 1
|
#define LWIP_IGMP 1
|
||||||
#define LWIP_ICMP 1
|
#define LWIP_ICMP 1
|
||||||
|
@ -59,192 +59,29 @@
|
|||||||
#include "lwip/igmp.h"
|
#include "lwip/igmp.h"
|
||||||
#include "lwip/dhcp.h"
|
#include "lwip/dhcp.h"
|
||||||
#include "lwip/autoip.h"
|
#include "lwip/autoip.h"
|
||||||
#endif
|
#endif /* NO_SYS */
|
||||||
|
|
||||||
/* include the port-dependent configuration */
|
/* include the port-dependent configuration */
|
||||||
#include "lwipcfg_msvc.h"
|
#include "lwipcfg_msvc.h"
|
||||||
|
|
||||||
|
|
||||||
/* some forward function definitions... */
|
/* some forward function definitions... */
|
||||||
err_t ethernetif_init(struct netif *netif);
|
err_t ethernetif_init(struct netif *netif);
|
||||||
void shutdown_adapter(void);
|
void shutdown_adapter(void);
|
||||||
void update_adapter(void);
|
void update_adapter(void);
|
||||||
|
|
||||||
#if NO_SYS
|
#if NO_SYS
|
||||||
/* functions used for timer execution */
|
/* functions used for timer execution */
|
||||||
void sys_init_timing();
|
void sys_init_timing();
|
||||||
u32_t sys_get_ms();
|
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;
|
||||||
|
|
||||||
/* THE ethernet interface */
|
void timers_init()
|
||||||
struct netif netif;
|
|
||||||
#if LWIP_HAVE_LOOPIF
|
|
||||||
/* THE loopback interface */
|
|
||||||
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 */
|
|
||||||
#if LWIP_UDP && LWIP_IGMP
|
|
||||||
void mcast_init(void)
|
|
||||||
{
|
|
||||||
struct udp_pcb *pcb;
|
|
||||||
struct pbuf* p;
|
|
||||||
struct ip_addr remote_addr;
|
|
||||||
char data[1024]={0};
|
|
||||||
int size = sizeof(data);
|
|
||||||
err_t err;
|
|
||||||
|
|
||||||
pcb = udp_new();
|
|
||||||
udp_bind(pcb, IP_ADDR_ANY, 10000);
|
|
||||||
|
|
||||||
pcb->multicast_ip.addr = inet_addr("192.168.5.5");
|
|
||||||
|
|
||||||
p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
|
|
||||||
if (p == NULL) {
|
|
||||||
err = ERR_MEM;
|
|
||||||
} else {
|
|
||||||
p->payload = (void*)data;
|
|
||||||
p->len = p->tot_len = size;
|
|
||||||
|
|
||||||
remote_addr.addr = inet_addr("232.0.0.0");
|
|
||||||
|
|
||||||
err = udp_sendto(pcb, p, &remote_addr, ntohs(20000));
|
|
||||||
|
|
||||||
pbuf_free(p);
|
|
||||||
}
|
|
||||||
udp_remove(pcb);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#define mcast_init()
|
|
||||||
#endif /* LWIP_UDP && LWIP_IGMP*/
|
|
||||||
|
|
||||||
/* This function initializes all network interfaces */
|
|
||||||
void my_netif_init()
|
|
||||||
{
|
|
||||||
struct ip_addr ipaddr, netmask, gw;
|
|
||||||
#if LWIP_HAVE_LOOPIF
|
|
||||||
struct ip_addr loop_ipaddr, loop_netmask, loop_gw;
|
|
||||||
#endif /* LWIP_HAVE_LOOPIF */
|
|
||||||
|
|
||||||
LWIP_PORT_INIT_GW(&gw);
|
|
||||||
LWIP_PORT_INIT_IPADDR(&ipaddr);
|
|
||||||
LWIP_PORT_INIT_NETMASK(&netmask);
|
|
||||||
printf("Starting lwIP, local interface IP is %s\n", inet_ntoa(*(struct in_addr*)&ipaddr));
|
|
||||||
|
|
||||||
#if NO_SYS
|
|
||||||
#if LWIP_ARP
|
|
||||||
netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, my_ethernet_input));
|
|
||||||
#else /* LWIP_ARP */
|
|
||||||
netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, ip_input));
|
|
||||||
#endif /* LWIP_ARP */
|
|
||||||
#else /* NO_SYS */
|
|
||||||
netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input));
|
|
||||||
#endif /* NO_SYS */
|
|
||||||
netif_set_up(&netif);
|
|
||||||
|
|
||||||
#if LWIP_HAVE_LOOPIF
|
|
||||||
IP4_ADDR(&loop_gw, 127,0,0,1);
|
|
||||||
IP4_ADDR(&loop_ipaddr, 127,0,0,1);
|
|
||||||
IP4_ADDR(&loop_netmask, 255,0,0,0);
|
|
||||||
|
|
||||||
printf("Starting lwIP, loopback interface IP is %s\n", inet_ntoa(*(struct in_addr*)&loop_ipaddr));
|
|
||||||
#if NO_SYS
|
|
||||||
netif_add(&loop_netif, &loop_ipaddr, &loop_netmask, &loop_gw, NULL, loopif_init, ip_input);
|
|
||||||
#else /* NO_SYS */
|
|
||||||
netif_add(&loop_netif, &loop_ipaddr, &loop_netmask, &loop_gw, NULL, loopif_init, tcpip_input);
|
|
||||||
#endif /* NO_SYS */
|
|
||||||
netif_set_up(&loop_netif);
|
|
||||||
#endif /* LWIP_HAVE_LOOPIF */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This is somewhat different to other ports: we have a main loop here:
|
|
||||||
* a dedicated task that waits for packets to arrive. This would normally be
|
|
||||||
* done from interrupt context with embedded hardware, but we don't get an
|
|
||||||
* interrupt in windows for that :-) */
|
|
||||||
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();
|
|
||||||
#else /* NO_SYS */
|
|
||||||
tcpip_init(0,0);
|
|
||||||
#endif /* NO_SYS */
|
|
||||||
my_netif_init();
|
|
||||||
|
|
||||||
#if LWIP_UDP
|
|
||||||
mcast_init();
|
|
||||||
#endif /* LWIP_UDP */
|
|
||||||
|
|
||||||
#if LWIP_TCP
|
|
||||||
httpd_init();
|
|
||||||
netio_init();
|
|
||||||
#endif /* LWIP_TCP */
|
|
||||||
|
|
||||||
|
|
||||||
#if NO_SYS
|
|
||||||
last_time = clock();
|
last_time = clock();
|
||||||
timerTcpFast = 0;
|
timerTcpFast = 0;
|
||||||
timerTcpSlow = 0;
|
timerTcpSlow = 0;
|
||||||
@ -254,11 +91,10 @@ void main_loop()
|
|||||||
timerIpReass = 0;
|
timerIpReass = 0;
|
||||||
timerAutoIP = 0;
|
timerAutoIP = 0;
|
||||||
timerIgmp = 0;
|
timerIgmp = 0;
|
||||||
#endif /* NO_SYS */
|
}
|
||||||
done = 0;
|
|
||||||
|
|
||||||
while (!done) {
|
void timers_update()
|
||||||
#if NO_SYS
|
{
|
||||||
int cur_time;
|
int cur_time;
|
||||||
int time_diff;
|
int time_diff;
|
||||||
|
|
||||||
@ -287,7 +123,6 @@ void main_loop()
|
|||||||
if (timerTcpSlow > ((TCP_TMR_INTERVAL)*2)) {
|
if (timerTcpSlow > ((TCP_TMR_INTERVAL)*2)) {
|
||||||
tcp_slowtmr();
|
tcp_slowtmr();
|
||||||
timerTcpSlow -= (TCP_TMR_INTERVAL)*2;
|
timerTcpSlow -= (TCP_TMR_INTERVAL)*2;
|
||||||
done = _kbhit();
|
|
||||||
}
|
}
|
||||||
#endif /* LWIP_TCP */
|
#endif /* LWIP_TCP */
|
||||||
#if LWIP_ARP
|
#if LWIP_ARP
|
||||||
@ -330,9 +165,126 @@ void main_loop()
|
|||||||
timerIgmp -= IGMP_TMR_INTERVAL;
|
timerIgmp -= IGMP_TMR_INTERVAL;
|
||||||
}
|
}
|
||||||
#endif /* LWIP_IGMP */
|
#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 */
|
#endif /* NO_SYS */
|
||||||
|
|
||||||
|
/* THE ethernet interface */
|
||||||
|
struct netif netif;
|
||||||
|
#if LWIP_HAVE_LOOPIF
|
||||||
|
/* THE loopback interface */
|
||||||
|
struct netif loop_netif;
|
||||||
|
#endif /* LWIP_HAVE_LOOPIF */
|
||||||
|
|
||||||
|
/* a simple multicast test */
|
||||||
|
#if LWIP_UDP && LWIP_IGMP
|
||||||
|
void mcast_init(void)
|
||||||
|
{
|
||||||
|
struct udp_pcb *pcb;
|
||||||
|
struct pbuf* p;
|
||||||
|
struct ip_addr remote_addr;
|
||||||
|
char data[1024]={0};
|
||||||
|
int size = sizeof(data);
|
||||||
|
err_t err;
|
||||||
|
|
||||||
|
pcb = udp_new();
|
||||||
|
udp_bind(pcb, IP_ADDR_ANY, 0);
|
||||||
|
|
||||||
|
LWIP_PORT_INIT_IPADDR(&pcb->multicast_ip);
|
||||||
|
|
||||||
|
p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
|
||||||
|
if (p == NULL) {
|
||||||
|
err = ERR_MEM;
|
||||||
|
} else {
|
||||||
|
p->payload = (void*)data;
|
||||||
|
p->len = p->tot_len = size;
|
||||||
|
|
||||||
|
remote_addr.addr = inet_addr("232.0.0.0");
|
||||||
|
|
||||||
|
err = udp_sendto(pcb, p, &remote_addr, ntohs(20000));
|
||||||
|
|
||||||
|
pbuf_free(p);
|
||||||
|
}
|
||||||
|
udp_remove(pcb);
|
||||||
|
}
|
||||||
|
#endif /* LWIP_UDP && LWIP_IGMP*/
|
||||||
|
|
||||||
|
/* This function initializes all network interfaces */
|
||||||
|
void my_netif_init()
|
||||||
|
{
|
||||||
|
struct ip_addr ipaddr, netmask, gw;
|
||||||
|
#if LWIP_HAVE_LOOPIF
|
||||||
|
struct ip_addr loop_ipaddr, loop_netmask, loop_gw;
|
||||||
|
#endif /* LWIP_HAVE_LOOPIF */
|
||||||
|
|
||||||
|
LWIP_PORT_INIT_GW(&gw);
|
||||||
|
LWIP_PORT_INIT_IPADDR(&ipaddr);
|
||||||
|
LWIP_PORT_INIT_NETMASK(&netmask);
|
||||||
|
printf("Starting lwIP, local interface IP is %s\n", inet_ntoa(*(struct in_addr*)&ipaddr));
|
||||||
|
|
||||||
|
#if NO_SYS
|
||||||
|
#if LWIP_ARP
|
||||||
|
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 */
|
||||||
|
#else /* NO_SYS */
|
||||||
|
netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input));
|
||||||
|
#endif /* NO_SYS */
|
||||||
|
netif_set_up(&netif);
|
||||||
|
|
||||||
|
#if LWIP_HAVE_LOOPIF
|
||||||
|
IP4_ADDR(&loop_gw, 127,0,0,1);
|
||||||
|
IP4_ADDR(&loop_ipaddr, 127,0,0,1);
|
||||||
|
IP4_ADDR(&loop_netmask, 255,0,0,0);
|
||||||
|
|
||||||
|
printf("Starting lwIP, loopback interface IP is %s\n", inet_ntoa(*(struct in_addr*)&loop_ipaddr));
|
||||||
|
#if NO_SYS
|
||||||
|
netif_add(&loop_netif, &loop_ipaddr, &loop_netmask, &loop_gw, NULL, loopif_init, ip_input);
|
||||||
|
#else /* NO_SYS */
|
||||||
|
netif_add(&loop_netif, &loop_ipaddr, &loop_netmask, &loop_gw, NULL, loopif_init, tcpip_input);
|
||||||
|
#endif /* NO_SYS */
|
||||||
|
netif_set_up(&loop_netif);
|
||||||
|
#endif /* LWIP_HAVE_LOOPIF */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This is somewhat different to other ports: we have a main loop here:
|
||||||
|
* a dedicated task that waits for packets to arrive. This would normally be
|
||||||
|
* done from interrupt context with embedded hardware, but we don't get an
|
||||||
|
* interrupt in windows for that :-) */
|
||||||
|
void main_loop()
|
||||||
|
{
|
||||||
|
#if NO_SYS
|
||||||
|
nosys_init();
|
||||||
|
#else /* NO_SYS */
|
||||||
|
tcpip_init(0,0);
|
||||||
|
#endif /* NO_SYS */
|
||||||
|
|
||||||
|
my_netif_init();
|
||||||
|
|
||||||
|
#if LWIP_UDP && LWIP_IGMP
|
||||||
|
mcast_init();
|
||||||
|
#endif /* LWIP_UDP && LWIP_IGMP */
|
||||||
|
|
||||||
|
#if LWIP_TCP
|
||||||
|
httpd_init();
|
||||||
|
netio_init();
|
||||||
|
#endif /* LWIP_TCP */
|
||||||
|
|
||||||
|
while (!_kbhit()) {
|
||||||
|
/* handle timers with NO_SYS=1 */
|
||||||
|
timers_update();
|
||||||
|
|
||||||
/* check for packets */
|
/* check for packets */
|
||||||
update_adapter();
|
update_adapter();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user