-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathACProtocol_User.c
278 lines (216 loc) · 9.55 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
/*******************************************************************************************
* 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. *
* *
* --------------------------------------------------------------------------------------- *
* Project: Capwap *
* *
* Author : Ludovico Rossi ([email protected]) *
* Del Moro Andrea ([email protected]) *
* Giovannini Federica ([email protected]) *
* Massimo Vellucci ([email protected]) *
* Mauro Bisson ([email protected]) *
*******************************************************************************************/
#include "CWAC.h"
#ifdef DMALLOC
#include "../dmalloc-5.5.0/dmalloc.h"
#endif
__inline__ CWBool CWACSupportIPv6() {
return (gNetworkPreferredFamily == CW_IPv6);
}
__inline__ char * CWACGetName() {
return gACName;
}
__inline__ int CWACGetStations() {
return gActiveStations;
}
__inline__ int CWACGetLimit() {
return gLimit;
}
__inline__ int CWACGetActiveWTPs() {
int tmp;
if(!CWErr(CWThreadMutexLock(&gActiveWTPsMutex)))
{
CWLog("F:%s L:%d Error locking mutex",__FILE__,__LINE__);
return 0;
}
tmp = gActiveWTPs;
CWThreadMutexUnlock(&gActiveWTPsMutex);
return tmp;
}
__inline__ int CWACGetMaxWTPs() {
return gMaxWTPs;
}
__inline__ int CWACGetSecurity() {
return gACDescriptorSecurity;
}
__inline__ int CWACGetRMACField() {
return gRMACField;
}
__inline__ int CWACGetWirelessField() {
return gWirelessField;
}
__inline__ int CWACGetDTLSPolicy() {
return gDTLSPolicy;
}
__inline__ int CWACGetHWVersion() {
return gACHWVersion;
}
__inline__ int CWACGetSWVersion() {
return gACSWVersion;
}
__inline__ int CWACGetInterfacesCount() {
return gInterfacesCount;
}
__inline__ 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);
}
__inline__ char *CWACGetInterfaceIPv6AddressAtIndex(int i) {
struct sockaddr_in6 *addrPtr;
addrPtr = (struct sockaddr_in6 *) &(gInterfaces[i].addr);
return (char*) addrPtr->sin6_addr.s6_addr;
}
__inline__ 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;
CW_CREATE_ARRAY_ERR((valPtr->vendorInfos), valPtr->vendorInfosCount, CWACVendorInfoValues, 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
CW_CREATE_OBJECT_SIZE_ERR((((valPtr->vendorInfos)[0]).valuePtr), 4, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
*(((valPtr->vendorInfos)[0]).valuePtr) = CWACGetHWVersion(); // HW version
// 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
CW_CREATE_OBJECT_SIZE_ERR(( ( (valPtr->vendorInfos)[1] ).valuePtr), 4, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
*(((valPtr->vendorInfos)[1] ).valuePtr) = CWACGetSWVersion(); // SW version
return CW_TRUE;
}
__inline__ 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;
CW_CREATE_ARRAY_ERR((*listPtr), (*countPtr), int, 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;
CW_CREATE_ARRAY_ERR(*listPtr, (*countPtr), struct in6_addr, 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;
CW_CREATE_ARRAY_ERR(valPtr->radios, valPtr->radiosCount, CWRadioAdminInfoValues, 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;
CW_CREATE_ARRAY_ERR(valPtr->radios, valPtr->radiosCount, CWRadioOperationalInfoValues, 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;
CW_CREATE_ARRAY_ERR(valPtr->radios, valPtr->radiosCount, CWRadioOperationalInfoValues, 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;
}
}