Network Services

Dependents:   PwrCond_mbed5

Fork of W5500Interface_K22F by Andrew McCartney

Committer:
dgriffin65
Date:
Thu Jun 15 20:29:03 2017 +0000
Revision:
15:14382459c8b7
Converted to a single library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dgriffin65 15:14382459c8b7 1 // DHCPClient.h 2013/4/10
dgriffin65 15:14382459c8b7 2 #ifndef DHCPCLIENT_H
dgriffin65 15:14382459c8b7 3 #define DHCPCLIENT_H
dgriffin65 15:14382459c8b7 4 #include "wiznet.h"
dgriffin65 15:14382459c8b7 5 #include "UDPSocket.h"
dgriffin65 15:14382459c8b7 6
dgriffin65 15:14382459c8b7 7 #define DHCP_OFFSET_OP 0
dgriffin65 15:14382459c8b7 8 #define DHCP_OFFSET_XID 4
dgriffin65 15:14382459c8b7 9 #define DHCP_OFFSET_YIADDR 16
dgriffin65 15:14382459c8b7 10 #define DHCP_OFFSET_SIADDR 20
dgriffin65 15:14382459c8b7 11 #define DHCP_OFFSET_OPTIONS 240
dgriffin65 15:14382459c8b7 12 #define DHCP_MAX_PACKET_SIZE 600
dgriffin65 15:14382459c8b7 13
dgriffin65 15:14382459c8b7 14 // DHCP Message Type
dgriffin65 15:14382459c8b7 15 #define DHCPDISCOVER 1
dgriffin65 15:14382459c8b7 16 #define DHCPOFFER 2
dgriffin65 15:14382459c8b7 17 #define DHCPREQUEST 3
dgriffin65 15:14382459c8b7 18 #define DHCPDECLINE 4
dgriffin65 15:14382459c8b7 19 #define DHCPACK 5
dgriffin65 15:14382459c8b7 20 #define DHCPNAK 6
dgriffin65 15:14382459c8b7 21 #define DHCPRELEASE 7
dgriffin65 15:14382459c8b7 22 #define DHCPINFORM 8
dgriffin65 15:14382459c8b7 23
dgriffin65 15:14382459c8b7 24 class DHCPClient {
dgriffin65 15:14382459c8b7 25 public:
dgriffin65 15:14382459c8b7 26 DHCPClient();
dgriffin65 15:14382459c8b7 27 int setup(NetworkStack *ns, int timeout_ms = 15*1000);
dgriffin65 15:14382459c8b7 28 uint8_t chaddr[6]; // MAC
dgriffin65 15:14382459c8b7 29 uint8_t yiaddr[4]; // IP
dgriffin65 15:14382459c8b7 30 uint8_t dnsaddr[4]; // DNS
dgriffin65 15:14382459c8b7 31 uint8_t gateway[4];
dgriffin65 15:14382459c8b7 32 uint8_t netmask[4];
dgriffin65 15:14382459c8b7 33 uint8_t siaddr[4];
dgriffin65 15:14382459c8b7 34 private:
dgriffin65 15:14382459c8b7 35 int discover();
dgriffin65 15:14382459c8b7 36 int request();
dgriffin65 15:14382459c8b7 37 int offer(uint8_t buf[], int size);
dgriffin65 15:14382459c8b7 38 void add_buf(uint8_t* buf, int len);
dgriffin65 15:14382459c8b7 39 void fill_buf(int len, uint8_t data = 0x00);
dgriffin65 15:14382459c8b7 40 void add_buf(uint8_t c);
dgriffin65 15:14382459c8b7 41 void add_option(uint8_t code, uint8_t* buf = NULL, int len = 0);
dgriffin65 15:14382459c8b7 42 bool verify(uint8_t buf[], int len);
dgriffin65 15:14382459c8b7 43 void callback();
dgriffin65 15:14382459c8b7 44 UDPSocket* m_udp;
dgriffin65 15:14382459c8b7 45 SocketAddress m_server;
dgriffin65 15:14382459c8b7 46 uint8_t xid[4];
dgriffin65 15:14382459c8b7 47 bool exit_flag;
dgriffin65 15:14382459c8b7 48 Timer m_interval;
dgriffin65 15:14382459c8b7 49 int m_retry;
dgriffin65 15:14382459c8b7 50 uint8_t m_buf[DHCP_MAX_PACKET_SIZE];
dgriffin65 15:14382459c8b7 51 int m_pos;
dgriffin65 15:14382459c8b7 52 //WIZnet_Chip* eth;
dgriffin65 15:14382459c8b7 53 };
dgriffin65 15:14382459c8b7 54 #endif //DHCPCLIENT_H