1

Dependents:   internet_radio_leo

Fork of WIZnetInterface by WIZnet

Committer:
WizLeo
Date:
Wed Jun 29 04:41:34 2016 +0000
Revision:
28:0baaa2970201
Parent:
0:6f28332c466f
1

Who changed what in which revision?

UserRevisionLine numberNew 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
Soohwan Kim 0:6f28332c466f 4 #include "eth_arch.h"
Soohwan Kim 0:6f28332c466f 5 #include "UDPSocket.h"
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
Soohwan Kim 0:6f28332c466f 24 class DHCPClient {
Soohwan Kim 0:6f28332c466f 25 public:
Soohwan Kim 0:6f28332c466f 26 DHCPClient();
Soohwan Kim 0:6f28332c466f 27 int setup(int timeout_ms = 15*1000);
Soohwan Kim 0:6f28332c466f 28 uint8_t chaddr[6]; // MAC
Soohwan Kim 0:6f28332c466f 29 uint8_t yiaddr[4]; // IP
Soohwan Kim 0:6f28332c466f 30 uint8_t dnsaddr[4]; // DNS
Soohwan Kim 0:6f28332c466f 31 uint8_t gateway[4];
Soohwan Kim 0:6f28332c466f 32 uint8_t netmask[4];
Soohwan Kim 0:6f28332c466f 33 uint8_t siaddr[4];
Soohwan Kim 0:6f28332c466f 34 private:
Soohwan Kim 0:6f28332c466f 35 int discover();
Soohwan Kim 0:6f28332c466f 36 int request();
Soohwan Kim 0:6f28332c466f 37 int offer(uint8_t buf[], int size);
Soohwan Kim 0:6f28332c466f 38 void add_buf(uint8_t* buf, int len);
Soohwan Kim 0:6f28332c466f 39 void fill_buf(int len, uint8_t data = 0x00);
Soohwan Kim 0:6f28332c466f 40 void add_buf(uint8_t c);
Soohwan Kim 0:6f28332c466f 41 void add_option(uint8_t code, uint8_t* buf = NULL, int len = 0);
Soohwan Kim 0:6f28332c466f 42 bool verify(uint8_t buf[], int len);
Soohwan Kim 0:6f28332c466f 43 void callback();
Soohwan Kim 0:6f28332c466f 44 UDPSocket* m_udp;
Soohwan Kim 0:6f28332c466f 45 Endpoint m_server;
Soohwan Kim 0:6f28332c466f 46 uint8_t xid[4];
Soohwan Kim 0:6f28332c466f 47 bool exit_flag;
Soohwan Kim 0:6f28332c466f 48 Timer m_interval;
Soohwan Kim 0:6f28332c466f 49 int m_retry;
Soohwan Kim 0:6f28332c466f 50 uint8_t m_buf[DHCP_MAX_PACKET_SIZE];
Soohwan Kim 0:6f28332c466f 51 int m_pos;
Soohwan Kim 0:6f28332c466f 52 WIZnet_Chip* eth;
Soohwan Kim 0:6f28332c466f 53 };
Soohwan Kim 0:6f28332c466f 54 #endif //DHCPCLIENT_H
Soohwan Kim 0:6f28332c466f 55