WIZnetInterface using namespace
Dependents: DualNetworkInterface-Basic
Fork of WIZnetInterface by
Socket/DHCPClient.hpp@20:3e61863c1f67, 2015-07-14 (annotated)
- Committer:
- SteveKim
- Date:
- Tue Jul 14 10:16:16 2015 +0000
- Revision:
- 20:3e61863c1f67
- Parent:
- Socket/DHCPClient.h@0:6f28332c466f
Dual Network Interface for mbed; - WIZwiki-W7500; - ESP8266
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Soohwan Kim |
0:6f28332c466f | 1 | // DHCPClient.h 2013/4/10 |
Soohwan Kim |
0:6f28332c466f | 2 | #ifndef DHCPCLIENT_H |
Soohwan Kim |
0:6f28332c466f | 3 | #define DHCPCLIENT_H |
SteveKim | 20:3e61863c1f67 | 4 | #include "eth_arch.hpp" |
SteveKim | 20:3e61863c1f67 | 5 | #include "UDPSocket.hpp" |
Soohwan Kim |
0:6f28332c466f | 6 | |
Soohwan Kim |
0:6f28332c466f | 7 | #define DHCP_OFFSET_OP 0 |
Soohwan Kim |
0:6f28332c466f | 8 | #define DHCP_OFFSET_XID 4 |
Soohwan Kim |
0:6f28332c466f | 9 | #define DHCP_OFFSET_YIADDR 16 |
Soohwan Kim |
0:6f28332c466f | 10 | #define DHCP_OFFSET_SIADDR 20 |
Soohwan Kim |
0:6f28332c466f | 11 | #define DHCP_OFFSET_OPTIONS 240 |
Soohwan Kim |
0:6f28332c466f | 12 | #define DHCP_MAX_PACKET_SIZE 600 |
Soohwan Kim |
0:6f28332c466f | 13 | |
Soohwan Kim |
0:6f28332c466f | 14 | // DHCP Message Type |
Soohwan Kim |
0:6f28332c466f | 15 | #define DHCPDISCOVER 1 |
Soohwan Kim |
0:6f28332c466f | 16 | #define DHCPOFFER 2 |
Soohwan Kim |
0:6f28332c466f | 17 | #define DHCPREQUEST 3 |
Soohwan Kim |
0:6f28332c466f | 18 | #define DHCPDECLINE 4 |
Soohwan Kim |
0:6f28332c466f | 19 | #define DHCPACK 5 |
Soohwan Kim |
0:6f28332c466f | 20 | #define DHCPNAK 6 |
Soohwan Kim |
0:6f28332c466f | 21 | #define DHCPRELEASE 7 |
Soohwan Kim |
0:6f28332c466f | 22 | #define DHCPINFORM 8 |
Soohwan Kim |
0:6f28332c466f | 23 | |
SteveKim | 20:3e61863c1f67 | 24 | namespace wiznet_space { |
SteveKim | 20:3e61863c1f67 | 25 | |
Soohwan Kim |
0:6f28332c466f | 26 | class DHCPClient { |
Soohwan Kim |
0:6f28332c466f | 27 | public: |
Soohwan Kim |
0:6f28332c466f | 28 | DHCPClient(); |
Soohwan Kim |
0:6f28332c466f | 29 | int setup(int timeout_ms = 15*1000); |
Soohwan Kim |
0:6f28332c466f | 30 | uint8_t chaddr[6]; // MAC |
Soohwan Kim |
0:6f28332c466f | 31 | uint8_t yiaddr[4]; // IP |
Soohwan Kim |
0:6f28332c466f | 32 | uint8_t dnsaddr[4]; // DNS |
Soohwan Kim |
0:6f28332c466f | 33 | uint8_t gateway[4]; |
Soohwan Kim |
0:6f28332c466f | 34 | uint8_t netmask[4]; |
Soohwan Kim |
0:6f28332c466f | 35 | uint8_t siaddr[4]; |
Soohwan Kim |
0:6f28332c466f | 36 | private: |
Soohwan Kim |
0:6f28332c466f | 37 | int discover(); |
Soohwan Kim |
0:6f28332c466f | 38 | int request(); |
Soohwan Kim |
0:6f28332c466f | 39 | int offer(uint8_t buf[], int size); |
Soohwan Kim |
0:6f28332c466f | 40 | void add_buf(uint8_t* buf, int len); |
Soohwan Kim |
0:6f28332c466f | 41 | void fill_buf(int len, uint8_t data = 0x00); |
Soohwan Kim |
0:6f28332c466f | 42 | void add_buf(uint8_t c); |
Soohwan Kim |
0:6f28332c466f | 43 | void add_option(uint8_t code, uint8_t* buf = NULL, int len = 0); |
Soohwan Kim |
0:6f28332c466f | 44 | bool verify(uint8_t buf[], int len); |
Soohwan Kim |
0:6f28332c466f | 45 | void callback(); |
Soohwan Kim |
0:6f28332c466f | 46 | UDPSocket* m_udp; |
Soohwan Kim |
0:6f28332c466f | 47 | Endpoint m_server; |
Soohwan Kim |
0:6f28332c466f | 48 | uint8_t xid[4]; |
Soohwan Kim |
0:6f28332c466f | 49 | bool exit_flag; |
Soohwan Kim |
0:6f28332c466f | 50 | Timer m_interval; |
Soohwan Kim |
0:6f28332c466f | 51 | int m_retry; |
Soohwan Kim |
0:6f28332c466f | 52 | uint8_t m_buf[DHCP_MAX_PACKET_SIZE]; |
Soohwan Kim |
0:6f28332c466f | 53 | int m_pos; |
Soohwan Kim |
0:6f28332c466f | 54 | WIZnet_Chip* eth; |
Soohwan Kim |
0:6f28332c466f | 55 | }; |
SteveKim | 20:3e61863c1f67 | 56 | |
SteveKim | 20:3e61863c1f67 | 57 | } |
SteveKim | 20:3e61863c1f67 | 58 | |
Soohwan Kim |
0:6f28332c466f | 59 | #endif //DHCPCLIENT_H |
Soohwan Kim |
0:6f28332c466f | 60 |