-
Notifications
You must be signed in to change notification settings - Fork 84
/
ACBinding.c
375 lines (295 loc) · 12.5 KB
/
ACBinding.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
/*******************************************************************************************
* Copyright (c) 2006-2009 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 *
* *
* Authors : 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) *
* Daniele De Sanctis (danieledesanctis@gmail.com) *
* Antonio Davoli (antonio.davoli@gmail.com) *
*******************************************************************************************/
#include "CWAC.h"
#ifdef DMALLOC
#include "../dmalloc-5.5.0/dmalloc.h"
#endif
CWBool CWACInitBinding(int i)
{
int j;
bindingValues* aux;
CW_CREATE_OBJECT_ERR(aux, bindingValues, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
(gWTPs[i].WTPProtocolManager).bindingValuesPtr=(void*) aux;
CW_CREATE_ARRAY_ERR(aux->qosValues, NUM_QOS_PROFILES, WTPQosValues, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
//Init default values
for(j=0; j<NUM_QOS_PROFILES; j++)
{
aux->qosValues[j].cwMin=gDefaultQosValues[j].cwMin;
aux->qosValues[j].cwMax=gDefaultQosValues[j].cwMax;
aux->qosValues[j].AIFS=gDefaultQosValues[j].AIFS;
aux->qosValues[j].queueDepth=0;
aux->qosValues[j].dot1PTag=0;
aux->qosValues[j].DSCPTag=0;
}
return CW_TRUE;
}
CWBool CWMergeQosValues(int WTPIndex)
{
int i;
bindingValues* aux;
aux=(bindingValues*)(gWTPs[WTPIndex].WTPProtocolManager).bindingValuesPtr;
for(i=0; i<NUM_QOS_PROFILES; i++)
{
if(gWTPs[WTPIndex].qosValues[i].cwMin==UNUSED_QOS_VALUE)
{gWTPs[WTPIndex].qosValues[i].cwMin=aux->qosValues[i].cwMin;}
if(gWTPs[WTPIndex].qosValues[i].cwMax==UNUSED_QOS_VALUE)
{gWTPs[WTPIndex].qosValues[i].cwMax=aux->qosValues[i].cwMax;}
if(gWTPs[WTPIndex].qosValues[i].AIFS==UNUSED_QOS_VALUE)
{gWTPs[WTPIndex].qosValues[i].AIFS=aux->qosValues[i].AIFS;}
}
return CW_TRUE;
}
/******************************************************************
* 2009 Updates: *
* Functions for management of Configuration Update *
* Request with OFDM Message Element *
******************************************************************/
CWBool CWMergeOFDMValues(int WTPIndex)
{
OFDMControlValues* aux;
aux=(OFDMControlValues *)(gWTPs[WTPIndex].WTPProtocolManager).bindingValuesPtr;
if(gWTPs[WTPIndex].ofdmValues->currentChan == UNUSED_OFDM_VALUE )
gWTPs[WTPIndex].ofdmValues->currentChan = aux->currentChan;
if(gWTPs[WTPIndex].ofdmValues->BandSupport == UNUSED_OFDM_VALUE )
gWTPs[WTPIndex].ofdmValues->BandSupport = aux->BandSupport;
if(gWTPs[WTPIndex].ofdmValues->TIThreshold == UNUSED_OFDM_VALUE )
gWTPs[WTPIndex].ofdmValues->TIThreshold = aux->TIThreshold;
return CW_TRUE;
}
CWBool CWAssembleWTPOFDM(CWProtocolMessage *msgPtr, int radioID)
{
const int totalMessageLength= BINDING_MSG_ELEMENT_TYPE_OFDM_CONTROL_LENGTH;
int* iPtr;
OFDMControlValues* valuesPtr;
CWLog("Assembling Binding Configuration Update Request [OFDM CASE]...");
if(msgPtr == NULL) return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
if((iPtr = ((int*)CWThreadGetSpecific(&gIndexSpecific))) == NULL) {
return CW_FALSE;
}
if(!CWMergeOFDMValues(*iPtr)) {return CW_FALSE;}
valuesPtr =gWTPs[*iPtr].ofdmValues;
/* create message */
CW_CREATE_PROTOCOL_MESSAGE(*msgPtr, totalMessageLength, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
CWProtocolStore8(msgPtr, radioID);
CWProtocolStore32(msgPtr, valuesPtr->currentChan);
CWProtocolStore8(msgPtr, valuesPtr->BandSupport);
CWProtocolStore32(msgPtr, valuesPtr->TIThreshold);
CWLog("Assembling Binding Configuration Update Request [OFDM CASE]: Message Assembled.");
return CWAssembleMsgElem(msgPtr, BINDING_MSG_ELEMENT_TYPE_OFDM_CONTROL);
}
CWBool CWAssembleWTPQoS (CWProtocolMessage *msgPtr, int radioID, int tagPackets)
{
const int headerLength=2;
const int messageBodyLength=32;
const int totalMessageLength= headerLength+messageBodyLength;
int i;
int* iPtr;
WTPQosValues* valuesPtr;
if(msgPtr == NULL) return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
if((iPtr = ((int*)CWThreadGetSpecific(&gIndexSpecific))) == NULL) {
return CW_FALSE;
}
if(!CWMergeQosValues(*iPtr)) {return CW_FALSE;}
valuesPtr=gWTPs[*iPtr].qosValues;
// create message
CW_CREATE_PROTOCOL_MESSAGE(*msgPtr, totalMessageLength, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
CWProtocolStore8(msgPtr, radioID);
CWProtocolStore8(msgPtr, tagPackets);
for(i=0; i<NUM_QOS_PROFILES; i++)
{
CWProtocolStore8(msgPtr, valuesPtr[i].queueDepth);
CWProtocolStore16(msgPtr, valuesPtr[i].cwMin);
CWProtocolStore16(msgPtr, valuesPtr[i].cwMax);
CWProtocolStore8(msgPtr, valuesPtr[i].AIFS);
CWProtocolStore8(msgPtr, valuesPtr[i].dot1PTag);
CWProtocolStore8(msgPtr, valuesPtr[i].DSCPTag);
}
return CWAssembleMsgElem(msgPtr, BINDING_MSG_ELEMENT_TYPE_WTP_QOS);
}
/*
* Elena Agostini - 08/2014: nl80211 support
*/
CWBool CWAssembleMsgElemACWTPMultiDomainCapability(CWProtocolMessage *msgPtr, int radioID, int firstChannel, int numChannels, int maxTxPower) {
if(msgPtr == NULL) return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
CW_CREATE_PROTOCOL_MESSAGE(*msgPtr, 8, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
CWProtocolStore8(msgPtr, radioID);
CWProtocolStore8(msgPtr, 0);
CWProtocolStore16(msgPtr, firstChannel);
CWProtocolStore16(msgPtr, numChannels);
CWProtocolStore16(msgPtr, maxTxPower);
return CWAssembleMsgElem(msgPtr, CW_MSG_ELEMENT_IEEE80211_MULTI_DOMAIN_CAPABILITY_CW_TYPE);
}
CWBool CWBindingAssembleConfigureResponse(CWProtocolMessage **msgElems, int *msgElemCountPtr)
{
CWWTPRadiosInfo radiosInfo;
int* iPtr;
const int tagPackets=0;
int k = -1, radioCount, radioID, j;
if(msgElems == NULL || msgElemCountPtr == NULL) return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
if((iPtr = ((int*)CWThreadGetSpecific(&gIndexSpecific))) == NULL) {
return CW_FALSE;
}
//Calculate the number of msg Elements
*msgElemCountPtr =0;
radiosInfo=gWTPs[*iPtr].WTPProtocolManager.radiosInfo;
radioCount=radiosInfo.radioCount;
//Elena Agostini: QoS + MultidomainCapability
*msgElemCountPtr = radioCount*2;
CWLog("Assembling Binding Configuration Response...");
//Reserve memory for msg Elements
CW_CREATE_PROTOCOL_MSG_ARRAY_ERR(*msgElems, *msgElemCountPtr, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
if(!CWThreadMutexLock(&(gWTPs[*iPtr].interfaceMutex)))
{
CWLog("Error locking a mutex");
CWCloseThread();
}
//Fill gWTPs[*iPtr].qosValues with default settings
gWTPs[*iPtr].qosValues=gDefaultQosValues;
for (j=0; j<radioCount; j++)
{
radioID=radiosInfo.radiosInfo[j].gWTPPhyInfo.radioID;// radiosInfo.radiosInfo[j].radioID;
// Assemble WTP QoS Message Element for each radio
if (!(CWAssembleWTPQoS(&((*msgElems)[++k]), radioID, tagPackets)))
{
int i;
for(i = 0; i <= k; i++) {CW_FREE_PROTOCOL_MESSAGE(*msgElems[i]);}
CW_FREE_OBJECT(*msgElems);
CWThreadMutexUnlock(&(gWTPs[*iPtr].interfaceMutex));
return CW_FALSE; // error will be handled by the caller
}
/*
* Elena Agostini - 07/2014: wtp radio multi domain capability
*/
if(!(CWAssembleMsgElemACWTPMultiDomainCapability(&((*msgElems)[++k]),
radiosInfo.radiosInfo[j].gWTPPhyInfo.radioID,
radiosInfo.radiosInfo[j].gWTPPhyInfo.phyFrequencyInfo.frequencyList[0].frequency,
radiosInfo.radiosInfo[j].gWTPPhyInfo.phyFrequencyInfo.totChannels,
radiosInfo.radiosInfo[j].gWTPPhyInfo.phyFrequencyInfo.frequencyList[0].maxTxPower
)
))
{
int i;
for(i = 0; i <= k; i++) {CW_FREE_PROTOCOL_MESSAGE(*msgElems[i]);}
CW_FREE_OBJECT(*msgElems);
CWThreadMutexUnlock(&(gWTPs[*iPtr].interfaceMutex));
return CW_FALSE; // error will be handled by the caller
}
}
gWTPs[*iPtr].qosValues=NULL;
CWThreadMutexUnlock(&(gWTPs[*iPtr].interfaceMutex));
CWLog("Binding Configuration Response Assembled");
return CW_TRUE;
}
/******************************************************************
* 2009 Updates: *
* Added new switch case for ofdm message management *
******************************************************************/
CWBool CWBindingAssembleConfigurationUpdateRequest(CWProtocolMessage **msgElems, int *msgElemCountPtr, int BindingMsgElement){
CWWTPRadiosInfo radiosInfo;
int* iPtr;
const int tagPackets=0;
int k = -1, radioCount, radioID, j;
if(msgElems == NULL || msgElemCountPtr == NULL) return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
if((iPtr = ((int*)CWThreadGetSpecific(&gIndexSpecific))) == NULL) {
return CW_FALSE;
}
*msgElemCountPtr =0;
radiosInfo=gWTPs[*iPtr].WTPProtocolManager.radiosInfo;
radioCount=radiosInfo.radioCount;
*msgElemCountPtr = radioCount;
CWLog("Assembling Binding Configuration Update Request...");
CW_CREATE_PROTOCOL_MSG_ARRAY_ERR(*msgElems, *msgElemCountPtr, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
/* Selection of type of Conf Update Request */
switch(BindingMsgElement) {
case BINDING_MSG_ELEMENT_TYPE_WTP_QOS:
{
for (j=0; j<radioCount; j++)
{
radioID=radiosInfo.radiosInfo[j].radioID;
// Assemble Message Elements
if (!(CWAssembleWTPQoS(&(*msgElems[++k]), radioID, tagPackets)))
{
int i;
for(i = 0; i <= k; i++) {CW_FREE_PROTOCOL_MESSAGE(*msgElems[i]);}
CW_FREE_OBJECT(*msgElems);
return CW_FALSE; // error will be handled by the caller
}
}
break;
}
case BINDING_MSG_ELEMENT_TYPE_OFDM_CONTROL:
{
for (j=0; j<radioCount; j++) {
radioID=radiosInfo.radiosInfo[j].radioID;
/* Assemble Message Elements */
if (!(CWAssembleWTPOFDM(&(*msgElems[++k]), radioID))) {
int i;
for(i = 0; i <= k; i++) {CW_FREE_PROTOCOL_MESSAGE(*msgElems[i]);}
CW_FREE_OBJECT(*msgElems);
return CW_FALSE; // error will be handled by the caller
}
}
break;
}
default:
{
return CW_FALSE; // error will be handled by the caller
}
}
CWLog("Binding Configuration Update Request Assembled");
return CW_TRUE;
}
CWBool CWBindingSaveConfigurationUpdateResponse(CWProtocolResultCode resultCode, int WTPIndex)
{
int i;
bindingValues* aux=(bindingValues*)gWTPs[WTPIndex].WTPProtocolManager.bindingValuesPtr;
if (resultCode==CW_PROTOCOL_SUCCESS)
{
if (gWTPs[WTPIndex].qosValues!=NULL)
{
for(i=0; i<NUM_QOS_PROFILES; i++)
{
aux->qosValues[i].cwMin=gWTPs[WTPIndex].qosValues[i].cwMin;
aux->qosValues[i].cwMax=gWTPs[WTPIndex].qosValues[i].cwMax;
aux->qosValues[i].AIFS=gWTPs[WTPIndex].qosValues[i].AIFS;
}
}
}
return CW_TRUE;
}