MQTT client test with W5200 ethernet shield
Dependents: IBMIoTClientEthernetExample_W5200
Fork of W5500Interface by
DHCPClient/DHCPClient.h@0:e11e8793c3ce, 2014-08-20 (annotated)
- Committer:
- Bongjun
- Date:
- Wed Aug 20 00:28:37 2014 +0000
- Revision:
- 0:e11e8793c3ce
first release.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bongjun | 0:e11e8793c3ce | 1 | // DHCPClient.h 2013/4/10 |
Bongjun | 0:e11e8793c3ce | 2 | #ifndef DHCPCLIENT_H |
Bongjun | 0:e11e8793c3ce | 3 | #define DHCPCLIENT_H |
Bongjun | 0:e11e8793c3ce | 4 | #include "wiznet.h" |
Bongjun | 0:e11e8793c3ce | 5 | #include "UDPSocket.h" |
Bongjun | 0:e11e8793c3ce | 6 | |
Bongjun | 0:e11e8793c3ce | 7 | #define DHCP_OFFSET_OP 0 |
Bongjun | 0:e11e8793c3ce | 8 | #define DHCP_OFFSET_XID 4 |
Bongjun | 0:e11e8793c3ce | 9 | #define DHCP_OFFSET_YIADDR 16 |
Bongjun | 0:e11e8793c3ce | 10 | #define DHCP_OFFSET_SIADDR 20 |
Bongjun | 0:e11e8793c3ce | 11 | #define DHCP_OFFSET_OPTIONS 240 |
Bongjun | 0:e11e8793c3ce | 12 | #define DHCP_MAX_PACKET_SIZE 600 |
Bongjun | 0:e11e8793c3ce | 13 | |
Bongjun | 0:e11e8793c3ce | 14 | // DHCP Message Type |
Bongjun | 0:e11e8793c3ce | 15 | #define DHCPDISCOVER 1 |
Bongjun | 0:e11e8793c3ce | 16 | #define DHCPOFFER 2 |
Bongjun | 0:e11e8793c3ce | 17 | #define DHCPREQUEST 3 |
Bongjun | 0:e11e8793c3ce | 18 | #define DHCPDECLINE 4 |
Bongjun | 0:e11e8793c3ce | 19 | #define DHCPACK 5 |
Bongjun | 0:e11e8793c3ce | 20 | #define DHCPNAK 6 |
Bongjun | 0:e11e8793c3ce | 21 | #define DHCPRELEASE 7 |
Bongjun | 0:e11e8793c3ce | 22 | #define DHCPINFORM 8 |
Bongjun | 0:e11e8793c3ce | 23 | |
Bongjun | 0:e11e8793c3ce | 24 | class DHCPClient { |
Bongjun | 0:e11e8793c3ce | 25 | public: |
Bongjun | 0:e11e8793c3ce | 26 | DHCPClient(); |
Bongjun | 0:e11e8793c3ce | 27 | int setup(int timeout_ms = 15*1000); |
Bongjun | 0:e11e8793c3ce | 28 | uint8_t chaddr[6]; // MAC |
Bongjun | 0:e11e8793c3ce | 29 | uint8_t yiaddr[4]; // IP |
Bongjun | 0:e11e8793c3ce | 30 | uint8_t dnsaddr[4]; // DNS |
Bongjun | 0:e11e8793c3ce | 31 | uint8_t gateway[4]; |
Bongjun | 0:e11e8793c3ce | 32 | uint8_t netmask[4]; |
Bongjun | 0:e11e8793c3ce | 33 | uint8_t siaddr[4]; |
Bongjun | 0:e11e8793c3ce | 34 | private: |
Bongjun | 0:e11e8793c3ce | 35 | int discover(); |
Bongjun | 0:e11e8793c3ce | 36 | int request(); |
Bongjun | 0:e11e8793c3ce | 37 | int offer(uint8_t buf[], int size); |
Bongjun | 0:e11e8793c3ce | 38 | void add_buf(uint8_t* buf, int len); |
Bongjun | 0:e11e8793c3ce | 39 | void fill_buf(int len, uint8_t data = 0x00); |
Bongjun | 0:e11e8793c3ce | 40 | void add_buf(uint8_t c); |
Bongjun | 0:e11e8793c3ce | 41 | void add_option(uint8_t code, uint8_t* buf = NULL, int len = 0); |
Bongjun | 0:e11e8793c3ce | 42 | bool verify(uint8_t buf[], int len); |
Bongjun | 0:e11e8793c3ce | 43 | void callback(); |
Bongjun | 0:e11e8793c3ce | 44 | UDPSocket* m_udp; |
Bongjun | 0:e11e8793c3ce | 45 | Endpoint m_server; |
Bongjun | 0:e11e8793c3ce | 46 | uint8_t xid[4]; |
Bongjun | 0:e11e8793c3ce | 47 | bool exit_flag; |
Bongjun | 0:e11e8793c3ce | 48 | Timer m_interval; |
Bongjun | 0:e11e8793c3ce | 49 | int m_retry; |
Bongjun | 0:e11e8793c3ce | 50 | uint8_t m_buf[DHCP_MAX_PACKET_SIZE]; |
Bongjun | 0:e11e8793c3ce | 51 | int m_pos; |
Bongjun | 0:e11e8793c3ce | 52 | WIZnet_Chip* eth; |
Bongjun | 0:e11e8793c3ce | 53 | }; |
Bongjun | 0:e11e8793c3ce | 54 | #endif //DHCPCLIENT_H |