-
Notifications
You must be signed in to change notification settings - Fork 84
/
WTPProtocol_User.c
463 lines (369 loc) · 15.8 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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
/*******************************************************************************************
* 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 ([email protected]) *
* Del Moro Andrea ([email protected]) *
* Giovannini Federica ([email protected]) *
* Massimo Vellucci ([email protected]) *
* Mauro Bisson ([email protected]) *
*******************************************************************************************/
#include "CWWTP.h"
#define MAC_ADDR_LEN 6
#ifdef DMALLOC
#include "../dmalloc-5.5.0/dmalloc.h"
#endif
__inline__ int CWWTPGetDiscoveryType() {
return CW_MSG_ELEMENT_DISCOVERY_TYPE_CONFIGURED;
}
//Elena Agostini
__inline__ int CWWTPGetMaxRadios() {
return gRadiosInfo.radioCount;
}
__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 0;
}
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););
*(int *)(((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););
*(int *)(((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););
*(int *)(((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););
*(int *)(((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););
*(int *)(((valPtr->vendorInfos)[2]).valuePtr) = 1234568; //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
#ifdef SPLIT_MAC
return CW_NATIVE_BRIDGING;
#else
return CW_LOCAL_BRIDGING;
#endif
}
__inline__ int CWWTPGetMACType() {
#ifdef SPLIT_MAC
return CW_SPLIT_MAC;
#else
return CW_LOCAL_MAC;
#endif
}
__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;
}
/*
* Elena Agostini - 02/2014
*
* ECN Support Msg Elem MUST be included in Join Request/Response Messages
*/
int CWWTPGetECNSupport ()
{
return gWTPECNSupport;
}
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;
}
int getInterfaceMacAddr(char* interface, unsigned char* macAddr)
{
struct ifreq ethreq;
int i,sock;
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) {
CWLog("Error Creating Socket for ioctl");
return -1;
}
memset(ðreq, 0, sizeof(ethreq));
strncpy(ethreq.ifr_name, interface, IFNAMSIZ);
/*
* Elena Agostini - 02/2014
*
* Eliminare interrogazione diretta del mac address?
*/
if (ioctl(sock, SIOCGIFHWADDR, ðreq)==-1) {
return -1;
}
for (i=0; i<MAC_ADDR_LEN; i++){
macAddr[i]=(unsigned char)ethreq.ifr_hwaddr.sa_data[i];
}
return 0;
}
/*
* Elena Agostini - 04/2014: Easier SessionID random value
*/
int initWTPSessionID(char * sessionID)
{
int i;
for(i=0; i< WTP_SESSIONID_LENGTH; i++)
{
sessionID[i] = (unsigned char)rand()%256;
}
return 0;
/*
unsigned char macAddr0[MAC_ADDR_LEN];
unsigned char macAddr1[MAC_ADDR_LEN];
int i,randomInteger;
char *buffer=sessionID;
// Elena Agostini - 02/2014
// BUG Valgrind: if getInterfaceMacAddr fail, macAddr0 and macAddr1
// aren't initialized
memset(macAddr0, 0, MAC_ADDR_LEN);
memset(macAddr1, 0, MAC_ADDR_LEN);
getInterfaceMacAddr(gEthInterfaceName,macAddr0);
getInterfaceMacAddr(gRadioInterfaceName_0,macAddr1);
randomInteger = CWRandomIntInRange(0, INT_MAX);
randomInteger = htonl(randomInteger);
CW_COPY_MEMORY(sessionID, macAddr0, MAC_ADDR_LEN);
CW_COPY_MEMORY(&(sessionID[MAC_ADDR_LEN]), macAddr1, MAC_ADDR_LEN);
CW_COPY_MEMORY(&(sessionID[MAC_ADDR_LEN+MAC_ADDR_LEN]),&(randomInteger), 4);
CWLog("################################ SESSION ID: ");
for (i=0;i<16;i++)
{
if (i%16==0) CWLog("\n%04x: ", i);
CWLog("%02x:", sessionID[i]);
}
CWLog("\n");
return 0;*/
}