forked from vollero/openCAPWAP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWTPDataCheckState.c
More file actions
179 lines (141 loc) · 6.1 KB
/
WTPDataCheckState.c
File metadata and controls
179 lines (141 loc) · 6.1 KB
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
/*******************************************************************************************
* 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 (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) *
*******************************************************************************************/
#include "CWWTP.h"
#ifdef DMALLOC
#include "../dmalloc-5.5.0/dmalloc.h"
#endif
CWBool CWAssembleChangeStateEventRequest(CWProtocolMessage **messagesPtr,
int *fragmentsNumPtr,
int PMTU,
int seqNum,
CWList msgElemList);
CWBool CWParseChangeStateEventResponseMessage(char *msg,
int len,
int seqNum,
void *values);
CWBool CWSaveChangeStateEventResponseMessage(void *changeStateEventResp);
CWStateTransition CWWTPEnterDataCheck() {
int seqNum;
CWLog("\n");
CWLog("######### Data Check State #########");
CWLog("\n");
CWLog("#________ Change State Event (Data Check) ________#");
/* Send Change State Event Request */
seqNum = CWGetSeqNum();
if(!CWErr(CWStartHeartbeatTimer())) {
return CW_ENTER_RESET;
}
if(!CWErr(CWWTPSendAcknowledgedPacket(seqNum,
NULL,
CWAssembleChangeStateEventRequest,
CWParseChangeStateEventResponseMessage,
CWSaveChangeStateEventResponseMessage,
NULL))) {
return CW_ENTER_RESET;
}
if(!CWErr(CWStopHeartbeatTimer())) {
return CW_ENTER_RESET;
}
return CW_ENTER_RUN;
}
CWBool CWAssembleChangeStateEventRequest(CWProtocolMessage **messagesPtr,
int *fragmentsNumPtr,
int PMTU,
int seqNum,
CWList msgElemList) {
CWProtocolMessage *msgElems= NULL;
CWProtocolMessage *msgElemsBinding= NULL;
const int msgElemCount = 2;
int msgElemBindingCount=0;
int resultCode = CW_PROTOCOL_SUCCESS;
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););
CWLog("Assembling Change State Event Request...");
/* Assemble Message Elements */
if (!(CWAssembleMsgElemRadioOperationalState(-1, &(msgElems[++k]))) ||
!(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;
}
if (!(CWAssembleMessage(messagesPtr,
fragmentsNumPtr,
PMTU,
seqNum,
CW_MSG_TYPE_VALUE_CHANGE_STATE_EVENT_REQUEST,
msgElems, msgElemCount,
msgElemsBinding,
msgElemBindingCount,
#ifdef CW_NO_DTLS
CW_PACKET_PLAIN
#else
CW_PACKET_CRYPT
#endif
)))
return CW_FALSE;
CWLog("Change State Event Request Assembled");
return CW_TRUE;
}
CWBool CWParseChangeStateEventResponseMessage(char *msg,
int len,
int seqNum,
void *values) {
CWControlHeaderValues controlVal;
CWProtocolMessage completeMsg;
if(msg == NULL) return CWErrorRaise(CW_ERROR_WRONG_ARG, NULL);
CWLog("Parsing Change State Event Response...");
completeMsg.msg = msg;
completeMsg.offset = 0;
/* error will be handled by the caller */
if(!(CWParseControlHeader(&completeMsg, &controlVal))) return CW_FALSE;
if(controlVal.messageTypeValue != CW_MSG_TYPE_VALUE_CHANGE_STATE_EVENT_RESPONSE)
return CWErrorRaise(CW_ERROR_INVALID_FORMAT,
"Message is not Change State Event Response 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;
if(controlVal.msgElemsLen != 0 )
return CWErrorRaise(CW_ERROR_INVALID_FORMAT,
"Change State Event Response must carry no message elements");
CWLog("Change State Event Response Parsed");
return CW_TRUE;
}
CWBool CWSaveChangeStateEventResponseMessage (void *changeStateEventResp)
{
CWDebugLog("Saving Change State Event Response...");
CWDebugLog("Change State Event Response Saved");
return CW_TRUE;
}