forked from vollero/openCAPWAP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWTPSulkingState.c
More file actions
112 lines (99 loc) · 4.32 KB
/
WTPSulkingState.c
File metadata and controls
112 lines (99 loc) · 4.32 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
/*******************************************************************************************
* 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
#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;
}
}
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;
}