A version of LWIP, provided for backwards compatibility.

Dependents:   AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers netserver.h Source File

netserver.h

00001 #ifndef NETSERVER_H
00002 #define NETSERVER_H
00003 
00004 #include "ipv4/lwip/ip_addr.h"
00005 #include "lwip/netif.h"
00006 #include "netif/etharp.h"
00007 
00008 namespace mbed {
00009   class TCPListener;
00010   class TCPCallbackListener;
00011   class TCPConnection;
00012 
00013   /**
00014    * Network main class
00015    * provides the basic network features.
00016    */
00017   class NetServer {
00018     public:
00019       /**
00020        * Default constructor tryes to bring the network interface up with dhcp.
00021        */
00022       NetServer();
00023       /**
00024        * Constructor for fix ip setting
00025        */
00026       NetServer(struct ip_addr me_ip, struct ip_addr netmask, struct ip_addr gateway);
00027       ~NetServer();
00028       
00029       /**
00030        * Set a diffrent ethernet address
00031        */
00032       void setMAC(const struct eth_addr &value) { mac = value; }
00033       
00034       /**
00035        * Get the current ethernet address
00036        */
00037       const struct eth_addr &getMAC() { return mac; }
00038       
00039       /**
00040        * Set MBed IP Address
00041        */
00042       void setIPAddr(const struct ip_addr &value) { ipaddr = value; }
00043       /**
00044        * Get MBed IP Address
00045        */
00046       const struct ip_addr &getIPAddr() { return ipaddr; }
00047       
00048       /**
00049        * Set Netmask
00050        */
00051       void setNetmask(const struct ip_addr &value) { netmask = value; }
00052       
00053       /**
00054        * Get Netmask
00055        */
00056       const struct ip_addr &getNetmask() { return netmask; }
00057 
00058       /**
00059        * Set default Gateway
00060        */
00061       void setGateway(const struct ip_addr &value) { gateway = value; }
00062       
00063       /**
00064        * Get default Gateway
00065        */
00066       const struct ip_addr &getGateway() { return gateway; }
00067       
00068       /**
00069        * Set first Domain Name Server
00070        */
00071       void setDNS1(const struct ip_addr &value) { firstdns = value; }
00072       
00073       /**
00074        * Get first Domain Name Server
00075        */
00076       const struct ip_addr &getDNS1() { return firstdns; }
00077       
00078       /**
00079        * Set second Domain Name Server
00080        */
00081       void setDNS2(const struct ip_addr &value) { seconddns = value; }
00082       
00083       /**
00084        * Get second Domain Name Server
00085        */
00086       const struct ip_addr &getDNS2() { return seconddns; }
00087       
00088       /**
00089        * Set MBed Hostname
00090        */
00091       void setHostname(char *value) { hostname = value; }
00092       
00093       /**
00094        * Get MBed Hostname
00095        */
00096       char *getHostname() { return hostname; }
00097       
00098       /**
00099        * Define if DHCP sould be used.
00100        * @param value Bool if true dhcp is used else a static ip setting is assumed.
00101        */
00102       void setUseDHCP(const bool &value) { dhcp = value; }
00103       
00104       /**
00105        * Is the mbed board trying to use DHCP?
00106        */
00107       const bool &getUseDHCP() { return dhcp; }
00108 
00109       /**
00110        * Initialise the network environment. Set up all services.
00111        * Please call after configuration.
00112        */
00113       void init();
00114 
00115       /**
00116        * Set the network interface up.
00117        * To enable the network interface after calling setDown()
00118        * Automaticly called from init().
00119        */
00120       void setUp();
00121       
00122       /**
00123        * Set the network interface down.
00124        * To disable the network interface temporary.
00125        * To make the interface avalible again use setUp().
00126        */
00127       void setDown();
00128       
00129       /**
00130        * This function waits until the network interface is Up.
00131        * To use to wait after init with DHCP. Helps continue work 
00132        * after the network interface is completly up.
00133        */
00134       void waitForDHCP();
00135 
00136 
00137       TCPCallbackListener *bindTCPPort(u16_t, err_t (*)(TCPCallbackListener *, struct tcp_pcb *, err_t));
00138       TCPListener *bindTCPPort(TCPListener *listener);
00139       void etablishTCPConnection(TCPConnection *);
00140     private:
00141       void emac_tmr();
00142       
00143       struct netif   *netif;
00144       struct netif    netif_data;
00145 
00146       struct eth_addr mac;
00147       
00148       struct ip_addr  ipaddr;
00149       struct ip_addr  netmask;
00150       struct ip_addr  gateway;
00151       
00152       struct ip_addr  firstdns;
00153       struct ip_addr  seconddns;
00154       
00155       bool            dhcp;
00156       
00157       Ticker tickFast, tickSlow, tickARP, eth_tick, dns_tick, dhcp_coarse, dhcp_fine;
00158       char *hostname;
00159   };
00160 
00161 };
00162 #endif /* NETSERVER_H */