This is WIZnet Ethernet Interface using Hardware TCP/IP chip, W5500, W5200 and W5100. One of them can be selected by enabling it in wiznet.h.
Fork of WIZnet_Library by
WIZnetInterface/DHCPClient/DHCPClient.h@9:8b3bc4434031, 2016-03-15 (annotated)
- Committer:
- rohangala
- Date:
- Tue Mar 15 11:36:55 2016 +0000
- Revision:
- 9:8b3bc4434031
- Parent:
- 0:b72d22e10709
final without caliberated;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jbkim | 0:b72d22e10709 | 1 | // DHCPClient.h 2013/4/10 |
jbkim | 0:b72d22e10709 | 2 | #ifndef DHCPCLIENT_H |
jbkim | 0:b72d22e10709 | 3 | #define DHCPCLIENT_H |
jbkim | 0:b72d22e10709 | 4 | #include "wiznet.h" |
jbkim | 0:b72d22e10709 | 5 | #include "UDPSocket.h" |
jbkim | 0:b72d22e10709 | 6 | |
jbkim | 0:b72d22e10709 | 7 | #define DHCP_OFFSET_OP 0 |
jbkim | 0:b72d22e10709 | 8 | #define DHCP_OFFSET_XID 4 |
jbkim | 0:b72d22e10709 | 9 | #define DHCP_OFFSET_YIADDR 16 |
jbkim | 0:b72d22e10709 | 10 | #define DHCP_OFFSET_SIADDR 20 |
jbkim | 0:b72d22e10709 | 11 | #define DHCP_OFFSET_OPTIONS 240 |
jbkim | 0:b72d22e10709 | 12 | #define DHCP_MAX_PACKET_SIZE 600 |
jbkim | 0:b72d22e10709 | 13 | |
jbkim | 0:b72d22e10709 | 14 | // DHCP Message Type |
jbkim | 0:b72d22e10709 | 15 | #define DHCPDISCOVER 1 |
jbkim | 0:b72d22e10709 | 16 | #define DHCPOFFER 2 |
jbkim | 0:b72d22e10709 | 17 | #define DHCPREQUEST 3 |
jbkim | 0:b72d22e10709 | 18 | #define DHCPDECLINE 4 |
jbkim | 0:b72d22e10709 | 19 | #define DHCPACK 5 |
jbkim | 0:b72d22e10709 | 20 | #define DHCPNAK 6 |
jbkim | 0:b72d22e10709 | 21 | #define DHCPRELEASE 7 |
jbkim | 0:b72d22e10709 | 22 | #define DHCPINFORM 8 |
jbkim | 0:b72d22e10709 | 23 | |
jbkim | 0:b72d22e10709 | 24 | class DHCPClient { |
jbkim | 0:b72d22e10709 | 25 | public: |
jbkim | 0:b72d22e10709 | 26 | DHCPClient(); |
jbkim | 0:b72d22e10709 | 27 | int setup(int timeout_ms = 15*1000); |
jbkim | 0:b72d22e10709 | 28 | uint8_t chaddr[6]; // MAC |
jbkim | 0:b72d22e10709 | 29 | uint8_t yiaddr[4]; // IP |
jbkim | 0:b72d22e10709 | 30 | uint8_t dnsaddr[4]; // DNS |
jbkim | 0:b72d22e10709 | 31 | uint8_t gateway[4]; |
jbkim | 0:b72d22e10709 | 32 | uint8_t netmask[4]; |
jbkim | 0:b72d22e10709 | 33 | uint8_t siaddr[4]; |
jbkim | 0:b72d22e10709 | 34 | private: |
jbkim | 0:b72d22e10709 | 35 | int discover(); |
jbkim | 0:b72d22e10709 | 36 | int request(); |
jbkim | 0:b72d22e10709 | 37 | int offer(uint8_t buf[], int size); |
jbkim | 0:b72d22e10709 | 38 | void add_buf(uint8_t* buf, int len); |
jbkim | 0:b72d22e10709 | 39 | void fill_buf(int len, uint8_t data = 0x00); |
jbkim | 0:b72d22e10709 | 40 | void add_buf(uint8_t c); |
jbkim | 0:b72d22e10709 | 41 | void add_option(uint8_t code, uint8_t* buf = NULL, int len = 0); |
jbkim | 0:b72d22e10709 | 42 | bool verify(uint8_t buf[], int len); |
jbkim | 0:b72d22e10709 | 43 | void callback(); |
jbkim | 0:b72d22e10709 | 44 | UDPSocket* m_udp; |
jbkim | 0:b72d22e10709 | 45 | Endpoint m_server; |
jbkim | 0:b72d22e10709 | 46 | uint8_t xid[4]; |
jbkim | 0:b72d22e10709 | 47 | bool exit_flag; |
jbkim | 0:b72d22e10709 | 48 | Timer m_interval; |
jbkim | 0:b72d22e10709 | 49 | int m_retry; |
jbkim | 0:b72d22e10709 | 50 | uint8_t m_buf[DHCP_MAX_PACKET_SIZE]; |
jbkim | 0:b72d22e10709 | 51 | int m_pos; |
jbkim | 0:b72d22e10709 | 52 | WIZnet_Chip* eth; |
jbkim | 0:b72d22e10709 | 53 | }; |
jbkim | 0:b72d22e10709 | 54 | #endif //DHCPCLIENT_H |
jbkim | 0:b72d22e10709 | 55 |