EtherCard
Ardino interface library for the ENC28J60 Ethernet controller chip (GPL).
 All Classes Functions Variables Pages
EtherCard.h
1 // This code slightly follows the conventions of, but is not derived from:
2 // EHTERSHIELD_H library for Arduino etherShield
3 // Copyright (c) 2008 Xing Yu. All right reserved. (this is LGPL v2.1)
4 // It is however derived from the enc28j60 and ip code (which is GPL v2)
5 // Author: Pascal Stang
6 // Modified by: Guido Socher
7 // DHCP code: Andrew Lindsay
8 // Hence: GPL V2
9 //
10 // 2010-05-19 <jc@wippler.nl>
11 //
12 //
13 // PIN Connections (Using Arduino UNO):
14 // VCC - 3.3V
15 // GND - GND
16 // SCK - Pin 13
17 // SO - Pin 12
18 // SI - Pin 11
19 // CS - Pin 8
20 //
21 #define __PROG_TYPES_COMPAT__
22 
23 #ifndef EtherCard_h
24 #define EtherCard_h
25 
26 
27 #if ARDUINO >= 100
28 #include <Arduino.h> // Arduino 1.0
29 #define WRITE_RESULT size_t
30 #define WRITE_RETURN return 1;
31 #else
32 #include <WProgram.h> // Arduino 0022
33 #define WRITE_RESULT void
34 #define WRITE_RETURN
35 #endif
36 
37 #include <avr/pgmspace.h>
38 #include "enc28j60.h"
39 #include "net.h"
40 
41 /** This type definition defines the structure of a UDP server event handler callback funtion */
42 typedef void (*UdpServerCallback)(
43  uint16_t dest_port, ///< Port the packet was sent to
44  uint8_t src_ip[4], ///< IP address of the sender
45  const char *data, ///< UDP payload data
46  uint16_t len); ///< Length of the payload data
47 
48 /** This structure describes the structure of memory used within the ENC28J60 network interface. */
49 typedef struct {
50  uint8_t count; ///< Number of allocated pages
51  uint8_t first; ///< First allocated page
52  uint8_t last; ///< Last allocated page
53 } StashHeader;
54 
55 /** This class provides access to the memory within the ENC28J60 network interface. */
56 class Stash : public /*Stream*/ Print, private StashHeader {
57  uint8_t curr; //!< Current page
58  uint8_t offs; //!< Current offset in page
59 
60  typedef struct {
61  union {
62  uint8_t bytes[64];
63  uint16_t words[32];
64  struct {
65  StashHeader head;
66  uint8_t filler[59];
67  uint8_t tail;
68  uint8_t next;
69  };
70  };
71  uint8_t bnum;
72  } Block;
73 
74  static uint8_t allocBlock ();
75  static void freeBlock (uint8_t block);
76  static uint8_t fetchByte (uint8_t blk, uint8_t off);
77 
78  static Block bufs[2];
79  static uint8_t map[256/8];
80 
81 public:
82  static void initMap (uint8_t last);
83  static void load (uint8_t idx, uint8_t blk);
84  static uint8_t freeCount ();
85 
86  Stash () : curr (0) { first = 0; }
87  Stash (uint8_t fd) { open(fd); }
88 
89  uint8_t create ();
90  uint8_t open (uint8_t blk);
91  void save ();
92  void release ();
93 
94  void put (char c);
95  char get ();
96  uint16_t size ();
97 
98  virtual WRITE_RESULT write(uint8_t b) { put(b); WRITE_RETURN }
99 
100  // virtual int available() {
101  // if (curr != last)
102  // return 1;
103  // load(1, last);
104  // return offs < bufs[1].tail;
105  // }
106  // virtual int read() {
107  // return available() ? get() : -1;
108  // }
109  // virtual int peek() {
110  // return available() ? bufs[1].bytes[offs] : -1;
111  // }
112  // virtual void flush() {
113  // curr = last;
114  // offs = 63;
115  // }
116 
117  static void prepare (PGM_P fmt, ...);
118  static uint16_t length ();
119  static void extract (uint16_t offset, uint16_t count, void* buf);
120  static void cleanup ();
121 
122  friend void dumpBlock (const char* msg, uint8_t idx); // optional
123  friend void dumpStash (const char* msg, void* ptr); // optional
124 };
125 
126 /** This class populates network send / recieve buffers.
127 * Provides print type access to buffer
128 */
129 class BufferFiller : public Print {
130  uint8_t *start; //!< Pointer to start of buffer
131  uint8_t *ptr; //!< Pointer to cursor position
132 public:
133  /** @brief Empty constructor
134  */
136 
137  /** @brief Constructor
138  * @param buf Pointer to the ethernet data buffer
139  */
140  BufferFiller (uint8_t* buf) : start (buf), ptr (buf) {}
141 
142  /** @brief Add formatted text to buffer
143  * @param fmt Format string
144  * @param ... parameters for format string
145  */
146  void emit_p (PGM_P fmt, ...);
147 
148  /** @brief Add data to buffer from character buffer
149  * @param s Pointer to data
150  * @param n Number of characters to copy
151  */
152  void emit_raw (const char* s, uint16_t n) { memcpy(ptr, s, n); ptr += n; }
153 
154  /** @brief Add data to buffer from program space string
155  * @param p Program space string pointer
156  * @param n Number of characters to copy
157  */
158  void emit_raw_p (PGM_P p, uint16_t n) { memcpy_P(ptr, p, n); ptr += n; }
159 
160  /** @brief Get pointer to start of buffer
161  * @return <i>uint8_t*</i> Pointer to start of buffer
162  */
163  uint8_t* buffer () const { return start; }
164 
165  /** @brief Get cursor position
166  * @return <i>uint16_t</i> Cursor postion
167  */
168  uint16_t position () const { return ptr - start; }
169 
170  /** @brief Write one byte to buffer
171  * @param v Byte to add to buffer
172  */
173  virtual WRITE_RESULT write (uint8_t v) { *ptr++ = v; WRITE_RETURN }
174 };
175 
176 /** This class provides the main interface to a ENC28J60 based network interface card and is the class most users will use.
177 * @note All TCP/IP client (outgoing) connections are made from source port in range 2816-3071. Do not use these source ports for other purposes.
178 */
179 class EtherCard : public Ethernet {
180 public:
181  static uint8_t mymac[6]; ///< MAC address
182  static uint8_t myip[4]; ///< IP address
183  static uint8_t netmask[4]; ///< Netmask
184  static uint8_t broadcastip[4]; ///< Subnet broadcast address
185  static uint8_t gwip[4]; ///< Gateway
186  static uint8_t dhcpip[4]; ///< DHCP server IP address
187  static uint8_t dnsip[4]; ///< DNS server IP address
188  static uint8_t hisip[4]; ///< DNS lookup result
189  static uint16_t hisport; ///< TCP port to connect to (default 80)
190  static bool using_dhcp; ///< True if using DHCP
191  static bool persist_tcp_connection; ///< False to break connections on first packet received
192 
193  // EtherCard.cpp
194  /** @brief Initialise the network interface
195  * @param size Size of data buffer
196  * @param macaddr Hardware address to assign to the network interface (6 bytes)
197  * @param csPin Arduino pin number connected to chip select. Default = 8
198  * @return <i>uint8_t</i> Firmware version or zero on failure.
199  */
200  static uint8_t begin (const uint16_t size, const uint8_t* macaddr,
201  uint8_t csPin =8);
202 
203  /** @brief Configure network interface with static IP
204  * @param my_ip IP address (4 bytes). 0 for no change.
205  * @param gw_ip Gateway address (4 bytes). 0 for no change. Default = 0
206  * @param dns_ip DNS address (4 bytes). 0 for no change. Default = 0
207  * @param mask Subnet mask (4 bytes). 0 for no change. Default = 0
208  * @return <i>bool</i> Returns true on success - actually always true
209  */
210  static bool staticSetup (const uint8_t* my_ip,
211  const uint8_t* gw_ip = 0,
212  const uint8_t* dns_ip = 0,
213  const uint8_t* mask = 0);
214 
215  // tcpip.cpp
216  /** @brief Does not seem to be implemented
217  * @todo Remove declaration or impelement
218  */
219  static void initIp (uint8_t *myip, uint16_t wwwp);
220 
221  /** @brief Sends a UDP packet to the IP address of last processed recieved packet
222  * @param data Pointer to data payload
223  * @param len Size of data payload (max 220)
224  * @param port Destination IP port
225  */
226  static void makeUdpReply (char *data, uint8_t len, uint16_t port);
227 
228  /** @brief Parse recieved data
229  * @param plen Size of data to parse (e.g. return value of packetRecieve()).
230  * @return <i>uint16_t</i> Offset of TCP payload data in data buffer or zero if packet processed
231  * @note Data buffer is shared by recieve and transmit functions
232  * @note Only handles ARP and IP
233  */
234  static uint16_t packetLoop (uint16_t plen);
235 
236  /** @brief Accept a TCP/IP connection
237  * @param port IP port to accept on - do nothing if wrong port
238  * @param plen Number of bytes in packet
239  * @return <i>uint16_t</i> Offset within packet of TCP payload. Zero for no data.
240  */
241  static uint16_t accept (uint16_t port, uint16_t plen);
242 
243  /** @brief Send a respons to a HTTP request
244  * @param dlen Size of the HTTP (TCP) payload
245  */
246  static void httpServerReply (uint16_t dlen);
247 
248  /** @brief Send a response to a HTTP request
249  * @param dlen Size of the HTTP (TCP) payload
250  * @param flags TCP flags
251  */
252  static void httpServerReply_with_flags (uint16_t dlen , uint8_t flags);
253 
254  /** @brief Aknowledge TCP message
255  * @todo Is this / should this be private?
256  */
257  static void httpServerReplyAck ();
258 
259  /** @brief Set the gateway address
260  * @param gwipaddr Gateway address (4 bytes)
261  */
262  static void setGwIp (const uint8_t *gwipaddr);
263 
264  /** @brief Updates the broadcast address based on current IP address and subnet mask
265  */
266  static void updateBroadcastAddress();
267 
268  /** @brief Check if got gateway hardware address (ARP lookup)
269  * @return <i>unit8_t</i> True if gateway found
270  */
271  static uint8_t clientWaitingGw ();
272 
273  /** @brief
274  * @todo Document clientTcpReq
275  * @return <i>unit8_t</i>
276  */
277  static uint8_t clientTcpReq (uint8_t (*r)(uint8_t,uint8_t,uint16_t,uint16_t),
278  uint16_t (*d)(uint8_t),uint16_t port);
279 
280  /** @brief
281  * @todo Document browseUrl
282  */
283  static void browseUrl (prog_char *urlbuf, const char *urlbuf_varpart,
284  prog_char *hoststr, const prog_char *additionalheaderline,
285  void (*callback)(uint8_t,uint16_t,uint16_t));
286 
287  /** @brief
288  * @todo Document browseUrl
289  */
290  static void browseUrl (prog_char *urlbuf, const char *urlbuf_varpart,
291  prog_char *hoststr,
292  void (*callback)(uint8_t,uint16_t,uint16_t));
293 
294  /** @brief
295  * @todo Document httpPost
296  */
297  static void httpPost (prog_char *urlbuf, prog_char *hoststr,
298  prog_char *additionalheaderline, const char *postval,
299  void (*callback)(uint8_t,uint16_t,uint16_t));
300 
301  /** @brief Send NTP request
302  * @param ntpip IP address of NTP server
303  * @param srcport IP port to send from
304  */
305  static void ntpRequest (uint8_t *ntpip,uint8_t srcport);
306 
307  /** @brief Process network time protocol response
308  * @param time Pointer to integer to hold result
309  * @param dstport_l Destination port to expect response. Set to zero to accept on any port
310  * @return <i>uint8_t</i> True (1) on success
311  */
312  static uint8_t ntpProcessAnswer (uint32_t *time, uint8_t dstport_l);
313 
314  /** @brief Prepare a UDP message for transmission
315  * @param sport Source port
316  * @param dip Pointer to 4 byte destination IP address
317  * @param dport Destination port
318  */
319  static void udpPrepare (uint16_t sport, const uint8_t *dip, uint16_t dport);
320 
321  /** @brief Transmit UDP packet
322  * @param len Size of payload
323  */
324  static void udpTransmit (uint16_t len);
325 
326  /** @brief Sends a UDP packet
327  * @param data Pointer to data
328  * @param len Size of payload (maximum 220 octets / bytes)
329  * @param sport Source port
330  * @param dip Pointer to 4 byte destination IP address
331  * @param dport Destination port
332  */
333  static void sendUdp (const char *data, uint8_t len, uint16_t sport,
334  const uint8_t *dip, uint16_t dport);
335 
336  /** @brief Resister the function to handle ping events
337  * @param cb Pointer to function
338  */
339  static void registerPingCallback (void (*cb)(uint8_t*));
340 
341  /** @brief Send ping
342  * @param destip Ponter to 4 byte destination IP address
343  */
344  static void clientIcmpRequest (const uint8_t *destip);
345 
346  /** @brief Check for ping response
347  * @param ip_monitoredhost Pointer to 4 byte IP address of host to check
348  * @return <i>uint8_t</i> True (1) if ping response from specified host
349  */
350  static uint8_t packetLoopIcmpCheckReply (const uint8_t *ip_monitoredhost);
351 
352  /** @brief Send a wake on lan message
353  * @param wolmac Pointer to 6 byte hardware (MAC) address of host to send message to
354  */
355  static void sendWol (uint8_t *wolmac);
356 
357  // new stash-based API
358  /** @brief Send TCP request
359  */
360  static uint8_t tcpSend ();
361 
362  /** @brief Get TCP reply
363  * @return <i>char*</i> Pointer to TCP reply payload. NULL if no data.
364  */
365  static const char* tcpReply (uint8_t fd);
366 
367  /** @brief Configure TCP connections to be persistent or not
368  * @param persist True to maintain TCP connection. False to finish TCP connection after first packet.
369  */
370  static void persistTcpConnection(bool persist);
371 
372  //udpserver.cpp
373  /** @brief Register function to handle incomint UDP events
374  * @param callback Function to handle event
375  * @param port Port to listen on
376  */
377  static void udpServerListenOnPort(UdpServerCallback callback, uint16_t port);
378 
379  /** @brief Pause listing on UDP port
380  * @brief port Port to pause
381  */
382  static void udpServerPauseListenOnPort(uint16_t port);
383 
384  /** @brief Resume listing on UDP port
385  * @brief port Port to pause
386  */
387  static void udpServerResumeListenOnPort(uint16_t port);
388 
389  /** @brief Check if UDP server is listening on any ports
390  * @return <i>bool</i> True if listening on any ports
391  */
392  static bool udpServerListening(); //called by tcpip, in packetLoop
393 
394  /** @brief Passes packet to UDP Server
395  * @param len Not used
396  * @return <i>bool</i> True if packet processed
397  */
398  static bool udpServerHasProcessedPacket(uint16_t len); //called by tcpip, in packetLoop
399 
400  // dhcp.cpp
401  /** @brief Update DHCP state
402  * @param len Length of recieved data packet
403  */
404  static void DhcpStateMachine(uint16_t len);
405 
406  /** @brief Not implemented
407  * @todo Implement dhcpStartTime or remove declaration
408  */
409  static uint32_t dhcpStartTime ();
410 
411  /** @brief Not implemented
412  * @todo Implement dhcpLeaseTime or remove declaration
413  */
414  static uint32_t dhcpLeaseTime ();
415 
416  /** @brief Not implemented
417  * @todo Implement dhcpLease or remove declaration
418  */
419  static bool dhcpLease ();
420 
421  /** @brief Configure network interface with DHCP
422  * @return <i>bool</i> True if DHCP successful
423  * @note Blocks until DHCP complete or timeout after 60 seconds
424  */
425  static bool dhcpSetup ();
426 
427  // dns.cpp
428  /** @brief Perform DNS lookup
429  * @param name Host name to lookup
430  * @param fromRam Set true to look up cached name. Default = false
431  * @return <i>bool</i> True on success.
432  * @note Result is stored in <i>hisip</i> member
433  */
434  static bool dnsLookup (const prog_char* name, bool fromRam =false);
435 
436  // webutil.cpp
437  /** @brief Copies an IP address
438  * @param dst Pointer to the 4 byte destination
439  * @param src Pointer to the 4 byte source
440  * @note There is no check of source or destination size. Ensure both are 4 bytes
441  */
442  static void copyIp (uint8_t *dst, const uint8_t *src);
443 
444  /** @brief Copies a hardware address
445  * @param dst Pointer to the 6 byte destination
446  * @param src Pointer to the 6 byte destination
447  * @note There is no check of source or destination size. Ensure both are 6 bytes
448  */
449  static void copyMac (uint8_t *dst, const uint8_t *src);
450 
451  /** @brief Output to serial port in dotted decimal IP format
452  * @param buf Pointer to 4 byte IP address
453  * @note There is no check of source or destination size. Ensure both are 4 bytes
454  */
455  static void printIp (const uint8_t *buf);
456 
457  /** @brief Output message and IP address to serial port in dotted decimal IP format
458  * @param msg Pointer to null terminated string
459  * @param buf Pointer to 4 byte IP address
460  * @note There is no check of source or destination size. Ensure both are 4 bytes
461  */
462  static void printIp (const char* msg, const uint8_t *buf);
463 
464  /** @brief Output Flash String Helper and IP address to serial port in dotted decimal IP format
465  * @param ifsh Pointer to Flash String Helper
466  * @param buf Pointer to 4 byte IP address
467  * @note There is no check of source or destination size. Ensure both are 4 bytes
468  * @todo What is a FlashStringHelper?
469  */
470  static void printIp (const __FlashStringHelper *ifsh, const uint8_t *buf);
471 
472  /** @brief Search for a string of the form key=value in a string that looks like q?xyz=abc&uvw=defgh HTTP/1.1\\r\\n
473  * @param str Pointer to the null terminated string to search
474  * @param strbuf Pointer to buffer to hold null terminated result string
475  * @param maxlen Maximum length of result
476  * @param key Pointer to null terminated string holding the key to search for
477  * @return <i>unit_t</i> Length of the value. 0 if not found
478  * @note Ensure strbuf has memory allocated of at least maxlen + 1 (to accomodate result plus terminating null)
479  */
480  static uint8_t findKeyVal(const char *str,char *strbuf,
481  uint8_t maxlen, const char *key);
482 
483  /** @brief Decode a URL string e.g "hello%20joe" or "hello+joe" becomes "hello joe"
484  * @param urlbuf Pointer to the null terminated URL
485  * @note urlbuf is modified
486  */
487  static void urlDecode(char *urlbuf);
488 
489  /** @brief Encode a URL, replacing illegal charaters like ' '
490  * @param str Pointer to the null terminated string to encode
491  * @param urlbuf Pointer to a buffer to contain the null terminated encoded URL
492  * @note There must be enough space in urlbuf. In the worst case that is 3 times the length of str
493  */
494  static void urlEncode(char *str,char *urlbuf);
495 
496  /** @brief Convert an IP address from dotted decimal formated string to 4 bytes
497  * @param bytestr Pointer to the 4 byte array to store IP address
498  * @param str Pointer to string to parse
499  * @return <i>uint8_t</i> 0 on success
500  */
501  static uint8_t parseIp(uint8_t *bytestr,char *str);
502 
503  /** @brief Convert a byte array to a human readable display string
504  * @param resultstr Pointer to a buffer to hold the resulting null terminated string
505  * @param bytestr Pointer to the byte array containing the address to convert
506  * @param len Length of the array (4 for IP address, 6 for hardware (MAC) address)
507  * @param separator Delimiter character (typically '.' for IP address and ':' for hardware (MAC) address)
508  * @param base Base for numerical representation (typically 10 for IP address and 16 for hardware (MAC) address
509  */
510  static void makeNetStr(char *resultstr,uint8_t *bytestr,uint8_t len,
511  char separator,uint8_t base);
512 };
513 
514 extern EtherCard ether; //!< Global presentation of EtherCard class
515 
516 #endif
static uint32_t dhcpStartTime()
Not implemented.
static uint8_t broadcastip[4]
Subnet broadcast address.
Definition: EtherCard.h:184
static void httpServerReplyAck()
Aknowledge TCP message.
Definition: tcpip.cpp:275
static uint8_t clientTcpReq(uint8_t(*r)(uint8_t, uint8_t, uint16_t, uint16_t), uint16_t(*d)(uint8_t), uint16_t port)
Definition: tcpip.cpp:479
static uint8_t clientWaitingGw()
Check if got gateway hardware address (ARP lookup)
Definition: tcpip.cpp:420
static void httpPost(prog_char *urlbuf, prog_char *hoststr, prog_char *additionalheaderline, const char *postval, void(*callback)(uint8_t, uint16_t, uint16_t))
Definition: tcpip.cpp:544
void emit_p(PGM_P fmt,...)
Add formatted text to buffer.
Definition: EtherCard.cpp:270
static uint8_t findKeyVal(const char *str, char *strbuf, uint8_t maxlen, const char *key)
Search for a string of the form key=value in a string that looks like q?xyz=abc&uvw=defgh HTTP/1...
Definition: webutil.cpp:43
static void DhcpStateMachine(uint16_t len)
Update DHCP state.
Definition: dhcp.cpp:286
uint16_t position() const
Get cursor position.
Definition: EtherCard.h:168
static void setGwIp(const uint8_t *gwipaddr)
Set the gateway address.
Definition: tcpip.cpp:436
BufferFiller()
Empty constructor.
Definition: EtherCard.h:135
static uint16_t packetLoop(uint16_t plen)
Parse recieved data.
Definition: tcpip.cpp:623
static void ntpRequest(uint8_t *ntpip, uint8_t srcport)
Send NTP request.
Definition: tcpip.cpp:308
uint8_t first
First allocated page.
Definition: EtherCard.h:51
static uint8_t netmask[4]
Netmask.
Definition: EtherCard.h:183
static void updateBroadcastAddress()
Updates the broadcast address based on current IP address and subnet mask.
Definition: tcpip.cpp:441
static uint8_t begin(const uint16_t size, const uint8_t *macaddr, uint8_t csPin=8)
Initialise the network interface.
Definition: EtherCard.cpp:347
static uint8_t ntpProcessAnswer(uint32_t *time, uint8_t dstport_l)
Process network time protocol response.
Definition: tcpip.cpp:330
static uint16_t hisport
TCP port to connect to (default 80)
Definition: EtherCard.h:189
static void clientIcmpRequest(const uint8_t *destip)
Send ping.
Definition: tcpip.cpp:287
static bool udpServerHasProcessedPacket(uint16_t len)
Passes packet to UDP Server.
Definition: udpserver.cpp:54
static void registerPingCallback(void(*cb)(uint8_t *))
Resister the function to handle ping events.
Definition: tcpip.cpp:588
static void browseUrl(prog_char *urlbuf, const char *urlbuf_varpart, prog_char *hoststr, const prog_char *additionalheaderline, void(*callback)(uint8_t, uint16_t, uint16_t))
Definition: tcpip.cpp:534
static void httpServerReply_with_flags(uint16_t dlen, uint8_t flags)
Send a response to a HTTP request.
Definition: tcpip.cpp:280
void emit_raw_p(PGM_P p, uint16_t n)
Add data to buffer from program space string.
Definition: EtherCard.h:158
BufferFiller(uint8_t *buf)
Constructor.
Definition: EtherCard.h:140
static void urlEncode(char *str, char *urlbuf)
Encode a URL, replacing illegal charaters like ' '.
Definition: webutil.cpp:128
static void sendWol(uint8_t *wolmac)
Send a wake on lan message.
Definition: tcpip.cpp:380
uint8_t * buffer() const
Get pointer to start of buffer.
Definition: EtherCard.h:163
virtual WRITE_RESULT write(uint8_t v)
Write one byte to buffer.
Definition: EtherCard.h:173
static uint8_t gwip[4]
Gateway.
Definition: EtherCard.h:185
static void udpTransmit(uint16_t len)
Transmit UDP packet.
Definition: tcpip.cpp:361
This class populates network send / recieve buffers.
Definition: EtherCard.h:129
This class provides access to the memory within the ENC28J60 network interface.
Definition: EtherCard.h:56
static void udpPrepare(uint16_t sport, const uint8_t *dip, uint16_t dport)
Prepare a UDP message for transmission.
Definition: tcpip.cpp:341
static uint16_t accept(uint16_t port, uint16_t plen)
Accept a TCP/IP connection.
Definition: tcpip.cpp:599
static uint8_t tcpSend()
Send TCP request.
Definition: tcpip.cpp:576
static bool dhcpLease()
Not implemented.
static void udpServerPauseListenOnPort(uint16_t port)
Pause listing on UDP port.
Definition: udpserver.cpp:32
static void httpServerReply(uint16_t dlen)
Send a respons to a HTTP request.
Definition: tcpip.cpp:258
static bool persist_tcp_connection
False to break connections on first packet received.
Definition: EtherCard.h:191
static bool udpServerListening()
Check if UDP server is listening on any ports.
Definition: udpserver.cpp:50
This class provide low-level interfacing with the ENC28J60 network interface.
Definition: enc28j60.h:17
static bool staticSetup(const uint8_t *my_ip, const uint8_t *gw_ip=0, const uint8_t *dns_ip=0, const uint8_t *mask=0)
Configure network interface with static IP.
Definition: EtherCard.cpp:356
static void udpServerListenOnPort(UdpServerCallback callback, uint16_t port)
Register function to handle incomint UDP events.
Definition: udpserver.cpp:24
static uint8_t myip[4]
IP address.
Definition: EtherCard.h:182
static void makeNetStr(char *resultstr, uint8_t *bytestr, uint8_t len, char separator, uint8_t base)
Convert a byte array to a human readable display string.
Definition: webutil.cpp:184
static void udpServerResumeListenOnPort(uint16_t port)
Resume listing on UDP port.
Definition: udpserver.cpp:41
static void persistTcpConnection(bool persist)
Configure TCP connections to be persistent or not.
Definition: tcpip.cpp:749
static uint8_t parseIp(uint8_t *bytestr, char *str)
Convert an IP address from dotted decimal formated string to 4 bytes.
Definition: webutil.cpp:152
uint8_t count
Number of allocated pages.
Definition: EtherCard.h:50
static void makeUdpReply(char *data, uint8_t len, uint16_t port)
Sends a UDP packet to the IP address of last processed recieved packet.
Definition: tcpip.cpp:182
static bool dhcpSetup()
Configure network interface with DHCP.
Definition: dhcp.cpp:263
static void initIp(uint8_t *myip, uint16_t wwwp)
Does not seem to be implemented.
static uint32_t dhcpLeaseTime()
Not implemented.
static void sendUdp(const char *data, uint8_t len, uint16_t sport, const uint8_t *dip, uint16_t dport)
Sends a UDP packet.
Definition: tcpip.cpp:371
static uint8_t hisip[4]
DNS lookup result.
Definition: EtherCard.h:188
uint8_t last
Last allocated page.
Definition: EtherCard.h:52
static uint8_t packetLoopIcmpCheckReply(const uint8_t *ip_monitoredhost)
Check for ping response.
Definition: tcpip.cpp:592
static const char * tcpReply(uint8_t fd)
Get TCP reply.
Definition: tcpip.cpp:581
static bool using_dhcp
True if using DHCP.
Definition: EtherCard.h:190
static void copyIp(uint8_t *dst, const uint8_t *src)
Copies an IP address.
Definition: webutil.cpp:9
static bool dnsLookup(const prog_char *name, bool fromRam=false)
Perform DNS lookup.
Definition: dns.cpp:81
static uint8_t dhcpip[4]
DHCP server IP address.
Definition: EtherCard.h:186
void emit_raw(const char *s, uint16_t n)
Add data to buffer from character buffer.
Definition: EtherCard.h:152
static uint8_t mymac[6]
MAC address.
Definition: EtherCard.h:181
static void printIp(const uint8_t *buf)
Output to serial port in dotted decimal IP format.
Definition: webutil.cpp:29
static void urlDecode(char *urlbuf)
Decode a URL string e.g "hello%20joe" or "hello+joe" becomes "hello joe".
Definition: webutil.cpp:94
This structure describes the structure of memory used within the ENC28J60 network interface...
Definition: EtherCard.h:49
static void copyMac(uint8_t *dst, const uint8_t *src)
Copies a hardware address.
Definition: webutil.cpp:13
static uint8_t dnsip[4]
DNS server IP address.
Definition: EtherCard.h:187
This class provides the main interface to a ENC28J60 based network interface card and is the class mo...
Definition: EtherCard.h:179