-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWTPProtocol_User.c
352 lines (279 loc) · 12.9 KB
/
WTPProtocol_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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*******************************************************************************************
* 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 "CWWTP.h"
#ifdef DMALLOC
#include "../dmalloc-5.5.0/dmalloc.h"
#endif
__inline__ int CWWTPGetDiscoveryType() {
return CW_MSG_ELEMENT_DISCOVERY_TYPE_CONFIGURED;
}
__inline__ int CWWTPGetMaxRadios() {
return 1;
}
__inline__ int CWWTPGetRadiosInUse()
{
/*for (i=0; i<gRadiosInfo.radioCount; i++)
{
if((gRadiosInfo.radiosInfo[i].operationalState) == ENABLED)
active++;
}
return active;
*/
return gRadiosInfo.radioCount;
}
__inline__ int CWWTPGetEncCapabilities() {
return 2569;
}
CWBool CWWTPGetBoardData(CWWTPVendorInfos *valPtr) {
if(valPtr == NULL) return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
valPtr->vendorInfosCount = 2; // we fill 2 information (just the required ones)
CW_CREATE_ARRAY_ERR((valPtr->vendorInfos), valPtr->vendorInfosCount, CWWTPVendorInfoValues, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
// my vendor identifier (IANA assigned "SMI Network Management Private Enterprise Code")
(valPtr->vendorInfos)[0].vendorIdentifier = 23456;
(valPtr->vendorInfos)[0].type = CW_WTP_MODEL_NUMBER;
(valPtr->vendorInfos)[0].length = sizeof(long int); // just one int
CW_CREATE_OBJECT_SIZE_ERR(( ( (valPtr->vendorInfos)[0] ).valuePtr), (valPtr->vendorInfos)[0].length, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
*(((valPtr->vendorInfos)[0]).valuePtr) = 123456; // MODEL NUMBER
// my vendor identifier (IANA assigned "SMI Network Management Private Enterprise Code")
(valPtr->vendorInfos)[1].vendorIdentifier = 23456;
(valPtr->vendorInfos)[1].type = CW_WTP_SERIAL_NUMBER;
(valPtr->vendorInfos)[1].length = sizeof(long int); // just one int
CW_CREATE_OBJECT_SIZE_ERR(( ( (valPtr->vendorInfos)[1] ).valuePtr), (valPtr->vendorInfos)[1].length, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
*(((valPtr->vendorInfos)[1]).valuePtr) = 123456; // SERIAL NUMBER
return CW_TRUE;
}
CWBool CWWTPGetVendorInfos(CWWTPVendorInfos *valPtr) {
if(valPtr == NULL) return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
valPtr->vendorInfosCount = 3; // we fill 3 information (just the required ones)
CW_CREATE_ARRAY_ERR((valPtr->vendorInfos), valPtr->vendorInfosCount, CWWTPVendorInfoValues, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
// my vendor identifier (IANA assigned "SMI Network Management Private Enterprise Code")
(valPtr->vendorInfos)[0].vendorIdentifier = 23456;
(valPtr->vendorInfos)[0].type = CW_WTP_HARDWARE_VERSION;
(valPtr->vendorInfos)[0].length = sizeof(long int); // just one int
CW_CREATE_OBJECT_SIZE_ERR(( ( (valPtr->vendorInfos)[0] ).valuePtr), (valPtr->vendorInfos)[0].length, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
*(((valPtr->vendorInfos)[0]).valuePtr) = 123456; // HW version
// my vendor identifier (IANA assigned "SMI Network Management Private Enterprise Code")
((valPtr->vendorInfos)[1]).vendorIdentifier = 23456;
((valPtr->vendorInfos)[1]).type = CW_WTP_SOFTWARE_VERSION;
((valPtr->vendorInfos)[1]).length = sizeof(long int); // just one int
CW_CREATE_OBJECT_SIZE_ERR(( ( (valPtr->vendorInfos)[1] ).valuePtr), (valPtr->vendorInfos)[1].length, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
*(((valPtr->vendorInfos)[1]).valuePtr) = 12347; // SW version
// my vendor identifier (IANA assigned "SMI Network Management Private Enterprise Code")
(valPtr->vendorInfos)[2].vendorIdentifier = 23456;
(valPtr->vendorInfos)[2].type = CW_BOOT_VERSION;
(valPtr->vendorInfos)[2].length = sizeof(long int); // just one int
CW_CREATE_OBJECT_SIZE_ERR(( ( (valPtr->vendorInfos)[2] ).valuePtr), (valPtr->vendorInfos)[2].length, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
*(((valPtr->vendorInfos)[2]).valuePtr) = 1234568; // Boot version
return CW_TRUE;
}
__inline__ void CWWTPDestroyVendorInfos(CWWTPVendorInfos *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);
}
__inline__ int CWWTPGetFrameTunnelMode() {
//it may be also 802.3_FrameTunnelMode - NativeFrameTunnelMode - All
return CW_LOCAL_BRIDGING;
}
__inline__ int CWWTPGetMACType() {
return CW_LOCAL_MAC;
}
__inline__ char *CWWTPGetLocation() {
return gWTPLocation;
}
__inline__ int CWWTPGetSessionID() {
return CWRandomIntInRange(0, INT_MAX);
}
__inline__ int CWWTPGetIPv4Address() {
struct sockaddr_in myAddr;
unsigned int len = sizeof(myAddr);
//CWDebugLog("WTPGetIPv4Address");
/* assume the socket is connected */
getsockname(gWTPSocket, (struct sockaddr*) &myAddr, &len);
return ntohl(myAddr.sin_addr.s_addr); // TO-DO: this is garbage if we are an IPv6 client
}
__inline__ void CWWTPGetIPv6Address(struct sockaddr_in6* myAddr) {
unsigned int len = sizeof(*myAddr);
/* assume the socket is connected */
getsockname(gWTPSocket, (struct sockaddr*) myAddr, &len);
}
__inline__ int CWWTPGetIPv4StatusDuplicate() {
return gIPv4StatusDuplicate;
}
__inline__ int CWWTPGetIPv6StatusDuplicate() {
return gIPv6StatusDuplicate;
}
__inline__ char *CWWTPGetName() {
return gWTPName;
}
/*CWBool CWWTPGetRadiosInformation(CWRadiosInformation *valPtr) {
if(valPtr == NULL) return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
valPtr->radiosCount = 2;
CW_CREATE_ARRAY_ERR(valPtr->radios, valPtr->radiosCount, CWRadioInformationValues, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
(valPtr->radios)[0].ID = 0; // first radio
(valPtr->radios)[0].type = CW_802_DOT_11b;
(valPtr->radios)[1].ID = 1; // second radio
(valPtr->radios)[1].type = CW_802_DOT_11b;
return CW_TRUE;
}
*/
/* L'AC ha la funzione ridefinita */
CWBool CWGetWTPRadiosAdminState(CWRadiosAdminInfo *valPtr)
{
int i;
if(valPtr == NULL) return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
valPtr->radiosCount = gRadiosInfo.radioCount;
CW_CREATE_ARRAY_ERR(valPtr->radios, valPtr->radiosCount, CWRadioAdminInfoValues, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
for (i=0; i<gRadiosInfo.radioCount; i++)
{
(valPtr->radios)[i].ID = gRadiosInfo.radiosInfo[i].radioID; // first radio
(valPtr->radios)[i].state = gRadiosInfo.radiosInfo[i].adminState;
(valPtr->radios)[i].cause = gRadiosInfo.radiosInfo[i].adminCause;
}
return CW_TRUE;
}
CWBool CWGetWTPRadiosOperationalState(int radioID, CWRadiosOperationalInfo *valPtr)
{
int i;
CWBool found = CW_FALSE;
if(valPtr == NULL) return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
if(radioID<0) {
valPtr->radiosCount = gRadiosInfo.radioCount;
CW_CREATE_ARRAY_ERR(valPtr->radios, valPtr->radiosCount, CWRadioOperationalInfoValues, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
for (i=0; i<gRadiosInfo.radioCount; i++)
{
(valPtr->radios)[i].ID = gRadiosInfo.radiosInfo[i].radioID;
(valPtr->radios)[i].state = gRadiosInfo.radiosInfo[i].operationalState;
(valPtr->radios)[i].cause = gRadiosInfo.radiosInfo[i].operationalCause;
}
return CW_TRUE;
}
else {
for (i=0; i<gRadiosInfo.radioCount; i++)
{
if(gRadiosInfo.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)[0].ID = gRadiosInfo.radiosInfo[i].radioID;
(valPtr->radios)[0].state = gRadiosInfo.radiosInfo[i].operationalState;
(valPtr->radios)[0].cause = gRadiosInfo.radiosInfo[i].operationalCause;
break;
}
}
return found;
}
}
CWBool CWGetDecryptErrorReport(int radioID, CWDecryptErrorReportInfo *valPtr)
{
int i;
CWBool found = CW_FALSE;
/*
CWMACAddress add, add2;
for(i=0; i<6; i++) add[i]=i;
for(i=0; i<6; i++) add2[i]=99;
CWListElement elem,elem2;
elem.data = add;
elem.next = &elem2;
elem2.data = &add2;
elem2.next = NULL;
gRadiosInfo.radiosInfo[0].decryptErrorMACAddressList = &elem;
*/
if(valPtr == NULL) return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
valPtr->radios=NULL;
if(radioID<0) {
valPtr->radiosCount = gRadiosInfo.radioCount;
CW_CREATE_ARRAY_ERR(valPtr->radios, valPtr->radiosCount, CWDecryptErrorReportValues, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
for (i=0; i<gRadiosInfo.radioCount; i++)
{
(valPtr->radios)[i].ID = gRadiosInfo.radiosInfo[i].radioID;
(valPtr->radios)[i].numEntries = CWCountElementInList(gRadiosInfo.radiosInfo[i].decryptErrorMACAddressList);
(valPtr->radios[i]).decryptErrorMACAddressList = NULL;
CW_CREATE_ARRAY_ERR((valPtr->radios[i]).decryptErrorMACAddressList, (valPtr->radios[i]).numEntries, CWMACAddress, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
int j;
CWListElement *temp;
temp = gRadiosInfo.radiosInfo[i].decryptErrorMACAddressList;
for(j=0; j<(valPtr->radios[i]).numEntries; j++)
{
CW_COPY_MEMORY((valPtr->radios[i]).decryptErrorMACAddressList[j],temp->data, sizeof(CWMACAddress));
temp = temp->next;
}
}
return CW_TRUE;
}
else {
for (i=0; i<gRadiosInfo.radioCount; i++)
{
if(gRadiosInfo.radiosInfo[i].radioID == radioID)
{
found = CW_TRUE;
valPtr->radiosCount = 1;
CW_CREATE_ARRAY_ERR(valPtr->radios, valPtr->radiosCount, CWDecryptErrorReportValues, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
(valPtr->radios)[0].ID = gRadiosInfo.radiosInfo[i].radioID;
(valPtr->radios)[0].numEntries = CWCountElementInList(gRadiosInfo.radiosInfo[i].decryptErrorMACAddressList);
(valPtr->radios[0]).decryptErrorMACAddressList = NULL;
CW_CREATE_ARRAY_ERR((valPtr->radios[0]).decryptErrorMACAddressList, (valPtr->radios[0]).numEntries, CWMACAddress, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
int j;
CWListElement *temp;
temp = gRadiosInfo.radiosInfo[0].decryptErrorMACAddressList;
for(j=0; j<(valPtr->radios[0]).numEntries; j++)
{
CW_COPY_MEMORY((valPtr->radios[0]).decryptErrorMACAddressList[j],temp->data, 6);
temp = temp->next;
}
}
}
return found;
}
}
int CWWTPGetACIndex()
{
return 1; //valore predefinito
}
char* CWWTPGetACName()
{
return gACInfoPtr->name;
}
int CWWTPGetStatisticsTimer ()
{
return gWTPStatisticsTimer;
}
CWBool CWWTPGetACNameWithIndex (CWACNamesWithIndex *ACsInfo)
{
if(ACsInfo == NULL) return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
ACsInfo->count = 2;
CW_CREATE_ARRAY_ERR(ACsInfo->ACNameIndex, ACsInfo->count, CWACNameWithIndexValues, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
(ACsInfo->ACNameIndex)[0].index = 0; // first radio
CW_CREATE_STRING_FROM_STRING_ERR((ACsInfo->ACNameIndex)[0].ACName, "ACPrimary", return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
(ACsInfo->ACNameIndex)[1].index = 1; // first radio
CW_CREATE_STRING_FROM_STRING_ERR((ACsInfo->ACNameIndex)[1].ACName, "ACSecondary", return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););;
return CW_TRUE;
}