📄 dhcp_comm.h
字号:
/******************************************************************************\
Copyright (c) 2007, UTStarcom,Inc. (ShenZhen R&D Center)
All Rights Reserved.
Subsystem : WIMAX
Group : GW/AnchorEP/DHCP
File : dhcp_comm.h
Version :
Build :
Author : kevin.shi
Maintained by : kevin.shi
Create Date : 2007-01-01
Last Modify :
Description : DHCP server/relay include file for shared data structures
\******************************************************************************/
/*
-----------------------------------------------------------
Software Develop CodeName :
Module Reference :
-----------------------------------------------------------
Change History:
07-01.01 kevin.shi create file.
*/
#ifndef _DHCP_COMM_H_
#define _DHCP_COMM_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "dhcp_client.h"
#include "global.h"
#include "dhcp_list.h"
#include "dhcp_db.h"
#include "dhcp_hash.h"
#include "dhcp.h"
#include "gw_common.h"
#include "gw_up_if.h"
//#define SUPPORT_SELF_WATCHER
#define DHCP_RESOURCE_MAX_NUM 2048
#define DHCP_BINDING_MAX_NUM 1024
#define MAX_NUM_BINDED 500 /* maximum number of dhcp_binding ( this is used in garbage_collect(); ) */
#define MAXPATHLEN 64 /* Maximum length of database names. */
/*#define DHCP_MSGQ_MAX_NUM 512
#define DHCP_MSGQ_MAX_LEN 1024*/
#define GC_INTERVAL 60 /* interval between garbage collections, now 60 seconds per 1/10 monitoring, in total, 10 minitues for all */
#define MEMORIZE 90 /* Seconds of delay before re-using offered lease. */
#define E_NOMORE -2 /* Error code: no more space in options field. */
#define DHCP_MAX_HOPS 16 /* Hops before discard, up to 16. */
#define DHCP_SPORT 67 /* Port monitored by DHCP servers */
#define DHCP_CPORT 68 /* Port monitored by DHCP clients */
#define DHCP_MAX_MSGSIZE 590 /* Allows minimum message on Ethernet */
#define DHCP_MIN_LEASE 60 /* default value of max lease (secs). */
#define DHCP_MAX_LEASE (0xffffffff) /* default value of max lease (secs). */
#define DHCP_DEFAULT_LEASE 3600 /* default lease length (secs). */
#ifndef GOOD
#define GOOD 1
#endif
#ifndef BAD
#define BAD 0
#endif
#ifdef SUPPORT_SELF_WATCHER
#include <intLib.h>
#define MAIN_TASK_NAME "tDhcp"
#define COMM_TASK_LOCK() (taskLock())
#define COMM_TASK_UNLOCK() (taskUnlock())
typedef int INTLEVEL;
#define COMM_INT_DISABLE() (intLock())
#define COMM_INT_ENABLE(spl) (intUnlock(spl))
#include <taskLib.h>
#include <sysLib.h>
#define COMM_SLEEP(millisec) do { \
taskDelay(millisec*sysClkRateGet()/1000); \
} while(0)
#define COMM_ENTER_CS(semId) (semTake(semId,WAIT_FOREVER))
#define COMM_LEAVE_CS(semId) (semGive(semId))
extern unsigned int gCommSelfWatcherCount;
extern unsigned int gCommSelfWatcherTick;
extern void Comm_StartSelfWatcher();
#endif
#define DHCP_SYS_CUR_TICKING ((unsigned int)tickGet())
extern char * gDhcpStateString[];
extern char * gDhcpMsgString[];
extern char * gDhcpActingString[];
#ifdef _DHCP_DEBUG_
#define DHCP_TRACE_ALL 3
#define DHCP_TRACE_DETAIL 4
#define DHCP_TRACE_NORMAL 5
#define DHCP_TRACE_WARNING 6
#define DHCP_TRACE_ERROR 7
#define DHCP_TRACE_FATAL 10
#define DHCP_TRACE_ALARM 20
#define DHCP_TRACE_INFO 30
#define DHCP_DUMP_ALL 3
#define DHCP_DUMP_DETAIL 4
#define DHCP_DUMP_NORMAL 5
#define DHCP_DUMP_WARNING 6
#define DHCP_DUMP_ERROR 7
#define DHCP_DUMP_FATAL 10
#define DHCP_DUMP_ALARM 20
#define DHCP_DUMP_INFO 30
#ifdef _DHCP_USING_PRIV_DEBUG_
extern unsigned int gDhcpTraceLevel;
extern unsigned int gDhcpDumpLevel;
extern void dhcp_breakpoint();
extern void Dhcp_Exception_Handle();
#define DHCP_TRACE(level,args...) do { \
if(level >= gDhcpTraceLevel) { \
printf("[T:%u][%8s][%10s:%4u][BS]",DHCP_SYS_CUR_TICKING,__FILE__,__FUNCTION__, __LINE__); \
printf(##args); \
} \
}while (0)
#define DHCP_DUMP(level,buffer,length) do { \
unsigned int i; \
unsigned char temp[3]; \
unsigned char display[256]; \
unsigned char *pBuffer = (unsigned char *)buffer; \
if(level >= gDhcpDumpLevel){ \
display[0] = 0; \
for(i=0; i < length; i++) { \
sprintf(temp, (i%8 == 7 && i != length-1 && i%16 != 15) ? "%02x-" : "%02x ", *pBuffer++);\
strcat(display, temp); \
if(i%16 == 15) { \
printf("%s\n", display); \
display[0] = 0; \
} \
} \
if(display[0] !=0) \
printf("%s\n", display); \
} \
}while(0)
#define TRACE0(args...) DHCP_TRACE(DHCP_TRACE_ALL,##args)
#define TRACE1(args...) DHCP_TRACE(DHCP_TRACE_DETAIL,##args)
#define TRACE2(args...) DHCP_TRACE(DHCP_TRACE_NORMAL,##args)
#define TRACE3(args...) DHCP_TRACE(DHCP_TRACE_ERROR,##args)
#ifdef TRACE
#undef TRACE
#define TRACE(args...) DHCP_TRACE(DHCP_TRACE_INFO,##args)
#endif
#define DUMP0(buffer,length) DHCP_DUMP(DHCP_DUMP_ALL,buffer,length)
#define DUMP1(buffer,length) DHCP_DUMP(DHCP_DUMP_DETAIL,buffer,length)
#define DUMP2(buffer,length) DHCP_DUMP(DHCP_DUMP_NORMAL,buffer,length)
#define DUMP3(buffer,length) DHCP_DUMP(DHCP_DUMP_ERROR,buffer,length)
#ifdef DUMP
#undef DUMP
#define DUMP(buffer,length) DHCP_DUMP(DHCP_DUMP_INFO,buffer,length)
#endif
#define DHCP_ASSERT(_Good_Condition_) do{ \
if (!(_Good_Condition_)) { \
TRACE("ERROR "#_Good_Condition_"\n"); \
dhcp_breakpoint(); \
Dhcp_Exception_Handle(); \
return ERROR; \
} \
}while (0)
#define DHCP_ASSERT2(_Good_Condition_,_Exception_Action_) do{ \
if (!(_Good_Condition_)) { \
TRACE("ERROR "#_Good_Condition_"\n"); \
dhcp_breakpoint(); \
Dhcp_Exception_Handle(); \
_Exception_Action_; \
} \
}while (0)
#define DHCP_FSM_TRACE(state,msg) do {\
if(state >= ADFS_W4_INIT_DISCOVER && state <= ADFS_W4_NORMAL_ACK \
&& msg >= DHCPDISCOVER && msg <= DHCPINFORM) { \
TRACE3("state %s msg %s\n",gDhcpStateString[state],gDhcpMsgString[msg]); \
} \
}while(0)
#else
#define DHCP_TRACE(level,args...) do{}while (0)
#define DHCP_DUMP(level,buffer,length) do{}while(0)
#define TRACE0(args...) DHCP_TRACE(DHCP_TRACE_ALL,##args)
#define TRACE1(args...) DHCP_TRACE(DHCP_TRACE_DETAIL,##args)
#define TRACE2(args...) DHCP_TRACE(DHCP_TRACE_NORMAL,##args)
#define TRACE3(args...) DHCP_TRACE(DHCP_TRACE_ERROR,##args)
#ifdef TRACE
#undef TRACE
#define TRACE(args...) DHCP_TRACE(DHCP_TRACE_INFO,##args)
#endif
#define DUMP0(buffer,length) DHCP_DUMP(DHCP_DUMP_ALL,buffer,length)
#define DUMP1(buffer,length) DHCP_DUMP(DHCP_DUMP_DETAIL,buffer,length)
#define DUMP2(buffer,length) DHCP_DUMP(DHCP_DUMP_NORMAL,buffer,length)
#define DUMP3(buffer,length) DHCP_DUMP(DHCP_DUMP_ERROR,buffer,length)
#ifdef DUMP
#undef DUMP
#define DUMP(buffer,length) DHCP_DUMP(DHCP_DUMP_INFO,buffer,length)
#endif
#define DHCP_ASSERT(_Good_Condition_) do{}while (0)
#define DHCP_ASSERT2(_Good_Condition_,_Exception_Action_) do{}while (0)
#define DHCP_FSM_TRACE(state,msg) do {}while(0)
#endif /* _DHCP_USING_PRIV_DEBUG_ */
#endif /* _DHCP_DEBUG_ */
extern int g_dhcp_errno;
extern unsigned char *g_dhcp_err_file;
extern unsigned char *g_dhcp_err_func;
extern unsigned int g_dhcp_err_line;
#define DHCP_ERRNO_SET(error_no) do { \
if (error_no != 0) { \
g_dhcp_errno = (error_no); \
g_dhcp_err_file = __FILE__; \
g_dhcp_err_line = __LINE__; \
g_dhcp_err_func = __FUNCTION__; \
} \
}while (0)
#define DHCP_ERRNO_CLEAR() do{ \
g_dhcp_errno = 0; \
}while(0)
#define DHCP_ERRNO_GET() (g_dhcp_errno)
#define DHCP_ERRNO_CLASS1 0x10000000
#define DHCP_ERRNO_CLASS2 0x20000000
#define DHCP_ERRNO_HASH (DHCP_ERRNO_CLASS1 + 0x01)
#define DHCP_ERRNO_TIME (DHCP_ERRNO_CLASS1 + 0x10)
#define DHCP_ERRNO_FSM (DHCP_ERRNO_CLASS1 + 0x20)
#define DHCP_ERRNO_RES (DHCP_ERRNO_CLASS1 + 0x30)
#define DHCP_ERRNO_PROTOCOL (DHCP_ERRNO_CLASS1 + 0x40)
#define DHCP_ERRNO_COMM (DHCP_ERRNO_CLASS1 + 0x50)
#define DHCP_ERRNO_INITREBOOT (DHCP_ERRNO_CLASS1 + 0x100)
extern void dhcp_print_errno();
typedef XTIMER_ID AEP_TMR_ID;
typedef XTIMERIDFUNC AEP_TMR_FUNC;
#define AEP_TIMER_DHCP 0xAA
#define DHCP_TIMER_DURATION 100 /* ms */
typedef GW_TIMER_MSG_S St_AepTmrMsg;
/*extern MSG_Q_ID g_msgq_gwcp;
#define AEP_MSG_Q_ID g_msgq_gwcp*/
typedef struct buf_vec{
char *bv_base;
unsigned int bv_len;
}St_BufVec;
typedef struct msg
{
/*struct ether_header *ether;*/
struct ip *ip;
struct udphdr *udp;
struct dhcp *dhcp;
}St_Msg;
struct client_id {
unsigned char idtype;
unsigned char idlen;
char id [MAXOPT];
struct in_addr subnet;
};
struct u_shorts {
int num;
unsigned short shorts[10];
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -