2013-05-01 14:52:55 +02:00
|
|
|
#include "wtp.h"
|
|
|
|
#include "capwap_dfa.h"
|
|
|
|
#include "wtp_dfa.h"
|
2016-03-30 10:39:04 +02:00
|
|
|
#include "wtp_radio.h"
|
2013-05-01 14:52:55 +02:00
|
|
|
|
2014-03-02 19:31:27 +01:00
|
|
|
/* */
|
2016-03-30 10:39:04 +02:00
|
|
|
static void wtp_dfa_state_dtlsconnect_timeout(EV_P_ ev_timer *w, int revents)
|
|
|
|
{
|
2016-04-29 08:32:49 +02:00
|
|
|
log_printf(LOG_DEBUG, "DTLS Connect Timeout");
|
2014-03-02 19:31:27 +01:00
|
|
|
wtp_teardown_connection();
|
|
|
|
}
|
|
|
|
|
2013-05-01 14:52:55 +02:00
|
|
|
/* */
|
2016-03-30 10:39:04 +02:00
|
|
|
void wtp_dfa_state_dead_enter(void)
|
|
|
|
{
|
|
|
|
ev_break(EV_DEFAULT_UC_ EVBREAK_ALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
void wtp_dfa_state_dtlsconnect_enter(void)
|
|
|
|
{
|
|
|
|
ev_timer_init(&g_wtp.timercontrol, wtp_dfa_state_dtlsconnect_timeout,
|
|
|
|
WTP_DTLS_INTERVAL / 1000.0, 0.);
|
|
|
|
ev_timer_start(EV_DEFAULT_UC_ &g_wtp.timercontrol);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
void wtp_start_dtlssetup(void)
|
|
|
|
{
|
2013-05-01 14:52:55 +02:00
|
|
|
/* Create DTLS session */
|
2014-09-10 21:58:23 +02:00
|
|
|
if (!capwap_crypt_createsession(&g_wtp.dtls, &g_wtp.dtlscontext)) {
|
2013-11-07 22:06:29 +01:00
|
|
|
wtp_dfa_change_state(CAPWAP_SULKING_STATE);
|
2016-03-26 20:26:57 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (capwap_crypt_open(&g_wtp.dtls) == CAPWAP_HANDSHAKE_ERROR) {
|
2016-08-17 15:18:35 +02:00
|
|
|
wtp_abort_connecting();
|
2016-03-30 10:39:04 +02:00
|
|
|
} else
|
2016-03-26 20:26:57 +01:00
|
|
|
wtp_dfa_change_state(CAPWAP_DTLS_CONNECT_STATE);
|
2013-05-01 14:52:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
2016-03-30 10:39:04 +02:00
|
|
|
void wtp_start_datachannel(void)
|
|
|
|
{
|
2014-09-10 21:58:23 +02:00
|
|
|
union sockaddr_capwap dataaddr;
|
|
|
|
|
|
|
|
/* Set AC data address */
|
|
|
|
memcpy(&dataaddr, &g_wtp.dtls.peeraddr, sizeof(union sockaddr_capwap));
|
|
|
|
CAPWAP_SET_NETWORK_PORT(&dataaddr, (CAPWAP_GET_NETWORK_PORT(&g_wtp.dtls.peeraddr) + 1));
|
|
|
|
|
2014-12-28 15:48:52 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
char addr[INET6_ADDRSTRLEN];
|
2016-03-30 14:47:57 +02:00
|
|
|
log_printf(LOG_DEBUG, "Create data channel with peer %s:%d",
|
2016-03-30 10:39:04 +02:00
|
|
|
capwap_address_to_string(&dataaddr, addr, INET6_ADDRSTRLEN),
|
|
|
|
(int)CAPWAP_GET_NETWORK_PORT(&dataaddr));
|
2014-12-28 15:48:52 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-18 15:06:39 +01:00
|
|
|
/* Bind data address and Connect to AC data channel */
|
2016-03-26 20:26:57 +01:00
|
|
|
if (wtp_kmod_create(g_wtp.net.localaddr.ss.ss_family, &dataaddr.ss, &g_wtp.sessionid, g_wtp.mtu) != 0) {
|
2014-09-10 21:58:23 +02:00
|
|
|
/* Error to send packets */
|
2016-03-30 14:47:57 +02:00
|
|
|
log_printf(LOG_ERR, "Error to send data channel keepalive packet");
|
2014-02-19 19:16:33 +01:00
|
|
|
wtp_teardown_connection();
|
2016-03-26 20:26:57 +01:00
|
|
|
return;
|
2013-11-07 22:06:29 +01:00
|
|
|
}
|
2016-03-26 20:26:57 +01:00
|
|
|
|
2016-03-30 14:47:57 +02:00
|
|
|
log_printf(LOG_ERR, "Data channel connected");
|
2016-03-26 20:26:57 +01:00
|
|
|
/* Reset AC Prefered List Position */
|
|
|
|
g_wtp.acpreferedselected = 0;
|
|
|
|
|
|
|
|
/* Set timer */
|
|
|
|
wtp_dfa_change_state(CAPWAP_RUN_STATE);
|
2013-05-01 14:52:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
2016-03-30 10:39:04 +02:00
|
|
|
static void wtp_dfa_state_dtlsteardown_timeout(EV_P_ ev_timer *w, int revents)
|
2016-03-26 17:20:50 +01:00
|
|
|
{
|
2013-05-01 14:52:55 +02:00
|
|
|
/* Free and reset resource */
|
2016-03-26 17:25:15 +01:00
|
|
|
if (g_wtp.dtls.enable)
|
2014-09-10 21:58:23 +02:00
|
|
|
capwap_crypt_freesession(&g_wtp.dtls);
|
2013-05-01 14:52:55 +02:00
|
|
|
|
2013-06-09 17:41:52 +02:00
|
|
|
/* */
|
|
|
|
if (g_wtp.acname.name) {
|
|
|
|
capwap_free(g_wtp.acname.name);
|
|
|
|
g_wtp.acname.name = NULL;
|
|
|
|
}
|
|
|
|
|
2016-03-30 10:39:04 +02:00
|
|
|
wtp_socket_io_stop();
|
|
|
|
capwap_close_sockets(&g_wtp.net);
|
|
|
|
|
2013-05-01 14:52:55 +02:00
|
|
|
/* */
|
2016-03-26 21:08:25 +01:00
|
|
|
wtp_reset_state();
|
2013-05-01 14:52:55 +02:00
|
|
|
|
2013-06-05 19:39:03 +02:00
|
|
|
/* */
|
|
|
|
if (!g_wtp.running) {
|
2013-11-07 22:06:29 +01:00
|
|
|
wtp_dfa_change_state(CAPWAP_DEAD_STATE);
|
2016-03-26 17:20:50 +01:00
|
|
|
} else if ((g_wtp.faileddtlssessioncount >= WTP_FAILED_DTLS_SESSION_RETRY) ||
|
|
|
|
(g_wtp.faileddtlsauthfailcount >= WTP_FAILED_DTLS_SESSION_RETRY)) {
|
2013-11-07 22:06:29 +01:00
|
|
|
wtp_dfa_change_state(CAPWAP_SULKING_STATE);
|
2016-03-30 10:39:04 +02:00
|
|
|
} else
|
2013-11-07 22:06:29 +01:00
|
|
|
wtp_dfa_change_state(CAPWAP_IDLE_STATE);
|
2016-03-30 10:39:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
void wtp_dfa_state_dtlsteardown_enter(void)
|
|
|
|
{
|
|
|
|
wtp_timeout_stop_all();
|
|
|
|
ev_timer_init(&g_wtp.timercontrol, wtp_dfa_state_dtlsteardown_timeout,
|
|
|
|
WTP_DTLS_SESSION_DELETE / 1000.0, 0.);
|
|
|
|
ev_timer_start(EV_DEFAULT_UC_ &g_wtp.timercontrol);
|
2013-05-01 14:52:55 +02:00
|
|
|
}
|
2014-03-02 19:31:27 +01:00
|
|
|
|
|
|
|
/* */
|
|
|
|
void wtp_dfa_state_dtlsteardown(struct capwap_parsed_packet* packet) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Teardown connection */
|
2016-03-26 17:20:50 +01:00
|
|
|
void wtp_teardown_connection(void)
|
|
|
|
{
|
2014-03-02 19:31:27 +01:00
|
|
|
g_wtp.teardown = 1;
|
|
|
|
|
2016-03-30 10:39:04 +02:00
|
|
|
wtp_radio_reset();
|
2014-09-10 21:58:23 +02:00
|
|
|
|
2016-03-30 10:39:04 +02:00
|
|
|
ev_io_stop(EV_DEFAULT_UC_ &g_wtp.socket_ev);
|
|
|
|
|
|
|
|
/* DTLS Control */
|
2016-03-26 17:25:15 +01:00
|
|
|
if (g_wtp.dtls.enable)
|
2014-09-10 21:58:23 +02:00
|
|
|
capwap_crypt_close(&g_wtp.dtls);
|
2014-03-02 19:31:27 +01:00
|
|
|
|
2014-09-10 21:58:23 +02:00
|
|
|
/* Close data channel session */
|
|
|
|
wtp_kmod_resetsession();
|
2014-03-02 19:31:27 +01:00
|
|
|
|
|
|
|
wtp_dfa_change_state(CAPWAP_DTLS_TEARDOWN_STATE);
|
|
|
|
}
|
2016-08-17 15:18:35 +02:00
|
|
|
|
|
|
|
/* abort a possible DTLS connection before the handshake complete */
|
|
|
|
void wtp_abort_connecting(void)
|
|
|
|
{
|
|
|
|
/* DTLS Control */
|
|
|
|
if (g_wtp.dtls.enable)
|
|
|
|
capwap_crypt_close(&g_wtp.dtls);
|
|
|
|
|
|
|
|
/* close the control Socket */
|
|
|
|
wtp_socket_io_stop();
|
|
|
|
capwap_close_sockets(&g_wtp.net);
|
|
|
|
wtp_dfa_change_state(CAPWAP_SULKING_STATE);
|
|
|
|
}
|