WIZnetInterface using namespace

Dependents:   DualNetworkInterface-Basic

Fork of WIZnetInterface by WIZnet

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DHCPClient.hpp Source File

DHCPClient.hpp

00001 // DHCPClient.h 2013/4/10
00002 #ifndef DHCPCLIENT_H
00003 #define DHCPCLIENT_H
00004 #include "eth_arch.hpp"
00005 #include "UDPSocket.hpp"
00006 
00007 #define DHCP_OFFSET_OP 0
00008 #define DHCP_OFFSET_XID 4
00009 #define DHCP_OFFSET_YIADDR 16
00010 #define DHCP_OFFSET_SIADDR 20
00011 #define DHCP_OFFSET_OPTIONS 240
00012 #define DHCP_MAX_PACKET_SIZE 600
00013 
00014 // DHCP Message Type
00015 #define DHCPDISCOVER 1
00016 #define DHCPOFFER    2
00017 #define DHCPREQUEST  3
00018 #define DHCPDECLINE  4
00019 #define DHCPACK      5
00020 #define DHCPNAK      6
00021 #define DHCPRELEASE  7
00022 #define DHCPINFORM   8
00023 
00024 namespace wiznet_space {
00025     
00026 class DHCPClient {
00027 public:
00028     DHCPClient();
00029     int setup(int timeout_ms = 15*1000);
00030     uint8_t chaddr[6]; // MAC
00031     uint8_t yiaddr[4]; // IP
00032     uint8_t dnsaddr[4]; // DNS
00033     uint8_t gateway[4];
00034     uint8_t netmask[4];
00035     uint8_t siaddr[4];
00036 private:
00037     int discover();
00038     int request();
00039     int offer(uint8_t buf[], int size);
00040     void add_buf(uint8_t* buf, int len);
00041     void fill_buf(int len, uint8_t data = 0x00);
00042     void add_buf(uint8_t c);
00043     void add_option(uint8_t code, uint8_t* buf = NULL, int len = 0);
00044     bool verify(uint8_t buf[], int len);
00045     void callback();
00046     UDPSocket* m_udp;
00047     Endpoint m_server;
00048     uint8_t xid[4];
00049     bool exit_flag;
00050     Timer m_interval;
00051     int m_retry;
00052     uint8_t m_buf[DHCP_MAX_PACKET_SIZE];
00053     int m_pos;
00054     WIZnet_Chip* eth;
00055 };
00056 
00057 }
00058 
00059 #endif //DHCPCLIENT_H
00060