提交 | 用户 | age
|
a7db3c
|
1 |
//*****************************************************************************
|
Q |
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.0
|
|
7 |
//! \date 2013/11/18
|
|
8 |
//! \par Revision history
|
|
9 |
//! <2013/11/18> 1st Release
|
|
10 |
//! <2012/12/20> V1.1.0
|
|
11 |
//! 1. Move unreferenced DEFINE to dhcp.c
|
|
12 |
//! <2012/12/26> V1.1.1
|
|
13 |
//! \author Eric Jung & MidnightCow
|
|
14 |
//! \copyright
|
|
15 |
//!
|
|
16 |
//! Copyright (c) 2013, WIZnet Co., LTD.
|
|
17 |
//! All rights reserved.
|
|
18 |
//!
|
|
19 |
//! Redistribution and use in source and binary forms, with or without
|
|
20 |
//! modification, are permitted provided that the following conditions
|
|
21 |
//! are met:
|
|
22 |
//!
|
|
23 |
//! * Redistributions of source code must retain the above copyright
|
|
24 |
//! notice, this list of conditions and the following disclaimer.
|
|
25 |
//! * Redistributions in binary form must reproduce the above copyright
|
|
26 |
//! notice, this list of conditions and the following disclaimer in the
|
|
27 |
//! documentation and/or other materials provided with the distribution.
|
|
28 |
//! * Neither the name of the <ORGANIZATION> nor the names of its
|
|
29 |
//! contributors may be used to endorse or promote products derived
|
|
30 |
//! from this software without specific prior written permission.
|
|
31 |
//!
|
|
32 |
//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
33 |
//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
34 |
//! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
35 |
//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
36 |
//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
37 |
//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
38 |
//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
39 |
//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
40 |
//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
41 |
//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
42 |
//! THE POSSIBILITY OF SUCH DAMAGE.
|
|
43 |
//
|
|
44 |
//*****************************************************************************
|
|
45 |
#ifndef _DHCP_H_
|
|
46 |
#define _DHCP_H_
|
|
47 |
|
|
48 |
/*
|
|
49 |
* @brief
|
|
50 |
* @details If you want to display debug & procssing message, Define _DHCP_DEBUG_
|
|
51 |
* @note If defined, it dependens on <stdio.h>
|
|
52 |
*/
|
|
53 |
//#define _DHCP_DEBUG_
|
|
54 |
|
|
55 |
|
|
56 |
/* Retry to processing DHCP */
|
|
57 |
#define MAX_DHCP_RETRY 2 ///< Maxium retry count
|
|
58 |
#define DHCP_WAIT_TIME 10 ///< Wait Time 10s
|
|
59 |
|
|
60 |
|
|
61 |
/* UDP port numbers for DHCP */
|
|
62 |
#define DHCP_SERVER_PORT 67 ///< DHCP server port number
|
|
63 |
#define DHCP_CLIENT_PORT 68 ///< DHCP client port number
|
|
64 |
|
|
65 |
|
|
66 |
#define MAGIC_COOKIE 0x63825363 ///< Any number. You can be modifyed it any number
|
|
67 |
|
|
68 |
#define DCHP_HOST_NAME "WIZnet\0"
|
|
69 |
|
|
70 |
/*
|
|
71 |
* @brief return value of @ref DHCP_run()
|
|
72 |
*/
|
|
73 |
enum
|
|
74 |
{
|
|
75 |
DHCP_FAILED = 0, ///< Procssing Fail
|
|
76 |
DHCP_RUNNING, ///< Procssing DHCP proctocol
|
|
77 |
DHCP_IP_ASSIGN, ///< First Occupy IP from DHPC server (if cbfunc == null, act as default default_ip_assign)
|
|
78 |
DHCP_IP_CHANGED, ///< Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update)
|
|
79 |
DHCP_IP_LEASED, ///< Stand by
|
|
80 |
DHCP_STOPPED ///< Stop procssing DHCP protocol
|
|
81 |
};
|
|
82 |
|
|
83 |
/*
|
|
84 |
* @brief DHCP client initialization (outside of the main loop)
|
|
85 |
* @param s - socket number
|
|
86 |
* @param buf - buffer for procssing DHCP message
|
|
87 |
*/
|
|
88 |
void DHCP_init(uint8_t s, uint8_t * buf);
|
|
89 |
|
|
90 |
/*
|
|
91 |
* @brief DHCP 1s Tick Timer handler
|
|
92 |
* @note SHOULD BE register to your system 1s Tick timer handler
|
|
93 |
*/
|
|
94 |
void DHCP_time_handler(void);
|
|
95 |
|
|
96 |
/*
|
|
97 |
* @brief Register call back function
|
|
98 |
* @param ip_assign - callback func when IP is assigned from DHCP server first
|
|
99 |
* @param ip_update - callback func when IP is changed
|
|
100 |
* @prarm ip_conflict - callback func when the assigned IP is conflict with others.
|
|
101 |
*/
|
|
102 |
void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void));
|
|
103 |
|
|
104 |
/*
|
|
105 |
* @brief DHCP client in the main loop
|
|
106 |
* @return The value is as the follow \n
|
|
107 |
* @ref DHCP_FAILED \n
|
|
108 |
* @ref DHCP_RUNNING \n
|
|
109 |
* @ref DHCP_IP_ASSIGN \n
|
|
110 |
* @ref DHCP_IP_CHANGED \n
|
|
111 |
* @ref DHCP_IP_LEASED \n
|
|
112 |
* @ref DHCP_STOPPED \n
|
|
113 |
*
|
|
114 |
* @note This function is always called by you main task.
|
|
115 |
*/
|
|
116 |
uint8_t DHCP_run(void);
|
|
117 |
|
|
118 |
/*
|
|
119 |
* @brief Stop DHCP procssing
|
|
120 |
* @note If you want to restart. call DHCP_init() and DHCP_run()
|
|
121 |
*/
|
|
122 |
void DHCP_stop(void);
|
|
123 |
|
|
124 |
/* Get Network information assigned from DHCP server */
|
|
125 |
/*
|
|
126 |
* @brief Get IP address
|
|
127 |
* @param ip - IP address to be returned
|
|
128 |
*/
|
|
129 |
void getIPfromDHCP(uint8_t* ip);
|
|
130 |
/*
|
|
131 |
* @brief Get Gateway address
|
|
132 |
* @param ip - Gateway address to be returned
|
|
133 |
*/
|
|
134 |
void getGWfromDHCP(uint8_t* ip);
|
|
135 |
/*
|
|
136 |
* @brief Get Subnet mask value
|
|
137 |
* @param ip - Subnet mask to be returned
|
|
138 |
*/
|
|
139 |
void getSNfromDHCP(uint8_t* ip);
|
|
140 |
/*
|
|
141 |
* @brief Get DNS address
|
|
142 |
* @param ip - DNS address to be returned
|
|
143 |
*/
|
|
144 |
void getDNSfromDHCP(uint8_t* ip);
|
|
145 |
|
|
146 |
/*
|
|
147 |
* @brief Get the leased time by DHCP sever
|
|
148 |
* @retrun unit 1s
|
|
149 |
*/
|
|
150 |
uint32_t getDHCPLeasetime(void);
|
|
151 |
|
|
152 |
#endif /* _DHCP_H_ */
|