io6Library
WIZnet Dual Stack TCP/IP Ethernet Controller Driver
dhcpv4.h
Go to the documentation of this file.
1 //*****************************************************************************
2 //
44 //
45 //*****************************************************************************
46 #ifndef _DHCP_H_
47 #define _DHCP_H_
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 /*
54  * @brief
55  * @details If you want to display debug & processing message, Define _DHCPV4_DEBUG_
56  * @note If defined, it depends on <stdio.h>
57  */
58 //#define _DHCPV4_DEBUG_
59 
60 
61 /* Retry to processing DHCP */
62 #define MAX_DHCPV4_RETRY 2
63 #define DHCPV4_WAIT_TIME 10
64 
65 
66 /* UDP port numbers for DHCP */
67 #define DHCPV4_SERVER_PORT 67
68 #define DHCPV4_CLIENT_PORT 68
69 
70 
71 #define MAGIC_COOKIE 0x63825363
72 
73 #define DCHPV4_HOST_NAME "WIZnet\0"
74 
75 /*
76  * @brief return value of @ref DHCPv4_run()
77  */
78 enum
79 {
86 };
87 
88 /*
89  * @brief DHCP client initialization (outside of the main loop)
90  * @param s - socket number
91  * @param buf - buffer for processing DHCP message
92  */
93 void DHCPv4_init(uint8_t s, uint8_t * buf);
94 
95 /*
96  * @brief DHCP 1s Tick Timer handler
97  * @note SHOULD BE register to your system 1s Tick timer handler
98  */
99 void DHCPv4_time_handler(void);
100 
101 /*
102  * @brief Register call back function
103  * @param ip_assign - callback func when IP is assigned from DHCP server first
104  * @param ip_update - callback func when IP is changed
105  * @param ip_conflict - callback func when the assigned IP is conflict with others.
106  */
107 void reg_dhcpv4_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void));
108 
109 /*
110  * @brief DHCP client in the main loop
111  * @return The value is as the follow \n
112  * @ref DHCPV4_FAILED \n
113  * @ref DHCPv4_runNING \n
114  * @ref DHCP_IPV4_ASSIGN \n
115  * @ref DHCP_IPV4_CHANGED \n
116  * @ref DHCP_IPV4_LEASED \n
117  * @ref DHCPV4_STOPPED \n
118  *
119  * @note This function is always called by you main task.
120  */
121 uint8_t DHCPv4_run(void);
122 
123 /*
124  * @brief Stop DHCP processing
125  * @note If you want to restart. call DHCPv4_init() and DHCPv4_run()
126  */
127 void DHCPv4_stop(void);
128 
129 /* Get Network information assigned from DHCP server */
130 /*
131  * @brief Get IP address
132  * @param ip - IP address to be returned
133  */
134 void getIPfromDHCPv4(uint8_t* ip);
135 /*
136  * @brief Get Gateway address
137  * @param ip - Gateway address to be returned
138  */
139 void getGWfromDHCPv4(uint8_t* ip);
140 /*
141  * @brief Get Subnet mask value
142  * @param ip - Subnet mask to be returned
143  */
144 void getSNfromDHCPv4(uint8_t* ip);
145 /*
146  * @brief Get DNS address
147  * @param ip - DNS address to be returned
148  */
149 void getDNSfromDHCPv4(uint8_t* ip);
150 
151 /*
152  * @brief Get the leased time by DHCP sever
153  * @return unit 1s
154  */
155 uint32_t getDHCPv4Leasetime(void);
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #endif /* _DHCP_H_ */
getIPfromDHCPv4
void getIPfromDHCPv4(uint8_t *ip)
Definition: dhcpv4.c:974
getDHCPv4Leasetime
uint32_t getDHCPv4Leasetime(void)
Definition: dhcpv4.c:1006
DHCP_IPV4_LEASED
@ DHCP_IPV4_LEASED
Stand by.
Definition: dhcpv4.h:84
getSNfromDHCPv4
void getSNfromDHCPv4(uint8_t *ip)
Definition: dhcpv4.c:990
DHCP_IPV4_CHANGED
@ DHCP_IPV4_CHANGED
Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update)
Definition: dhcpv4.h:83
DHCPv4_time_handler
void DHCPv4_time_handler(void)
Definition: dhcpv4.c:969
DHCP_IPV4_ASSIGN
@ DHCP_IPV4_ASSIGN
First Occupy IP from DHPC server (if cbfunc == null, act as default default_ip_assign)
Definition: dhcpv4.h:82
getGWfromDHCPv4
void getGWfromDHCPv4(uint8_t *ip)
Definition: dhcpv4.c:982
DHCPv4_stop
void DHCPv4_stop(void)
Definition: dhcpv4.c:838
DHCPV4_FAILED
@ DHCPV4_FAILED
Processing Fail.
Definition: dhcpv4.h:80
getDNSfromDHCPv4
void getDNSfromDHCPv4(uint8_t *ip)
Definition: dhcpv4.c:998
DHCPV4_STOPPED
@ DHCPV4_STOPPED
Stop processing DHCP protocol.
Definition: dhcpv4.h:85
DHCPv4_init
void DHCPv4_init(uint8_t s, uint8_t *buf)
Definition: dhcpv4.c:932
DHCPv4_run
uint8_t DHCPv4_run(void)
Definition: dhcpv4.c:707
reg_dhcpv4_cbfunc
void reg_dhcpv4_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void))
Definition: dhcpv4.c:284
DHCPV4_RUNNING
@ DHCPV4_RUNNING
Processing DHCP protocol.
Definition: dhcpv4.h:81