freewtp/src/wtp/wtp_dfa_idle.c

57 lines
1.6 KiB
C
Raw Normal View History

2013-05-01 14:52:55 +02:00
#include "wtp.h"
#include "capwap_dfa.h"
#include "wtp_dfa.h"
/* */
void wtp_dfa_state_idle(void) {
long discoveryinterval;
2013-11-07 22:06:29 +01:00
/* Remove teardown */
2013-09-16 22:10:37 +02:00
g_wtp.teardown = 0;
capwap_timeout_unsetall(g_wtp.timeout);
2013-09-16 22:10:37 +02:00
2013-11-07 22:06:29 +01:00
/* */
2013-05-01 14:52:55 +02:00
if (!g_wtp.acdiscoveryrequest && (g_wtp.acpreferedarray->count > 0)) {
2013-11-07 22:06:29 +01:00
while (g_wtp.acpreferedselected < g_wtp.acpreferedarray->count) {
union sockaddr_capwap localaddr;
union sockaddr_capwap peeraddr;
2013-11-07 22:06:29 +01:00
/* Found in configuration file the AC address */
memcpy(&peeraddr, capwap_array_get_item_pointer(g_wtp.acpreferedarray, g_wtp.acpreferedselected), sizeof(union sockaddr_capwap));
2013-11-07 22:06:29 +01:00
/* Next AC */
g_wtp.acpreferedselected++;
/* Retrieve local address */
if (!capwap_network_get_localaddress(&localaddr, &peeraddr, g_wtp.net.bindiface)) {
CAPWAP_SET_NETWORK_PORT(&localaddr, CAPWAP_GET_NETWORK_PORT(&g_wtp.net.localaddr));
2013-05-01 14:52:55 +02:00
/* */
capwap_crypt_setconnection(&g_wtp.dtls, g_wtp.net.socket, &localaddr, &peeraddr);
2013-11-07 22:06:29 +01:00
/* */
if (!g_wtp.enabledtls) {
wtp_send_join(); /* Bypass DTLS connection */
} else {
wtp_start_dtlssetup(); /* Create DTLS connection */
2013-11-07 22:06:29 +01:00
}
return;
2013-11-07 22:06:29 +01:00
}
}
2013-05-01 14:52:55 +02:00
}
2013-11-07 22:06:29 +01:00
/* Discovery AC */
g_wtp.acpreferedselected = 0;
2013-05-01 14:52:55 +02:00
/* Set discovery interval */
g_wtp.discoverycount = 0;
discoveryinterval = capwap_get_rand(g_wtp.discoveryinterval - WTP_MIN_DISCOVERY_INTERVAL) + WTP_MIN_DISCOVERY_INTERVAL;
2013-11-07 22:06:29 +01:00
2013-05-01 14:52:55 +02:00
/* Change state */
wtp_dfa_change_state(CAPWAP_DISCOVERY_STATE);
2013-11-07 22:06:29 +01:00
2013-05-01 14:52:55 +02:00
/* Wait before send Discovery Request */
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, discoveryinterval, wtp_dfa_state_discovery_timeout, NULL, NULL);
2013-05-01 14:52:55 +02:00
}