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 type definition defines the structure of a DHCP Option callback funtion */
49 typedef void (*DhcpOptionCallback)(
50  uint8_t option, ///< The option number
51  const byte* data, ///< DHCP option data
52  uint8_t len); ///< Length of the DHCP option data
53 
54 
55 /** This structure describes the structure of memory used within the ENC28J60 network interface. */
56 typedef struct {
57  uint8_t count; ///< Number of allocated pages
58  uint8_t first; ///< First allocated page
59  uint8_t last; ///< Last allocated page
60 } StashHeader;
61 
62 /** This class provides access to the memory within the ENC28J60 network interface. */
63 class Stash : public /*Stream*/ Print, private StashHeader {
64  uint8_t curr; //!< Current page
65  uint8_t offs; //!< Current offset in page
66 
67  typedef struct {
68  union {
69  uint8_t bytes[64];
70  uint16_t words[32];
71  struct {
72  StashHeader head;
73  uint8_t filler[59];
74  uint8_t tail;
75  uint8_t next;
76  };
77  };
78  uint8_t bnum;
79  } Block;
80 
81  static uint8_t allocBlock ();
82  static void freeBlock (uint8_t block);
83  static uint8_t fetchByte (uint8_t blk, uint8_t off);
84 
85  static Block bufs[2];
86  static uint8_t map[256/8];
87 
88 public:
89  static void initMap (uint8_t last);
90  static void load (uint8_t idx, uint8_t blk);
91  static uint8_t freeCount ();
92 
93  Stash () : curr (0) { first = 0; }
94  Stash (uint8_t fd) { open(fd); }
95 
96  uint8_t create ();
97  uint8_t open (uint8_t blk);
98  void save ();
99  void release ();
100 
101  void put (char c);
102  char get ();
103  uint16_t size ();
104 
105  virtual WRITE_RESULT write(uint8_t b) { put(b); WRITE_RETURN }
106 
107  // virtual int available() {
108  // if (curr != last)
109  // return 1;
110  // load(1, last);
111  // return offs < bufs[1].tail;
112  // }
113  // virtual int read() {
114  // return available() ? get() : -1;
115  // }
116  // virtual int peek() {
117  // return available() ? bufs[1].bytes[offs] : -1;
118  // }
119  // virtual void flush() {
120  // curr = last;
121  // offs = 63;
122  // }
123 
124  static void prepare (PGM_P fmt, ...);
125  static uint16_t length ();
126  static void extract (uint16_t offset, uint16_t count, void* buf);
127  static void cleanup ();
128 
129  friend void dumpBlock (const char* msg, uint8_t idx); // optional
130  friend void dumpStash (const char* msg, void* ptr); // optional
131 };
132 
133 /** This class populates network send and receive buffers.
134 *
135 * This class provides formatted printing into memory. Users can use it to write into send buffers.
136 *
137 * Nota: PGM_P: is a pointer to a string in program space (defined in the source code)
138 *
139 * # Format string
140 *
141 * | Format | Parameter | Output
142 * |--------|-------------|----------
143 * | $D | uint16_t | Decimal representation
144 * | $T ¤ | double | Decimal representation with 3 digits after decimal sign ([-]d.ddd)
145 * | $H | uint16_t | Hexadecimal value of lsb (from 00 to ff)
146 * | $L | long | Decimal representation
147 * | $S | const char* | Copy null terminated string from main memory
148 * | $F | PGM_P | Copy null terminated string from program space
149 * | $E | byte* | Copy null terminated string from EEPROM space
150 * | $$ | _none_ | '$'
151 *
152 * ¤ _Available only if FLOATEMIT is defined_
153 *
154 * # Examples
155 * ~~~~~~~~~~~~~{.c}
156 * uint16_t ddd = 123;
157 * double ttt = 1.23;
158 * uint16_t hhh = 0xa4;
159 * long lll = 123456789;
160 * char * sss;
161 * char fff[] PROGMEM = "MyMemory";
162 *
163 * sss[0] = 'G';
164 * sss[1] = 'P';
165 * sss[2] = 'L';
166 * sss[3] = 0;
167 * buf.emit_p( PSTR("ddd=$D\n"), ddd ); // "ddd=123\n"
168 * buf.emit_p( PSTR("ttt=$T\n"), ttt ); // "ttt=1.23\n" **TO CHECK**
169 * buf.emit_p( PSTR("hhh=$H\n"), hhh ); // "hhh=a4\n"
170 * buf.emit_p( PSTR("lll=$L\n"), lll ); // "lll=123456789\n"
171 * buf.emit_p( PSTR("sss=$S\n"), sss ); // "sss=GPL\n"
172 * buf.emit_p( PSTR("fff=$F\n"), fff ); // "fff=MyMemory\n"
173 * ~~~~~~~~~~~~~
174 *
175 */
176 class BufferFiller : public Print {
177  uint8_t *start; //!< Pointer to start of buffer
178  uint8_t *ptr; //!< Pointer to cursor position
179 public:
180  /** @brief Empty constructor
181  */
183 
184  /** @brief Constructor
185  * @param buf Pointer to the ethernet data buffer
186  */
187  BufferFiller (uint8_t* buf) : start (buf), ptr (buf) {}
188 
189  /** @brief Add formatted text to buffer
190  * @param fmt Format string (see Class description)
191  * @param ... parameters for format string
192  */
193  void emit_p (PGM_P fmt, ...);
194 
195  /** @brief Add data to buffer from main memory
196  * @param s Pointer to data
197  * @param n Number of characters to copy
198  */
199  void emit_raw (const char* s, uint16_t n) { memcpy(ptr, s, n); ptr += n; }
200 
201  /** @brief Add data to buffer from program space string
202  * @param p Program space string pointer
203  * @param n Number of characters to copy
204  */
205  void emit_raw_p (PGM_P p, uint16_t n) { memcpy_P(ptr, p, n); ptr += n; }
206 
207  /** @brief Get pointer to start of buffer
208  * @return <i>uint8_t*</i> Pointer to start of buffer
209  */
210  uint8_t* buffer () const { return start; }
211 
212  /** @brief Get cursor position
213  * @return <i>uint16_t</i> Cursor postion
214  */
215  uint16_t position () const { return ptr - start; }
216 
217  /** @brief Write one byte to buffer
218  * @param v Byte to add to buffer
219  */
220  virtual WRITE_RESULT write (uint8_t v) { *ptr++ = v; WRITE_RETURN }
221 };
222 
223 /** This class provides the main interface to a ENC28J60 based network interface card and is the class most users will use.
224 * @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.
225 */
226 class EtherCard : public Ethernet {
227 public:
228  static uint8_t mymac[6]; ///< MAC address
229  static uint8_t myip[4]; ///< IP address
230  static uint8_t netmask[4]; ///< Netmask
231  static uint8_t broadcastip[4]; ///< Subnet broadcast address
232  static uint8_t gwip[4]; ///< Gateway
233  static uint8_t dhcpip[4]; ///< DHCP server IP address
234  static uint8_t dnsip[4]; ///< DNS server IP address
235  static uint8_t hisip[4]; ///< DNS lookup result
236  static uint16_t hisport; ///< TCP port to connect to (default 80)
237  static bool using_dhcp; ///< True if using DHCP
238  static bool persist_tcp_connection; ///< False to break connections on first packet received
239  static int16_t delaycnt; ///< Counts number of cycles of packetLoop when no packet recieved - used to trigger periodic gateway ARP request
240 
241  // EtherCard.cpp
242  /** @brief Initialise the network interface
243  * @param size Size of data buffer
244  * @param macaddr Hardware address to assign to the network interface (6 bytes)
245  * @param csPin Arduino pin number connected to chip select. Default = 8
246  * @return <i>uint8_t</i> Firmware version or zero on failure.
247  */
248  static uint8_t begin (const uint16_t size, const uint8_t* macaddr,
249  uint8_t csPin =8);
250 
251  /** @brief Configure network interface with static IP
252  * @param my_ip IP address (4 bytes). 0 for no change.
253  * @param gw_ip Gateway address (4 bytes). 0 for no change. Default = 0
254  * @param dns_ip DNS address (4 bytes). 0 for no change. Default = 0
255  * @param mask Subnet mask (4 bytes). 0 for no change. Default = 0
256  * @return <i>bool</i> Returns true on success - actually always true
257  */
258  static bool staticSetup (const uint8_t* my_ip,
259  const uint8_t* gw_ip = 0,
260  const uint8_t* dns_ip = 0,
261  const uint8_t* mask = 0);
262 
263  // tcpip.cpp
264  /** @brief Sends a UDP packet to the IP address of last processed recieved packet
265  * @param data Pointer to data payload
266  * @param len Size of data payload (max 220)
267  * @param port Source IP port
268  */
269  static void makeUdpReply (const char *data, uint8_t len, uint16_t port);
270 
271  /** @brief Parse recieved data
272  * @param plen Size of data to parse (e.g. return value of packetRecieve()).
273  * @return <i>uint16_t</i> Offset of TCP payload data in data buffer or zero if packet processed
274  * @note Data buffer is shared by recieve and transmit functions
275  * @note Only handles ARP and IP
276  */
277  static uint16_t packetLoop (uint16_t plen);
278 
279  /** @brief Accept a TCP/IP connection
280  * @param port IP port to accept on - do nothing if wrong port
281  * @param plen Number of bytes in packet
282  * @return <i>uint16_t</i> Offset within packet of TCP payload. Zero for no data.
283  */
284  static uint16_t accept (uint16_t port, uint16_t plen);
285 
286  /** @brief Send a respons to a HTTP request
287  * @param dlen Size of the HTTP (TCP) payload
288  */
289  static void httpServerReply (uint16_t dlen);
290 
291  /** @brief Send a response to a HTTP request
292  * @param dlen Size of the HTTP (TCP) payload
293  * @param flags TCP flags
294  */
295  static void httpServerReply_with_flags (uint16_t dlen , uint8_t flags);
296 
297  /** @brief Acknowledge TCP message
298  * @todo Is this / should this be private?
299  */
300  static void httpServerReplyAck ();
301 
302  /** @brief Set the gateway address
303  * @param gwipaddr Gateway address (4 bytes)
304  */
305  static void setGwIp (const uint8_t *gwipaddr);
306 
307  /** @brief Updates the broadcast address based on current IP address and subnet mask
308  */
309  static void updateBroadcastAddress();
310 
311  /** @brief Check if got gateway hardware address (ARP lookup)
312  * @return <i>unit8_t</i> True if gateway found
313  */
314  static uint8_t clientWaitingGw ();
315 
316  /** @brief Prepare a TCP request
317  * @param result_cb Pointer to callback function that handles TCP result
318  * @param datafill_cb Pointer to callback function that handles TCP data payload
319  * @param port Remote TCP/IP port to connect to
320  * @return <i>unit8_t</i> ID of TCP/IP session (0-7)
321  * @note Return value provides id of the request to allow up to 7 concurrent requests
322  */
323  static uint8_t clientTcpReq (uint8_t (*result_cb)(uint8_t,uint8_t,uint16_t,uint16_t),
324  uint16_t (*datafill_cb)(uint8_t),uint16_t port);
325 
326  /** @brief Prepare HTTP request
327  * @param urlbuf Pointer to c-string URL folder
328  * @param urlbuf_varpart Pointer to c-string URL file
329  * @param hoststr Pointer to c-string hostname
330  * @param additionalheaderline Pointer to c-string with additional HTTP header info
331  * @param callback Pointer to callback function to handle response
332  * @note Request sent in main packetloop
333  */
334  static void browseUrl (const char *urlbuf, const char *urlbuf_varpart,
335  const char *hoststr, const char *additionalheaderline,
336  void (*callback)(uint8_t,uint16_t,uint16_t));
337 
338  /** @brief Prepare HTTP request
339  * @param urlbuf Pointer to c-string URL folder
340  * @param urlbuf_varpart Pointer to c-string URL file
341  * @param hoststr Pointer to c-string hostname
342  * @param callback Pointer to callback function to handle response
343  * @note Request sent in main packetloop
344  */
345  static void browseUrl (const char *urlbuf, const char *urlbuf_varpart,
346  const char *hoststr,
347  void (*callback)(uint8_t,uint16_t,uint16_t));
348 
349  /** @brief Prepare HTTP post message
350  * @param urlbuf Pointer to c-string URL folder
351  * @param hoststr Pointer to c-string hostname
352  * @param additionalheaderline Pointer to c-string with additional HTTP header info
353  * @param postval Pointer to c-string HTML Post value
354  * @param callback Pointer to callback function to handle response
355  * @note Request sent in main packetloop
356  */
357  static void httpPost (const char *urlbuf, const char *hoststr,
358  const char *additionalheaderline, const char *postval,
359  void (*callback)(uint8_t,uint16_t,uint16_t));
360 
361  /** @brief Send NTP request
362  * @param ntpip IP address of NTP server
363  * @param srcport IP port to send from
364  */
365  static void ntpRequest (uint8_t *ntpip,uint8_t srcport);
366 
367  /** @brief Process network time protocol response
368  * @param time Pointer to integer to hold result
369  * @param dstport_l Destination port to expect response. Set to zero to accept on any port
370  * @return <i>uint8_t</i> True (1) on success
371  */
372  static uint8_t ntpProcessAnswer (uint32_t *time, uint8_t dstport_l);
373 
374  /** @brief Prepare a UDP message for transmission
375  * @param sport Source port
376  * @param dip Pointer to 4 byte destination IP address
377  * @param dport Destination port
378  */
379  static void udpPrepare (uint16_t sport, const uint8_t *dip, uint16_t dport);
380 
381  /** @brief Transmit UDP packet
382  * @param len Size of payload
383  */
384  static void udpTransmit (uint16_t len);
385 
386  /** @brief Sends a UDP packet
387  * @param data Pointer to data
388  * @param len Size of payload (maximum 220 octets / bytes)
389  * @param sport Source port
390  * @param dip Pointer to 4 byte destination IP address
391  * @param dport Destination port
392  */
393  static void sendUdp (const char *data, uint8_t len, uint16_t sport,
394  const uint8_t *dip, uint16_t dport);
395 
396  /** @brief Resister the function to handle ping events
397  * @param cb Pointer to function
398  */
399  static void registerPingCallback (void (*cb)(uint8_t*));
400 
401  /** @brief Send ping
402  * @param destip Ponter to 4 byte destination IP address
403  */
404  static void clientIcmpRequest (const uint8_t *destip);
405 
406  /** @brief Check for ping response
407  * @param ip_monitoredhost Pointer to 4 byte IP address of host to check
408  * @return <i>uint8_t</i> True (1) if ping response from specified host
409  */
410  static uint8_t packetLoopIcmpCheckReply (const uint8_t *ip_monitoredhost);
411 
412  /** @brief Send a wake on lan message
413  * @param wolmac Pointer to 6 byte hardware (MAC) address of host to send message to
414  */
415  static void sendWol (uint8_t *wolmac);
416 
417  // new stash-based API
418  /** @brief Send TCP request
419  */
420  static uint8_t tcpSend ();
421 
422  /** @brief Get TCP reply
423  * @return <i>char*</i> Pointer to TCP reply payload. NULL if no data.
424  */
425  static const char* tcpReply (uint8_t fd);
426 
427  /** @brief Configure TCP connections to be persistent or not
428  * @param persist True to maintain TCP connection. False to finish TCP connection after first packet.
429  */
430  static void persistTcpConnection(bool persist);
431 
432  //udpserver.cpp
433  /** @brief Register function to handle incomint UDP events
434  * @param callback Function to handle event
435  * @param port Port to listen on
436  */
437  static void udpServerListenOnPort(UdpServerCallback callback, uint16_t port);
438 
439  /** @brief Pause listing on UDP port
440  * @brief port Port to pause
441  */
442  static void udpServerPauseListenOnPort(uint16_t port);
443 
444  /** @brief Resume listing on UDP port
445  * @brief port Port to pause
446  */
447  static void udpServerResumeListenOnPort(uint16_t port);
448 
449  /** @brief Check if UDP server is listening on any ports
450  * @return <i>bool</i> True if listening on any ports
451  */
452  static bool udpServerListening(); //called by tcpip, in packetLoop
453 
454  /** @brief Passes packet to UDP Server
455  * @param len Not used
456  * @return <i>bool</i> True if packet processed
457  */
458  static bool udpServerHasProcessedPacket(uint16_t len); //called by tcpip, in packetLoop
459 
460  // dhcp.cpp
461  /** @brief Update DHCP state
462  * @param len Length of recieved data packet
463  */
464  static void DhcpStateMachine(uint16_t len);
465 
466  /** @brief Not implemented
467  * @todo Implement dhcpStartTime or remove declaration
468  */
469  static uint32_t dhcpStartTime ();
470 
471  /** @brief Not implemented
472  * @todo Implement dhcpLeaseTime or remove declaration
473  */
474  static uint32_t dhcpLeaseTime ();
475 
476  /** @brief Not implemented
477  * @todo Implement dhcpLease or remove declaration
478  */
479  static bool dhcpLease ();
480 
481  /** @brief Configure network interface with DHCP
482  * @return <i>bool</i> True if DHCP successful
483  * @note Blocks until DHCP complete or timeout after 60 seconds
484  */
485  static bool dhcpSetup ();
486 
487  /** @brief Register a callback for a specific DHCP option number
488  * @param <i>option</i> The option number to request from the DHCP server
489  * @param <i>callback</i> The function to be call when the option is received
490  */
491  static void dhcpAddOptionCallback(uint8_t option, DhcpOptionCallback callback);
492 
493  // dns.cpp
494  /** @brief Perform DNS lookup
495  * @param name Host name to lookup
496  * @param fromRam Set true to look up cached name. Default = false
497  * @return <i>bool</i> True on success.
498  * @note Result is stored in <i>hisip</i> member
499  */
500  static bool dnsLookup (const char* name, bool fromRam =false);
501 
502  // webutil.cpp
503  /** @brief Copies an IP address
504  * @param dst Pointer to the 4 byte destination
505  * @param src Pointer to the 4 byte source
506  * @note There is no check of source or destination size. Ensure both are 4 bytes
507  */
508  static void copyIp (uint8_t *dst, const uint8_t *src);
509 
510  /** @brief Copies a hardware address
511  * @param dst Pointer to the 6 byte destination
512  * @param src Pointer to the 6 byte destination
513  * @note There is no check of source or destination size. Ensure both are 6 bytes
514  */
515  static void copyMac (uint8_t *dst, const uint8_t *src);
516 
517  /** @brief Output to serial port in dotted decimal IP format
518  * @param buf Pointer to 4 byte IP address
519  * @note There is no check of source or destination size. Ensure both are 4 bytes
520  */
521  static void printIp (const uint8_t *buf);
522 
523  /** @brief Output message and IP address to serial port in dotted decimal IP format
524  * @param msg Pointer to null terminated string
525  * @param buf Pointer to 4 byte IP address
526  * @note There is no check of source or destination size. Ensure both are 4 bytes
527  */
528  static void printIp (const char* msg, const uint8_t *buf);
529 
530  /** @brief Output Flash String Helper and IP address to serial port in dotted decimal IP format
531  * @param ifsh Pointer to Flash String Helper
532  * @param buf Pointer to 4 byte IP address
533  * @note There is no check of source or destination size. Ensure both are 4 bytes
534  * @todo What is a FlashStringHelper?
535  */
536  static void printIp (const __FlashStringHelper *ifsh, const uint8_t *buf);
537 
538  /** @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
539  * @param str Pointer to the null terminated string to search
540  * @param strbuf Pointer to buffer to hold null terminated result string
541  * @param maxlen Maximum length of result
542  * @param key Pointer to null terminated string holding the key to search for
543  * @return <i>unit_t</i> Length of the value. 0 if not found
544  * @note Ensure strbuf has memory allocated of at least maxlen + 1 (to accomodate result plus terminating null)
545  */
546  static uint8_t findKeyVal(const char *str,char *strbuf,
547  uint8_t maxlen, const char *key);
548 
549  /** @brief Decode a URL string e.g "hello%20joe" or "hello+joe" becomes "hello joe"
550  * @param urlbuf Pointer to the null terminated URL
551  * @note urlbuf is modified
552  */
553  static void urlDecode(char *urlbuf);
554 
555  /** @brief Encode a URL, replacing illegal charaters like ' '
556  * @param str Pointer to the null terminated string to encode
557  * @param urlbuf Pointer to a buffer to contain the null terminated encoded URL
558  * @note There must be enough space in urlbuf. In the worst case that is 3 times the length of str
559  */
560  static void urlEncode(char *str,char *urlbuf);
561 
562  /** @brief Convert an IP address from dotted decimal formated string to 4 bytes
563  * @param bytestr Pointer to the 4 byte array to store IP address
564  * @param str Pointer to string to parse
565  * @return <i>uint8_t</i> 0 on success
566  */
567  static uint8_t parseIp(uint8_t *bytestr,char *str);
568 
569  /** @brief Convert a byte array to a human readable display string
570  * @param resultstr Pointer to a buffer to hold the resulting null terminated string
571  * @param bytestr Pointer to the byte array containing the address to convert
572  * @param len Length of the array (4 for IP address, 6 for hardware (MAC) address)
573  * @param separator Delimiter character (typically '.' for IP address and ':' for hardware (MAC) address)
574  * @param base Base for numerical representation (typically 10 for IP address and 16 for hardware (MAC) address
575  */
576  static void makeNetStr(char *resultstr,uint8_t *bytestr,uint8_t len,
577  char separator,uint8_t base);
578 };
579 
580 extern EtherCard ether; //!< Global presentation of EtherCard class
581 
582 #endif
static uint32_t dhcpStartTime()
Not implemented.
static uint8_t broadcastip[4]
Subnet broadcast address.
Definition: EtherCard.h:231
static void httpServerReplyAck()
Acknowledge TCP message.
Definition: tcpip.cpp:275
static bool dnsLookup(const char *name, bool fromRam=false)
Perform DNS lookup.
Definition: dns.cpp:88
static int16_t delaycnt
Counts number of cycles of packetLoop when no packet recieved - used to trigger periodic gateway ARP ...
Definition: EtherCard.h:239
static uint8_t clientTcpReq(uint8_t(*result_cb)(uint8_t, uint8_t, uint16_t, uint16_t), uint16_t(*datafill_cb)(uint8_t), uint16_t port)
Prepare a TCP request.
Definition: tcpip.cpp:481
static uint8_t clientWaitingGw()
Check if got gateway hardware address (ARP lookup)
Definition: tcpip.cpp:421
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:308
uint16_t position() const
Get cursor position.
Definition: EtherCard.h:215
static void setGwIp(const uint8_t *gwipaddr)
Set the gateway address.
Definition: tcpip.cpp:437
BufferFiller()
Empty constructor.
Definition: EtherCard.h:182
static uint16_t packetLoop(uint16_t plen)
Parse recieved data.
Definition: tcpip.cpp:625
static void ntpRequest(uint8_t *ntpip, uint8_t srcport)
Send NTP request.
Definition: tcpip.cpp:308
static void browseUrl(const char *urlbuf, const char *urlbuf_varpart, const char *hoststr, const char *additionalheaderline, void(*callback)(uint8_t, uint16_t, uint16_t))
Prepare HTTP request.
Definition: tcpip.cpp:536
uint8_t first
First allocated page.
Definition: EtherCard.h:58
static uint8_t netmask[4]
Netmask.
Definition: EtherCard.h:230
static void updateBroadcastAddress()
Updates the broadcast address based on current IP address and subnet mask.
Definition: tcpip.cpp:443
static uint8_t begin(const uint16_t size, const uint8_t *macaddr, uint8_t csPin=8)
Initialise the network interface.
Definition: EtherCard.cpp:348
static void makeUdpReply(const 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 uint8_t ntpProcessAnswer(uint32_t *time, uint8_t dstport_l)
Process network time protocol response.
Definition: tcpip.cpp:330
static void httpPost(const char *urlbuf, const char *hoststr, const char *additionalheaderline, const char *postval, void(*callback)(uint8_t, uint16_t, uint16_t))
Prepare HTTP post message.
Definition: tcpip.cpp:546
static uint16_t hisport
TCP port to connect to (default 80)
Definition: EtherCard.h:236
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:590
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:205
BufferFiller(uint8_t *buf)
Constructor.
Definition: EtherCard.h:187
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:381
uint8_t * buffer() const
Get pointer to start of buffer.
Definition: EtherCard.h:210
virtual WRITE_RESULT write(uint8_t v)
Write one byte to buffer.
Definition: EtherCard.h:220
static uint8_t gwip[4]
Gateway.
Definition: EtherCard.h:232
static void udpTransmit(uint16_t len)
Transmit UDP packet.
Definition: tcpip.cpp:362
This class populates network send and receive buffers.
Definition: EtherCard.h:176
This class provides access to the memory within the ENC28J60 network interface.
Definition: EtherCard.h:63
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:601
static uint8_t tcpSend()
Send TCP request.
Definition: tcpip.cpp:578
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:238
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:357
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:229
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:751
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:57
static bool dhcpSetup()
Configure network interface with DHCP.
Definition: dhcp.cpp:278
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:372
static void dhcpAddOptionCallback(uint8_t option, DhcpOptionCallback callback)
Register a callback for a specific DHCP option number.
Definition: dhcp.cpp:300
static uint8_t hisip[4]
DNS lookup result.
Definition: EtherCard.h:235
uint8_t last
Last allocated page.
Definition: EtherCard.h:59
static uint8_t packetLoopIcmpCheckReply(const uint8_t *ip_monitoredhost)
Check for ping response.
Definition: tcpip.cpp:594
static const char * tcpReply(uint8_t fd)
Get TCP reply.
Definition: tcpip.cpp:583
static bool using_dhcp
True if using DHCP.
Definition: EtherCard.h:237
static void copyIp(uint8_t *dst, const uint8_t *src)
Copies an IP address.
Definition: webutil.cpp:9
static uint8_t dhcpip[4]
DHCP server IP address.
Definition: EtherCard.h:233
void emit_raw(const char *s, uint16_t n)
Add data to buffer from main memory.
Definition: EtherCard.h:199
static uint8_t mymac[6]
MAC address.
Definition: EtherCard.h:228
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:56
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:234
This class provides the main interface to a ENC28J60 based network interface card and is the class mo...
Definition: EtherCard.h:226