W5500 driver for mbed OS 5

Dependents:   http-webserver-example mbed-os-example-sockets

Fork of W5500Interface by Sergei G

Committer:
Bongjun
Date:
Thu Aug 16 07:33:40 2018 +0000
Revision:
18:afec30f0922a
Parent:
9:351e20cf7d05
change spi frame bits : 32->8

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Bongjun 9:351e20cf7d05 1 /*
Bongjun 9:351e20cf7d05 2 * DHCPClient.h
Bongjun 9:351e20cf7d05 3 * Mbed OS5 support added by Sergei G <https://os.mbed.com/users/sgnezdov/>
Bongjun 9:351e20cf7d05 4 * Ported here on Aug/09/2018
Bongjun 9:351e20cf7d05 5 *
Bongjun 9:351e20cf7d05 6 */
Bongjun 6:e2ab76b2be07 7 // DHCPClient.h 2013/4/10
Bongjun 6:e2ab76b2be07 8 #ifndef DHCPCLIENT_H
Bongjun 6:e2ab76b2be07 9 #define DHCPCLIENT_H
Bongjun 6:e2ab76b2be07 10 #include "wiznet.h"
Bongjun 6:e2ab76b2be07 11 #include "UDPSocket.h"
Bongjun 6:e2ab76b2be07 12
Bongjun 6:e2ab76b2be07 13 #define DHCP_OFFSET_OP 0
Bongjun 6:e2ab76b2be07 14 #define DHCP_OFFSET_XID 4
Bongjun 6:e2ab76b2be07 15 #define DHCP_OFFSET_YIADDR 16
Bongjun 6:e2ab76b2be07 16 #define DHCP_OFFSET_SIADDR 20
Bongjun 6:e2ab76b2be07 17 #define DHCP_OFFSET_OPTIONS 240
Bongjun 6:e2ab76b2be07 18 #define DHCP_MAX_PACKET_SIZE 600
Bongjun 6:e2ab76b2be07 19
Bongjun 6:e2ab76b2be07 20 // DHCP Message Type
Bongjun 6:e2ab76b2be07 21 #define DHCPDISCOVER 1
Bongjun 6:e2ab76b2be07 22 #define DHCPOFFER 2
Bongjun 6:e2ab76b2be07 23 #define DHCPREQUEST 3
Bongjun 6:e2ab76b2be07 24 #define DHCPDECLINE 4
Bongjun 6:e2ab76b2be07 25 #define DHCPACK 5
Bongjun 6:e2ab76b2be07 26 #define DHCPNAK 6
Bongjun 6:e2ab76b2be07 27 #define DHCPRELEASE 7
Bongjun 6:e2ab76b2be07 28 #define DHCPINFORM 8
Bongjun 6:e2ab76b2be07 29
Bongjun 6:e2ab76b2be07 30 class DHCPClient {
Bongjun 6:e2ab76b2be07 31 public:
Bongjun 6:e2ab76b2be07 32 DHCPClient();
Bongjun 6:e2ab76b2be07 33 int setup(NetworkStack *ns, uint8_t mac_addr[6], int timeout_ms = 15*1000);
Bongjun 6:e2ab76b2be07 34 uint8_t chaddr[6]; // MAC
Bongjun 6:e2ab76b2be07 35 uint8_t yiaddr[4]; // IP
Bongjun 6:e2ab76b2be07 36 uint8_t dnsaddr[4]; // DNS
Bongjun 6:e2ab76b2be07 37 uint8_t gateway[4];
Bongjun 6:e2ab76b2be07 38 uint8_t netmask[4];
Bongjun 6:e2ab76b2be07 39 uint8_t siaddr[4];
Bongjun 6:e2ab76b2be07 40 private:
Bongjun 6:e2ab76b2be07 41 int discover();
Bongjun 6:e2ab76b2be07 42 int request();
Bongjun 6:e2ab76b2be07 43 int offer(uint8_t buf[], int size);
Bongjun 6:e2ab76b2be07 44 void add_buf(uint8_t* buf, int len);
Bongjun 6:e2ab76b2be07 45 void fill_buf(int len, uint8_t data = 0x00);
Bongjun 6:e2ab76b2be07 46 void add_buf(uint8_t c);
Bongjun 6:e2ab76b2be07 47 void add_option(uint8_t code, uint8_t* buf = NULL, int len = 0);
Bongjun 6:e2ab76b2be07 48 bool verify(uint8_t buf[], int len);
Bongjun 6:e2ab76b2be07 49 void callback();
Bongjun 6:e2ab76b2be07 50 UDPSocket* m_udp;
Bongjun 6:e2ab76b2be07 51 SocketAddress m_server;
Bongjun 6:e2ab76b2be07 52 uint8_t xid[4];
Bongjun 6:e2ab76b2be07 53 bool exit_flag;
Bongjun 6:e2ab76b2be07 54 Timer m_interval;
Bongjun 6:e2ab76b2be07 55 int m_retry;
Bongjun 6:e2ab76b2be07 56 uint8_t m_buf[DHCP_MAX_PACKET_SIZE];
Bongjun 6:e2ab76b2be07 57 int m_pos;
Bongjun 6:e2ab76b2be07 58 //WIZnet_Chip* eth;
Bongjun 6:e2ab76b2be07 59 };
Bongjun 6:e2ab76b2be07 60 #endif //DHCPCLIENT_H