forked from vollero/openCAPWAP
-
Notifications
You must be signed in to change notification settings - Fork 2
/
WTPSulkingState.c
122 lines (111 loc) · 5.22 KB
/
WTPSulkingState.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
/*******************************************************************************************
* 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 (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 CW_DEBUGGING
int gCWSilentInterval = 5;
#else
int gCWSilentInterval = 30;
#endif
/*
* WTP enters sulking when no AC is responding to Discovery Request.
*/
CWStateTransition CWWTPEnterSulking()
{
struct timeval timeout, before, after, delta, newTimeout;
CWLog("\n");
CWLog("######### Sulking State #########");
/*
* wait for Silent Interval and discard
* all the packets that are coming
*/
timeout.tv_sec = newTimeout.tv_sec = gCWSilentInterval;
timeout.tv_usec = newTimeout.tv_usec = 0;
gettimeofday(&before, NULL);
CW_REPEAT_FOREVER {
/* check if something is available to read until newTimeout */
if (CWNetworkTimedPollRead(gWTPSocket, &newTimeout)) {
/*
* success
* if there was no error, raise a "success error", so we can easily handle
* all the cases in the switch
*/
CWErrorRaise(CW_ERROR_SUCCESS, NULL);
}
switch (CWErrorGetLastErrorCode()) {
case CW_ERROR_TIME_EXPIRED:
goto cw_sulk_time_over;
break;
case CW_ERROR_SUCCESS:
/* there's something to read */
{
CWNetworkLev4Address addr;
char buf[CW_BUFFER_SIZE];
int readBytes;
/* read and discard */
if (!CWErr
(CWNetworkReceiveUnsafe(gWTPSocket, buf, CW_BUFFER_SIZE, 0, &addr, &readBytes))) {
return CW_QUIT;
}
if (readBytes == 0)
/* no error, but not data == orderly shutdown */
return CW_QUIT;
}
case CW_ERROR_INTERRUPTED:
/*
* something to read OR interrupted by the
* system
* wait for the remaining time (NetworkPoll
* will be recalled with the remaining time)
*/
gettimeofday(&after, NULL);
CWTimevalSubtract(&delta, &after, &before);
if (CWTimevalSubtract(&newTimeout, &timeout, &delta) == 1) {
/* negative delta: time is over */
goto cw_sulk_time_over;
}
break;
default:
CWErrorHandleLast();
goto cw_error;
break;
}
}
cw_sulk_time_over:
CWLog("End of Sulking Period");
cw_error:
return CW_ENTER_DISCOVERY;
}