friendev EtherDune TCP/IP library
/home/jander/temp/etherdune/NetworkService.h
Go to the documentation of this file.
1 // EtherDune Network Service base class
2 // Author: Javier Peletier <jm@friendev.com>
3 // Summary: Base class for any network service running in EtherDune
4 //
5 // Copyright (c) 2015 All Rights Reserved, http://friendev.com
6 //
7 // This source is subject to the GPLv2 license.
8 // Please see the License.txt file for more information.
9 // All other rights reserved.
10 //
11 // THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
12 // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13 // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
14 // PARTICULAR PURPOSE.
15 
16 
89 
90 #ifndef __NETWORKSERVICE_H_
91 #define __NETWORKSERVICE_H_
92 
93 #include "ENC28J60.h"
94 #include "List.h"
95 
96 class ARPService;
97 class DNSClient;
98 
99 
100 class NetworkService : private ListItem, public ENC28J60
101 {
102  friend class DNSClient;
103  friend class ENC28J60;
104 
105 private:
106 
107  static List activeServices;
108 
109  static void processIncomingPacket();
110  static void notifyOnDNSResolve(uint8_t status, uint16_t identification, const IPAddress& ip);
111 
112 protected:
113 
114  static EthBuffer packet;
115  static ARPService ARP;
116 
117  NetworkService();
118  ~NetworkService();
119 
120  static bool sendIPPacket(uint16_t length);
121  static void prepareIPPacket(const IPAddress& remoteIP);
122  static bool sameLAN(IPAddress& dst);
123 
128  virtual bool onPacketReceived() = 0;
129 
130 
131  virtual void tick();
132  virtual void onDNSResolve(uint8_t status, uint16_t identification, const IPAddress& ip);
133 
134 public:
139  static IPAddress dnsIP;
140 
141 
142  static bool begin(uint8_t cspin);
143  static void loop();
144  static DNSClient& DNS();
145 
146 };
147 
149 
150 
151 #endif
Stores a MAC address in memory.
Definition: inet.h:252
Base list item class.
Definition: List.h:29
Union of all the different protocol headers and layers to help EtherDune interpret or build packet...
Definition: inet.h:496
static DNSClient & DNS()
Obtains access to the DNS service singleton instance.
static EthBuffer packet
in-memory packet buffer currently being processed.
virtual void onDNSResolve(uint8_t status, uint16_t identification, const IPAddress &ip)
Called on each network service every time a DNS response is received.
static bool begin(uint8_t cspin)
Initializes EtherDune and the underlying hardware
represents an IP address in memory
Definition: inet.h:181
static IPAddress netmask
Subnet mask.
Basic linked list class.
Definition: List.h:43
static IPAddress gatewayIP
IP address of the gateway in this network.
virtual void tick()
This is a timer function that is called every NETWORK_TIMER_RESOLUTION milliseconds on every service...
virtual bool onPacketReceived()=0
Called every time a packet is received.
Encapsulates access to the ENC28J60 hardware.
Definition: ENC28J60.h:37
static IPAddress dnsIP
IP address of the DNS server to use.
static MACAddress localMAC
Ethernet MAC address.
Implements the ARP protocol as an EtherDune service.
Definition: ARP.h:31
static bool sendIPPacket(uint16_t length)
Puts the current in-memory packet in the network
static ARPService ARP
ARP singleton instance.
EtherDune DNS Service.
Definition: DNS.h:52
static void prepareIPPacket(const IPAddress &remoteIP)
Sets up common IP header values for all outgoing IP packets and calculates the IP header checksum ...
static void loop()
Gives processing time to EtherDune so that it can check for incoming packets or send queued packets...
static bool sameLAN(IPAddress &dst)
Determines whether the given IP is in the same subnet as localIP
static IPAddress localIP
IP address of this application.
Abstract base class for any network service running in EtherDune.
NetworkService net