A version of LWIP, provided for backwards compatibility.
Dependents: AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more
netserver.cpp
00001 #include "lwip/opt.h" 00002 #include "lwip/stats.h" 00003 #include "lwip/sys.h" 00004 #include "lwip/pbuf.h" 00005 #include "lwip/udp.h" 00006 #include "lwip/tcp.h" 00007 #include "lwip/dns.h" 00008 #include "lwip/dhcp.h" 00009 #include "lwip/init.h" 00010 #include "lwip/netif.h" 00011 #include "netif/etharp.h" 00012 #include "netif/loopif.h" 00013 #include "netif/rmiiif.h" 00014 00015 #include "netserver.h" 00016 #include "tcplistener.h" 00017 #include "tcpcallbacklistener.h" 00018 #include "tcpconnection.h" 00019 00020 using namespace std; 00021 using namespace mbed; 00022 00023 NetServer::NetServer() : netif(&netif_data), dhcp(true), hostname("mbed-c3p0") { 00024 IP4_ADDR(&netmask, 255,255,255,255); 00025 IP4_ADDR(&gateway, 0,0,0,0); 00026 IP4_ADDR(&ipaddr, 0,0,0,0); 00027 mac.addr[0] = 0x00; 00028 mac.addr[1] = 0x30; 00029 mac.addr[2] = 0x6C; 00030 mac.addr[3] = 0x00; 00031 mac.addr[4] = 0x00; 00032 mac.addr[5] = 0x02; 00033 } 00034 00035 NetServer::NetServer(struct ip_addr ip, struct ip_addr nm, struct ip_addr gw) 00036 : netif(&netif_data), ipaddr(ip), netmask(nm), gateway(gw), dhcp(false), hostname("mbed-c3p0") { 00037 } 00038 00039 NetServer::~NetServer() { 00040 00041 } 00042 00043 void NetServer::emac_tmr() { 00044 emac_input(&netif_data); 00045 } 00046 00047 void NetServer::init() { 00048 lwip_init(); 00049 00050 netif->hwaddr_len = ETHARP_HWADDR_LEN; 00051 *((struct eth_addr *)&(netif->hwaddr[0])) = mac; 00052 00053 netif = netif_add(netif, &ipaddr, &netmask, &gateway, NULL, emac_init, ip_input); 00054 netif->hostname = this->hostname; 00055 netif_set_default(netif); 00056 if(!dhcp) { 00057 netif_set_up(netif); 00058 } else { 00059 dhcp_start(netif); 00060 } 00061 00062 tickARP.attach_us( ðarp_tmr, ARP_TMR_INTERVAL * 1000); 00063 tickFast.attach_us(&tcp_fasttmr, TCP_FAST_INTERVAL * 1000); 00064 tickSlow.attach_us(&tcp_slowtmr, TCP_SLOW_INTERVAL * 1000); 00065 eth_tick.attach_us<NetServer>(this,&emac_tmr, TCP_FAST_INTERVAL * 1000); 00066 dns_tick.attach_us(&dns_tmr, DNS_TMR_INTERVAL * 1000); 00067 if(dhcp) { 00068 dhcp_coarse.attach_us(&dhcp_coarse_tmr, DHCP_COARSE_TIMER_MSECS * 1000); 00069 dhcp_fine.attach_us(&dhcp_fine_tmr, DHCP_FINE_TIMER_MSECS * 1000); 00070 } 00071 } 00072 00073 void NetServer::setUp() { 00074 netif_set_up(netif); 00075 } 00076 00077 void NetServer::setDown() { 00078 netif_set_down(netif); 00079 } 00080 00081 void NetServer::waitForDHCP() { 00082 while(!netif_is_up(netif)) { 00083 wait(1); 00084 } 00085 } 00086 00087 TCPCallbackListener *NetServer::bindTCPPort(u16_t port, err_t (*accept)(TCPCallbackListener *, struct tcp_pcb *, err_t)) { 00088 TCPCallbackListener *listener = new TCPCallbackListener(port, accept); 00089 listener->bind(); 00090 return listener; 00091 } 00092 00093 TCPListener *NetServer::bindTCPPort(TCPListener *listener) { 00094 listener->bind(); 00095 return listener; 00096 } 00097 00098 void NetServer::etablishTCPConnection(TCPConnection *con) { 00099 con->connect(); 00100 }
Generated on Tue Jul 12 2022 16:06:19 by 1.7.2