-
Notifications
You must be signed in to change notification settings - Fork 84
/
WTPIEEEConfigurationState.c
313 lines (265 loc) · 11.7 KB
/
WTPIEEEConfigurationState.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
/*******************************************************************************************
* 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
/*_________________________________________________________*/
/* *******************___FUNCTIONS___******************* */
CWBool CWAssembleIEEEConfigurationResponse(CWProtocolMessage **messagesPtr,
int *fragmentsNumPtr,
int PMTU,
int seqNum,
int resultCode,
int radioID,
int wlanID,
char * bssidAssigned);
CWBool CWParseIEEEConfigurationRequestMessage (char *msg,
int len,
int seqNum,
ACInterfaceRequestInfo * interfaceInfo);
CWBool CWSaveIEEEConfigurationRequestMessage(ACInterfaceRequestInfo * interfaceInfo);
CWBool CWWTPIEEEConfigurationReceiveSendPacket(int seqNum, CWList msgElemlist);
/*
* Send Configure Request on the active session.
*/
CWBool CWAssembleIEEEConfigurationResponse(CWProtocolMessage **messagesPtr,
int *fragmentsNumPtr,
int PMTU,
int seqNum,
int resultCode,
int radioID,
int wlanID,
char * bssid) {
CWProtocolMessage *msgElems= NULL;
CWProtocolMessage *msgElemsBinding= NULL;
const int msgElemCount = 2;
const int msgElemBindingCount=0;
int k = -1;
if(messagesPtr == NULL || fragmentsNumPtr == NULL)
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
CW_CREATE_PROTOCOL_MSG_ARRAY_ERR(msgElems,
msgElemCount,
return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
CWDebugLog("Assembling IEEE configuration Response...");
if(bssid == NULL)
{
if((!(CWAssembleMsgElemResultCode(&(msgElems[++k]), resultCode))))
{
int i;
for(i = 0; i <= k; i++) { CW_FREE_PROTOCOL_MESSAGE(msgElems[i]);}
CW_FREE_OBJECT(msgElems);
/* error will be handled by the caller */
return CW_FALSE;
}
}
else
{
if ((!(CWAssembleMsgElemResultCode(&(msgElems[++k]), resultCode))) ||
(!(CWAssembleMsgElemAssignedWTPSSID(&(msgElems[++k]), radioID, wlanID, bssid)))
)
{
int i;
for(i = 0; i <= k; i++) { CW_FREE_PROTOCOL_MESSAGE(msgElems[i]);}
CW_FREE_OBJECT(msgElems);
/* error will be handled by the caller */
return CW_FALSE;
}
}
if (!(CWAssembleMessage(messagesPtr,
fragmentsNumPtr,
PMTU,
seqNum,
CW_MSG_TYPE_VALUE_WLAN_CONFIGURATION_RESPONSE,
msgElems,
msgElemCount,
msgElemsBinding,
msgElemBindingCount,
#ifdef CW_NO_DTLS
CW_PACKET_PLAIN
#else
CW_PACKET_CRYPT
#endif
)))
return CW_FALSE;
CWDebugLog("IEEE Configuration Request Assembled");
return CW_TRUE;
}
CWBool CWParseIEEEConfigurationRequestMessage (char *msg,
int len,
int seqNum,
ACInterfaceRequestInfo * interfaceInfo) {
CWControlHeaderValues controlVal;
CWProtocolMessage completeMsg;
CWBool bindingMsgElemFound = CW_FALSE;
int offsetTillMessages;
int i=0;
int j=0;
if(msg == NULL || interfaceInfo == NULL)
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
CWDebugLog("Parsing IEEE Configuration Response...");
completeMsg.msg = msg;
completeMsg.offset = 0;
/* error will be handled by the caller */
if(!(CWParseControlHeader(&completeMsg, &controlVal))) return CW_FALSE;
/* different type */
if (controlVal.messageTypeValue != CW_MSG_TYPE_VALUE_WLAN_CONFIGURATION_REQUEST)
return CWErrorRaise(CW_ERROR_INVALID_FORMAT,
"Message is not IEE Wlan Configuration Request as Expected");
if (controlVal.seqNum != seqNum)
return CWErrorRaise(CW_ERROR_INVALID_FORMAT,
"Different Sequence Number");
/* skip timestamp */
controlVal.msgElemsLen -= CW_CONTROL_HEADER_OFFSET_FOR_MSG_ELEMS;
offsetTillMessages = completeMsg.offset;
/* parse message elements */
while((completeMsg.offset-offsetTillMessages) < controlVal.msgElemsLen) {
unsigned short int type=0; /* = CWProtocolRetrieve32(&completeMsg); */
unsigned short int len=0; /* = CWProtocolRetrieve16(&completeMsg); */
CWParseFormatMsgElem(&completeMsg,&type,&len);
// CWLog("Parsing Message Element: %u, len: %u complete: %d", type, len, completeMsg.offset);
switch(type) {
case CW_MSG_ELEMENT_IEEE80211_ADD_WLAN_CW_TYPE:
if(!(CWParseACAddWlan(&completeMsg, len, interfaceInfo))) return CW_FALSE;
break;
case CW_MSG_ELEMENT_IEEE80211_DELETE_WLAN_CW_TYPE:
if(!(CWParseACDelWlan(&completeMsg, len, interfaceInfo))) return CW_FALSE;
break;
case CW_MSG_ELEMENT_IEEE80211_UPDATE_WLAN_CW_TYPE:
if(!(CWParseACUpdateWlan(&completeMsg, len, interfaceInfo))) return CW_FALSE;
break;
default:
return CWErrorRaise(CW_ERROR_INVALID_FORMAT, "Unrecognized Message Element");
}
}
if(completeMsg.offset != len)
return CWErrorRaise(CW_ERROR_INVALID_FORMAT,
"Garbage at the End of the Message");
completeMsg.offset = offsetTillMessages;
CWDebugLog("IEEE Configuration Request Parsed");
return CW_TRUE;
}
CWBool CWSaveIEEEConfigurationRequestMessage(ACInterfaceRequestInfo * interfaceACInfo) {
if(interfaceACInfo == NULL)
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
//RFC radioID > 0 wlanID > 0
/*if(interfaceACInfo->radioID <= 0 || interfaceACInfo->wlanID <= 0)
return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
*/
int indexRadio = CWIEEEBindingGetIndexFromDevID(interfaceACInfo->radioID);
int indexWlan = CWIEEEBindingGetIndexFromDevID(interfaceACInfo->wlanID);
// CWLog("WLAN Interface op %d on radioID: %d wlanID: %d", interfaceACInfo->operation, indexRadio, indexWlan);
//Add Wlan
if(interfaceACInfo->operation == CW_OP_ADD_WLAN)
{
if(
(indexWlan < WTP_MAX_INTERFACES) &&
(indexRadio < WTP_RADIO_MAX) &&
(gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].typeInterface == CW_STA_MODE)
)
{
//gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].wlanID = indexWlan;
CW_COPY_MEMORY(gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].capability, interfaceACInfo->capability, WLAN_CAPABILITY_NUM_FIELDS);
gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].capabilityBit = interfaceACInfo->capabilityBit;
//---- Key
gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].keyIndex = interfaceACInfo->keyIndex;
gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].keyStatus = interfaceACInfo->keyStatus;
gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].keyLength = interfaceACInfo->keyLength;
CW_COPY_MEMORY(gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].key, interfaceACInfo->key, WLAN_KEY_LEN);
//---- Key
CW_COPY_MEMORY(gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].groupTSC, interfaceACInfo->groupTSC, WLAN_GROUP_TSC_LEN);
gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].qos = interfaceACInfo->qos;
gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].authType = interfaceACInfo->authType;
gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].MACmode = interfaceACInfo->MACmode;
gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].frameTunnelMode = interfaceACInfo->tunnelMode;
gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].suppressSSID = interfaceACInfo->suppressSSID;
CW_CREATE_STRING_FROM_STRING_ERR(gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].SSID, interfaceACInfo->SSID, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
if(!CWWTPSetAPInterface(indexRadio, indexWlan, &(gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan])))
goto failure;
//Add interface to bridge
/* if(gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].frameTunnelMode == CW_LOCAL_BRIDGING)
// if(CWWTPGetFrameTunnelMode() == CW_LOCAL_BRIDGING)
{
CWLog("Local Bridging tunnel mode. Adding %s to %s", gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].ifName, gBridgeInterfaceName);
if(!CWAddNewBridgeInterface(globalNLSock.ioctl_sock, gBridgeInterfaceName, gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].realWlanID))
goto failure;
}
*/
goto success;
}
else
goto failure;
}
//Delete Wlan
else if(interfaceACInfo->operation == CW_OP_DEL_WLAN)
{
if(
(indexWlan < WTP_MAX_INTERFACES) &&
(indexRadio < WTP_RADIO_MAX) &&
(gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].typeInterface == CW_AP_MODE)
)
{
if(!CWWTPDeleteWLANAPInterface(indexRadio, indexWlan))
goto failure;
//Delete interface from structure
if(gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].SSID != NULL)
{
CW_FREE_OBJECT(gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].SSID);
gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].SSID=NULL;
}
gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.interfaces[indexWlan].typeInterface = CW_STA_MODE;
//TODO: Serve?
gRadiosInfo.radiosInfo[indexRadio].gWTPPhyInfo.numInterfaces--;
//Delete BSS
if(!CWWTPDeleteBSS(indexRadio, indexWlan))
goto failure;
goto success;
}
else
goto failure;
}
//Update Wlan
else if(interfaceACInfo->operation == CW_OP_UPDATE_WLAN)
{
//TODO
CWLog("IEEE update WLAN operation");
goto success;
}
else
{
CWLog("IEEE Unknwon type of WLAN operation");
goto failure;
}
success:
// CW_FREE_OBJECT(interfaceACInfo);
CWLog("IEEE Configuration Request Saved");
return CW_TRUE;
failure:
// CW_FREE_OBJECT(interfaceACInfo);
CWLog("IEEE Configuration Request NOT Saved");
return CW_FALSE;
}