forked from vollero/openCAPWAP
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CWCommon.h
185 lines (162 loc) · 6.61 KB
/
CWCommon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*******************************************************************************************
* Copyright (c) 2006-9 Laboratorio di Sistemi di Elaborazione e Bioingegneria Informatica *
* Universita' Campus BioMedico - Italy *
* *
* This program is free software; you can redistribute it and/or modify it under the terms *
* of the GNU General Public License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with this *
* program; if not, write to the: *
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, *
* MA 02111-1307, USA. *
*
* In addition, as a special exception, the copyright holders give permission to link the *
* code of portions of this program with the OpenSSL library under certain conditions as *
* described in each individual source file, and distribute linked combinations including *
* the two. You must obey the GNU General Public License in all respects for all of the *
* code used other than OpenSSL. If you modify file(s) with this exception, you may *
* extend this exception to your version of the file(s), but you are not obligated to do *
* so. If you do not wish to do so, delete this exception statement from your version. *
* If you delete this exception statement from all source files in the program, then also *
* delete it here. *
*
* *
* --------------------------------------------------------------------------------------- *
* Project: Capwap *
* *
* Author : Ludovico Rossi (ludo@bluepixysw.com) *
* Del Moro Andrea (andrea_delmoro@libero.it) *
* Giovannini Federica (giovannini.federica@gmail.com) *
* Massimo Vellucci (m.vellucci@unicampus.it) *
* Mauro Bisson (mauro.bis@gmail.com) *
* Antonio Davoli (antonio.davoli@gmail.com) *
*******************************************************************************************/
#ifndef __CAPWAP_CWCommon_HEADER__
#define __CAPWAP_CWCommon_HEADER__
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <signal.h>
#include <unistd.h>
#ifdef MACOSX
#include <netinet/if_ether.h>
#else
#include <linux/if_ether.h>
#endif
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "wireless_copy.h"
#include "ralloc.h"
#ifdef HAVE_VALGRIND_MEMCHECK_H
#include <valgrind/memcheck.h>
#endif
#ifdef HAVE_VALGRIND_VALGRIND_H
#include <valgrind/valgrind.h>
#endif
// make sure the types really have the right sizes
#define CW_COMPILE_TIME_ASSERT(name, x) typedef int CWDummy_ ## name[(x) * 2 - 1]
// if you get a compile error, change types (NOT VALUES!) according to your system
CW_COMPILE_TIME_ASSERT(int_size, sizeof(int) == 4);
CW_COMPILE_TIME_ASSERT(char_size, sizeof(char) == 1);
#define CW_BLOCK_ALLOC 16
#define CW_BUFFER_SIZE 65536
#define CW_ZERO_MEMORY bzero
#define CW_COPY_MEMORY(dst, src, len) bcopy(src, dst, len)
#define CW_REPEAT_FOREVER while(1)
#define DEFAULT_LOG_SIZE 1000000
typedef enum {
CW_FALSE = 0,
CW_TRUE = 1
} CWBool;
typedef enum {
CW_ENTER_SULKING,
CW_ENTER_DISCOVERY,
CW_ENTER_JOIN,
CW_ENTER_CONFIGURE,
CW_ENTER_DATA_CHECK,
CW_ENTER_RUN,
CW_ENTER_RESET,
CW_QUIT
} CWStateTransition;
extern char *gCWConfigFileName;
extern char *gCWSettingsFileName;
extern int gCWForceMTU;
extern int gCWRetransmitTimer;
extern int gCWNeighborDeadInterval;
extern int gCWNeighborDeadRestartDelta;
extern int gCWWaitJoin;
extern int gCWMaxRetransmit;
extern int gMaxLogFileSize;
extern int gEnabledLog;
extern int gDataChannelKeepAliveInterval;
extern int gConfigDataChannelKeepAliveInterval;
extern int gAggressiveDataChannelKeepAliveInterval;
extern int gEchoInterval;
#define CW_ON_ERROR(cond, on_err) \
do { \
if (!(cond)) { \
on_err \
} \
} while (0)
#define CW_FREE_OBJECT(ptr) \
do { \
ralloc_free((ptr)); \
(ptr) = NULL; \
} while (0)
#define CW_FREE_OBJECTS_ARRAY(array, size) \
do { \
int _i = 0; \
for(_i = ((size)-1); _i >= 0; _i--) \
ralloc_free((array)[_i]); \
ralloc_free((array)); \
(array) = NULL; \
} while (0)
#define CW_PRINT_STRING_ARRAY(array, size) \
do { \
int i = 0; \
for(i = 0; i < (size); i++) \
printf("[%d]: **%s**\n", i, (array)[i]); \
} while (0)
static inline void *ralloc_memdup(const void *ctx, void *src, size_t size)
{
void *dest;
if (!(dest = ralloc_size(ctx, size)))
return NULL;
return memcpy(dest, src, size);
}
#include "CWStevens.h"
#include "config.h"
#include "CWLog.h"
#include "CWErrorHandling.h"
#include "CWRandom.h"
//#include "CWTimer.h"
#include "timerlib.h"
#include "CWThread.h"
#include "CWNetwork.h"
#include "CWList.h"
#include "CWSafeList.h"
#include "CWProtocol.h"
#include "CWSecurity.h"
#include "CWConfigFile.h"
int CWTimevalSubtract(struct timeval *res, const struct timeval *x, const struct timeval *y);
CWBool CWParseSettingsFile();
void CWErrorHandlingInitLib();
#endif