source: ctrl/firmware/Main/SES/Wiznet/Internet/DHCP/dhcp.h

Last change on this file was 79, checked in by Zed, 3 months ago

DHCP client can get IP-address from fritz!box

File size: 5.2 KB
Line 
1//*****************************************************************************
2//
3//! \file dhcp.h
4//! \brief DHCP APIs Header file.
5//! \details Processig DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
6//! \version 1.1.1
7//! \date 2019/10/08
8//! \par  Revision history
9//!       <2019/10/08> compare DHCP server ip address
10//!       <2013/11/18> 1st Release
11//!       <2012/12/20> V1.1.0
12//!         1. Move unreferenced DEFINE to dhcp.c
13//!       <2012/12/26> V1.1.1
14//! \author Eric Jung & MidnightCow
15//! \copyright
16//!
17//! Copyright (c)  2013, WIZnet Co., LTD.
18//! All rights reserved.
19//!
20//! Redistribution and use in source and binary forms, with or without
21//! modification, are permitted provided that the following conditions
22//! are met:
23//!
24//!     * Redistributions of source code must retain the above copyright
25//! notice, this list of conditions and the following disclaimer.
26//!     * Redistributions in binary form must reproduce the above copyright
27//! notice, this list of conditions and the following disclaimer in the
28//! documentation and/or other materials provided with the distribution.
29//!     * Neither the name of the <ORGANIZATION> nor the names of its
30//! contributors may be used to endorse or promote products derived
31//! from this software without specific prior written permission.
32//!
33//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35//! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
37//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
43//! THE POSSIBILITY OF SUCH DAMAGE.
44//
45//*****************************************************************************
46#ifndef _DHCP_H_
47#define _DHCP_H_
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53/*
54 * @brief
55 * @details If you want to display debug & processing message, Define _DHCP_DEBUG_
56 * @note    If defined, it depends on <stdio.h>
57 */
58//#define _DHCP_DEBUG_
59
60
61/* Retry to processing DHCP */
62#define MAX_DHCP_RETRY          2        ///< Maximum retry count
63#define DHCP_WAIT_TIME          10       ///< Wait Time 10s
64
65
66/* UDP port numbers for DHCP */
67#define DHCP_SERVER_PORT        67            ///< DHCP server port number
68#define DHCP_CLIENT_PORT         68           ///< DHCP client port number
69
70
71#define MAGIC_COOKIE             0x63825363  ///< You should not modify it number.
72
73#define DCHP_HOST_NAME           "WIZnet\0"
74
75/*
76 * @brief return value of @ref DHCP_run()
77 */
78enum
79{
80   DHCP_FAILED = 0,  ///< Processing Fail
81   DHCP_RUNNING,     ///< Processing DHCP protocol
82   DHCP_IP_ASSIGN,   ///< First Occupy IP from DHPC server      (if cbfunc == null, act as default default_ip_assign)
83   DHCP_IP_CHANGED,  ///< Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update)
84   DHCP_IP_LEASED,   ///< Stand by
85   DHCP_STOPPED      ///< Stop processing DHCP protocol
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 */
93void DHCP_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 */
99void DHCP_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 */
107void reg_dhcp_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 DHCP_FAILED     \n
113 *            @ref DHCP_RUNNING    \n
114 *            @ref DHCP_IP_ASSIGN  \n
115 *            @ref DHCP_IP_CHANGED \n
116 *                        @ref DHCP_IP_LEASED  \n
117 *            @ref DHCP_STOPPED    \n
118 *
119 * @note This function is always called by you main task.
120 */ 
121uint8_t DHCP_run(void);
122
123/*
124 * @brief Stop DHCP processing
125 * @note If you want to restart. call DHCP_init() and DHCP_run()
126 */ 
127void    DHCP_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 */
134void getIPfromDHCP(uint8_t* ip);
135/*
136 * @brief Get Gateway address
137 * @param ip  - Gateway address to be returned
138 */
139void getGWfromDHCP(uint8_t* ip);
140/*
141 * @brief Get Subnet mask value
142 * @param ip  - Subnet mask to be returned
143 */
144void getSNfromDHCP(uint8_t* ip);
145/*
146 * @brief Get DNS address
147 * @param ip  - DNS address to be returned
148 */
149void getDNSfromDHCP(uint8_t* ip);
150
151/*
152 * @brief Get the leased time by DHCP sever
153 * @return unit 1s
154 */
155uint32_t getDHCPLeasetime(void);
156
157#ifdef __cplusplus
158}
159#endif
160
161#endif  /* _DHCP_H_ */
Note: See TracBrowser for help on using the repository browser.