forked from vollero/openCAPWAP
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ACProtocol_User.c
312 lines (253 loc) · 10.2 KB
/
ACProtocol_User.c
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*******************************************************************************************
* Copyright (c) 2006-7 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) *
*******************************************************************************************/
#include "CWAC.h"
CWBool CWACSupportIPv6()
{
return (gNetworkPreferredFamily == CW_IPv6);
}
char *CWACGetName()
{
return gACName;
}
int CWACGetStations()
{
return gActiveStations;
}
int CWACGetLimit()
{
return gLimit;
}
int CWACGetActiveWTPs()
{
int tmp;
if (!CWErr(CWThreadMutexLock(&gActiveWTPsMutex)))
return 0;
tmp = gActiveWTPs;
CWThreadMutexUnlock(&gActiveWTPsMutex);
return tmp;
}
int CWACGetMaxWTPs()
{
return gMaxWTPs;
}
int CWACGetSecurity()
{
return gACDescriptorSecurity;
}
int CWACGetRMACField()
{
return gRMACField;
}
int CWACGetWirelessField()
{
return gWirelessField;
}
int CWACGetDTLSPolicy()
{
return gDTLSPolicy;
}
int CWACGetHWVersion()
{
return gACHWVersion;
}
int CWACGetSWVersion()
{
return gACSWVersion;
}
int CWACGetInterfacesCount()
{
return gInterfacesCount;
}
int CWACGetInterfaceIPv4AddressAtIndex(int i)
{
struct sockaddr_in *addrPtr;
if (gNetworkPreferredFamily == CW_IPv4) {
addrPtr = (struct sockaddr_in *)&(gInterfaces[i].addr);
} else {
addrPtr = (struct sockaddr_in *)&(gInterfaces[i].addrIPv4);
}
return ntohl(addrPtr->sin_addr.s_addr);
}
unsigned char *CWACGetInterfaceIPv6AddressAtIndex(int i)
{
struct sockaddr_in6 *addrPtr;
addrPtr = (struct sockaddr_in6 *)&(gInterfaces[i].addr);
return (unsigned char *)addrPtr->sin6_addr.s6_addr;
}
int CWACGetInterfaceWTPCountAtIndex(int i)
{
return gInterfaces[i].WTPCount;
}
CWBool CWACGetVendorInfos(CWACVendorInfos * valPtr)
{
if (valPtr == NULL)
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
valPtr->vendorInfosCount = 2;
if (!(valPtr->vendorInfos = ralloc_array(NULL, CWACVendorInfoValues, valPtr->vendorInfosCount)))
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
// my vendor identifier (IANA assigned "SMI Network Management Private Enterprise Code")
valPtr->vendorInfos[0].vendorIdentifier = 65432;
valPtr->vendorInfos[0].type = CW_AC_HARDWARE_VERSION;
valPtr->vendorInfos[0].length = 4; // just one int
if (!(valPtr->vendorInfos[0].valuePtr = ralloc_size(NULL, 4)))
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
*valPtr->vendorInfos[0].valuePtr = CWACGetHWVersion(); // HW version - TODO: wrong, should be string
// my vendor identifier (IANA assigned "SMI Network Management Private Enterprise Code")
valPtr->vendorInfos[1].vendorIdentifier = 65432;
valPtr->vendorInfos[1].type = CW_AC_SOFTWARE_VERSION;
valPtr->vendorInfos[1].length = 4; // just one int
if (!(valPtr->vendorInfos[1].valuePtr = ralloc_size(NULL, 4)))
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
*valPtr->vendorInfos[1].valuePtr = CWACGetSWVersion(); // SW version - TODO: wrong, should be string
return CW_TRUE;
}
void CWACDestroyVendorInfos(CWACVendorInfos * valPtr)
{
int i;
if (valPtr == NULL)
return;
for (i = 0; i < valPtr->vendorInfosCount; i++) {
CW_FREE_OBJECT((valPtr->vendorInfos)[i].valuePtr);
}
CW_FREE_OBJECT(valPtr->vendorInfos);
}
CWBool CWACGetACIPv4List(int **listPtr, int *countPtr)
{
struct in_addr addr;
// TO-DO this func should return the addresses of eventual other ACs in a cluster. Hey, what? What is the WTP
// supposed to do with that?
if (listPtr == NULL || countPtr == NULL)
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
*countPtr = 2;
if (!((*listPtr) = ralloc_array(NULL, int, (*countPtr))))
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
inet_pton(AF_INET, "192.168.1.2", &addr); // TO-DO take the addresses from config file?
(*listPtr)[0] = addr.s_addr;
inet_pton(AF_INET, "192.168.1.66", &addr);
(*listPtr)[1] = addr.s_addr;
return CW_TRUE;
}
CWBool CWACGetACIPv6List(struct in6_addr ** listPtr, int *countPtr)
{
// TO-DO this func should return the addresses of eventual other ACs in a cluster. Hey, what? What is the WTP
// supposed to do with that?
if (listPtr == NULL || countPtr == NULL)
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
*countPtr = 2;
if (!(*listPtr = ralloc_array(NULL, struct in6_addr, (*countPtr))))
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
inet_pton(AF_INET6, "5f1b:df00:ce3e:e200:0020:0800:2078:e3e3", &((*listPtr)[0])); // TO-DO take the addresses from config file?
inet_pton(AF_INET6, "5f1b:df00:ce3e:e200:0020:0800:2078:e3e4", &((*listPtr)[1]));
return CW_TRUE;
}
CWBool CWACGetDiscoveryTimer(int *timer)
{
*timer = gDiscoveryTimer;
return CW_TRUE;
}
CWBool CWACGetEchoRequestTimer(int *timer)
{
*timer = gEchoRequestTimer;
return CW_TRUE;
}
CWBool CWACGetIdleTimeout(int *timer)
{
*timer = gIdleTimeout;
return CW_TRUE;
}
/* Il WTP ha la funzione ridefinita */
CWBool CWGetWTPRadiosAdminState(CWRadiosAdminInfo * valPtr)
{
int *WTPIndexPtr;
if (valPtr == NULL)
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
if ((WTPIndexPtr = ((int *)CWThreadGetSpecific(&gIndexSpecific))) == NULL) {
return CW_FALSE;
}
valPtr->radiosCount = gWTPs[*WTPIndexPtr].WTPProtocolManager.radiosInfo.radioCount;
if (!(valPtr->radios = ralloc_array(NULL, CWRadioAdminInfoValues, valPtr->radiosCount)))
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
int i;
for (i = 0; i < valPtr->radiosCount; i++) {
(valPtr->radios)[i].ID = gWTPs[*WTPIndexPtr].WTPProtocolManager.radiosInfo.radiosInfo[i].radioID;
(valPtr->radios)[i].state = gWTPs[*WTPIndexPtr].WTPProtocolManager.radiosInfo.radiosInfo[i].adminState;
(valPtr->radios)[i].cause = gWTPs[*WTPIndexPtr].WTPProtocolManager.radiosInfo.radiosInfo[i].adminCause;
}
return CW_TRUE;
}
CWBool CWGetWTPRadiosOperationalState(int radioID, CWRadiosOperationalInfo * valPtr)
{
int i;
CWBool found = CW_FALSE;
int *WTPIndexPtr;
if (valPtr == NULL)
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
if ((WTPIndexPtr = ((int *)CWThreadGetSpecific(&gIndexSpecific))) == NULL) {
return CW_FALSE;
}
if (radioID < 0) {
valPtr->radiosCount = gWTPs[*WTPIndexPtr].WTPProtocolManager.radiosInfo.radioCount;
if (!(valPtr->radios = ralloc_array(NULL, CWRadioOperationalInfoValues, valPtr->radiosCount)))
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
for (i = 0; i < valPtr->radiosCount; i++) {
(valPtr->radios)[i].ID =
gWTPs[*WTPIndexPtr].WTPProtocolManager.radiosInfo.radiosInfo[i].radioID;
(valPtr->radios)[i].state =
gWTPs[*WTPIndexPtr].WTPProtocolManager.radiosInfo.radiosInfo[i].operationalState;
(valPtr->radios)[i].cause =
gWTPs[*WTPIndexPtr].WTPProtocolManager.radiosInfo.radiosInfo[i].operationalCause;
}
return CW_TRUE;
} else {
for (i = 0; i < valPtr->radiosCount; i++) {
if (gWTPs[*WTPIndexPtr].WTPProtocolManager.radiosInfo.radiosInfo[i].radioID == radioID) {
found = CW_TRUE;
valPtr->radiosCount = 1;
if (!(valPtr->radios = ralloc_array(NULL, CWRadioOperationalInfoValues, valPtr->radiosCount)))
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);
(valPtr->radios)[i].ID =
gWTPs[*WTPIndexPtr].WTPProtocolManager.radiosInfo.radiosInfo[i].radioID;
(valPtr->radios)[i].state =
gWTPs[*WTPIndexPtr].WTPProtocolManager.radiosInfo.radiosInfo[i].operationalState;
(valPtr->radios)[i].cause =
gWTPs[*WTPIndexPtr].WTPProtocolManager.radiosInfo.radiosInfo[i].operationalCause;
break;
}
}
return found;
}
}