-
Notifications
You must be signed in to change notification settings - Fork 84
/
ACDiscoveryState.c
285 lines (238 loc) · 11.2 KB
/
ACDiscoveryState.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
/*******************************************************************************************
* 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 "CWAC.h"
#ifdef DMALLOC
#include "../dmalloc-5.5.0/dmalloc.h"
#endif
/*__________________________________________________________*/
/* *******************___PROTOTYPES___******************* */
__inline__ int CWACGetHWVersion();
__inline__ int CWACGetSWVersion();
__inline__ int CWACGetStations();
__inline__ int CWACGetLimit();
__inline__ int CWACGetActiveWTPs();
__inline__ int CWACGetMaxWTPs();
__inline__ int CWACGetSecurity();
__inline__ char *CWACGetName();
__inline__ int CWACGetInterfacesCount();
/*_________________________________________________________*/
/* *******************___FUNCTIONS___******************* */
/* send Discovery Response to the host at the specified address */
CWBool CWAssembleDiscoveryResponse(CWProtocolMessage **messagesPtr, int seqNum, WTPglobalPhyInfo * tmpPhyInfo) {
CWProtocolMessage *msgElems= NULL;
int msgElemCount = 4;
CWProtocolMessage *msgElemsBinding= NULL;
int msgElemBindingCount=0;
int fragmentsNum;
int indexWTPRadio=0;
int k = -1;
if(messagesPtr == NULL) return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
if(CWACSupportIPv6()) {
msgElemCount++;
}
CWLog("Send Discovery Response");
CW_CREATE_PROTOCOL_MSG_ARRAY_ERR(msgElems,
msgElemCount,
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
/* Assemble Message Elements */
if (
(!(CWAssembleMsgElemACDescriptor(&(msgElems[++k])))) ||
(!(CWAssembleMsgElemACName(&(msgElems[++k])))) ||
(!(CWAssembleMsgElemCWControlIPv4Addresses(&(msgElems[++k]))))
/*(CWACSupportIPv6() && (!(CWAssembleMsgElemCWControlIPv6Addresses(&(msgElems[++k])))))*/
) {
CWErrorHandleLast();
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
}
//Elena Agostini - 07/2014: wtp radio info replay
for(indexWTPRadio=0; indexWTPRadio<tmpPhyInfo->numPhyActive; indexWTPRadio++)
{
if(!(CWAssembleMsgElemACWTPRadioInformation(&(msgElems[++k]), tmpPhyInfo->singlePhyInfo[indexWTPRadio].radioID, tmpPhyInfo->singlePhyInfo[indexWTPRadio].phyStandardValue)))
{
CWErrorHandleLast();
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
}
}
return CWAssembleMessage(messagesPtr,
&fragmentsNum,
0,
seqNum,
CW_MSG_TYPE_VALUE_DISCOVERY_RESPONSE,
msgElems,
msgElemCount,
msgElemsBinding,
msgElemBindingCount,
CW_PACKET_PLAIN);
}
CWBool CWParseDiscoveryRequestMessage(char *msg,
int len,
int *seqNumPtr,
CWDiscoveryRequestValues *valuesPtr) {
CWControlHeaderValues controlVal;
CWProtocolTransportHeaderValues transportVal;
char RadioInfoABGN;
int numPhyInterface;
int offsetTillMessages;
CWProtocolMessage completeMsg;
//Elena Agostini: nl80211 support
valuesPtr->tmpPhyInfo.numPhyActive=0;
CW_CREATE_ARRAY_CALLOC_ERR(valuesPtr->tmpPhyInfo.singlePhyInfo, WTP_RADIO_MAX, ACWTPSinglePhyInfo, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
if(msg == NULL || seqNumPtr == NULL || valuesPtr == NULL)
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
CWDebugLog("Parse Discovery Request");
completeMsg.msg = msg;
completeMsg.offset = 0;
CWBool dataFlag = CW_FALSE;
if(!(CWParseTransportHeader(&completeMsg, &transportVal, &dataFlag, NULL)))
/* will be handled by the caller */
return CW_FALSE;
if(!(CWParseControlHeader(&completeMsg, &controlVal)))
/* will be handled by the caller */
return CW_FALSE;
/* different type */
if(controlVal.messageTypeValue != CW_MSG_TYPE_VALUE_DISCOVERY_REQUEST)
return CWErrorRaise(CW_ERROR_INVALID_FORMAT, "Message is not Discovery Request as Expected");
*seqNumPtr = controlVal.seqNum;
/* skip timestamp */
controlVal.msgElemsLen -= CW_CONTROL_HEADER_OFFSET_FOR_MSG_ELEMS;
offsetTillMessages = completeMsg.offset;
/* (*valuesPtr).radios.radiosCount = 0; */
/* parse message elements */
while((completeMsg.offset-offsetTillMessages) < controlVal.msgElemsLen) {
unsigned short int elemType = 0;/* = CWProtocolRetrieve32(&completeMsg); */
unsigned short int elemLen = 0; /* = CWProtocolRetrieve16(&completeMsg); */
CWParseFormatMsgElem(&completeMsg,&elemType,&elemLen);
/* CWDebugLog("Parsing Message Element: %u, elemLen: %u", elemType, elemLen); */
switch(elemType) {
case CW_MSG_ELEMENT_DISCOVERY_TYPE_CW_TYPE:
if(!(CWParseDiscoveryType(&completeMsg, elemLen, valuesPtr)))
/* will be handled by the caller */
return CW_FALSE;
break;
case CW_MSG_ELEMENT_WTP_BOARD_DATA_CW_TYPE:
if(!(CWParseWTPBoardData(&completeMsg, elemLen, &(valuesPtr->WTPBoardData))))
/* will be handled by the caller */
return CW_FALSE;
break;
case CW_MSG_ELEMENT_WTP_DESCRIPTOR_CW_TYPE:
if(!(CWParseWTPDescriptor(&completeMsg, elemLen, &(valuesPtr->WTPDescriptor))))
/* will be handled by the caller */
return CW_FALSE;
break;
case CW_MSG_ELEMENT_WTP_FRAME_TUNNEL_MODE_CW_TYPE:
if(!(CWParseWTPFrameTunnelMode(&completeMsg, elemLen, &(valuesPtr->frameTunnelMode))))
/* will be handled by the caller */
return CW_FALSE;
break;
case CW_MSG_ELEMENT_WTP_MAC_TYPE_CW_TYPE:
if(!(CWParseWTPMACType(&completeMsg, elemLen, &(valuesPtr->MACType))))
/* will be handled by the caller */
return CW_FALSE;
break;
case CW_MSG_ELEMENT_IEEE80211_WTP_RADIO_INFORMATION_CW_TYPE:
if(valuesPtr->tmpPhyInfo.numPhyActive < WTP_RADIO_MAX)
if(!(CWParseWTPRadioInformation(&completeMsg,
elemLen,
&(valuesPtr->tmpPhyInfo.singlePhyInfo[valuesPtr->tmpPhyInfo.numPhyActive].radioID),
&(valuesPtr->tmpPhyInfo.singlePhyInfo[valuesPtr->tmpPhyInfo.numPhyActive].phyStandardValue)
)
))return CW_FALSE;
valuesPtr->tmpPhyInfo.numPhyActive++;
break;
/*case CW_MSG_ELEMENT_WTP_RADIO_INFO_CW_TYPE:
// just count how many radios we have, so we can allocate the array
(*valuesPtr).radios.radiosCount++;
completeMsg.offset += elemLen;
break;
*/
default:
return CWErrorRaise(CW_ERROR_INVALID_FORMAT,
"Unrecognized Message Element");
}
/*CWDebugLog("bytes: %d/%d", (completeMsg.offset-offsetTillMessages), controlVal.msgElemsLen);*/
}
if(completeMsg.offset != len) return CWErrorRaise(CW_ERROR_INVALID_FORMAT, "Garbage at the End of the Message");
/*
// actually read each radio info
CW_CREATE_ARRAY_ERR((*valuesPtr).radios.radios, (*valuesPtr).radios.radiosCount, CWRadioInformationValues,
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
i = 0;
completeMsg.offset = offsetTillMessages;
while(i < (*valuesPtr).radios.radiosCount && (completeMsg.offset-offsetTillMessages) < controlVal.msgElemsLen) {
unsigned short int type=0;// = CWProtocolRetrieve32(&completeMsg);
unsigned short int len=0;// = CWProtocolRetrieve16(&completeMsg);
CWParseFormatMsgElem(&completeMsg,&type,&len);
switch(type) {
case CW_MSG_ELEMENT_WTP_RADIO_INFO_CW_TYPE:
if(!(CWParseWTPRadioInfo(&completeMsg, len, &(valuesPtr->radios), i))) return CW_FALSE; // will be handled by the caller
i++;
break;
default:
completeMsg.offset += len;
break;
}
}
*/
return CW_TRUE;
}
void CWDestroyDiscoveryRequestValues(CWDiscoveryRequestValues *valPtr) {
int i;
if(valPtr == NULL) return;
for(i = 0; i < (valPtr->WTPDescriptor.vendorInfos).vendorInfosCount; i++) {
CW_FREE_OBJECT(((valPtr->WTPDescriptor.vendorInfos).vendorInfos)[i].valuePtr);
}
CW_FREE_OBJECT((valPtr->WTPDescriptor.vendorInfos).vendorInfos);
/*
* BUG ML11
*
* 10/10/2009 - Donato Capitella
*/
for(i = 0; i < valPtr->WTPBoardData.vendorInfosCount; i++) {
CW_FREE_OBJECT(valPtr->WTPBoardData.vendorInfos[i].valuePtr);
}
CW_FREE_OBJECT(valPtr->WTPBoardData.vendorInfos);
//Elena Agostini: nl80211 support
if(valPtr->tmpPhyInfo.numPhyActive > 0)
CW_FREE_OBJECT(valPtr->tmpPhyInfo.singlePhyInfo);
/*CW_FREE_OBJECT((valPtr->radios).radios);*/
}