Reengineering the timeout manager. Allows to create an arbitrary number of timer
with the possibility to invoke a callback function on timeout.
This commit is contained in:
parent
aa87719432
commit
6042161d75
26
src/ac/ac.c
26
src/ac/ac.c
@ -48,22 +48,16 @@ static int ac_init(void) {
|
||||
g_ac.dfa.transport.type = CAPWAP_UDP_TRANSPORT;
|
||||
|
||||
/* */
|
||||
g_ac.dfa.timers.discovery = AC_DEFAULT_DISCOVERY_INTERVAL;
|
||||
g_ac.dfa.timers.echorequest = AC_DEFAULT_ECHO_INTERVAL;
|
||||
g_ac.dfa.decrypterrorreport_interval = AC_DEFAULT_DECRYPT_ERROR_PERIOD_INTERVAL;
|
||||
g_ac.dfa.idletimeout.timeout = AC_DEFAULT_IDLE_TIMEOUT_INTERVAL;
|
||||
g_ac.dfa.wtpfallback.mode = AC_DEFAULT_WTP_FALLBACK_MODE;
|
||||
g_ac.dfa.timers.discovery = AC_DISCOVERY_INTERVAL / 1000;
|
||||
g_ac.dfa.timers.echorequest = AC_ECHO_INTERVAL / 1000;
|
||||
g_ac.dfa.decrypterrorreport_interval = AC_DECRYPT_ERROR_PERIOD_INTERVAL / 1000;
|
||||
g_ac.dfa.idletimeout.timeout = AC_IDLE_TIMEOUT_INTERVAL / 1000;
|
||||
g_ac.dfa.wtpfallback.mode = AC_WTP_FALLBACK_MODE;
|
||||
|
||||
/* */
|
||||
g_ac.dfa.acipv4list.addresses = capwap_array_create(sizeof(struct in_addr), 0, 0);
|
||||
g_ac.dfa.acipv6list.addresses = capwap_array_create(sizeof(struct in6_addr), 0, 0);
|
||||
|
||||
/* */
|
||||
g_ac.dfa.rfcWaitJoin = AC_DEFAULT_WAITJOIN_INTERVAL;
|
||||
g_ac.dfa.rfcWaitDTLS = AC_DEFAULT_WAITDTLS_INTERVAL;
|
||||
g_ac.dfa.rfcChangeStatePendingTimer = AC_DEFAULT_CHANGE_STATE_PENDING_TIMER;
|
||||
g_ac.dfa.rfcDataCheckTimer = AC_DEFAULT_DATA_CHECK_TIMER;
|
||||
|
||||
/* Sessions */
|
||||
g_ac.sessions = capwap_list_create();
|
||||
g_ac.sessionsdata = capwap_list_create();
|
||||
@ -352,8 +346,9 @@ static int ac_parsing_configuration_1_0(config_t* config) {
|
||||
|
||||
/* Set Timer of AC */
|
||||
if (config_lookup_int(config, "application.timer.discovery", &configInt) == CONFIG_TRUE) {
|
||||
if ((configInt >= AC_DEFAULT_DISCOVERY_INTERVAL) && (configInt <= AC_MAX_DISCOVERY_INTERVAL)) {
|
||||
g_ac.dfa.timers.discovery = (unsigned char)configInt;
|
||||
configInt *= 1000; /* Set timeout in ms */
|
||||
if ((configInt >= AC_MIN_DISCOVERY_INTERVAL) && (configInt <= AC_MAX_DISCOVERY_INTERVAL)) {
|
||||
g_ac.dfa.timers.discovery = (unsigned char)(configInt / 1000);
|
||||
} else {
|
||||
capwap_logging_error("Invalid configuration file, invalid application.timer.discovery value");
|
||||
return 0;
|
||||
@ -361,8 +356,9 @@ static int ac_parsing_configuration_1_0(config_t* config) {
|
||||
}
|
||||
|
||||
if (config_lookup_int(config, "application.timer.echorequest", &configInt) == CONFIG_TRUE) {
|
||||
if ((configInt > 0) && (configInt < AC_MAX_ECHO_INTERVAL)) {
|
||||
g_ac.dfa.timers.echorequest = (unsigned char)configInt;
|
||||
configInt *= 1000;
|
||||
if ((configInt >= AC_MIN_ECHO_INTERVAL) && (configInt <= AC_MAX_ECHO_INTERVAL)) {
|
||||
g_ac.dfa.timers.echorequest = (unsigned char)(configInt / 1000);
|
||||
} else {
|
||||
capwap_logging_error("Invalid configuration file, invalid application.timer.echorequest value");
|
||||
return 0;
|
||||
|
62
src/ac/ac.h
62
src/ac/ac.h
@ -26,31 +26,37 @@
|
||||
#define AC_ERROR_MEMORY_LEAK 1
|
||||
|
||||
/* Min and max dfa values */
|
||||
#define AC_MIN_WAITDTLS_INTERVAL 30
|
||||
#define AC_DEFAULT_WAITDTLS_INTERVAL 60
|
||||
#define AC_MIN_WAITJOIN_INTERVAL 20
|
||||
#define AC_DEFAULT_WAITJOIN_INTERVAL 60
|
||||
#define AC_DEFAULT_CHANGE_STATE_PENDING_TIMER 25
|
||||
#define AC_MIN_DISCOVERY_INTERVAL 2
|
||||
#define AC_DEFAULT_DISCOVERY_INTERVAL 20
|
||||
#define AC_MAX_DISCOVERY_INTERVAL 180
|
||||
#define AC_DEFAULT_ECHO_INTERVAL 30
|
||||
#define AC_MAX_ECHO_INTERVAL 256
|
||||
#define AC_DEFAULT_DECRYPT_ERROR_PERIOD_INTERVAL 120
|
||||
#define AC_DEFAULT_IDLE_TIMEOUT_INTERVAL 300
|
||||
#define AC_DEFAULT_WTP_FALLBACK_MODE CAPWAP_WTP_FALLBACK_ENABLED
|
||||
#define AC_DEFAULT_DATA_CHECK_TIMER 30
|
||||
#define AC_MAX_DATA_CHECK_TIMER 256
|
||||
#define AC_DEFAULT_RETRANSMIT_INTERVAL 3
|
||||
#define AC_MAX_RETRANSMIT 5
|
||||
#define AC_DEFAULT_DTLS_SESSION_DELETE 5
|
||||
#define AC_DTLS_INTERVAL 60000
|
||||
|
||||
/* AC DFA */
|
||||
#define AC_JOIN_INTERVAL 60000
|
||||
|
||||
#define AC_CHANGE_STATE_PENDING_INTERVAL 25000
|
||||
|
||||
#define AC_DATA_CHECK_INTERVAL 30000
|
||||
|
||||
#define AC_RETRANSMIT_INTERVAL 3000
|
||||
#define AC_MAX_RETRANSMIT 5
|
||||
|
||||
#define AC_DTLS_SESSION_DELETE_INTERVAL 5000
|
||||
|
||||
#define AC_MIN_ECHO_INTERVAL 1000
|
||||
#define AC_ECHO_INTERVAL 30000
|
||||
#define AC_MAX_ECHO_INTERVAL 256000
|
||||
|
||||
#define AC_MAX_DATA_KEEPALIVE_INTERVAL 256000
|
||||
|
||||
#define AC_MIN_DISCOVERY_INTERVAL 2000
|
||||
#define AC_DISCOVERY_INTERVAL 20000
|
||||
#define AC_MAX_DISCOVERY_INTERVAL 180000
|
||||
|
||||
#define AC_DECRYPT_ERROR_PERIOD_INTERVAL 120000
|
||||
#define AC_IDLE_TIMEOUT_INTERVAL 300000
|
||||
#define AC_WTP_FALLBACK_MODE CAPWAP_WTP_FALLBACK_ENABLED
|
||||
|
||||
/* */
|
||||
struct ac_state {
|
||||
/* */
|
||||
struct capwap_ecnsupport_element ecn;
|
||||
struct capwap_transport_element transport;
|
||||
|
||||
struct capwap_timers_element timers;
|
||||
unsigned short decrypterrorreport_interval;
|
||||
struct capwap_idletimeout_element idletimeout;
|
||||
@ -59,20 +65,6 @@ struct ac_state {
|
||||
/* */
|
||||
struct capwap_acipv4list_element acipv4list;
|
||||
struct capwap_acipv6list_element acipv6list;
|
||||
|
||||
/* */
|
||||
int rfcWaitJoin;
|
||||
int rfcChangeStatePendingTimer;
|
||||
int rfcDataCheckTimer;
|
||||
int rfcDTLSSessionDelete;
|
||||
|
||||
/* Request retransmit */
|
||||
int rfcRetransmitInterval;
|
||||
int rfcRetransmitCount;
|
||||
int rfcMaxRetransmit;
|
||||
|
||||
/* Dtls */
|
||||
int rfcWaitDTLS;
|
||||
};
|
||||
|
||||
/* AC */
|
||||
|
@ -708,66 +708,61 @@ static uint32_t ac_dfa_state_configure_create_response(struct ac_session_t* sess
|
||||
|
||||
/* */
|
||||
void ac_dfa_state_configure(struct ac_session_t* session, struct capwap_parsed_packet* packet) {
|
||||
struct ac_soap_response* response;
|
||||
struct capwap_header_data capwapheader;
|
||||
struct capwap_packet_txmng* txmngpacket;
|
||||
uint32_t result = CAPWAP_RESULTCODE_FAILURE;
|
||||
|
||||
ASSERT(session != NULL);
|
||||
|
||||
if (packet) {
|
||||
struct ac_soap_response* response;
|
||||
uint32_t result = CAPWAP_RESULTCODE_FAILURE;
|
||||
ASSERT(packet != NULL);
|
||||
|
||||
/* Create response */
|
||||
capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, GET_WBID_HEADER(packet->rxmngpacket->header));
|
||||
txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, CAPWAP_CONFIGURATION_STATUS_RESPONSE, packet->rxmngpacket->ctrlmsg.seq, session->mtu);
|
||||
/* Create response */
|
||||
capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, GET_WBID_HEADER(packet->rxmngpacket->header));
|
||||
txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, CAPWAP_CONFIGURATION_STATUS_RESPONSE, packet->rxmngpacket->ctrlmsg.seq, session->mtu);
|
||||
|
||||
/* Parsing request and add message element for respone message */
|
||||
response = ac_dfa_state_configure_parsing_request(session, packet);
|
||||
if (response) {
|
||||
result = ac_dfa_state_configure_create_response(session, packet, response, txmngpacket);
|
||||
ac_soapclient_free_response(response);
|
||||
/* Parsing request and add message element for respone message */
|
||||
response = ac_dfa_state_configure_parsing_request(session, packet);
|
||||
if (response) {
|
||||
result = ac_dfa_state_configure_create_response(session, packet, response, txmngpacket);
|
||||
ac_soapclient_free_response(response);
|
||||
}
|
||||
|
||||
/* With error add result code message element */
|
||||
if (!CAPWAP_RESULTCODE_OK(result)) {
|
||||
struct capwap_resultcode_element resultcode = { .code = result };
|
||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_RESULTCODE, &resultcode);
|
||||
|
||||
/* */
|
||||
if (result == CAPWAP_RESULTCODE_FAILURE) {
|
||||
/* TODO: Add AC List Message Elements */
|
||||
}
|
||||
}
|
||||
|
||||
/* With error add result code message element */
|
||||
if (!CAPWAP_RESULTCODE_OK(result)) {
|
||||
struct capwap_resultcode_element resultcode = { .code = result };
|
||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_RESULTCODE, &resultcode);
|
||||
/* Configure response complete, get fragment packets */
|
||||
ac_free_reference_last_response(session);
|
||||
capwap_packet_txmng_get_fragment_packets(txmngpacket, session->responsefragmentpacket, session->fragmentid);
|
||||
if (session->responsefragmentpacket->count > 1) {
|
||||
session->fragmentid++;
|
||||
}
|
||||
|
||||
/* */
|
||||
if (result == CAPWAP_RESULTCODE_FAILURE) {
|
||||
/* TODO: Add AC List Message Elements */
|
||||
}
|
||||
}
|
||||
/* Free packets manager */
|
||||
capwap_packet_txmng_free(txmngpacket);
|
||||
|
||||
/* Configure response complete, get fragment packets */
|
||||
ac_free_reference_last_response(session);
|
||||
capwap_packet_txmng_get_fragment_packets(txmngpacket, session->responsefragmentpacket, session->fragmentid);
|
||||
if (session->responsefragmentpacket->count > 1) {
|
||||
session->fragmentid++;
|
||||
}
|
||||
/* Save remote sequence number */
|
||||
session->remoteseqnumber = packet->rxmngpacket->ctrlmsg.seq;
|
||||
capwap_get_packet_digest(packet->rxmngpacket, packet->connection, session->lastrecvpackethash);
|
||||
|
||||
/* Free packets manager */
|
||||
capwap_packet_txmng_free(txmngpacket);
|
||||
/* Send Configure response to WTP */
|
||||
if (!capwap_crypt_sendto_fragmentpacket(&session->dtls, session->connection.socket.socket[session->connection.socket.type], session->responsefragmentpacket, &session->connection.localaddr, &session->connection.remoteaddr)) {
|
||||
/* Response is already created and saved. When receive a re-request, DFA autoresponse */
|
||||
capwap_logging_debug("Warning: error to send configuration status response packet");
|
||||
}
|
||||
|
||||
/* Save remote sequence number */
|
||||
session->remoteseqnumber = packet->rxmngpacket->ctrlmsg.seq;
|
||||
capwap_get_packet_digest(packet->rxmngpacket, packet->connection, session->lastrecvpackethash);
|
||||
|
||||
/* Send Configure response to WTP */
|
||||
if (!capwap_crypt_sendto_fragmentpacket(&session->dtls, session->connection.socket.socket[session->connection.socket.type], session->responsefragmentpacket, &session->connection.localaddr, &session->connection.remoteaddr)) {
|
||||
/* Response is already created and saved. When receive a re-request, DFA autoresponse */
|
||||
capwap_logging_debug("Warning: error to send configuration status response packet");
|
||||
}
|
||||
|
||||
/* Change state */
|
||||
if (CAPWAP_RESULTCODE_OK(result)) {
|
||||
ac_dfa_change_state(session, CAPWAP_DATA_CHECK_STATE);
|
||||
capwap_timeout_set(session->dfa.rfcChangeStatePendingTimer, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
} else {
|
||||
ac_session_teardown(session);
|
||||
}
|
||||
/* Change state */
|
||||
if (CAPWAP_RESULTCODE_OK(result)) {
|
||||
ac_dfa_change_state(session, CAPWAP_DATA_CHECK_STATE);
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_CHANGE_STATE_PENDING_INTERVAL, ac_dfa_state_datacheck_timeout, session, NULL);
|
||||
} else {
|
||||
/* Configure timeout */
|
||||
ac_session_teardown(session);
|
||||
}
|
||||
}
|
||||
|
@ -172,68 +172,68 @@ static uint32_t ac_dfa_state_datacheck_create_response(struct ac_session_t* sess
|
||||
return CAPWAP_RESULTCODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* */
|
||||
void ac_dfa_state_datacheck_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param) {
|
||||
ac_session_teardown((struct ac_session_t*)context); /* Configure timeout */
|
||||
}
|
||||
|
||||
/* */
|
||||
void ac_dfa_state_datacheck(struct ac_session_t* session, struct capwap_parsed_packet* packet) {
|
||||
struct ac_soap_response* response;
|
||||
struct capwap_header_data capwapheader;
|
||||
struct capwap_packet_txmng* txmngpacket;
|
||||
uint32_t result = CAPWAP_RESULTCODE_FAILURE;
|
||||
|
||||
ASSERT(session != NULL);
|
||||
|
||||
if (packet) {
|
||||
struct ac_soap_response* response;
|
||||
uint32_t result = CAPWAP_RESULTCODE_FAILURE;
|
||||
ASSERT(packet != NULL);
|
||||
|
||||
/* Create response */
|
||||
capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, GET_WBID_HEADER(packet->rxmngpacket->header));
|
||||
txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, CAPWAP_CHANGE_STATE_EVENT_RESPONSE, packet->rxmngpacket->ctrlmsg.seq, session->mtu);
|
||||
/* Create response */
|
||||
capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, GET_WBID_HEADER(packet->rxmngpacket->header));
|
||||
txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, CAPWAP_CHANGE_STATE_EVENT_RESPONSE, packet->rxmngpacket->ctrlmsg.seq, session->mtu);
|
||||
|
||||
/* Parsing request and add message element for respone message */
|
||||
response = ac_dfa_state_datacheck_parsing_request(session, packet);
|
||||
if (response) {
|
||||
result = ac_dfa_state_datacheck_create_response(session, packet, response, txmngpacket);
|
||||
ac_soapclient_free_response(response);
|
||||
/* Parsing request and add message element for respone message */
|
||||
response = ac_dfa_state_datacheck_parsing_request(session, packet);
|
||||
if (response) {
|
||||
result = ac_dfa_state_datacheck_create_response(session, packet, response, txmngpacket);
|
||||
ac_soapclient_free_response(response);
|
||||
}
|
||||
|
||||
/* With error add result code message element */
|
||||
if (!CAPWAP_RESULTCODE_OK(result)) {
|
||||
struct capwap_resultcode_element resultcode = { .code = result };
|
||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_RESULTCODE, &resultcode);
|
||||
|
||||
/* */
|
||||
if (result == CAPWAP_RESULTCODE_FAILURE) {
|
||||
/* TODO: Add AC List Message Elements */
|
||||
}
|
||||
}
|
||||
|
||||
/* With error add result code message element */
|
||||
if (!CAPWAP_RESULTCODE_OK(result)) {
|
||||
struct capwap_resultcode_element resultcode = { .code = result };
|
||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_RESULTCODE, &resultcode);
|
||||
/* Change event response complete, get fragment packets */
|
||||
ac_free_reference_last_response(session);
|
||||
capwap_packet_txmng_get_fragment_packets(txmngpacket, session->responsefragmentpacket, session->fragmentid);
|
||||
if (session->responsefragmentpacket->count > 1) {
|
||||
session->fragmentid++;
|
||||
}
|
||||
|
||||
/* */
|
||||
if (result == CAPWAP_RESULTCODE_FAILURE) {
|
||||
/* TODO: Add AC List Message Elements */
|
||||
}
|
||||
}
|
||||
/* Free packets manager */
|
||||
capwap_packet_txmng_free(txmngpacket);
|
||||
|
||||
/* Change event response complete, get fragment packets */
|
||||
ac_free_reference_last_response(session);
|
||||
capwap_packet_txmng_get_fragment_packets(txmngpacket, session->responsefragmentpacket, session->fragmentid);
|
||||
if (session->responsefragmentpacket->count > 1) {
|
||||
session->fragmentid++;
|
||||
}
|
||||
/* Save remote sequence number */
|
||||
session->remoteseqnumber = packet->rxmngpacket->ctrlmsg.seq;
|
||||
capwap_get_packet_digest(packet->rxmngpacket, packet->connection, session->lastrecvpackethash);
|
||||
|
||||
/* Free packets manager */
|
||||
capwap_packet_txmng_free(txmngpacket);
|
||||
/* Send Change event response to WTP */
|
||||
if (!capwap_crypt_sendto_fragmentpacket(&session->dtls, session->connection.socket.socket[session->connection.socket.type], session->responsefragmentpacket, &session->connection.localaddr, &session->connection.remoteaddr)) {
|
||||
/* Response is already created and saved. When receive a re-request, DFA autoresponse */
|
||||
capwap_logging_debug("Warning: error to send change event response packet");
|
||||
}
|
||||
|
||||
/* Save remote sequence number */
|
||||
session->remoteseqnumber = packet->rxmngpacket->ctrlmsg.seq;
|
||||
capwap_get_packet_digest(packet->rxmngpacket, packet->connection, session->lastrecvpackethash);
|
||||
|
||||
/* Send Change event response to WTP */
|
||||
if (!capwap_crypt_sendto_fragmentpacket(&session->dtls, session->connection.socket.socket[session->connection.socket.type], session->responsefragmentpacket, &session->connection.localaddr, &session->connection.remoteaddr)) {
|
||||
/* Response is already created and saved. When receive a re-request, DFA autoresponse */
|
||||
capwap_logging_debug("Warning: error to send change event response packet");
|
||||
}
|
||||
|
||||
/* Change state */
|
||||
if (CAPWAP_RESULTCODE_OK(result)) {
|
||||
ac_dfa_change_state(session, CAPWAP_DATA_CHECK_TO_RUN_STATE);
|
||||
capwap_timeout_set(session->dfa.rfcDataCheckTimer, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
} else {
|
||||
ac_session_teardown(session);
|
||||
}
|
||||
/* Change state */
|
||||
if (CAPWAP_RESULTCODE_OK(result)) {
|
||||
ac_dfa_change_state(session, CAPWAP_DATA_CHECK_TO_RUN_STATE);
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_DATA_CHECK_INTERVAL, ac_dfa_state_datacheck_timeout, session, NULL);
|
||||
} else {
|
||||
/* Configure timeout */
|
||||
ac_session_teardown(session);
|
||||
}
|
||||
}
|
||||
@ -242,7 +242,5 @@ void ac_dfa_state_datacheck(struct ac_session_t* session, struct capwap_parsed_p
|
||||
void ac_dfa_state_datacheck_to_run(struct ac_session_t* session, struct capwap_parsed_packet* packet) {
|
||||
ASSERT(session != NULL);
|
||||
|
||||
if (!packet) {
|
||||
ac_session_teardown(session); /* Configure timeout */
|
||||
}
|
||||
ac_session_teardown(session);
|
||||
}
|
||||
|
@ -21,6 +21,11 @@ static int ac_bio_data_send(struct capwap_dtls* dtls, char* buffer, int length,
|
||||
return capwap_sendto(sessiondata->connection.socket.socket[sessiondata->connection.socket.type], buffer, length, &sessiondata->connection.localaddr, &sessiondata->connection.remoteaddr);
|
||||
}
|
||||
|
||||
/* */
|
||||
void ac_dtls_setup_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param) {
|
||||
ac_session_teardown((struct ac_session_t*)context); /* Configure timeout */
|
||||
}
|
||||
|
||||
/* */
|
||||
int ac_dtls_setup(struct ac_session_t* session) {
|
||||
ASSERT(session != NULL);
|
||||
@ -36,7 +41,7 @@ int ac_dtls_setup(struct ac_session_t* session) {
|
||||
|
||||
/* Wait DTLS handshake complete */
|
||||
ac_dfa_change_state(session, CAPWAP_DTLS_CONNECT_STATE);
|
||||
capwap_timeout_set(session->dfa.rfcWaitDTLS, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_DTLS_INTERVAL, ac_dtls_setup_timeout, session, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -6,4 +6,5 @@
|
||||
/* */
|
||||
void ac_dfa_state_imagedata(struct ac_session_t* session, struct capwap_parsed_packet* packet) {
|
||||
/* TODO */
|
||||
ac_session_teardown(session);
|
||||
}
|
||||
|
@ -578,8 +578,14 @@ static uint32_t ac_dfa_state_join_create_response(struct ac_session_t* session,
|
||||
return CAPWAP_RESULTCODE_SUCCESS;
|
||||
}
|
||||
|
||||
/* */
|
||||
void ac_dfa_state_join_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param) {
|
||||
ac_session_teardown((struct ac_session_t*)context); /* Join timeout */
|
||||
}
|
||||
|
||||
/* */
|
||||
void ac_dfa_state_join(struct ac_session_t* session, struct capwap_parsed_packet* packet) {
|
||||
unsigned short binding;
|
||||
struct ac_soap_response* response;
|
||||
struct capwap_header_data capwapheader;
|
||||
struct capwap_packet_txmng* txmngpacket;
|
||||
@ -588,99 +594,94 @@ void ac_dfa_state_join(struct ac_session_t* session, struct capwap_parsed_packet
|
||||
struct capwap_resultcode_element resultcode = { .code = CAPWAP_RESULTCODE_FAILURE };
|
||||
|
||||
ASSERT(session != NULL);
|
||||
|
||||
if (packet) {
|
||||
unsigned short binding;
|
||||
ASSERT(packet != NULL);
|
||||
|
||||
/* Check binding */
|
||||
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
|
||||
if (ac_valid_binding(binding)) {
|
||||
if (packet->rxmngpacket->ctrlmsg.type == CAPWAP_JOIN_REQUEST) {
|
||||
/* Get sessionid and verify unique id */
|
||||
sessionid = (struct capwap_sessionid_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_SESSIONID);
|
||||
if (!ac_has_sessionid(sessionid)) {
|
||||
char* wtpid;
|
||||
/* Check binding */
|
||||
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
|
||||
if (ac_valid_binding(binding)) {
|
||||
if (packet->rxmngpacket->ctrlmsg.type == CAPWAP_JOIN_REQUEST) {
|
||||
/* Get sessionid and verify unique id */
|
||||
sessionid = (struct capwap_sessionid_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_SESSIONID);
|
||||
if (!ac_has_sessionid(sessionid)) {
|
||||
char* wtpid;
|
||||
|
||||
/* Checking macaddress for detect if WTP already connected */
|
||||
wtpboarddata = (struct capwap_wtpboarddata_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_WTPBOARDDATA);
|
||||
/* Checking macaddress for detect if WTP already connected */
|
||||
wtpboarddata = (struct capwap_wtpboarddata_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_WTPBOARDDATA);
|
||||
|
||||
/* Get printable WTPID */
|
||||
wtpid = ac_get_printable_wtpid(wtpboarddata);
|
||||
if (wtpid && !ac_has_wtpid(wtpid)) {
|
||||
/* Request authorization of Backend for complete join */
|
||||
response = ac_soap_authorizewtpsession(session, wtpid);
|
||||
if (response) {
|
||||
resultcode.code = ac_dfa_state_join_check_authorizejoin(session, response);
|
||||
ac_soapclient_free_response(response);
|
||||
} else {
|
||||
resultcode.code = CAPWAP_RESULTCODE_JOIN_FAILURE_UNKNOWN_SOURCE;
|
||||
}
|
||||
/* Get printable WTPID */
|
||||
wtpid = ac_get_printable_wtpid(wtpboarddata);
|
||||
if (wtpid && !ac_has_wtpid(wtpid)) {
|
||||
/* Request authorization of Backend for complete join */
|
||||
response = ac_soap_authorizewtpsession(session, wtpid);
|
||||
if (response) {
|
||||
resultcode.code = ac_dfa_state_join_check_authorizejoin(session, response);
|
||||
ac_soapclient_free_response(response);
|
||||
} else {
|
||||
resultcode.code = CAPWAP_RESULTCODE_JOIN_FAILURE_UNKNOWN_SOURCE;
|
||||
}
|
||||
|
||||
/* */
|
||||
if (CAPWAP_RESULTCODE_OK(resultcode.code)) {
|
||||
session->wtpid = wtpid;
|
||||
memcpy(&session->sessionid, sessionid, sizeof(struct capwap_sessionid_element));
|
||||
session->binding = binding;
|
||||
} else {
|
||||
capwap_free(wtpid);
|
||||
}
|
||||
} else {
|
||||
resultcode.code = CAPWAP_RESULTCODE_JOIN_FAILURE_ID_ALREADY_IN_USE;
|
||||
resultcode.code = CAPWAP_RESULTCODE_JOIN_FAILURE_UNKNOWN_SOURCE;
|
||||
}
|
||||
|
||||
/* */
|
||||
if (CAPWAP_RESULTCODE_OK(resultcode.code)) {
|
||||
session->wtpid = wtpid;
|
||||
memcpy(&session->sessionid, sessionid, sizeof(struct capwap_sessionid_element));
|
||||
session->binding = binding;
|
||||
} else {
|
||||
capwap_free(wtpid);
|
||||
}
|
||||
} else {
|
||||
resultcode.code = CAPWAP_RESULTCODE_MSG_UNEXPECTED_INVALID_CURRENT_STATE;
|
||||
resultcode.code = CAPWAP_RESULTCODE_JOIN_FAILURE_ID_ALREADY_IN_USE;
|
||||
}
|
||||
} else {
|
||||
resultcode.code = CAPWAP_RESULTCODE_JOIN_FAILURE_BINDING_NOT_SUPPORTED;
|
||||
resultcode.code = CAPWAP_RESULTCODE_MSG_UNEXPECTED_INVALID_CURRENT_STATE;
|
||||
}
|
||||
} else {
|
||||
resultcode.code = CAPWAP_RESULTCODE_JOIN_FAILURE_BINDING_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
/* Create response */
|
||||
capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, binding);
|
||||
txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, CAPWAP_JOIN_RESPONSE, packet->rxmngpacket->ctrlmsg.seq, session->mtu);
|
||||
/* Create response */
|
||||
capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, binding);
|
||||
txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, CAPWAP_JOIN_RESPONSE, packet->rxmngpacket->ctrlmsg.seq, session->mtu);
|
||||
|
||||
/* */
|
||||
/* */
|
||||
if (CAPWAP_RESULTCODE_OK(resultcode.code)) {
|
||||
response = ac_dfa_state_join_parsing_request(session, packet);
|
||||
if (response) {
|
||||
resultcode.code = ac_dfa_state_join_create_response(session, packet, response, txmngpacket);
|
||||
ac_soapclient_free_response(response);
|
||||
}
|
||||
}
|
||||
|
||||
/* Add always result code message element */
|
||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_RESULTCODE, &resultcode);
|
||||
|
||||
/* Join response complete, get fragment packets */
|
||||
ac_free_reference_last_response(session);
|
||||
capwap_packet_txmng_get_fragment_packets(txmngpacket, session->responsefragmentpacket, session->fragmentid);
|
||||
if (session->responsefragmentpacket->count > 1) {
|
||||
session->fragmentid++;
|
||||
}
|
||||
|
||||
/* Free packets manager */
|
||||
capwap_packet_txmng_free(txmngpacket);
|
||||
|
||||
/* Save remote sequence number */
|
||||
session->remoteseqnumber = packet->rxmngpacket->ctrlmsg.seq;
|
||||
capwap_get_packet_digest(packet->rxmngpacket, packet->connection, session->lastrecvpackethash);
|
||||
|
||||
/* Send Join response to WTP */
|
||||
if (capwap_crypt_sendto_fragmentpacket(&session->dtls, session->connection.socket.socket[session->connection.socket.type], session->responsefragmentpacket, &session->connection.localaddr, &session->connection.remoteaddr)) {
|
||||
if (CAPWAP_RESULTCODE_OK(resultcode.code)) {
|
||||
response = ac_dfa_state_join_parsing_request(session, packet);
|
||||
if (response) {
|
||||
resultcode.code = ac_dfa_state_join_create_response(session, packet, response, txmngpacket);
|
||||
ac_soapclient_free_response(response);
|
||||
}
|
||||
}
|
||||
|
||||
/* Add always result code message element */
|
||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_RESULTCODE, &resultcode);
|
||||
|
||||
/* Join response complete, get fragment packets */
|
||||
ac_free_reference_last_response(session);
|
||||
capwap_packet_txmng_get_fragment_packets(txmngpacket, session->responsefragmentpacket, session->fragmentid);
|
||||
if (session->responsefragmentpacket->count > 1) {
|
||||
session->fragmentid++;
|
||||
}
|
||||
|
||||
/* Free packets manager */
|
||||
capwap_packet_txmng_free(txmngpacket);
|
||||
|
||||
/* Save remote sequence number */
|
||||
session->remoteseqnumber = packet->rxmngpacket->ctrlmsg.seq;
|
||||
capwap_get_packet_digest(packet->rxmngpacket, packet->connection, session->lastrecvpackethash);
|
||||
|
||||
/* Send Join response to WTP */
|
||||
if (capwap_crypt_sendto_fragmentpacket(&session->dtls, session->connection.socket.socket[session->connection.socket.type], session->responsefragmentpacket, &session->connection.localaddr, &session->connection.remoteaddr)) {
|
||||
if (CAPWAP_RESULTCODE_OK(resultcode.code)) {
|
||||
ac_dfa_change_state(session, CAPWAP_POSTJOIN_STATE);
|
||||
} else {
|
||||
ac_session_teardown(session);
|
||||
}
|
||||
ac_dfa_change_state(session, CAPWAP_POSTJOIN_STATE);
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_JOIN_INTERVAL, ac_dfa_state_join_timeout, session, NULL);
|
||||
} else {
|
||||
/* Error to send packets */
|
||||
capwap_logging_debug("Warning: error to send join response packet");
|
||||
ac_session_teardown(session);
|
||||
}
|
||||
} else {
|
||||
/* Join timeout */
|
||||
/* Error to send packets */
|
||||
capwap_logging_debug("Warning: error to send join response packet");
|
||||
ac_session_teardown(session);
|
||||
}
|
||||
}
|
||||
@ -688,19 +689,15 @@ void ac_dfa_state_join(struct ac_session_t* session, struct capwap_parsed_packet
|
||||
/* */
|
||||
void ac_dfa_state_postjoin(struct ac_session_t* session, struct capwap_parsed_packet* packet) {
|
||||
ASSERT(session != NULL);
|
||||
ASSERT(packet != NULL);
|
||||
|
||||
if (packet) {
|
||||
if (packet->rxmngpacket->ctrlmsg.type == CAPWAP_CONFIGURATION_STATUS_REQUEST) {
|
||||
ac_dfa_change_state(session, CAPWAP_CONFIGURE_STATE);
|
||||
ac_dfa_state_configure(session, packet);
|
||||
} else if (packet->rxmngpacket->ctrlmsg.type == CAPWAP_IMAGE_DATA_REQUEST) {
|
||||
ac_dfa_change_state(session, CAPWAP_IMAGE_DATA_STATE);
|
||||
ac_dfa_state_imagedata(session, packet);
|
||||
} else {
|
||||
ac_session_teardown(session);
|
||||
}
|
||||
if (packet->rxmngpacket->ctrlmsg.type == CAPWAP_CONFIGURATION_STATUS_REQUEST) {
|
||||
ac_dfa_change_state(session, CAPWAP_CONFIGURE_STATE);
|
||||
ac_dfa_state_configure(session, packet);
|
||||
} else if (packet->rxmngpacket->ctrlmsg.type == CAPWAP_IMAGE_DATA_REQUEST) {
|
||||
ac_dfa_change_state(session, CAPWAP_IMAGE_DATA_STATE);
|
||||
ac_dfa_state_imagedata(session, packet);
|
||||
} else {
|
||||
/* Join timeout */
|
||||
ac_session_teardown(session);
|
||||
}
|
||||
}
|
||||
|
@ -5,41 +5,23 @@
|
||||
|
||||
/* */
|
||||
void ac_dfa_state_reset(struct ac_session_t* session, struct capwap_parsed_packet* packet) {
|
||||
ASSERT(session != NULL);
|
||||
unsigned short binding;
|
||||
|
||||
if (packet) {
|
||||
unsigned short binding;
|
||||
ASSERT(session != NULL);
|
||||
ASSERT(packet != NULL);
|
||||
|
||||
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
|
||||
if ((binding == session->binding) && (packet->rxmngpacket->ctrlmsg.type == CAPWAP_RESET_RESPONSE) && ((session->localseqnumber - 1) == packet->rxmngpacket->ctrlmsg.seq)) {
|
||||
struct capwap_resultcode_element* resultcode;
|
||||
|
||||
/* Check the success of the Request */
|
||||
resultcode = (struct capwap_resultcode_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_RESULTCODE);
|
||||
if (resultcode && !CAPWAP_RESULTCODE_OK(resultcode->code)) {
|
||||
capwap_logging_warning("Receive Reset Response with error: %d", (int)resultcode->code);
|
||||
}
|
||||
|
||||
/* */
|
||||
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
|
||||
if ((binding == session->binding) && (packet->rxmngpacket->ctrlmsg.type == CAPWAP_RESET_RESPONSE) && ((session->localseqnumber - 1) == packet->rxmngpacket->ctrlmsg.seq)) {
|
||||
struct capwap_resultcode_element* resultcode;
|
||||
|
||||
/* Check the success of the Request */
|
||||
resultcode = (struct capwap_resultcode_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_RESULTCODE);
|
||||
if (resultcode && !CAPWAP_RESULTCODE_OK(resultcode->code)) {
|
||||
capwap_logging_warning("Receive Reset Response with error: %d", (int)resultcode->code);
|
||||
}
|
||||
|
||||
/* */
|
||||
ac_free_reference_last_request(session);
|
||||
ac_session_teardown(session);
|
||||
}
|
||||
} else {
|
||||
/* No Reset Response received */
|
||||
session->dfa.rfcRetransmitCount++;
|
||||
if (session->dfa.rfcRetransmitCount >= session->dfa.rfcMaxRetransmit) {
|
||||
/* Timeout reset state */
|
||||
ac_free_reference_last_request(session);
|
||||
ac_session_teardown(session);
|
||||
} else {
|
||||
/* Retransmit Reset Request */
|
||||
if (!capwap_crypt_sendto_fragmentpacket(&session->dtls, session->connection.socket.socket[session->connection.socket.type], session->requestfragmentpacket, &session->connection.localaddr, &session->connection.remoteaddr)) {
|
||||
capwap_logging_debug("Warning: error to resend reset request packet");
|
||||
}
|
||||
|
||||
/* Update timeout */
|
||||
capwap_timeout_set(session->dfa.rfcRetransmitInterval, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
}
|
||||
ac_free_reference_last_request(session);
|
||||
ac_session_teardown(session);
|
||||
}
|
||||
}
|
||||
|
@ -78,94 +78,75 @@ static void receive_ieee80211_wlan_configuration_response(struct ac_session_t* s
|
||||
/* */
|
||||
void ac_dfa_state_run(struct ac_session_t* session, struct capwap_parsed_packet* packet) {
|
||||
ASSERT(session != NULL);
|
||||
ASSERT(packet != NULL);
|
||||
|
||||
if (packet) {
|
||||
if (capwap_is_request_type(packet->rxmngpacket->ctrlmsg.type) || ((session->localseqnumber - 1) == packet->rxmngpacket->ctrlmsg.seq)) {
|
||||
switch (packet->rxmngpacket->ctrlmsg.type) {
|
||||
case CAPWAP_CONFIGURATION_UPDATE_RESPONSE: {
|
||||
/* TODO */
|
||||
if (capwap_is_request_type(packet->rxmngpacket->ctrlmsg.type) || ((session->localseqnumber - 1) == packet->rxmngpacket->ctrlmsg.seq)) {
|
||||
switch (packet->rxmngpacket->ctrlmsg.type) {
|
||||
case CAPWAP_CONFIGURATION_UPDATE_RESPONSE: {
|
||||
/* TODO */
|
||||
|
||||
/* */
|
||||
capwap_timeout_set(AC_MAX_ECHO_INTERVAL, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_CHANGE_STATE_EVENT_REQUEST: {
|
||||
/* TODO */
|
||||
capwap_timeout_set(AC_MAX_ECHO_INTERVAL, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_ECHO_REQUEST: {
|
||||
if (!receive_echo_request(session, packet)) {
|
||||
capwap_timeout_set(AC_MAX_ECHO_INTERVAL, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
} else {
|
||||
ac_session_teardown(session);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_CLEAR_CONFIGURATION_RESPONSE: {
|
||||
/* TODO */
|
||||
|
||||
/* */
|
||||
capwap_timeout_set(AC_MAX_ECHO_INTERVAL, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_WTP_EVENT_REQUEST: {
|
||||
/* TODO */
|
||||
capwap_timeout_set(AC_MAX_ECHO_INTERVAL, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_DATA_TRANSFER_REQUEST: {
|
||||
/* TODO */
|
||||
capwap_timeout_set(AC_MAX_ECHO_INTERVAL, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_DATA_TRANSFER_RESPONSE: {
|
||||
/* TODO */
|
||||
|
||||
/* */
|
||||
capwap_timeout_set(AC_MAX_ECHO_INTERVAL, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_STATION_CONFIGURATION_RESPONSE: {
|
||||
/* TODO */
|
||||
|
||||
/* */
|
||||
capwap_timeout_set(AC_MAX_ECHO_INTERVAL, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_IEEE80211_WLAN_CONFIGURATION_RESPONSE: {
|
||||
receive_ieee80211_wlan_configuration_response(session, packet);
|
||||
capwap_timeout_set(AC_MAX_ECHO_INTERVAL, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ((session->requestfragmentpacket->count > 0)) {
|
||||
/* No response received */
|
||||
session->dfa.rfcRetransmitCount++;
|
||||
if (session->dfa.rfcRetransmitCount >= session->dfa.rfcMaxRetransmit) {
|
||||
/* Timeout */
|
||||
ac_free_reference_last_request(session);
|
||||
ac_session_teardown(session);
|
||||
} else {
|
||||
/* Retransmit request */
|
||||
if (!capwap_crypt_sendto_fragmentpacket(&session->dtls, session->connection.socket.socket[session->connection.socket.type], session->requestfragmentpacket, &session->connection.localaddr, &session->connection.remoteaddr)) {
|
||||
capwap_logging_debug("Warning: error to resend request packet");
|
||||
/* */
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_MAX_ECHO_INTERVAL, ac_dfa_teardown_timeout, session, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Update timeout */
|
||||
capwap_timeout_set(session->dfa.rfcRetransmitInterval, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
case CAPWAP_CHANGE_STATE_EVENT_REQUEST: {
|
||||
/* TODO */
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_MAX_ECHO_INTERVAL, ac_dfa_teardown_timeout, session, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_ECHO_REQUEST: {
|
||||
if (!receive_echo_request(session, packet)) {
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_MAX_ECHO_INTERVAL, ac_dfa_teardown_timeout, session, NULL);
|
||||
} else {
|
||||
ac_session_teardown(session);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_CLEAR_CONFIGURATION_RESPONSE: {
|
||||
/* TODO */
|
||||
|
||||
/* */
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_MAX_ECHO_INTERVAL, ac_dfa_teardown_timeout, session, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_WTP_EVENT_REQUEST: {
|
||||
/* TODO */
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_MAX_ECHO_INTERVAL, ac_dfa_teardown_timeout, session, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_DATA_TRANSFER_REQUEST: {
|
||||
/* TODO */
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_MAX_ECHO_INTERVAL, ac_dfa_teardown_timeout, session, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_DATA_TRANSFER_RESPONSE: {
|
||||
/* TODO */
|
||||
|
||||
/* */
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_MAX_ECHO_INTERVAL, ac_dfa_teardown_timeout, session, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_STATION_CONFIGURATION_RESPONSE: {
|
||||
/* TODO */
|
||||
|
||||
/* */
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_MAX_ECHO_INTERVAL, ac_dfa_teardown_timeout, session, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_IEEE80211_WLAN_CONFIGURATION_RESPONSE: {
|
||||
receive_ieee80211_wlan_configuration_response(session, packet);
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_MAX_ECHO_INTERVAL, ac_dfa_teardown_timeout, session, NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ac_session_teardown(session);
|
||||
}
|
||||
}
|
||||
|
@ -503,16 +503,13 @@ static struct ac_session_t* ac_create_session(struct sockaddr_storage* wtpaddres
|
||||
|
||||
/* */
|
||||
session->timeout = capwap_timeout_init();
|
||||
session->idtimercontrol = capwap_timeout_createtimer(session->timeout);
|
||||
|
||||
/* Duplicate state for DFA */
|
||||
memcpy(&session->dfa, &g_ac.dfa, sizeof(struct ac_state));
|
||||
session->dfa.acipv4list.addresses = capwap_array_clone(g_ac.dfa.acipv4list.addresses);
|
||||
session->dfa.acipv6list.addresses = capwap_array_clone(g_ac.dfa.acipv6list.addresses);
|
||||
|
||||
session->dfa.rfcRetransmitInterval = AC_DEFAULT_RETRANSMIT_INTERVAL;
|
||||
session->dfa.rfcMaxRetransmit = AC_MAX_RETRANSMIT;
|
||||
session->dfa.rfcDTLSSessionDelete = AC_DEFAULT_DTLS_SESSION_DELETE;
|
||||
|
||||
/* Add default AC list if empty*/
|
||||
if ((session->dfa.acipv4list.addresses->count == 0) && (session->dfa.acipv6list.addresses->count == 0)) {
|
||||
if (acaddress->ss_family == AF_INET) {
|
||||
@ -588,6 +585,8 @@ static struct ac_session_data_t* ac_create_session_data(struct sockaddr_storage*
|
||||
|
||||
/* */
|
||||
sessiondata->timeout = capwap_timeout_init();
|
||||
sessiondata->idtimercontrol = capwap_timeout_createtimer(sessiondata->timeout);
|
||||
sessiondata->idtimerkeepalivedead = capwap_timeout_createtimer(sessiondata->timeout);
|
||||
|
||||
/* Connection info */
|
||||
memcpy(&sessiondata->connection.socket, sock, sizeof(struct capwap_socket));
|
||||
|
@ -39,10 +39,9 @@ static int ac_session_action_resetwtp(struct ac_session_t* session, struct ac_no
|
||||
|
||||
/* Send Reset Request to WTP */
|
||||
if (capwap_crypt_sendto_fragmentpacket(&session->dtls, session->connection.socket.socket[session->connection.socket.type], session->requestfragmentpacket, &session->connection.localaddr, &session->connection.remoteaddr)) {
|
||||
session->dfa.rfcRetransmitCount = 0;
|
||||
capwap_timeout_killall(session->timeout);
|
||||
capwap_timeout_set(session->dfa.rfcRetransmitInterval, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
session->retransmitcount = 0;
|
||||
ac_dfa_change_state(session, CAPWAP_RESET_STATE);
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_RETRANSMIT_INTERVAL, ac_dfa_retransmition_timeout, session, NULL);
|
||||
} else {
|
||||
capwap_logging_debug("Warning: error to send reset request packet");
|
||||
ac_free_reference_last_request(session);
|
||||
@ -94,9 +93,8 @@ static int ac_session_action_addwlan(struct ac_session_t* session, struct ac_not
|
||||
|
||||
/* Send WLAN Configuration Request to WTP */
|
||||
if (capwap_crypt_sendto_fragmentpacket(&session->dtls, session->connection.socket.socket[session->connection.socket.type], session->requestfragmentpacket, &session->connection.localaddr, &session->connection.remoteaddr)) {
|
||||
session->dfa.rfcRetransmitCount = 0;
|
||||
capwap_timeout_killall(session->timeout);
|
||||
capwap_timeout_set(session->dfa.rfcRetransmitInterval, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
session->retransmitcount = 0;
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_RETRANSMIT_INTERVAL, ac_dfa_retransmition_timeout, session, NULL);
|
||||
} else {
|
||||
capwap_logging_debug("Warning: error to send reset request packet");
|
||||
ac_free_reference_last_request(session);
|
||||
@ -139,7 +137,7 @@ static int ac_session_action_execute(struct ac_session_t* session, struct ac_ses
|
||||
|
||||
if (valid) {
|
||||
ac_dfa_change_state(session, CAPWAP_RUN_STATE);
|
||||
capwap_timeout_set(AC_MAX_ECHO_INTERVAL, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_MAX_ECHO_INTERVAL, ac_dfa_teardown_timeout, session, NULL);
|
||||
} else {
|
||||
result = CAPWAP_ERROR_CLOSE;
|
||||
}
|
||||
@ -165,7 +163,6 @@ static int ac_session_action_execute(struct ac_session_t* session, struct ac_ses
|
||||
/* */
|
||||
static int ac_network_read(struct ac_session_t* session, void* buffer, int length) {
|
||||
int result = 0;
|
||||
long indextimer;
|
||||
long waittimeout;
|
||||
|
||||
ASSERT(session != NULL);
|
||||
@ -213,7 +210,7 @@ static int ac_network_read(struct ac_session_t* session, void* buffer, int lengt
|
||||
if ((oldaction == CAPWAP_DTLS_ACTION_HANDSHAKE) && (session->dtls.action == CAPWAP_DTLS_ACTION_DATA)) {
|
||||
if (session->state == CAPWAP_DTLS_CONNECT_STATE) {
|
||||
ac_dfa_change_state(session, CAPWAP_JOIN_STATE);
|
||||
capwap_timeout_set(session->dfa.rfcWaitJoin, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_JOIN_INTERVAL, ac_dfa_state_join_timeout, session, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -233,10 +230,10 @@ static int ac_network_read(struct ac_session_t* session, void* buffer, int lengt
|
||||
|
||||
capwap_lock_exit(&session->sessionlock);
|
||||
|
||||
/* Update timeout */
|
||||
capwap_timeout_update(session->timeout);
|
||||
waittimeout = capwap_timeout_get(session->timeout, &indextimer);
|
||||
if ((waittimeout <= 0) && (indextimer != CAPWAP_TIMER_UNDEF)) {
|
||||
/* Get timeout */
|
||||
waittimeout = capwap_timeout_getcoming(session->timeout);
|
||||
if (!waittimeout) {
|
||||
capwap_timeout_hasexpired(session->timeout);
|
||||
return AC_ERROR_TIMEOUT;
|
||||
}
|
||||
|
||||
@ -250,6 +247,7 @@ static int ac_network_read(struct ac_session_t* session, void* buffer, int lengt
|
||||
/* */
|
||||
static void ac_dfa_execute(struct ac_session_t* session, struct capwap_parsed_packet* packet) {
|
||||
ASSERT(session != NULL);
|
||||
ASSERT(packet != NULL);
|
||||
|
||||
/* Execute state */
|
||||
switch (session->state) {
|
||||
@ -481,16 +479,14 @@ static void ac_session_run(struct ac_session_t* session) {
|
||||
} else {
|
||||
/* Wait Join request */
|
||||
ac_dfa_change_state(session, CAPWAP_JOIN_STATE);
|
||||
capwap_timeout_set(session->dfa.rfcWaitJoin, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_JOIN_INTERVAL, ac_dfa_state_join_timeout, session, NULL);
|
||||
}
|
||||
|
||||
while (session->state != CAPWAP_DTLS_TEARDOWN_STATE) {
|
||||
/* Get packet */
|
||||
length = ac_network_read(session, buffer, sizeof(buffer));
|
||||
if (length < 0) {
|
||||
if (length == AC_ERROR_TIMEOUT) {
|
||||
ac_dfa_execute(session, NULL);
|
||||
} else if ((length == CAPWAP_ERROR_SHUTDOWN) || (length == CAPWAP_ERROR_CLOSE)) {
|
||||
if ((length == CAPWAP_ERROR_SHUTDOWN) || (length == CAPWAP_ERROR_CLOSE)) {
|
||||
ac_session_teardown(session);
|
||||
}
|
||||
} else if (length > 0) {
|
||||
@ -602,7 +598,7 @@ static void ac_session_run(struct ac_session_t* session) {
|
||||
}
|
||||
|
||||
/* Wait teardown timeout before kill session */
|
||||
capwap_timeout_wait(session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
capwap_timeout_wait(AC_DTLS_SESSION_DELETE_INTERVAL);
|
||||
ac_dfa_state_teardown(session);
|
||||
|
||||
/* Release reference session */
|
||||
@ -668,11 +664,6 @@ void ac_session_teardown(struct ac_session_t* session) {
|
||||
capwap_crypt_close(&session->dtls);
|
||||
}
|
||||
|
||||
/* */
|
||||
capwap_timeout_killall(session->timeout);
|
||||
capwap_timeout_set(session->dfa.rfcDTLSSessionDelete, session->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
ac_dfa_change_state(session, CAPWAP_DTLS_TEARDOWN_STATE);
|
||||
|
||||
/* Cancel all notify event */
|
||||
if (session->notifyevent->first) {
|
||||
char buffer[5];
|
||||
@ -692,6 +683,10 @@ void ac_session_teardown(struct ac_session_t* session) {
|
||||
capwap_itemlist_free(capwap_itemlist_remove(session->notifyevent, session->notifyevent->first));
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
ac_dfa_change_state(session, CAPWAP_DTLS_TEARDOWN_STATE);
|
||||
capwap_timeout_unset(session->timeout, session->idtimercontrol);
|
||||
}
|
||||
|
||||
/* */
|
||||
@ -835,3 +830,32 @@ struct ac_soap_response* ac_session_send_soap_request(struct ac_session_t* sessi
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/* */
|
||||
void ac_dfa_retransmition_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param) {
|
||||
struct ac_session_t* session = (struct ac_session_t*)context;
|
||||
|
||||
if (!session->requestfragmentpacket->count) {
|
||||
ac_session_teardown(session);
|
||||
} else {
|
||||
session->retransmitcount++;
|
||||
if (session->retransmitcount >= AC_MAX_RETRANSMIT) {
|
||||
/* Timeout reset state */
|
||||
ac_free_reference_last_request(session);
|
||||
ac_session_teardown(session);
|
||||
} else {
|
||||
/* Retransmit Reset Request */
|
||||
capwap_logging_debug("Retransmition request packet");
|
||||
if (!capwap_crypt_sendto_fragmentpacket(&session->dtls, session->connection.socket.socket[session->connection.socket.type], session->requestfragmentpacket, &session->connection.localaddr, &session->connection.remoteaddr)) {
|
||||
capwap_logging_error("Error to send request packet");
|
||||
}
|
||||
|
||||
/* Update timeout */
|
||||
capwap_timeout_set(session->timeout, session->idtimercontrol, AC_RETRANSMIT_INTERVAL, ac_dfa_retransmition_timeout, session, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ac_dfa_teardown_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param) {
|
||||
ac_session_teardown((struct ac_session_t*)context);
|
||||
}
|
||||
|
@ -66,7 +66,10 @@ struct ac_session_data_t {
|
||||
unsigned short mtu;
|
||||
struct capwap_connection connection;
|
||||
struct capwap_dtls dtls;
|
||||
struct timeout_control* timeout;
|
||||
|
||||
struct capwap_timeout* timeout;
|
||||
unsigned long idtimercontrol;
|
||||
unsigned long idtimerkeepalivedead;
|
||||
|
||||
capwap_event_t waitpacket;
|
||||
capwap_lock_t sessionlock;
|
||||
@ -105,7 +108,9 @@ struct ac_session_t {
|
||||
unsigned short mtu;
|
||||
struct capwap_dtls dtls;
|
||||
struct capwap_connection connection;
|
||||
struct timeout_control* timeout;
|
||||
|
||||
struct capwap_timeout* timeout;
|
||||
unsigned long idtimercontrol;
|
||||
|
||||
capwap_event_t waitpacket;
|
||||
capwap_lock_t sessionlock;
|
||||
@ -121,6 +126,7 @@ struct ac_session_t {
|
||||
struct capwap_list* requestfragmentpacket;
|
||||
struct capwap_list* responsefragmentpacket;
|
||||
unsigned char lastrecvpackethash[16];
|
||||
int retransmitcount;
|
||||
};
|
||||
|
||||
/* Session */
|
||||
@ -162,16 +168,29 @@ void ac_msgqueue_notify_closethread(pthread_t threadid);
|
||||
/* */
|
||||
int ac_dtls_setup(struct ac_session_t* session);
|
||||
int ac_dtls_data_setup(struct ac_session_data_t* sessiondata);
|
||||
void ac_dtls_setup_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param);
|
||||
|
||||
/* */
|
||||
void ac_dfa_retransmition_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param);
|
||||
void ac_dfa_teardown_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param);
|
||||
|
||||
/* */
|
||||
void ac_dfa_state_join(struct ac_session_t* session, struct capwap_parsed_packet* packet);
|
||||
void ac_dfa_state_postjoin(struct ac_session_t* session, struct capwap_parsed_packet* packet);
|
||||
void ac_dfa_state_join_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param);
|
||||
|
||||
void ac_dfa_state_configure(struct ac_session_t* session, struct capwap_parsed_packet* packet);
|
||||
|
||||
void ac_dfa_state_imagedata(struct ac_session_t* session, struct capwap_parsed_packet* packet);
|
||||
|
||||
void ac_dfa_state_datacheck(struct ac_session_t* session, struct capwap_parsed_packet* packet);
|
||||
void ac_dfa_state_datacheck_to_run(struct ac_session_t* session, struct capwap_parsed_packet* packet);
|
||||
void ac_dfa_state_imagedata(struct ac_session_t* session, struct capwap_parsed_packet* packet);
|
||||
void ac_dfa_state_datacheck_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param);
|
||||
|
||||
void ac_dfa_state_run(struct ac_session_t* session, struct capwap_parsed_packet* packet);
|
||||
|
||||
void ac_dfa_state_reset(struct ac_session_t* session, struct capwap_parsed_packet* packet);
|
||||
|
||||
void ac_dfa_state_teardown(struct ac_session_t* session);
|
||||
|
||||
/* Soap function */
|
||||
|
@ -17,7 +17,6 @@ static int ac_session_data_action_execute(struct ac_session_data_t* sessiondata,
|
||||
|
||||
/* */
|
||||
static int ac_network_read(struct ac_session_data_t* sessiondata, void* buffer, int length) {
|
||||
long indextimer;
|
||||
long waittimeout;
|
||||
int result = CAPWAP_ERROR_AGAIN;
|
||||
|
||||
@ -63,8 +62,8 @@ static int ac_network_read(struct ac_session_data_t* sessiondata, void* buffer,
|
||||
if (result == CAPWAP_ERROR_AGAIN) {
|
||||
/* Check is handshake complete */
|
||||
if ((oldaction == CAPWAP_DTLS_ACTION_HANDSHAKE) && (sessiondata->dtls.action == CAPWAP_DTLS_ACTION_DATA)) {
|
||||
capwap_timeout_kill(sessiondata->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
capwap_timeout_set(AC_MAX_DATA_CHECK_TIMER, sessiondata->timeout, CAPWAP_TIMER_DATA_KEEPALIVEDEAD);
|
||||
capwap_timeout_unset(sessiondata->timeout, sessiondata->idtimercontrol);
|
||||
capwap_timeout_set(sessiondata->timeout, sessiondata->idtimerkeepalivedead, AC_MAX_DATA_KEEPALIVE_INTERVAL, NULL, NULL, NULL);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -83,10 +82,10 @@ static int ac_network_read(struct ac_session_data_t* sessiondata, void* buffer,
|
||||
|
||||
capwap_lock_exit(&sessiondata->sessionlock);
|
||||
|
||||
/* Update timeout */
|
||||
capwap_timeout_update(sessiondata->timeout);
|
||||
waittimeout = capwap_timeout_get(sessiondata->timeout, &indextimer);
|
||||
if ((waittimeout <= 0) && (indextimer != CAPWAP_TIMER_UNDEF)) {
|
||||
/* Get timeout */
|
||||
waittimeout = capwap_timeout_getcoming(sessiondata->timeout);
|
||||
if (!waittimeout) {
|
||||
capwap_timeout_hasexpired(sessiondata->timeout);
|
||||
return AC_ERROR_TIMEOUT;
|
||||
}
|
||||
|
||||
@ -312,13 +311,13 @@ static void ac_session_data_run(struct ac_session_data_t* sessiondata) {
|
||||
/* Create DTLS channel */
|
||||
if (sessiondata->enabledtls) {
|
||||
if (ac_dtls_data_setup(sessiondata)) {
|
||||
capwap_timeout_set(AC_DEFAULT_WAITDTLS_INTERVAL, sessiondata->timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
capwap_timeout_set(sessiondata->timeout, sessiondata->idtimercontrol, AC_DTLS_INTERVAL, NULL, NULL, NULL);
|
||||
} else {
|
||||
capwap_logging_debug("Unable to start DTLS data");
|
||||
sessiondata->running = 0;
|
||||
}
|
||||
} else {
|
||||
capwap_timeout_set(AC_MAX_DATA_CHECK_TIMER, sessiondata->timeout, CAPWAP_TIMER_DATA_KEEPALIVEDEAD);
|
||||
capwap_timeout_set(sessiondata->timeout, sessiondata->idtimerkeepalivedead, AC_MAX_DATA_KEEPALIVE_INTERVAL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
/* */
|
||||
@ -356,7 +355,7 @@ static void ac_session_data_run(struct ac_session_data_t* sessiondata) {
|
||||
ac_session_data_keepalive(sessiondata, &packet);
|
||||
|
||||
/* Update timeout */
|
||||
capwap_timeout_set(AC_MAX_DATA_CHECK_TIMER, sessiondata->timeout, CAPWAP_TIMER_DATA_KEEPALIVEDEAD);
|
||||
capwap_timeout_set(sessiondata->timeout, sessiondata->idtimerkeepalivedead, AC_MAX_DATA_KEEPALIVE_INTERVAL, NULL, NULL, NULL);
|
||||
} else {
|
||||
/* TODO */
|
||||
}
|
||||
|
@ -297,6 +297,7 @@ void capwap_hash_add(struct capwap_hash* hash, const void* key, void* data) {
|
||||
ASSERT(key != NULL);
|
||||
|
||||
hashvalue = hash->item_hash(key, hash->keysize, hash->count);
|
||||
ASSERT(hashvalue < hash->count);
|
||||
|
||||
/* Search position where insert item */
|
||||
search = hash->items[hashvalue];
|
||||
|
@ -309,21 +309,19 @@ int capwap_compare_ip(struct sockaddr_storage* addr1, struct sockaddr_storage* a
|
||||
}
|
||||
|
||||
/* Wait receive packet with timeout */
|
||||
int capwap_wait_recvready(struct pollfd* fds, int fdscount, struct timeout_control* timeout) {
|
||||
int capwap_wait_recvready(struct pollfd* fds, int fdscount, struct capwap_timeout* timeout) {
|
||||
int i;
|
||||
int readysocket;
|
||||
int polltimeout = -1;
|
||||
int polltimeout = CAPWAP_TIMEOUT_INFINITE;
|
||||
|
||||
ASSERT(fds);
|
||||
ASSERT(fdscount > 0);
|
||||
|
||||
/* Check timeout */
|
||||
if (timeout) {
|
||||
long indextimer;
|
||||
|
||||
capwap_timeout_update(timeout);
|
||||
polltimeout = capwap_timeout_get(timeout, &indextimer);
|
||||
if ((polltimeout <= 0) && (indextimer != CAPWAP_TIMER_UNDEF)) {
|
||||
polltimeout = capwap_timeout_getcoming(timeout);
|
||||
if (!polltimeout) {
|
||||
capwap_timeout_hasexpired(timeout);
|
||||
return CAPWAP_RECV_ERROR_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@ -343,12 +341,8 @@ int capwap_wait_recvready(struct pollfd* fds, int fdscount, struct timeout_contr
|
||||
return CAPWAP_RECV_ERROR_SOCKET;
|
||||
}
|
||||
}
|
||||
} else if (readysocket == 0) {
|
||||
/* Update timer for detect timeout */
|
||||
if (timeout) {
|
||||
capwap_timeout_update(timeout);
|
||||
}
|
||||
|
||||
} else if (!readysocket && timeout) {
|
||||
capwap_timeout_hasexpired(timeout);
|
||||
return CAPWAP_RECV_ERROR_TIMEOUT;
|
||||
} else if (errno == EINTR) {
|
||||
return CAPWAP_RECV_ERROR_INTR;
|
||||
@ -451,7 +445,7 @@ int capwap_recvfrom_fd(int fd, void* buffer, int* size, struct sockaddr_storage*
|
||||
}
|
||||
|
||||
/* Receive packet with timeout */
|
||||
int capwap_recvfrom(struct pollfd* fds, int fdscount, void* buffer, int* size, struct sockaddr_storage* recvfromaddr, struct sockaddr_storage* recvtoaddr, struct timeout_control* timeout) {
|
||||
int capwap_recvfrom(struct pollfd* fds, int fdscount, void* buffer, int* size, struct sockaddr_storage* recvfromaddr, struct sockaddr_storage* recvtoaddr, struct capwap_timeout* timeout) {
|
||||
int index;
|
||||
|
||||
ASSERT(fds);
|
||||
|
@ -86,9 +86,9 @@ int capwap_compare_ip(struct sockaddr_storage* addr1, struct sockaddr_storage* a
|
||||
int capwap_sendto(int sock, void* buffer, int size, struct sockaddr_storage* sendfromaddr, struct sockaddr_storage* sendtoaddr);
|
||||
int capwap_sendto_fragmentpacket(int sock, struct capwap_list* fragmentlist, struct sockaddr_storage* sendfromaddr, struct sockaddr_storage* sendtoaddr);
|
||||
|
||||
int capwap_wait_recvready(struct pollfd* fds, int fdscount, struct timeout_control* timeout);
|
||||
int capwap_wait_recvready(struct pollfd* fds, int fdscount, struct capwap_timeout* timeout);
|
||||
int capwap_recvfrom_fd(int fd, void* buffer, int* size, struct sockaddr_storage* recvfromaddr, struct sockaddr_storage* recvtoaddr);
|
||||
int capwap_recvfrom(struct pollfd* fds, int fdscount, void* buffer, int* size, struct sockaddr_storage* recvfromaddr, struct sockaddr_storage* recvtoaddr, struct timeout_control* timeout);
|
||||
int capwap_recvfrom(struct pollfd* fds, int fdscount, void* buffer, int* size, struct sockaddr_storage* recvfromaddr, struct sockaddr_storage* recvtoaddr, struct capwap_timeout* timeout);
|
||||
|
||||
int capwap_ipv4_mapped_ipv6(struct sockaddr_storage* source, struct sockaddr_storage* dest);
|
||||
int capwap_address_from_string(const char* ip, struct sockaddr_storage* address);
|
||||
|
@ -1,131 +1,314 @@
|
||||
#include "capwap.h"
|
||||
|
||||
/* */
|
||||
struct timeout_control* capwap_timeout_init(void) {
|
||||
struct timeout_control* timeout;
|
||||
#define CAPWAP_TIMEOUT_HASH_COUNT 128
|
||||
|
||||
timeout = (struct timeout_control*)capwap_alloc(sizeof(struct timeout_control));
|
||||
memset(timeout, 0, sizeof(struct timeout_control));
|
||||
/* */
|
||||
static unsigned long capwap_timeout_hash_item_gethash(const void* key, unsigned long keysize, unsigned long hashsize) {
|
||||
return (*(unsigned long*)key % hashsize);
|
||||
}
|
||||
|
||||
/* */
|
||||
static int capwap_timeout_hash_item_cmp(const void* key1, const void* key2, unsigned long keysize) {
|
||||
unsigned long value1 = *(unsigned long*)key1;
|
||||
unsigned long value2 = *(unsigned long*)key2;
|
||||
|
||||
return ((value1 == value2) ? 0 : ((value1 < value2) ? -1 : 1));
|
||||
}
|
||||
|
||||
/* */
|
||||
static long capwap_timeout_getdelta(struct timeval* time1, struct timeval* time2) {
|
||||
return (time1->tv_sec - time2->tv_sec) * 1000 + (time1->tv_usec - time2->tv_usec) / 1000;
|
||||
}
|
||||
|
||||
/* */
|
||||
static unsigned long capwap_timeout_set_bitfield(struct capwap_timeout* timeout) {
|
||||
int i, j;
|
||||
|
||||
ASSERT(timeout != NULL);
|
||||
|
||||
/* Search free bitfield */
|
||||
for (i = 0; i < CAPWAP_TIMEOUT_BITFIELD_SIZE; i++) {
|
||||
if (timeout->timeoutbitfield[i] != 0xffffffff) {
|
||||
uint32_t bitfield = timeout->timeoutbitfield[i];
|
||||
|
||||
for (j = 0; j < 32; j++) {
|
||||
if (!(bitfield & (1 << j))) {
|
||||
timeout->timeoutbitfield[i] |= (1 << j);
|
||||
return (i * 32 + j + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return CAPWAP_TIMEOUT_INDEX_NO_SET;
|
||||
}
|
||||
|
||||
/* */
|
||||
static void capwap_timeout_clear_bitfield(struct capwap_timeout* timeout, unsigned long value) {
|
||||
ASSERT(timeout != NULL);
|
||||
ASSERT(value > 0);
|
||||
|
||||
timeout->timeoutbitfield[(value - 1) / 32] &= ~(1 << ((value - 1) % 32));
|
||||
}
|
||||
|
||||
/* */
|
||||
static void capwap_timeout_additem(struct capwap_list* itemstimeout, struct capwap_list_item* itemlist) {
|
||||
struct capwap_list_item* search;
|
||||
struct capwap_list_item* last = NULL;
|
||||
struct capwap_timeout_item* item = (struct capwap_timeout_item*)itemlist->item;
|
||||
|
||||
/* */
|
||||
search = itemstimeout->first;
|
||||
while (search) {
|
||||
struct capwap_timeout_item* itemsearch = (struct capwap_timeout_item*)search->item;
|
||||
|
||||
if (capwap_timeout_getdelta(&item->expire, &itemsearch->expire) < 0) {
|
||||
capwap_itemlist_insert_before(itemstimeout, last, itemlist);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Next */
|
||||
last = search;
|
||||
search = search->next;
|
||||
}
|
||||
|
||||
/* */
|
||||
if (!search) {
|
||||
capwap_itemlist_insert_after(itemstimeout, NULL, itemlist);
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
static void capwap_timeout_setexpire(long durate, struct timeval* now, struct timeval* expire) {
|
||||
expire->tv_sec = now->tv_sec + durate / 1000;
|
||||
expire->tv_usec = now->tv_usec + durate % 1000;
|
||||
if (expire->tv_usec >= 1000000) {
|
||||
expire->tv_sec++;
|
||||
expire->tv_usec -= 1000000;
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
struct capwap_timeout* capwap_timeout_init(void) {
|
||||
struct capwap_timeout* timeout;
|
||||
|
||||
/* */
|
||||
timeout = (struct capwap_timeout*)capwap_alloc(sizeof(struct capwap_timeout));
|
||||
memset(timeout, 0, sizeof(struct capwap_timeout));
|
||||
|
||||
/* */
|
||||
timeout->itemsreference = capwap_hash_create(CAPWAP_TIMEOUT_HASH_COUNT, sizeof(unsigned long), capwap_timeout_hash_item_gethash, capwap_timeout_hash_item_cmp, NULL);
|
||||
timeout->itemstimeout = capwap_list_create();
|
||||
|
||||
return timeout;
|
||||
}
|
||||
|
||||
/* */
|
||||
void capwap_timeout_free(struct timeout_control* timeout) {
|
||||
void capwap_timeout_free(struct capwap_timeout* timeout) {
|
||||
ASSERT(timeout != NULL);
|
||||
|
||||
capwap_hash_free(timeout->itemsreference);
|
||||
capwap_list_free(timeout->itemstimeout);
|
||||
capwap_free(timeout);
|
||||
}
|
||||
|
||||
/* */
|
||||
void capwap_timeout_update(struct timeout_control* timeout) {
|
||||
int i;
|
||||
unsigned long capwap_timeout_createtimer(struct capwap_timeout* timeout) {
|
||||
unsigned long index;
|
||||
|
||||
ASSERT(timeout != NULL);
|
||||
|
||||
/* Create new timeout index */
|
||||
index = capwap_timeout_set_bitfield(timeout);
|
||||
capwap_logging_debug("Create new timer: %lu", index);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
/* */
|
||||
void capwap_timeout_deletetimer(struct capwap_timeout* timeout, unsigned long index) {
|
||||
ASSERT(timeout != NULL);
|
||||
ASSERT(index != CAPWAP_TIMEOUT_INDEX_NO_SET);
|
||||
|
||||
capwap_logging_debug("Delete timer: %lu", index);
|
||||
|
||||
/* Unset timeout timer */
|
||||
capwap_timeout_unset(timeout, index);
|
||||
|
||||
/* Release timer index */
|
||||
capwap_timeout_clear_bitfield(timeout, index);
|
||||
}
|
||||
|
||||
/* */
|
||||
unsigned long capwap_timeout_set(struct capwap_timeout* timeout, unsigned long index, long durate, capwap_timeout_expire callback, void* context, void* param) {
|
||||
struct capwap_list_item* itemlist;
|
||||
struct capwap_timeout_item* item;
|
||||
struct timeval now;
|
||||
|
||||
ASSERT(timeout);
|
||||
|
||||
|
||||
ASSERT(timeout != NULL);
|
||||
ASSERT(durate >= 0);
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
|
||||
for (i = 0; i < CAPWAP_MAX_TIMER; i++) {
|
||||
if (timeout->items[i].enable && (timeout->items[i].delta >= 0)) {
|
||||
timeout->items[i].delta = (timeout->items[i].timestop.tv_sec - now.tv_sec) * 1000 + (timeout->items[i].timestop.tv_usec - now.tv_usec) / 1000;
|
||||
if (timeout->items[i].delta < 0) {
|
||||
timeout->items[i].delta = 0;
|
||||
} else if (timeout->items[i].delta > timeout->items[i].durate) {
|
||||
/* Changed system time */
|
||||
timeout->items[i].delta = timeout->items[i].durate;
|
||||
memcpy(&timeout->items[i].timestop, &now, sizeof(struct timeval));
|
||||
timeout->items[i].timestop.tv_sec += timeout->items[i].durate;
|
||||
}
|
||||
|
||||
if (index == CAPWAP_TIMEOUT_INDEX_NO_SET) {
|
||||
index = capwap_timeout_createtimer(timeout);
|
||||
} else {
|
||||
/* Check can update timeout timer */
|
||||
itemlist = (struct capwap_list_item*)capwap_hash_search(timeout->itemsreference, &index);
|
||||
if (itemlist) {
|
||||
/* Remove from timeout list */
|
||||
capwap_itemlist_remove(timeout->itemstimeout, itemlist);
|
||||
|
||||
/* Update timeout */
|
||||
item = (struct capwap_timeout_item*)itemlist->item;
|
||||
item->durate = durate;
|
||||
capwap_timeout_setexpire(item->durate, &now, &item->expire);
|
||||
item->callback = callback;
|
||||
item->context = context;
|
||||
item->param = param;
|
||||
|
||||
capwap_logging_debug("Update timeout: %lu %ld", item->index, item->durate);
|
||||
|
||||
/* Add itemlist into order list */
|
||||
capwap_timeout_additem(timeout->itemstimeout, itemlist);
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create new timeout timer */
|
||||
itemlist = capwap_itemlist_create(sizeof(struct capwap_timeout_item));
|
||||
item = (struct capwap_timeout_item*)itemlist->item;
|
||||
|
||||
/* */
|
||||
item->index = index;
|
||||
item->durate = durate;
|
||||
capwap_timeout_setexpire(item->durate, &now, &item->expire);
|
||||
item->callback = callback;
|
||||
item->context = context;
|
||||
item->param = param;
|
||||
|
||||
capwap_logging_debug("Set timeout: %lu %ld", item->index, item->durate);
|
||||
|
||||
/* Add itemlist into hash for rapid searching */
|
||||
capwap_hash_add(timeout->itemsreference, (const void*)&item->index, (void*)itemlist);
|
||||
|
||||
/* Add itemlist into order list */
|
||||
capwap_timeout_additem(timeout->itemstimeout, itemlist);
|
||||
|
||||
return item->index;
|
||||
}
|
||||
|
||||
/* */
|
||||
long capwap_timeout_get(struct timeout_control* timeout, long* index) {
|
||||
long i;
|
||||
long delta = 0;
|
||||
void capwap_timeout_unset(struct capwap_timeout* timeout, unsigned long index) {
|
||||
struct capwap_list_item* itemlist;
|
||||
|
||||
ASSERT(timeout != NULL);
|
||||
ASSERT(index != NULL);
|
||||
|
||||
*index = CAPWAP_TIMER_UNDEF;
|
||||
for (i = 0; i < CAPWAP_MAX_TIMER; i++) {
|
||||
if (timeout->items[i].enable) {
|
||||
if (timeout->items[i].delta <= 0) {
|
||||
*index = i;
|
||||
delta = 0;
|
||||
break;
|
||||
} else if (!delta || (delta > timeout->items[i].delta)) {
|
||||
*index = i;
|
||||
delta = timeout->items[i].delta;
|
||||
}
|
||||
ASSERT(index != CAPWAP_TIMEOUT_INDEX_NO_SET);
|
||||
|
||||
/* */
|
||||
itemlist = (struct capwap_list_item*)capwap_hash_search(timeout->itemsreference, &index);
|
||||
if (itemlist) {
|
||||
capwap_logging_debug("Unset timeout: %lu", index);
|
||||
capwap_hash_delete(timeout->itemsreference, &index);
|
||||
capwap_itemlist_free(capwap_itemlist_remove(timeout->itemstimeout, itemlist));
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
void capwap_timeout_unsetall(struct capwap_timeout* timeout) {
|
||||
capwap_hash_deleteall(timeout->itemsreference);
|
||||
capwap_list_flush(timeout->itemstimeout);
|
||||
}
|
||||
|
||||
/* */
|
||||
long capwap_timeout_getcoming(struct capwap_timeout* timeout) {
|
||||
long delta;
|
||||
struct timeval now;
|
||||
struct capwap_list_item* search;
|
||||
struct capwap_timeout_item* item;
|
||||
|
||||
ASSERT(timeout != NULL);
|
||||
|
||||
/* */
|
||||
search = timeout->itemstimeout->first;
|
||||
if (!search) {
|
||||
return CAPWAP_TIMEOUT_INFINITE;
|
||||
}
|
||||
|
||||
/* */
|
||||
gettimeofday(&now, NULL);
|
||||
item = (struct capwap_timeout_item*)search->item;
|
||||
delta = capwap_timeout_getdelta(&item->expire, &now);
|
||||
|
||||
if (delta <= 0) {
|
||||
return 0;
|
||||
} else if (delta <= item->durate) {
|
||||
return delta;
|
||||
}
|
||||
|
||||
/* Recalculate all timeouts because delta > item->durate */
|
||||
while (search) {
|
||||
struct capwap_timeout_item* itemsearch = (struct capwap_timeout_item*)search->item;
|
||||
|
||||
capwap_timeout_setexpire(itemsearch->durate, &now, &itemsearch->expire);
|
||||
search = search->next;
|
||||
}
|
||||
|
||||
return item->durate;
|
||||
}
|
||||
|
||||
/* */
|
||||
unsigned long capwap_timeout_hasexpired(struct capwap_timeout* timeout) {
|
||||
long delta;
|
||||
struct capwap_timeout_item* item;
|
||||
struct capwap_list_item* itemlist;
|
||||
unsigned long index;
|
||||
capwap_timeout_expire callback;
|
||||
void* context;
|
||||
void* param;
|
||||
|
||||
ASSERT(timeout != NULL);
|
||||
|
||||
/* */
|
||||
delta = capwap_timeout_getcoming(timeout);
|
||||
if ((delta > 0) || (delta == CAPWAP_TIMEOUT_INFINITE)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* */
|
||||
itemlist = capwap_itemlist_remove_head(timeout->itemstimeout);
|
||||
item = (struct capwap_timeout_item*)itemlist->item;
|
||||
|
||||
capwap_logging_debug("Expired timeout: %lu", item->index);
|
||||
|
||||
/* Cache callback before release timeout timer */
|
||||
index = item->index;
|
||||
callback = item->callback;
|
||||
context = item->context;
|
||||
param = item->param;
|
||||
|
||||
/* Free memory */
|
||||
capwap_hash_delete(timeout->itemsreference, &index);
|
||||
capwap_itemlist_free(itemlist);
|
||||
|
||||
/* */
|
||||
if (callback) {
|
||||
callback(timeout, index, context, param);
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
/* */
|
||||
int capwap_timeout_wait(long durate) {
|
||||
if (durate < 0) {
|
||||
return -1;
|
||||
} else if (durate > 0) {
|
||||
if (usleep((useconds_t)durate * 1000)) {
|
||||
return ((errno == EINTR) ? 0 : -1);
|
||||
}
|
||||
}
|
||||
|
||||
return delta;
|
||||
}
|
||||
|
||||
/* */
|
||||
void capwap_timeout_wait(struct timeout_control* timeout, unsigned long index) {
|
||||
ASSERT(timeout != NULL);
|
||||
ASSERT(index < CAPWAP_MAX_TIMER);
|
||||
|
||||
if (timeout->items[index].enable) {
|
||||
for (capwap_timeout_update(timeout); timeout->items[index].delta > 0; capwap_timeout_update(timeout)) {
|
||||
usleep((useconds_t)timeout->items[index].delta * 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
int capwap_timeout_isenable(struct timeout_control* timeout, unsigned long index) {
|
||||
ASSERT(timeout != NULL);
|
||||
ASSERT(index < CAPWAP_MAX_TIMER);
|
||||
|
||||
return (timeout->items[index].enable ? 1 : 0);
|
||||
}
|
||||
|
||||
/* */
|
||||
int capwap_timeout_hasexpired(struct timeout_control* timeout, unsigned long index) {
|
||||
ASSERT(timeout != NULL);
|
||||
ASSERT(index < CAPWAP_MAX_TIMER);
|
||||
|
||||
if (timeout->items[index].enable && (timeout->items[index].delta <= 0)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* */
|
||||
void capwap_timeout_set(unsigned long value, struct timeout_control* timeout, unsigned long index) {
|
||||
ASSERT(timeout != NULL);
|
||||
ASSERT(index < CAPWAP_MAX_TIMER);
|
||||
|
||||
/* Set timeout in ms */
|
||||
timeout->items[index].enable = 1;
|
||||
timeout->items[index].delta = value * 1000;
|
||||
timeout->items[index].durate = timeout->items[index].delta;
|
||||
gettimeofday(&timeout->items[index].timestop, NULL);
|
||||
timeout->items[index].timestop.tv_sec += value;
|
||||
}
|
||||
|
||||
/* */
|
||||
void capwap_timeout_kill(struct timeout_control* timeout, unsigned long index) {
|
||||
ASSERT(timeout != NULL);
|
||||
ASSERT(index < CAPWAP_MAX_TIMER);
|
||||
|
||||
timeout->items[index].enable = 0;
|
||||
}
|
||||
|
||||
/* */
|
||||
void capwap_timeout_killall(struct timeout_control* timeout) {
|
||||
long i;
|
||||
|
||||
ASSERT(timeout != NULL);
|
||||
|
||||
for (i = 0; i < CAPWAP_MAX_TIMER; i++) {
|
||||
timeout->items[i].enable = 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -1,39 +1,49 @@
|
||||
#ifndef __CAPWAP_TIMEOUT_HEADER__
|
||||
#define __CAPWAP_TIMEOUT_HEADER__
|
||||
|
||||
#define CAPWAP_TIMER_UNDEF -1
|
||||
#define CAPWAP_TIMER_CONTROL_CONNECTION 0
|
||||
#define CAPWAP_TIMER_CONTROL_ECHO 1
|
||||
#define CAPWAP_TIMER_DATA_KEEPALIVE 2
|
||||
#define CAPWAP_TIMER_DATA_KEEPALIVEDEAD 3
|
||||
#define CAPWAP_MAX_TIMER 4
|
||||
#include "capwap_hash.h"
|
||||
#include "capwap_list.h"
|
||||
|
||||
/* */
|
||||
struct timeout_control_item {
|
||||
int enable;
|
||||
long delta;
|
||||
unsigned long durate;
|
||||
struct timeval timestop;
|
||||
};
|
||||
#define CAPWAP_TIMEOUT_BITFIELD_SIZE 128
|
||||
#define CAPWAP_TIMEOUT_INFINITE -1
|
||||
#define CAPWAP_TIMEOUT_INDEX_NO_SET 0
|
||||
|
||||
struct timeout_control {
|
||||
struct timeout_control_item items[CAPWAP_MAX_TIMER];
|
||||
/* */
|
||||
struct capwap_timeout {
|
||||
uint32_t timeoutbitfield[CAPWAP_TIMEOUT_BITFIELD_SIZE];
|
||||
struct capwap_hash* itemsreference;
|
||||
struct capwap_list* itemstimeout;
|
||||
};
|
||||
|
||||
/* */
|
||||
struct timeout_control* capwap_timeout_init(void);
|
||||
void capwap_timeout_free(struct timeout_control* timeout);
|
||||
typedef void (*capwap_timeout_expire)(struct capwap_timeout* timeout, unsigned long index, void* context, void* param);
|
||||
|
||||
long capwap_timeout_get(struct timeout_control* timeout, long* index);
|
||||
void capwap_timeout_update(struct timeout_control* timeout);
|
||||
void capwap_timeout_set(unsigned long value, struct timeout_control* timeout, unsigned long index);
|
||||
struct capwap_timeout_item {
|
||||
unsigned long index;
|
||||
long durate;
|
||||
struct timeval expire;
|
||||
capwap_timeout_expire callback;
|
||||
void* context;
|
||||
void* param;
|
||||
};
|
||||
|
||||
void capwap_timeout_wait(struct timeout_control* timeout, unsigned long index);
|
||||
/* */
|
||||
struct capwap_timeout* capwap_timeout_init(void);
|
||||
void capwap_timeout_free(struct capwap_timeout* timeout);
|
||||
|
||||
int capwap_timeout_isenable(struct timeout_control* timeout, unsigned long index);
|
||||
int capwap_timeout_hasexpired(struct timeout_control* timeout, unsigned long index);
|
||||
/* */
|
||||
unsigned long capwap_timeout_createtimer(struct capwap_timeout* timeout);
|
||||
void capwap_timeout_deletetimer(struct capwap_timeout* timeout, unsigned long index);
|
||||
|
||||
void capwap_timeout_kill(struct timeout_control* timeout, unsigned long index);
|
||||
void capwap_timeout_killall(struct timeout_control* timeout);
|
||||
/* */
|
||||
unsigned long capwap_timeout_set(struct capwap_timeout* timeout, unsigned long index, long durate, capwap_timeout_expire callback, void* context, void* param);
|
||||
void capwap_timeout_unset(struct capwap_timeout* timeout, unsigned long index);
|
||||
void capwap_timeout_unsetall(struct capwap_timeout* timeout);
|
||||
|
||||
long capwap_timeout_getcoming(struct capwap_timeout* timeout);
|
||||
unsigned long capwap_timeout_hasexpired(struct capwap_timeout* timeout);
|
||||
|
||||
int capwap_timeout_wait(long durate);
|
||||
|
||||
#endif /* __CAPWAP_TIMEOUT_HEADER__ */
|
||||
|
@ -15,9 +15,9 @@
|
||||
struct wtp_t g_wtp;
|
||||
|
||||
/* Local param */
|
||||
#define WTP_STANDARD_NAME "Unknown WTP"
|
||||
#define WTP_STANDARD_LOCATION "Unknown Location"
|
||||
#define WTP_WAIT_RADIO_INITIALIZATION 1
|
||||
#define WTP_STANDARD_NAME "Unknown WTP"
|
||||
#define WTP_STANDARD_LOCATION "Unknown Location"
|
||||
#define WTP_RADIO_INITIALIZATION_INTERVAL 1000
|
||||
|
||||
static char g_configurationfile[260] = WTP_STANDARD_CONFIGURATION_FILE;
|
||||
|
||||
@ -35,21 +35,16 @@ static int wtp_init(void) {
|
||||
g_wtp.location.value = (uint8_t*)capwap_duplicate_string(WTP_STANDARD_LOCATION);
|
||||
|
||||
/* State machine */
|
||||
g_wtp.dfa.state = CAPWAP_START_STATE;
|
||||
g_wtp.dfa.rfcMaxDiscoveryInterval = WTP_DEFAULT_DISCOVERY_INTERVAL;
|
||||
g_wtp.dfa.rfcMaxDiscoveries = WTP_DEFAULT_DISCOVERY_COUNT;
|
||||
g_wtp.dfa.rfcSilentInterval = WTP_DEFAULT_SILENT_INTERVAL;
|
||||
g_wtp.dfa.rfcRetransmitInterval = WTP_DEFAULT_RETRANSMIT_INTERVAL;
|
||||
g_wtp.dfa.rfcMaxRetransmit = WTP_MAX_RETRANSMIT;
|
||||
g_wtp.dfa.rfcWaitDTLS = WTP_DEFAULT_WAITDTLS_INTERVAL;
|
||||
g_wtp.dfa.rfcDataChannelKeepAlive = WTP_DEFAULT_DATACHANNEL_KEEPALIVE;
|
||||
g_wtp.dfa.rfcDataChannelDeadInterval = WTP_DEFAULT_DATACHANNEL_KEEPALIVEDEAD;
|
||||
g_wtp.dfa.rfcEchoInterval = WTP_DEFAULT_ECHO_INTERVAL;
|
||||
g_wtp.dfa.rfcDTLSSessionDelete = WTP_DEFAULT_DTLS_SESSION_DELETE;
|
||||
g_wtp.dfa.rfcMaxFailedDTLSSessionRetry = WTP_DEFAULT_FAILED_DTLS_SESSION_RETRY;
|
||||
g_wtp.state = CAPWAP_START_STATE;
|
||||
g_wtp.discoveryinterval = WTP_DISCOVERY_INTERVAL;
|
||||
g_wtp.echointerval = WTP_ECHO_INTERVAL;
|
||||
|
||||
/* */
|
||||
g_wtp.timeout = capwap_timeout_init();
|
||||
g_wtp.idtimercontrol = capwap_timeout_createtimer(g_wtp.timeout);
|
||||
g_wtp.idtimerecho = capwap_timeout_createtimer(g_wtp.timeout);
|
||||
g_wtp.idtimerkeepalive = capwap_timeout_createtimer(g_wtp.timeout);
|
||||
g_wtp.idtimerkeepalivedead = capwap_timeout_createtimer(g_wtp.timeout);
|
||||
|
||||
/* Socket */
|
||||
capwap_network_init(&g_wtp.net);
|
||||
@ -63,7 +58,7 @@ static int wtp_init(void) {
|
||||
|
||||
g_wtp.ecn.flag = CAPWAP_LIMITED_ECN_SUPPORT;
|
||||
g_wtp.transport.type = CAPWAP_UDP_TRANSPORT;
|
||||
g_wtp.statisticstimer.timer = WTP_DEFAULT_STATISTICSTIMER_INTERVAL;
|
||||
g_wtp.statisticstimer.timer = WTP_STATISTICSTIMER_INTERVAL / 1000;
|
||||
|
||||
g_wtp.mactype.type = CAPWAP_LOCALMAC;
|
||||
g_wtp.mactunnel.mode = CAPWAP_WTP_LOCAL_BRIDGING;
|
||||
@ -1322,7 +1317,7 @@ static void wtp_wait_radio_ready(void) {
|
||||
wtp_radio_update_fdevent(&fds);
|
||||
|
||||
for (;;) {
|
||||
capwap_timeout_set(WTP_WAIT_RADIO_INITIALIZATION, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, WTP_RADIO_INITIALIZATION_INTERVAL, NULL, NULL, NULL);
|
||||
|
||||
/* Wait packet */
|
||||
index = capwap_wait_recvready(fds.fdspoll, fds.fdstotalcount, g_wtp.timeout);
|
||||
@ -1337,7 +1332,7 @@ static void wtp_wait_radio_ready(void) {
|
||||
|
||||
/* */
|
||||
wtp_free_fds(&fds);
|
||||
capwap_timeout_killall(g_wtp.timeout);
|
||||
capwap_timeout_unset(g_wtp.timeout, g_wtp.idtimercontrol);
|
||||
}
|
||||
|
||||
/* */
|
||||
|
@ -18,61 +18,29 @@
|
||||
#define WTP_ERROR_INIT_BINDING -1003
|
||||
#define WTP_ERROR_MEMORY_LEAK 1
|
||||
|
||||
/* Min and max dfa values */
|
||||
#define WTP_MIN_DISCOVERY_INTERVAL 2
|
||||
#define WTP_DEFAULT_DISCOVERY_INTERVAL 20
|
||||
#define WTP_MAX_DISCOVERY_INTERVAL 180
|
||||
#define WTP_DEFAULT_DISCOVERY_COUNT 10
|
||||
#define WTP_DEFAULT_SILENT_INTERVAL 30
|
||||
#define WTP_DEFAULT_RETRANSMIT_INTERVAL 3
|
||||
/* */
|
||||
#define WTP_MIN_DISCOVERY_INTERVAL 2000
|
||||
#define WTP_DISCOVERY_INTERVAL 20000
|
||||
#define WTP_MAX_DISCOVERY_COUNT 10
|
||||
|
||||
#define WTP_SILENT_INTERVAL 30000
|
||||
|
||||
#define WTP_DTLS_INTERVAL 60000
|
||||
#define WTP_DTLS_SESSION_DELETE 5000
|
||||
#define WTP_FAILED_DTLS_SESSION_RETRY 3
|
||||
|
||||
#define WTP_RETRANSMIT_INTERVAL 3000
|
||||
#define WTP_MAX_RETRANSMIT 5
|
||||
#define WTP_MIN_WAITDTLS_INTERVAL 30
|
||||
#define WTP_DEFAULT_WAITDTLS_INTERVAL 60
|
||||
#define WTP_DEFAULT_STATISTICSTIMER_INTERVAL 120
|
||||
#define WTP_DEFAULT_DATACHANNEL_KEEPALIVE 30
|
||||
#define WTP_DEFAULT_DATACHANNEL_KEEPALIVEDEAD 60
|
||||
#define WTP_MAX_DATACHANNEL_KEEPALIVEDEAD 240
|
||||
#define WTP_DEFAULT_ECHO_INTERVAL 30
|
||||
#define WTP_DEFAULT_DTLS_SESSION_DELETE 5
|
||||
#define WTP_DEFAULT_FAILED_DTLS_SESSION_RETRY 3
|
||||
|
||||
#define WTP_DATACHANNEL_KEEPALIVE_INTERVAL 30000
|
||||
#define WTP_DATACHANNEL_KEEPALIVEDEAD 60000
|
||||
|
||||
#define WTP_STATISTICSTIMER_INTERVAL 120000
|
||||
|
||||
#define WTP_ECHO_INTERVAL 30000
|
||||
|
||||
#define WTP_INIT_REMOTE_SEQUENCE 0xff
|
||||
|
||||
/* WTP State machine */
|
||||
struct wtp_state {
|
||||
unsigned long state;
|
||||
|
||||
/* Discovery Information */
|
||||
int rfcDiscoveryInterval;
|
||||
int rfcMaxDiscoveryInterval;
|
||||
int rfcDiscoveryCount;
|
||||
int rfcMaxDiscoveries;
|
||||
|
||||
/* Sulking Information */
|
||||
int rfcSilentInterval;
|
||||
|
||||
/* Run */
|
||||
int rfcEchoInterval;
|
||||
|
||||
/* Dtls Information */
|
||||
int rfcFailedDTLSSessionCount;
|
||||
int rfcFailedDTLSAuthFailCount;
|
||||
int rfcMaxFailedDTLSSessionRetry;
|
||||
|
||||
/* Request retransmit */
|
||||
int rfcRetransmitInterval;
|
||||
int rfcRetransmitCount;
|
||||
int rfcMaxRetransmit;
|
||||
|
||||
/* Data channel */
|
||||
int rfcDataChannelKeepAlive;
|
||||
int rfcDataChannelDeadInterval;
|
||||
|
||||
/* Dtls */
|
||||
int rfcWaitDTLS;
|
||||
int rfcDTLSSessionDelete;
|
||||
};
|
||||
|
||||
/* */
|
||||
struct wtp_fds {
|
||||
struct pollfd* fdspoll;
|
||||
@ -95,8 +63,20 @@ struct wtp_t {
|
||||
struct wtp_fds fds;
|
||||
|
||||
/* */
|
||||
struct wtp_state dfa;
|
||||
struct timeout_control* timeout;
|
||||
unsigned long state;
|
||||
int teardown;
|
||||
|
||||
/* */
|
||||
int discoveryinterval;
|
||||
int discoverycount;
|
||||
int echointerval;
|
||||
|
||||
/* Timer */
|
||||
struct capwap_timeout* timeout;
|
||||
unsigned long idtimercontrol;
|
||||
unsigned long idtimerecho;
|
||||
unsigned long idtimerkeepalive;
|
||||
unsigned long idtimerkeepalivedead;
|
||||
|
||||
struct capwap_wtpname_element name;
|
||||
struct capwap_acname_element acname;
|
||||
@ -128,6 +108,7 @@ struct wtp_t {
|
||||
struct capwap_list* requestfragmentpacket;
|
||||
struct capwap_list* responsefragmentpacket;
|
||||
unsigned char lastrecvpackethash[16];
|
||||
int retransmitcount;
|
||||
|
||||
/* */
|
||||
int acdiscoveryrequest;
|
||||
@ -157,7 +138,8 @@ struct wtp_t {
|
||||
struct capwap_dtls_context dtlscontext;
|
||||
struct capwap_dtls ctrldtls;
|
||||
struct capwap_dtls datadtls;
|
||||
int teardown;
|
||||
int faileddtlssessioncount;
|
||||
int faileddtlsauthfailcount;
|
||||
};
|
||||
|
||||
extern struct wtp_t g_wtp;
|
||||
|
@ -91,12 +91,9 @@ static void wtp_send_invalid_request(struct capwap_packet_rxmng* rxmngpacket, st
|
||||
|
||||
/* WTP Execute state */
|
||||
static void wtp_dfa_execute(struct capwap_parsed_packet* packet) {
|
||||
switch (g_wtp.dfa.state) {
|
||||
case CAPWAP_IDLE_STATE: {
|
||||
wtp_dfa_state_idle(packet);
|
||||
break;
|
||||
}
|
||||
ASSERT(packet != NULL);
|
||||
|
||||
switch (g_wtp.state) {
|
||||
case CAPWAP_DISCOVERY_STATE: {
|
||||
wtp_dfa_state_discovery(packet);
|
||||
break;
|
||||
@ -127,11 +124,6 @@ static void wtp_dfa_execute(struct capwap_parsed_packet* packet) {
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_RESET_STATE: {
|
||||
wtp_dfa_state_reset(packet);
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_DATA_CHECK_STATE: {
|
||||
wtp_dfa_state_datacheck(packet);
|
||||
break;
|
||||
@ -143,7 +135,7 @@ static void wtp_dfa_execute(struct capwap_parsed_packet* packet) {
|
||||
}
|
||||
|
||||
default: {
|
||||
capwap_logging_debug("Unknown action event: %lu", g_wtp.dfa.state);
|
||||
capwap_logging_debug("Unknown action event: %lu", g_wtp.state);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -206,6 +198,28 @@ static void wtp_dfa_init_fdspool(struct wtp_fds* fds, struct capwap_network* net
|
||||
wtp_radio_update_fdevent(fds);
|
||||
}
|
||||
|
||||
/* */
|
||||
static void wtp_dfa_closeapp(void) {
|
||||
g_wtp.running = 0;
|
||||
|
||||
/* Teardown */
|
||||
wtp_teardown_connection();
|
||||
|
||||
/* Wait RFC teardown timeout */
|
||||
for (;;) {
|
||||
if (capwap_timeout_wait(capwap_timeout_getcoming(g_wtp.timeout)) < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (capwap_timeout_hasexpired(g_wtp.timeout) == g_wtp.idtimercontrol) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
ASSERT(g_wtp.state == CAPWAP_DEAD_STATE);
|
||||
}
|
||||
|
||||
/* WTP state machine */
|
||||
int wtp_dfa_running(void) {
|
||||
int res;
|
||||
@ -223,14 +237,10 @@ int wtp_dfa_running(void) {
|
||||
int index;
|
||||
struct sockaddr_storage recvfromaddr;
|
||||
struct sockaddr_storage recvtoaddr;
|
||||
int isrecvpacket = 0;
|
||||
|
||||
/* Init */
|
||||
memset(&packet, 0, sizeof(struct capwap_parsed_packet));
|
||||
|
||||
/* Start DFA with timeout */
|
||||
capwap_timeout_set(0, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
|
||||
/* Configure poll struct */
|
||||
wtp_dfa_init_fdspool(&g_wtp.fds, &g_wtp.net);
|
||||
|
||||
@ -242,27 +252,19 @@ int wtp_dfa_running(void) {
|
||||
|
||||
/* Init complete, start DFA */
|
||||
wtp_dfa_change_state(CAPWAP_IDLE_STATE);
|
||||
wtp_dfa_state_idle(NULL);
|
||||
wtp_dfa_state_idle();
|
||||
|
||||
/* */
|
||||
while (g_wtp.dfa.state != CAPWAP_DEAD_STATE) {
|
||||
while (g_wtp.state != CAPWAP_DEAD_STATE) {
|
||||
/* If request wait packet from AC */
|
||||
isrecvpacket = 0;
|
||||
buffer = bufferencrypt;
|
||||
buffersize = CAPWAP_MAX_PACKET_SIZE;
|
||||
index = wtp_recvfrom(&g_wtp.fds, buffer, &buffersize, &recvfromaddr, &recvtoaddr);
|
||||
if (!g_wtp.running) {
|
||||
capwap_logging_debug("Closing WTP, Teardown connection");
|
||||
|
||||
/* Manual teardown */
|
||||
index = CAPWAP_RECV_ERROR_TIMEOUT;
|
||||
wtp_teardown_connection();
|
||||
|
||||
/* Wait RFC teardown timeout */
|
||||
capwap_timeout_wait(g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
}
|
||||
|
||||
if (index >= 0) {
|
||||
wtp_dfa_closeapp();
|
||||
break;
|
||||
} else if (index >= 0) {
|
||||
if (g_wtp.teardown) {
|
||||
/* Drop packet */
|
||||
continue;
|
||||
@ -286,7 +288,7 @@ int wtp_dfa_running(void) {
|
||||
}
|
||||
|
||||
/* Check of packet */
|
||||
check = capwap_sanity_check(socket.isctrlsocket, g_wtp.dfa.state, buffer, buffersize, g_wtp.ctrldtls.enable, g_wtp.datadtls.enable);
|
||||
check = capwap_sanity_check(socket.isctrlsocket, g_wtp.state, buffer, buffersize, g_wtp.ctrldtls.enable, g_wtp.datadtls.enable);
|
||||
if (check == CAPWAP_DTLS_PACKET) {
|
||||
struct capwap_dtls* dtls = (socket.isctrlsocket ? &g_wtp.ctrldtls : &g_wtp.datadtls);
|
||||
|
||||
@ -302,7 +304,7 @@ int wtp_dfa_running(void) {
|
||||
/* Check is handshake complete */
|
||||
if ((oldaction == CAPWAP_DTLS_ACTION_HANDSHAKE) && (dtls->action == CAPWAP_DTLS_ACTION_DATA)) {
|
||||
if (socket.isctrlsocket) {
|
||||
if (g_wtp.dfa.state == CAPWAP_DTLS_CONNECT_STATE) {
|
||||
if (g_wtp.state == CAPWAP_DTLS_CONNECT_STATE) {
|
||||
check = CAPWAP_NONE_PACKET;
|
||||
wtp_send_join();
|
||||
} else {
|
||||
@ -310,7 +312,7 @@ int wtp_dfa_running(void) {
|
||||
wtp_teardown_connection();
|
||||
}
|
||||
} else {
|
||||
if (g_wtp.dfa.state == CAPWAP_DATA_CHECK_STATE) {
|
||||
if (g_wtp.state == CAPWAP_DATA_CHECK_STATE) {
|
||||
check = CAPWAP_NONE_PACKET;
|
||||
wtp_start_datachannel();
|
||||
} else {
|
||||
@ -434,7 +436,11 @@ int wtp_dfa_running(void) {
|
||||
}
|
||||
|
||||
/* Receive a complete packet */
|
||||
isrecvpacket = 1;
|
||||
wtp_dfa_execute(&packet);
|
||||
|
||||
/* Free packet */
|
||||
capwap_free_parsed_packet(&packet);
|
||||
wtp_free_packet_rxmng(socket.isctrlsocket);
|
||||
}
|
||||
}
|
||||
} else if ((index == CAPWAP_RECV_ERROR_INTR) || (index == WTP_RECV_NOERROR_RADIO)) {
|
||||
@ -444,15 +450,6 @@ int wtp_dfa_running(void) {
|
||||
/* Socket close */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Execute state */
|
||||
wtp_dfa_execute((isrecvpacket ? &packet : NULL));
|
||||
|
||||
/* Free memory */
|
||||
capwap_free_parsed_packet(&packet);
|
||||
if (isrecvpacket) {
|
||||
wtp_free_packet_rxmng(socket.isctrlsocket);
|
||||
}
|
||||
}
|
||||
|
||||
/* Free memory */
|
||||
@ -463,9 +460,9 @@ int wtp_dfa_running(void) {
|
||||
|
||||
/* Change WTP state machine */
|
||||
void wtp_dfa_change_state(int state) {
|
||||
if (state != g_wtp.dfa.state) {
|
||||
capwap_logging_debug("WTP change state from %s to %s", capwap_dfa_getname(g_wtp.dfa.state), capwap_dfa_getname(state));
|
||||
g_wtp.dfa.state = state;
|
||||
if (state != g_wtp.state) {
|
||||
capwap_logging_debug("WTP change state from %s to %s", capwap_dfa_getname(g_wtp.state), capwap_dfa_getname(state));
|
||||
g_wtp.state = state;
|
||||
}
|
||||
}
|
||||
|
||||
@ -479,3 +476,22 @@ void wtp_free_reference_last_response(void) {
|
||||
capwap_list_flush(g_wtp.responsefragmentpacket);
|
||||
memset(&g_wtp.lastrecvpackethash[0], 0, sizeof(g_wtp.lastrecvpackethash));
|
||||
}
|
||||
|
||||
/* */
|
||||
void wtp_dfa_retransmition_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param) {
|
||||
g_wtp.retransmitcount++;
|
||||
if (g_wtp.retransmitcount >= WTP_MAX_RETRANSMIT) {
|
||||
/* Timeout state */
|
||||
wtp_free_reference_last_request();
|
||||
wtp_teardown_connection();
|
||||
} else {
|
||||
/* Retransmit request */
|
||||
capwap_logging_debug("Retransmition request packet");
|
||||
if (!capwap_crypt_sendto_fragmentpacket(&g_wtp.ctrldtls, g_wtp.acctrlsock.socket[g_wtp.acctrlsock.type], g_wtp.requestfragmentpacket, &g_wtp.wtpctrladdress, &g_wtp.acctrladdress)) {
|
||||
capwap_logging_error("Error to send request packet");
|
||||
}
|
||||
|
||||
/* Update timeout */
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, WTP_RETRANSMIT_INTERVAL, wtp_dfa_retransmition_timeout, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
@ -38,15 +38,31 @@ void wtp_send_configure(void);
|
||||
void wtp_send_datacheck(void);
|
||||
|
||||
/* */
|
||||
void wtp_dfa_state_idle(struct capwap_parsed_packet* packet);
|
||||
void wtp_dfa_retransmition_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param);
|
||||
|
||||
/* */
|
||||
void wtp_dfa_state_idle(void);
|
||||
|
||||
void wtp_dfa_state_discovery(struct capwap_parsed_packet* packet);
|
||||
void wtp_dfa_state_discovery_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param);
|
||||
|
||||
void wtp_dfa_state_dtlsteardown(struct capwap_parsed_packet* packet);
|
||||
|
||||
void wtp_dfa_state_sulking(struct capwap_parsed_packet* packet);
|
||||
void wtp_dfa_state_sulking_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param);
|
||||
|
||||
void wtp_dfa_state_join(struct capwap_parsed_packet* packet);
|
||||
|
||||
void wtp_dfa_state_configure(struct capwap_parsed_packet* packet);
|
||||
|
||||
void wtp_dfa_state_datacheck(struct capwap_parsed_packet* packet);
|
||||
|
||||
void wtp_dfa_state_run(struct capwap_parsed_packet* packet);
|
||||
void wtp_dfa_state_reset(struct capwap_parsed_packet* packet);
|
||||
void wtp_dfa_state_run_echo_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param);
|
||||
void wtp_dfa_state_run_keepalive_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param);
|
||||
void wtp_dfa_state_run_keepalivedead_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param);
|
||||
|
||||
void wtp_dfa_state_reset(void);
|
||||
|
||||
/* */
|
||||
void wtp_send_data_wireless_packet(uint8_t radioid, uint8_t wlanid, const struct ieee80211_header_mgmt* mgmt, int mgmtlength, int leavenativeframe);
|
||||
|
@ -87,9 +87,9 @@ void wtp_send_configure(void) {
|
||||
|
||||
/* Send Configuration Status request to AC */
|
||||
if (capwap_crypt_sendto_fragmentpacket(&g_wtp.ctrldtls, g_wtp.acctrlsock.socket[g_wtp.acctrlsock.type], g_wtp.requestfragmentpacket, &g_wtp.wtpctrladdress, &g_wtp.acctrladdress)) {
|
||||
g_wtp.dfa.rfcRetransmitCount = 0;
|
||||
capwap_timeout_set(g_wtp.dfa.rfcRetransmitInterval, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
g_wtp.retransmitcount = 0;
|
||||
wtp_dfa_change_state(CAPWAP_CONFIGURE_STATE);
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, WTP_RETRANSMIT_INTERVAL, wtp_dfa_retransmition_timeout, NULL, NULL);
|
||||
} else {
|
||||
/* Error to send packets */
|
||||
capwap_logging_debug("Warning: error to send configuration status request packet");
|
||||
@ -100,53 +100,34 @@ void wtp_send_configure(void) {
|
||||
|
||||
/* */
|
||||
void wtp_dfa_state_configure(struct capwap_parsed_packet* packet) {
|
||||
unsigned short binding;
|
||||
struct capwap_timers_element* timers;
|
||||
struct capwap_resultcode_element* resultcode;
|
||||
|
||||
if (packet) {
|
||||
unsigned short binding;
|
||||
/* */
|
||||
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
|
||||
if (packet->rxmngpacket->isctrlpacket && (binding == g_wtp.binding) && (packet->rxmngpacket->ctrlmsg.type == CAPWAP_CONFIGURATION_STATUS_RESPONSE) && ((g_wtp.localseqnumber - 1) == packet->rxmngpacket->ctrlmsg.seq)) {
|
||||
/* Valid packet, free request packet */
|
||||
wtp_free_reference_last_request();
|
||||
|
||||
/* */
|
||||
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
|
||||
if (packet->rxmngpacket->isctrlpacket && (binding == g_wtp.binding) && (packet->rxmngpacket->ctrlmsg.type == CAPWAP_CONFIGURATION_STATUS_RESPONSE) && ((g_wtp.localseqnumber - 1) == packet->rxmngpacket->ctrlmsg.seq)) {
|
||||
/* Valid packet, free request packet */
|
||||
wtp_free_reference_last_request();
|
||||
|
||||
/* Check the success of the Request */
|
||||
resultcode = (struct capwap_resultcode_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_RESULTCODE);
|
||||
if (resultcode && !CAPWAP_RESULTCODE_OK(resultcode->code)) {
|
||||
capwap_logging_warning("Receive Configure Status Response with error: %d", (int)resultcode->code);
|
||||
wtp_teardown_connection();
|
||||
} else {
|
||||
/* Timers */
|
||||
timers = (struct capwap_timers_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_TIMERS);
|
||||
g_wtp.dfa.rfcMaxDiscoveryInterval = timers->discovery;
|
||||
g_wtp.dfa.rfcEchoInterval = timers->echorequest;
|
||||
|
||||
/* Binding values */
|
||||
if (!wtp_radio_setconfiguration(packet)) {
|
||||
wtp_send_datacheck(); /* Send change state event packet */
|
||||
} else {
|
||||
capwap_logging_warning("Receive Configure Status Response with invalid elements");
|
||||
wtp_teardown_connection();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* No Configuration status response received */
|
||||
g_wtp.dfa.rfcRetransmitCount++;
|
||||
if (g_wtp.dfa.rfcRetransmitCount >= g_wtp.dfa.rfcMaxRetransmit) {
|
||||
/* Timeout join state */
|
||||
wtp_free_reference_last_request();
|
||||
/* Check the success of the Request */
|
||||
resultcode = (struct capwap_resultcode_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_RESULTCODE);
|
||||
if (resultcode && !CAPWAP_RESULTCODE_OK(resultcode->code)) {
|
||||
capwap_logging_warning("Receive Configure Status Response with error: %d", (int)resultcode->code);
|
||||
wtp_teardown_connection();
|
||||
} else {
|
||||
/* Retransmit configuration status request */
|
||||
if (!capwap_crypt_sendto_fragmentpacket(&g_wtp.ctrldtls, g_wtp.acctrlsock.socket[g_wtp.acctrlsock.type], g_wtp.requestfragmentpacket, &g_wtp.wtpctrladdress, &g_wtp.acctrladdress)) {
|
||||
capwap_logging_debug("Warning: error to send configuration status request packet");
|
||||
}
|
||||
/* Timers */
|
||||
timers = (struct capwap_timers_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_TIMERS);
|
||||
g_wtp.discoveryinterval = timers->discovery * 1000;
|
||||
g_wtp.echointerval = timers->echorequest * 1000;
|
||||
|
||||
/* Update timeout */
|
||||
capwap_timeout_set(g_wtp.dfa.rfcRetransmitInterval, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
/* Binding values */
|
||||
if (!wtp_radio_setconfiguration(packet)) {
|
||||
wtp_send_datacheck(); /* Send change state event packet */
|
||||
} else {
|
||||
capwap_logging_warning("Receive Configure Status Response with invalid elements");
|
||||
wtp_teardown_connection();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ void wtp_send_datacheck(void) {
|
||||
|
||||
/* Send Change State Event request to AC */
|
||||
if (capwap_crypt_sendto_fragmentpacket(&g_wtp.ctrldtls, g_wtp.acctrlsock.socket[g_wtp.acctrlsock.type], g_wtp.requestfragmentpacket, &g_wtp.wtpctrladdress, &g_wtp.acctrladdress)) {
|
||||
g_wtp.dfa.rfcRetransmitCount = 0;
|
||||
capwap_timeout_set(g_wtp.dfa.rfcRetransmitInterval, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
g_wtp.retransmitcount = 0;
|
||||
wtp_dfa_change_state(CAPWAP_DATA_CHECK_STATE);
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, WTP_RETRANSMIT_INTERVAL, wtp_dfa_retransmition_timeout, NULL, NULL);
|
||||
} else {
|
||||
/* Error to send packets */
|
||||
capwap_logging_debug("Warning: error to send change state event request packet");
|
||||
@ -49,37 +49,19 @@ void wtp_dfa_state_datacheck(struct capwap_parsed_packet* packet) {
|
||||
unsigned short binding;
|
||||
struct capwap_resultcode_element* resultcode;
|
||||
|
||||
if (packet) {
|
||||
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
|
||||
if (packet->rxmngpacket->isctrlpacket && (binding == g_wtp.binding) && (packet->rxmngpacket->ctrlmsg.type == CAPWAP_CHANGE_STATE_EVENT_RESPONSE) && ((g_wtp.localseqnumber - 1) == packet->rxmngpacket->ctrlmsg.seq)) {
|
||||
/* Valid packet, free request packet */
|
||||
wtp_free_reference_last_request();
|
||||
/* */
|
||||
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
|
||||
if (packet->rxmngpacket->isctrlpacket && (binding == g_wtp.binding) && (packet->rxmngpacket->ctrlmsg.type == CAPWAP_CHANGE_STATE_EVENT_RESPONSE) && ((g_wtp.localseqnumber - 1) == packet->rxmngpacket->ctrlmsg.seq)) {
|
||||
/* Valid packet, free request packet */
|
||||
wtp_free_reference_last_request();
|
||||
|
||||
/* Check the success of the Request */
|
||||
resultcode = (struct capwap_resultcode_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_RESULTCODE);
|
||||
if (resultcode && !CAPWAP_RESULTCODE_OK(resultcode->code)) {
|
||||
capwap_logging_warning("Receive Data Check Response with error: %d", (int)resultcode->code);
|
||||
wtp_teardown_connection();
|
||||
} else {
|
||||
/* TODO: gestione richiesta */
|
||||
wtp_start_datachannel();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* No change state response received */
|
||||
g_wtp.dfa.rfcRetransmitCount++;
|
||||
if (g_wtp.dfa.rfcRetransmitCount >= g_wtp.dfa.rfcMaxRetransmit) {
|
||||
/* Timeout join state */
|
||||
wtp_free_reference_last_request();
|
||||
/* Check the success of the Request */
|
||||
resultcode = (struct capwap_resultcode_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_RESULTCODE);
|
||||
if (resultcode && !CAPWAP_RESULTCODE_OK(resultcode->code)) {
|
||||
capwap_logging_warning("Receive Data Check Response with error: %d", (int)resultcode->code);
|
||||
wtp_teardown_connection();
|
||||
} else {
|
||||
/* Retransmit change state request */
|
||||
if (!capwap_crypt_sendto_fragmentpacket(&g_wtp.ctrldtls, g_wtp.acctrlsock.socket[g_wtp.acctrlsock.type], g_wtp.requestfragmentpacket, &g_wtp.wtpctrladdress, &g_wtp.acctrladdress)) {
|
||||
capwap_logging_debug("Warning: error to send change state request packet");
|
||||
}
|
||||
|
||||
/* Update timeout */
|
||||
capwap_timeout_set(g_wtp.dfa.rfcRetransmitInterval, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
wtp_start_datachannel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,237 +21,242 @@ void wtp_free_discovery_response_array(void) {
|
||||
}
|
||||
|
||||
/* */
|
||||
void wtp_dfa_state_discovery(struct capwap_parsed_packet* packet) {
|
||||
struct capwap_array* controlip;
|
||||
void wtp_dfa_state_discovery_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param) {
|
||||
long discoveryinterval;
|
||||
|
||||
if (packet) {
|
||||
unsigned short binding;
|
||||
if (g_wtp.acdiscoveryresponse->count > 0) {
|
||||
int i, j, w;
|
||||
int countwtp = -1;
|
||||
int indexpreferred = -1;
|
||||
|
||||
struct sockaddr_storage checkaddr;
|
||||
struct sockaddr_in* checkaddripv4;
|
||||
struct sockaddr_in6* checkaddripv6;
|
||||
|
||||
/* */
|
||||
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
|
||||
if (packet->rxmngpacket->isctrlpacket && (binding == g_wtp.binding) && (packet->rxmngpacket->ctrlmsg.type == CAPWAP_DISCOVERY_RESPONSE) && ((g_wtp.localseqnumber - 1) == packet->rxmngpacket->ctrlmsg.seq)) {
|
||||
struct capwap_resultcode_element* resultcode;
|
||||
g_wtp.acctrladdress.ss_family = AF_UNSPEC;
|
||||
|
||||
/* Check the success of the Request */
|
||||
resultcode = (struct capwap_resultcode_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_RESULTCODE);
|
||||
if (!resultcode || CAPWAP_RESULTCODE_OK(resultcode->code)) {
|
||||
int i;
|
||||
struct wtp_discovery_response* response = (struct wtp_discovery_response*)capwap_array_get_item_pointer(g_wtp.acdiscoveryresponse, g_wtp.acdiscoveryresponse->count);
|
||||
/* Selected by preferred or less WTP by AC */
|
||||
for (i = 0; i < g_wtp.acdiscoveryresponse->count; i++) {
|
||||
struct wtp_discovery_response* response = (struct wtp_discovery_response*)capwap_array_get_item_pointer(g_wtp.acdiscoveryresponse, i);
|
||||
|
||||
/* */
|
||||
response->controlipv4 = capwap_array_create(sizeof(struct capwap_controlipv4_element), 0, 0);
|
||||
response->controlipv6 = capwap_array_create(sizeof(struct capwap_controlipv6_element), 0, 0);
|
||||
/* AC with IPv4 */
|
||||
if ((g_wtp.net.sock_family == AF_UNSPEC) || (g_wtp.net.sock_family == AF_INET)) {
|
||||
for (w = 0; w < response->controlipv4->count; w++) {
|
||||
struct capwap_controlipv4_element* controlipv4 = (struct capwap_controlipv4_element*)capwap_array_get_item_pointer(response->controlipv4, w);
|
||||
|
||||
/* Create controlipv4 */
|
||||
controlip = (struct capwap_array*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_CONTROLIPV4);
|
||||
if (controlip) {
|
||||
for (i = 0; i < controlip->count; i++) {
|
||||
struct capwap_controlipv4_element* src = *(struct capwap_controlipv4_element**)capwap_array_get_item_pointer(controlip, i);
|
||||
struct capwap_controlipv4_element* dst = (struct capwap_controlipv4_element*)capwap_array_get_item_pointer(response->controlipv4, i);
|
||||
/* Create IPv4 address */
|
||||
memset(&checkaddr, 0, sizeof(struct sockaddr_storage));
|
||||
checkaddripv4 = (struct sockaddr_in*)&checkaddr;
|
||||
checkaddripv4->sin_family = AF_INET;
|
||||
checkaddripv4->sin_port = htons(CAPWAP_CONTROL_PORT);
|
||||
memcpy(&checkaddripv4->sin_addr, &controlipv4->address, sizeof(struct in_addr));
|
||||
|
||||
memcpy(dst, src, sizeof(struct capwap_controlipv4_element));
|
||||
/* Check for preferred AC */
|
||||
for (j = 0; j < ((indexpreferred != -1) ? indexpreferred : g_wtp.acpreferedarray->count); j++) {
|
||||
struct sockaddr_storage* acpreferredaddr = (struct sockaddr_storage*)capwap_array_get_item_pointer(g_wtp.acpreferedarray, j);
|
||||
|
||||
if (!capwap_compare_ip(acpreferredaddr, &checkaddr)) {
|
||||
indexpreferred = j;
|
||||
memcpy(&g_wtp.acctrladdress, &checkaddr, sizeof(struct sockaddr_storage));
|
||||
capwap_get_network_socket(&g_wtp.net, &g_wtp.acctrlsock, capwap_get_socket(&g_wtp.net, g_wtp.acctrladdress.ss_family, IPPROTO_UDP, 1));
|
||||
capwap_get_network_socket(&g_wtp.net, &g_wtp.acdatasock, capwap_get_socket(&g_wtp.net, g_wtp.acctrladdress.ss_family, (g_wtp.transport.type == CAPWAP_UDP_TRANSPORT ? IPPROTO_UDP : IPPROTO_UDPLITE), CAPWAP_DATA_SOCKET));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check by number of WTP */
|
||||
if (indexpreferred == -1) {
|
||||
if ((countwtp == -1) || (countwtp > controlipv4->wtpcount)) {
|
||||
countwtp = controlipv4->wtpcount;
|
||||
memcpy(&g_wtp.acctrladdress, &checkaddr, sizeof(struct sockaddr_storage));
|
||||
capwap_get_network_socket(&g_wtp.net, &g_wtp.acctrlsock, capwap_get_socket(&g_wtp.net, g_wtp.acctrladdress.ss_family, IPPROTO_UDP, 1));
|
||||
capwap_get_network_socket(&g_wtp.net, &g_wtp.acdatasock, capwap_get_socket(&g_wtp.net, g_wtp.acctrladdress.ss_family, (g_wtp.transport.type == CAPWAP_UDP_TRANSPORT ? IPPROTO_UDP : IPPROTO_UDPLITE), CAPWAP_DATA_SOCKET));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Create controlipv6 */
|
||||
controlip = (struct capwap_array*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_CONTROLIPV6);
|
||||
if (controlip) {
|
||||
for (i = 0; i < (controlip)->count; i++) {
|
||||
struct capwap_controlipv6_element* src = *(struct capwap_controlipv6_element**)capwap_array_get_item_pointer((controlip), i);
|
||||
struct capwap_controlipv6_element* dst = (struct capwap_controlipv6_element*)capwap_array_get_item_pointer(response->controlipv6, i);
|
||||
/* AC with IPv6 */
|
||||
if ((g_wtp.net.sock_family == AF_UNSPEC) || (g_wtp.net.sock_family == AF_INET6)) {
|
||||
for (w = 0; w < response->controlipv6->count; w++) {
|
||||
struct capwap_controlipv6_element* controlipv6 = (struct capwap_controlipv6_element*)capwap_array_get_item_pointer(response->controlipv6, w);
|
||||
|
||||
memcpy(dst, src, sizeof(struct capwap_controlipv6_element));
|
||||
/* Create IPv6 address */
|
||||
memset(&checkaddr, 0, sizeof(struct sockaddr_storage));
|
||||
checkaddripv6 = (struct sockaddr_in6*)&checkaddr;
|
||||
checkaddripv6->sin6_family = AF_INET6;
|
||||
checkaddripv6->sin6_port = htons(CAPWAP_CONTROL_PORT);
|
||||
memcpy(&checkaddripv6->sin6_addr, &controlipv6->address, sizeof(struct in6_addr));
|
||||
|
||||
/* Check for preferred AC */
|
||||
for (j = 0; j < ((indexpreferred != -1) ? indexpreferred : g_wtp.acpreferedarray->count); j++) {
|
||||
struct sockaddr_storage* acpreferredaddr = (struct sockaddr_storage*)capwap_array_get_item_pointer(g_wtp.acpreferedarray, j);
|
||||
|
||||
if (!capwap_compare_ip(acpreferredaddr, &checkaddr)) {
|
||||
indexpreferred = j;
|
||||
memcpy(&g_wtp.acctrladdress, &checkaddr, sizeof(struct sockaddr_storage));
|
||||
capwap_get_network_socket(&g_wtp.net, &g_wtp.acctrlsock, capwap_get_socket(&g_wtp.net, g_wtp.acctrladdress.ss_family, IPPROTO_UDP, 1));
|
||||
capwap_get_network_socket(&g_wtp.net, &g_wtp.acdatasock, capwap_get_socket(&g_wtp.net, g_wtp.acctrladdress.ss_family, (g_wtp.transport.type == CAPWAP_UDP_TRANSPORT ? IPPROTO_UDP : IPPROTO_UDPLITE), CAPWAP_DATA_SOCKET));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check by number of WTP */
|
||||
if (indexpreferred == -1) {
|
||||
if ((countwtp == -1) || (countwtp > controlipv6->wtpcount)) {
|
||||
countwtp = controlipv6->wtpcount;
|
||||
memcpy(&g_wtp.acctrladdress, &checkaddr, sizeof(struct sockaddr_storage));
|
||||
capwap_get_network_socket(&g_wtp.net, &g_wtp.acctrlsock, capwap_get_socket(&g_wtp.net, g_wtp.acctrladdress.ss_family, IPPROTO_UDP, 1));
|
||||
capwap_get_network_socket(&g_wtp.net, &g_wtp.acdatasock, capwap_get_socket(&g_wtp.net, g_wtp.acctrladdress.ss_family, (g_wtp.transport.type == CAPWAP_UDP_TRANSPORT ? IPPROTO_UDP : IPPROTO_UDPLITE), CAPWAP_DATA_SOCKET));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (g_wtp.acdiscoveryresponse->count > 0) {
|
||||
int i, j, w;
|
||||
int countwtp = -1;
|
||||
int indexpreferred = -1;
|
||||
|
||||
struct sockaddr_storage checkaddr;
|
||||
struct sockaddr_in* checkaddripv4;
|
||||
struct sockaddr_in6* checkaddripv6;
|
||||
/* Free memory */
|
||||
wtp_free_discovery_response_array();
|
||||
|
||||
/* Change state if found AC */
|
||||
if (g_wtp.acctrladdress.ss_family != AF_UNSPEC) {
|
||||
memcpy(&g_wtp.acdataaddress, &g_wtp.acctrladdress, sizeof(struct sockaddr_storage));
|
||||
CAPWAP_SET_NETWORK_PORT(&g_wtp.acdataaddress, CAPWAP_GET_NETWORK_PORT(&g_wtp.acdataaddress) + 1);
|
||||
|
||||
/* Retrieve local address */
|
||||
if (capwap_get_localaddress_by_remoteaddress(&g_wtp.wtpctrladdress, &g_wtp.acctrladdress, g_wtp.net.bind_interface, (!(g_wtp.net.bind_ctrl_flags & CAPWAP_IPV6ONLY_FLAG) ? 1 : 0))) {
|
||||
struct sockaddr_storage sockinfo;
|
||||
socklen_t sockinfolen = sizeof(struct sockaddr_storage);
|
||||
|
||||
memset(&sockinfo, 0, sizeof(struct sockaddr_storage));
|
||||
if (!getsockname(g_wtp.acctrlsock.socket[g_wtp.acctrlsock.type], (struct sockaddr*)&sockinfo, &sockinfolen)) {
|
||||
CAPWAP_SET_NETWORK_PORT(&g_wtp.wtpctrladdress, CAPWAP_GET_NETWORK_PORT(&sockinfo));
|
||||
|
||||
/* */
|
||||
memcpy(&g_wtp.wtpdataaddress, &g_wtp.wtpctrladdress, sizeof(struct sockaddr_storage));
|
||||
CAPWAP_SET_NETWORK_PORT(&g_wtp.wtpdataaddress, CAPWAP_GET_NETWORK_PORT(&g_wtp.wtpdataaddress) + 1);
|
||||
|
||||
/* */
|
||||
if (!g_wtp.enabledtls) {
|
||||
wtp_send_join(); /* Bypass DTLS connection */
|
||||
} else {
|
||||
wtp_start_dtlssetup(); /* Create DTLS connection */
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* No Discovery response received */
|
||||
g_wtp.discoverycount++;
|
||||
if (g_wtp.discoverycount >= WTP_MAX_DISCOVERY_COUNT) {
|
||||
/* Timeout discovery state */
|
||||
wtp_dfa_change_state(CAPWAP_SULKING_STATE);
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, WTP_SILENT_INTERVAL, wtp_dfa_state_sulking_timeout, NULL, NULL);
|
||||
} else {
|
||||
int i;
|
||||
struct capwap_header_data capwapheader;
|
||||
struct capwap_packet_txmng* txmngpacket;
|
||||
|
||||
/* Update status radio */
|
||||
g_wtp.descriptor.radiosinuse = wtp_update_radio_in_use();
|
||||
|
||||
/* Build packet */
|
||||
capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, g_wtp.binding);
|
||||
txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, CAPWAP_DISCOVERY_REQUEST, g_wtp.localseqnumber++, g_wtp.mtu);
|
||||
|
||||
/* Add message element */
|
||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_DISCOVERYTYPE, &g_wtp.discoverytype);
|
||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_WTPBOARDDATA, &g_wtp.boarddata);
|
||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_WTPDESCRIPTOR, &g_wtp.descriptor);
|
||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_WTPFRAMETUNNELMODE, &g_wtp.mactunnel);
|
||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_WTPMACTYPE, &g_wtp.mactype);
|
||||
|
||||
if (g_wtp.binding == CAPWAP_WIRELESS_BINDING_IEEE80211) {
|
||||
wtp_create_80211_wtpradioinformation_element(txmngpacket);
|
||||
}
|
||||
|
||||
/* CAPWAP_ELEMENT_MTUDISCOVERY */ /* TODO */
|
||||
/* CAPWAP_ELEMENT_VENDORPAYLOAD */ /* TODO */
|
||||
|
||||
/* Discovery request complete, get fragment packets */
|
||||
wtp_free_reference_last_request();
|
||||
capwap_packet_txmng_get_fragment_packets(txmngpacket, g_wtp.requestfragmentpacket, g_wtp.fragmentid);
|
||||
if (g_wtp.requestfragmentpacket->count > 1) {
|
||||
g_wtp.fragmentid++;
|
||||
}
|
||||
|
||||
/* Free packets manager */
|
||||
capwap_packet_txmng_free(txmngpacket);
|
||||
|
||||
/* Send discovery request to AC */
|
||||
for (i = 0; i < g_wtp.acdiscoveryarray->count; i++) {
|
||||
int sock;
|
||||
struct sockaddr_storage* sendtoaddr = (struct sockaddr_storage*)capwap_array_get_item_pointer(g_wtp.acdiscoveryarray, i);
|
||||
|
||||
sock = capwap_get_socket(&g_wtp.net, sendtoaddr->ss_family, IPPROTO_UDP, 1);
|
||||
if (sock >= 0) {
|
||||
if (!capwap_sendto_fragmentpacket(sock, g_wtp.requestfragmentpacket, NULL, sendtoaddr)) {
|
||||
capwap_logging_debug("Warning: error to send discovery request packet");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Don't buffering a packets sent */
|
||||
wtp_free_reference_last_request();
|
||||
|
||||
/* Wait before send another Discovery Request */
|
||||
discoveryinterval = (capwap_get_rand(g_wtp.discoveryinterval - WTP_MIN_DISCOVERY_INTERVAL) + WTP_MIN_DISCOVERY_INTERVAL);
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, discoveryinterval, wtp_dfa_state_discovery_timeout, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
void wtp_dfa_state_discovery(struct capwap_parsed_packet* packet) {
|
||||
unsigned short binding;
|
||||
struct capwap_array* controlip;
|
||||
|
||||
ASSERT(packet != NULL);
|
||||
|
||||
/* */
|
||||
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
|
||||
if (packet->rxmngpacket->isctrlpacket && (binding == g_wtp.binding) && (packet->rxmngpacket->ctrlmsg.type == CAPWAP_DISCOVERY_RESPONSE) && ((g_wtp.localseqnumber - 1) == packet->rxmngpacket->ctrlmsg.seq)) {
|
||||
struct capwap_resultcode_element* resultcode;
|
||||
|
||||
/* Check the success of the Request */
|
||||
resultcode = (struct capwap_resultcode_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_RESULTCODE);
|
||||
if (!resultcode || CAPWAP_RESULTCODE_OK(resultcode->code)) {
|
||||
int i;
|
||||
struct wtp_discovery_response* response = (struct wtp_discovery_response*)capwap_array_get_item_pointer(g_wtp.acdiscoveryresponse, g_wtp.acdiscoveryresponse->count);
|
||||
|
||||
/* */
|
||||
g_wtp.acctrladdress.ss_family = AF_UNSPEC;
|
||||
response->controlipv4 = capwap_array_create(sizeof(struct capwap_controlipv4_element), 0, 0);
|
||||
response->controlipv6 = capwap_array_create(sizeof(struct capwap_controlipv6_element), 0, 0);
|
||||
|
||||
/* Selected by preferred or less WTP by AC */
|
||||
for (i = 0; i < g_wtp.acdiscoveryresponse->count; i++) {
|
||||
struct wtp_discovery_response* response = (struct wtp_discovery_response*)capwap_array_get_item_pointer(g_wtp.acdiscoveryresponse, i);
|
||||
/* Create controlipv4 */
|
||||
controlip = (struct capwap_array*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_CONTROLIPV4);
|
||||
if (controlip) {
|
||||
for (i = 0; i < controlip->count; i++) {
|
||||
struct capwap_controlipv4_element* src = *(struct capwap_controlipv4_element**)capwap_array_get_item_pointer(controlip, i);
|
||||
struct capwap_controlipv4_element* dst = (struct capwap_controlipv4_element*)capwap_array_get_item_pointer(response->controlipv4, i);
|
||||
|
||||
/* AC with IPv4 */
|
||||
if ((g_wtp.net.sock_family == AF_UNSPEC) || (g_wtp.net.sock_family == AF_INET)) {
|
||||
for (w = 0; w < response->controlipv4->count; w++) {
|
||||
struct capwap_controlipv4_element* controlipv4 = (struct capwap_controlipv4_element*)capwap_array_get_item_pointer(response->controlipv4, w);
|
||||
|
||||
/* Create IPv4 address */
|
||||
memset(&checkaddr, 0, sizeof(struct sockaddr_storage));
|
||||
checkaddripv4 = (struct sockaddr_in*)&checkaddr;
|
||||
checkaddripv4->sin_family = AF_INET;
|
||||
checkaddripv4->sin_port = htons(CAPWAP_CONTROL_PORT);
|
||||
memcpy(&checkaddripv4->sin_addr, &controlipv4->address, sizeof(struct in_addr));
|
||||
|
||||
/* Check for preferred AC */
|
||||
for (j = 0; j < ((indexpreferred != -1) ? indexpreferred : g_wtp.acpreferedarray->count); j++) {
|
||||
struct sockaddr_storage* acpreferredaddr = (struct sockaddr_storage*)capwap_array_get_item_pointer(g_wtp.acpreferedarray, j);
|
||||
|
||||
if (!capwap_compare_ip(acpreferredaddr, &checkaddr)) {
|
||||
indexpreferred = j;
|
||||
memcpy(&g_wtp.acctrladdress, &checkaddr, sizeof(struct sockaddr_storage));
|
||||
capwap_get_network_socket(&g_wtp.net, &g_wtp.acctrlsock, capwap_get_socket(&g_wtp.net, g_wtp.acctrladdress.ss_family, IPPROTO_UDP, 1));
|
||||
capwap_get_network_socket(&g_wtp.net, &g_wtp.acdatasock, capwap_get_socket(&g_wtp.net, g_wtp.acctrladdress.ss_family, (g_wtp.transport.type == CAPWAP_UDP_TRANSPORT ? IPPROTO_UDP : IPPROTO_UDPLITE), CAPWAP_DATA_SOCKET));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check by number of WTP */
|
||||
if (indexpreferred == -1) {
|
||||
if ((countwtp == -1) || (countwtp > controlipv4->wtpcount)) {
|
||||
countwtp = controlipv4->wtpcount;
|
||||
memcpy(&g_wtp.acctrladdress, &checkaddr, sizeof(struct sockaddr_storage));
|
||||
capwap_get_network_socket(&g_wtp.net, &g_wtp.acctrlsock, capwap_get_socket(&g_wtp.net, g_wtp.acctrladdress.ss_family, IPPROTO_UDP, 1));
|
||||
capwap_get_network_socket(&g_wtp.net, &g_wtp.acdatasock, capwap_get_socket(&g_wtp.net, g_wtp.acctrladdress.ss_family, (g_wtp.transport.type == CAPWAP_UDP_TRANSPORT ? IPPROTO_UDP : IPPROTO_UDPLITE), CAPWAP_DATA_SOCKET));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* AC with IPv6 */
|
||||
if ((g_wtp.net.sock_family == AF_UNSPEC) || (g_wtp.net.sock_family == AF_INET6)) {
|
||||
for (w = 0; w < response->controlipv6->count; w++) {
|
||||
struct capwap_controlipv6_element* controlipv6 = (struct capwap_controlipv6_element*)capwap_array_get_item_pointer(response->controlipv6, w);
|
||||
|
||||
/* Create IPv6 address */
|
||||
memset(&checkaddr, 0, sizeof(struct sockaddr_storage));
|
||||
checkaddripv6 = (struct sockaddr_in6*)&checkaddr;
|
||||
checkaddripv6->sin6_family = AF_INET6;
|
||||
checkaddripv6->sin6_port = htons(CAPWAP_CONTROL_PORT);
|
||||
memcpy(&checkaddripv6->sin6_addr, &controlipv6->address, sizeof(struct in6_addr));
|
||||
|
||||
/* Check for preferred AC */
|
||||
for (j = 0; j < ((indexpreferred != -1) ? indexpreferred : g_wtp.acpreferedarray->count); j++) {
|
||||
struct sockaddr_storage* acpreferredaddr = (struct sockaddr_storage*)capwap_array_get_item_pointer(g_wtp.acpreferedarray, j);
|
||||
|
||||
if (!capwap_compare_ip(acpreferredaddr, &checkaddr)) {
|
||||
indexpreferred = j;
|
||||
memcpy(&g_wtp.acctrladdress, &checkaddr, sizeof(struct sockaddr_storage));
|
||||
capwap_get_network_socket(&g_wtp.net, &g_wtp.acctrlsock, capwap_get_socket(&g_wtp.net, g_wtp.acctrladdress.ss_family, IPPROTO_UDP, 1));
|
||||
capwap_get_network_socket(&g_wtp.net, &g_wtp.acdatasock, capwap_get_socket(&g_wtp.net, g_wtp.acctrladdress.ss_family, (g_wtp.transport.type == CAPWAP_UDP_TRANSPORT ? IPPROTO_UDP : IPPROTO_UDPLITE), CAPWAP_DATA_SOCKET));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check by number of WTP */
|
||||
if (indexpreferred == -1) {
|
||||
if ((countwtp == -1) || (countwtp > controlipv6->wtpcount)) {
|
||||
countwtp = controlipv6->wtpcount;
|
||||
memcpy(&g_wtp.acctrladdress, &checkaddr, sizeof(struct sockaddr_storage));
|
||||
capwap_get_network_socket(&g_wtp.net, &g_wtp.acctrlsock, capwap_get_socket(&g_wtp.net, g_wtp.acctrladdress.ss_family, IPPROTO_UDP, 1));
|
||||
capwap_get_network_socket(&g_wtp.net, &g_wtp.acdatasock, capwap_get_socket(&g_wtp.net, g_wtp.acctrladdress.ss_family, (g_wtp.transport.type == CAPWAP_UDP_TRANSPORT ? IPPROTO_UDP : IPPROTO_UDPLITE), CAPWAP_DATA_SOCKET));
|
||||
}
|
||||
}
|
||||
}
|
||||
memcpy(dst, src, sizeof(struct capwap_controlipv4_element));
|
||||
}
|
||||
}
|
||||
|
||||
/* Free memory */
|
||||
wtp_free_discovery_response_array();
|
||||
/* Create controlipv6 */
|
||||
controlip = (struct capwap_array*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_CONTROLIPV6);
|
||||
if (controlip) {
|
||||
for (i = 0; i < (controlip)->count; i++) {
|
||||
struct capwap_controlipv6_element* src = *(struct capwap_controlipv6_element**)capwap_array_get_item_pointer((controlip), i);
|
||||
struct capwap_controlipv6_element* dst = (struct capwap_controlipv6_element*)capwap_array_get_item_pointer(response->controlipv6, i);
|
||||
|
||||
/* Change state if found AC */
|
||||
if (g_wtp.acctrladdress.ss_family != AF_UNSPEC) {
|
||||
memcpy(&g_wtp.acdataaddress, &g_wtp.acctrladdress, sizeof(struct sockaddr_storage));
|
||||
CAPWAP_SET_NETWORK_PORT(&g_wtp.acdataaddress, CAPWAP_GET_NETWORK_PORT(&g_wtp.acdataaddress) + 1);
|
||||
|
||||
/* Retrieve local address */
|
||||
if (capwap_get_localaddress_by_remoteaddress(&g_wtp.wtpctrladdress, &g_wtp.acctrladdress, g_wtp.net.bind_interface, (!(g_wtp.net.bind_ctrl_flags & CAPWAP_IPV6ONLY_FLAG) ? 1 : 0))) {
|
||||
struct sockaddr_storage sockinfo;
|
||||
socklen_t sockinfolen = sizeof(struct sockaddr_storage);
|
||||
|
||||
memset(&sockinfo, 0, sizeof(struct sockaddr_storage));
|
||||
if (!getsockname(g_wtp.acctrlsock.socket[g_wtp.acctrlsock.type], (struct sockaddr*)&sockinfo, &sockinfolen)) {
|
||||
CAPWAP_SET_NETWORK_PORT(&g_wtp.wtpctrladdress, CAPWAP_GET_NETWORK_PORT(&sockinfo));
|
||||
|
||||
/* */
|
||||
memcpy(&g_wtp.wtpdataaddress, &g_wtp.wtpctrladdress, sizeof(struct sockaddr_storage));
|
||||
CAPWAP_SET_NETWORK_PORT(&g_wtp.wtpdataaddress, CAPWAP_GET_NETWORK_PORT(&g_wtp.wtpdataaddress) + 1);
|
||||
|
||||
/* */
|
||||
if (!g_wtp.enabledtls) {
|
||||
wtp_send_join(); /* Bypass DTLS connection */
|
||||
} else {
|
||||
wtp_start_dtlssetup(); /* Create DTLS connection */
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
memcpy(dst, src, sizeof(struct capwap_controlipv6_element));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* No Discovery response received */
|
||||
g_wtp.dfa.rfcDiscoveryCount++;
|
||||
if (g_wtp.dfa.rfcDiscoveryCount >= g_wtp.dfa.rfcMaxDiscoveries) {
|
||||
/* Timeout discovery state */
|
||||
capwap_timeout_set(g_wtp.dfa.rfcSilentInterval, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
wtp_dfa_change_state(CAPWAP_SULKING_STATE);
|
||||
} else {
|
||||
int i;
|
||||
struct capwap_header_data capwapheader;
|
||||
struct capwap_packet_txmng* txmngpacket;
|
||||
|
||||
/* Update status radio */
|
||||
g_wtp.descriptor.radiosinuse = wtp_update_radio_in_use();
|
||||
|
||||
/* Build packet */
|
||||
capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, g_wtp.binding);
|
||||
txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, CAPWAP_DISCOVERY_REQUEST, g_wtp.localseqnumber++, g_wtp.mtu);
|
||||
|
||||
/* Add message element */
|
||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_DISCOVERYTYPE, &g_wtp.discoverytype);
|
||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_WTPBOARDDATA, &g_wtp.boarddata);
|
||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_WTPDESCRIPTOR, &g_wtp.descriptor);
|
||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_WTPFRAMETUNNELMODE, &g_wtp.mactunnel);
|
||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_WTPMACTYPE, &g_wtp.mactype);
|
||||
|
||||
if (g_wtp.binding == CAPWAP_WIRELESS_BINDING_IEEE80211) {
|
||||
wtp_create_80211_wtpradioinformation_element(txmngpacket);
|
||||
}
|
||||
|
||||
/* CAPWAP_ELEMENT_MTUDISCOVERY */ /* TODO */
|
||||
/* CAPWAP_ELEMENT_VENDORPAYLOAD */ /* TODO */
|
||||
|
||||
/* Discovery request complete, get fragment packets */
|
||||
wtp_free_reference_last_request();
|
||||
capwap_packet_txmng_get_fragment_packets(txmngpacket, g_wtp.requestfragmentpacket, g_wtp.fragmentid);
|
||||
if (g_wtp.requestfragmentpacket->count > 1) {
|
||||
g_wtp.fragmentid++;
|
||||
}
|
||||
|
||||
/* Free packets manager */
|
||||
capwap_packet_txmng_free(txmngpacket);
|
||||
|
||||
/* Send discovery request to AC */
|
||||
for (i = 0; i < g_wtp.acdiscoveryarray->count; i++) {
|
||||
int sock;
|
||||
struct sockaddr_storage* sendtoaddr = (struct sockaddr_storage*)capwap_array_get_item_pointer(g_wtp.acdiscoveryarray, i);
|
||||
|
||||
sock = capwap_get_socket(&g_wtp.net, sendtoaddr->ss_family, IPPROTO_UDP, 1);
|
||||
if (sock >= 0) {
|
||||
if (!capwap_sendto_fragmentpacket(sock, g_wtp.requestfragmentpacket, NULL, sendtoaddr)) {
|
||||
capwap_logging_debug("Warning: error to send discovery request packet");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Don't buffering a packets sent */
|
||||
wtp_free_reference_last_request();
|
||||
|
||||
/* Wait before send another Discovery Request */
|
||||
capwap_timeout_set(g_wtp.dfa.rfcDiscoveryInterval, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,11 @@
|
||||
#include "capwap_dfa.h"
|
||||
#include "wtp_dfa.h"
|
||||
|
||||
/* */
|
||||
static void wtp_dfa_state_dtlsconnect_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param) {
|
||||
wtp_teardown_connection();
|
||||
}
|
||||
|
||||
/* DTLS BIO send */
|
||||
int wtp_bio_send(struct capwap_dtls* dtls, char* buffer, int length, void* param) {
|
||||
struct capwap_socket* socket = ((dtls->session == CAPWAP_DTLS_CONTROL_SESSION) ? &g_wtp.acctrlsock : &g_wtp.acdatasock);
|
||||
@ -15,15 +20,15 @@ int wtp_bio_send(struct capwap_dtls* dtls, char* buffer, int length, void* param
|
||||
void wtp_start_dtlssetup(void) {
|
||||
/* Create DTLS session */
|
||||
if (!capwap_crypt_createsession(&g_wtp.ctrldtls, CAPWAP_DTLS_CONTROL_SESSION, &g_wtp.dtlscontext, wtp_bio_send, NULL)) {
|
||||
capwap_timeout_set(g_wtp.dfa.rfcSilentInterval, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
wtp_dfa_change_state(CAPWAP_SULKING_STATE);
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, WTP_SILENT_INTERVAL, wtp_dfa_state_sulking_timeout, NULL, NULL);
|
||||
} else {
|
||||
if (capwap_crypt_open(&g_wtp.ctrldtls, &g_wtp.acctrladdress) == CAPWAP_HANDSHAKE_ERROR) {
|
||||
capwap_timeout_set(g_wtp.dfa.rfcSilentInterval, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
wtp_dfa_change_state(CAPWAP_SULKING_STATE);
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, WTP_SILENT_INTERVAL, wtp_dfa_state_sulking_timeout, NULL, NULL);
|
||||
} else {
|
||||
capwap_timeout_set(g_wtp.dfa.rfcWaitDTLS, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
wtp_dfa_change_state(CAPWAP_DTLS_CONNECT_STATE);
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, WTP_DTLS_INTERVAL, wtp_dfa_state_dtlsconnect_timeout, NULL, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -40,7 +45,7 @@ void wtp_start_datachannel(void) {
|
||||
/* Create DTLS data session before send data keepalive */
|
||||
if (capwap_crypt_createsession(&g_wtp.datadtls, CAPWAP_DTLS_DATA_SESSION, &g_wtp.dtlscontext, wtp_bio_send, NULL)) {
|
||||
if (capwap_crypt_open(&g_wtp.datadtls, &g_wtp.acdataaddress) == CAPWAP_HANDSHAKE_CONTINUE) {
|
||||
capwap_timeout_set(g_wtp.dfa.rfcWaitDTLS, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION); /* Wait complete dtls handshake */
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, WTP_DTLS_INTERVAL, wtp_dfa_state_dtlsconnect_timeout, NULL, NULL); /* Wait complete dtls handshake */
|
||||
} else {
|
||||
wtp_teardown_connection();
|
||||
}
|
||||
@ -73,10 +78,10 @@ void wtp_start_datachannel(void) {
|
||||
g_wtp.acpreferedselected = 0;
|
||||
|
||||
/* Set timer */
|
||||
capwap_timeout_kill(g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
capwap_timeout_set(g_wtp.dfa.rfcEchoInterval, g_wtp.timeout, CAPWAP_TIMER_CONTROL_ECHO);
|
||||
capwap_timeout_set(g_wtp.dfa.rfcDataChannelDeadInterval, g_wtp.timeout, CAPWAP_TIMER_DATA_KEEPALIVEDEAD);
|
||||
wtp_dfa_change_state(CAPWAP_RUN_STATE);
|
||||
capwap_timeout_unset(g_wtp.timeout, g_wtp.idtimercontrol);
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimerecho, g_wtp.echointerval, wtp_dfa_state_run_echo_timeout, NULL, NULL);
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimerkeepalivedead, WTP_DATACHANNEL_KEEPALIVEDEAD, wtp_dfa_state_run_keepalivedead_timeout, NULL, NULL);
|
||||
} else {
|
||||
/* Error to send packets */
|
||||
capwap_logging_debug("Warning: error to send data channel keepalive packet");
|
||||
@ -92,32 +97,8 @@ void wtp_start_datachannel(void) {
|
||||
capwap_packet_txmng_free(txmngpacket);
|
||||
}
|
||||
|
||||
/* Teardown connection */
|
||||
void wtp_teardown_connection(void) {
|
||||
g_wtp.teardown = 1;
|
||||
|
||||
/* DTSL Control */
|
||||
if (g_wtp.ctrldtls.enable) {
|
||||
capwap_crypt_close(&g_wtp.ctrldtls);
|
||||
}
|
||||
|
||||
/* DTLS Data */
|
||||
if (g_wtp.datadtls.enable) {
|
||||
capwap_crypt_close(&g_wtp.datadtls);
|
||||
}
|
||||
|
||||
/* */
|
||||
capwap_timeout_killall(g_wtp.timeout);
|
||||
capwap_timeout_set(g_wtp.dfa.rfcDTLSSessionDelete, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
wtp_dfa_change_state(CAPWAP_DTLS_TEARDOWN_STATE);
|
||||
}
|
||||
|
||||
/* */
|
||||
void wtp_dfa_state_dtlsteardown(struct capwap_parsed_packet* packet) {
|
||||
if (packet) {
|
||||
return;
|
||||
}
|
||||
|
||||
static void wtp_dfa_state_dtlsteardown_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param) {
|
||||
/* Free and reset resource */
|
||||
if (g_wtp.ctrldtls.enable) {
|
||||
capwap_crypt_freesession(&g_wtp.ctrldtls);
|
||||
@ -142,11 +123,35 @@ void wtp_dfa_state_dtlsteardown(struct capwap_parsed_packet* packet) {
|
||||
/* */
|
||||
if (!g_wtp.running) {
|
||||
wtp_dfa_change_state(CAPWAP_DEAD_STATE);
|
||||
} else if ((g_wtp.dfa.rfcFailedDTLSSessionCount >= g_wtp.dfa.rfcMaxFailedDTLSSessionRetry) || (g_wtp.dfa.rfcFailedDTLSAuthFailCount >= g_wtp.dfa.rfcMaxFailedDTLSSessionRetry)) {
|
||||
capwap_timeout_set(g_wtp.dfa.rfcSilentInterval, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
} else if ((g_wtp.faileddtlssessioncount >= WTP_FAILED_DTLS_SESSION_RETRY) || (g_wtp.faileddtlsauthfailcount >= WTP_FAILED_DTLS_SESSION_RETRY)) {
|
||||
wtp_dfa_change_state(CAPWAP_SULKING_STATE);
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, WTP_SILENT_INTERVAL, wtp_dfa_state_sulking_timeout, NULL, NULL);
|
||||
} else {
|
||||
capwap_timeout_set(0, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
wtp_dfa_change_state(CAPWAP_IDLE_STATE);
|
||||
wtp_dfa_state_idle();
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
void wtp_dfa_state_dtlsteardown(struct capwap_parsed_packet* packet) {
|
||||
}
|
||||
|
||||
/* Teardown connection */
|
||||
void wtp_teardown_connection(void) {
|
||||
g_wtp.teardown = 1;
|
||||
|
||||
/* DTSL Control */
|
||||
if (g_wtp.ctrldtls.enable) {
|
||||
capwap_crypt_close(&g_wtp.ctrldtls);
|
||||
}
|
||||
|
||||
/* DTLS Data */
|
||||
if (g_wtp.datadtls.enable) {
|
||||
capwap_crypt_close(&g_wtp.datadtls);
|
||||
}
|
||||
|
||||
/* */
|
||||
wtp_dfa_change_state(CAPWAP_DTLS_TEARDOWN_STATE);
|
||||
capwap_timeout_unsetall(g_wtp.timeout);
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, WTP_DTLS_SESSION_DELETE, wtp_dfa_state_dtlsteardown_timeout, NULL, NULL);
|
||||
}
|
||||
|
@ -3,15 +3,12 @@
|
||||
#include "wtp_dfa.h"
|
||||
|
||||
/* */
|
||||
void wtp_dfa_state_idle(struct capwap_parsed_packet* packet) {
|
||||
/* Ignore packets */
|
||||
if (packet) {
|
||||
return;
|
||||
}
|
||||
void wtp_dfa_state_idle(void) {
|
||||
long discoveryinterval;
|
||||
|
||||
/* Remove teardown */
|
||||
g_wtp.teardown = 0;
|
||||
capwap_timeout_killall(g_wtp.timeout);
|
||||
capwap_timeout_unsetall(g_wtp.timeout);
|
||||
|
||||
/* */
|
||||
if (!g_wtp.acdiscoveryrequest && (g_wtp.acpreferedarray->count > 0)) {
|
||||
@ -58,12 +55,12 @@ void wtp_dfa_state_idle(struct capwap_parsed_packet* packet) {
|
||||
g_wtp.acpreferedselected = 0;
|
||||
|
||||
/* Set discovery interval */
|
||||
g_wtp.dfa.rfcDiscoveryInterval = capwap_get_rand(g_wtp.dfa.rfcMaxDiscoveryInterval - WTP_MIN_DISCOVERY_INTERVAL) + WTP_MIN_DISCOVERY_INTERVAL;
|
||||
g_wtp.dfa.rfcDiscoveryCount = 0;
|
||||
g_wtp.discoverycount = 0;
|
||||
discoveryinterval = capwap_get_rand(g_wtp.discoveryinterval - WTP_MIN_DISCOVERY_INTERVAL) + WTP_MIN_DISCOVERY_INTERVAL;
|
||||
|
||||
/* Change state */
|
||||
wtp_dfa_change_state(CAPWAP_DISCOVERY_STATE);
|
||||
|
||||
/* Wait before send Discovery Request */
|
||||
capwap_timeout_set(g_wtp.dfa.rfcDiscoveryInterval, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, discoveryinterval, wtp_dfa_state_discovery_timeout, NULL, NULL);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ void wtp_send_join(void) {
|
||||
struct capwap_packet_txmng* txmngpacket;
|
||||
|
||||
/* Reset DTLS counter */
|
||||
g_wtp.dfa.rfcFailedDTLSSessionCount = 0;
|
||||
g_wtp.faileddtlssessioncount = 0;
|
||||
|
||||
/* Update status radio */
|
||||
g_wtp.descriptor.radiosinuse = wtp_update_radio_in_use();
|
||||
@ -77,9 +77,9 @@ void wtp_send_join(void) {
|
||||
|
||||
/* Send join request to AC */
|
||||
if (capwap_crypt_sendto_fragmentpacket(&g_wtp.ctrldtls, g_wtp.acctrlsock.socket[g_wtp.acctrlsock.type], g_wtp.requestfragmentpacket, &g_wtp.wtpctrladdress, &g_wtp.acctrladdress)) {
|
||||
g_wtp.dfa.rfcRetransmitCount = 0;
|
||||
capwap_timeout_set(g_wtp.dfa.rfcRetransmitInterval, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
g_wtp.retransmitcount = 0;
|
||||
wtp_dfa_change_state(CAPWAP_JOIN_STATE);
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, WTP_RETRANSMIT_INTERVAL, wtp_dfa_retransmition_timeout, NULL, NULL);
|
||||
} else {
|
||||
/* Error to send packets */
|
||||
capwap_logging_debug("Warning: error to send join request packet");
|
||||
@ -95,58 +95,41 @@ void wtp_dfa_state_join(struct capwap_parsed_packet* packet) {
|
||||
struct capwap_acname_element* acname;
|
||||
struct capwap_resultcode_element* resultcode;
|
||||
|
||||
if (packet) {
|
||||
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
|
||||
if (packet->rxmngpacket->isctrlpacket && (binding == g_wtp.binding) && (packet->rxmngpacket->ctrlmsg.type == CAPWAP_JOIN_RESPONSE) && ((g_wtp.localseqnumber - 1) == packet->rxmngpacket->ctrlmsg.seq)) {
|
||||
/* Valid packet, free request packet */
|
||||
wtp_free_reference_last_request();
|
||||
/* */
|
||||
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
|
||||
if (packet->rxmngpacket->isctrlpacket && (binding == g_wtp.binding) && (packet->rxmngpacket->ctrlmsg.type == CAPWAP_JOIN_RESPONSE) && ((g_wtp.localseqnumber - 1) == packet->rxmngpacket->ctrlmsg.seq)) {
|
||||
/* Valid packet, free request packet */
|
||||
wtp_free_reference_last_request();
|
||||
|
||||
/* Check the success of the Request */
|
||||
resultcode = (struct capwap_resultcode_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_RESULTCODE);
|
||||
if (resultcode && !CAPWAP_RESULTCODE_OK(resultcode->code)) {
|
||||
capwap_logging_warning("Receive Join Response with error: %d", (int)resultcode->code);
|
||||
wtp_teardown_connection();
|
||||
} else {
|
||||
/* TODO: gestione richiesta CAPWAP_IMAGE_DATA_STATE <-> CAPWAP_CONFIGURE_STATE */
|
||||
|
||||
/* Check DTLS data policy */
|
||||
acdescriptor = (struct capwap_acdescriptor_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_ACDESCRIPTION);
|
||||
if (g_wtp.validdtlsdatapolicy & acdescriptor->dtlspolicy) {
|
||||
/* AC name associated */
|
||||
acname = (struct capwap_acname_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_ACNAME);
|
||||
g_wtp.acname.name = (uint8_t*)capwap_duplicate_string((const char*)acname->name);
|
||||
|
||||
/* DTLS data policy */
|
||||
g_wtp.dtlsdatapolicy = acdescriptor->dtlspolicy & g_wtp.validdtlsdatapolicy;
|
||||
|
||||
/* Binding values */
|
||||
if (!wtp_radio_setconfiguration(packet)) {
|
||||
wtp_send_configure(); /* Send configuration packet */
|
||||
} else {
|
||||
capwap_logging_warning("Receive Join Response with invalid elements");
|
||||
wtp_teardown_connection();
|
||||
}
|
||||
} else {
|
||||
capwap_logging_warning("Receive Join Response with invalid DTLS data policy");
|
||||
wtp_teardown_connection();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* No Join response received */
|
||||
g_wtp.dfa.rfcRetransmitCount++;
|
||||
if (g_wtp.dfa.rfcRetransmitCount >= g_wtp.dfa.rfcMaxRetransmit) {
|
||||
/* Timeout join state */
|
||||
wtp_free_reference_last_request();
|
||||
/* Check the success of the Request */
|
||||
resultcode = (struct capwap_resultcode_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_RESULTCODE);
|
||||
if (resultcode && !CAPWAP_RESULTCODE_OK(resultcode->code)) {
|
||||
capwap_logging_warning("Receive Join Response with error: %d", (int)resultcode->code);
|
||||
wtp_teardown_connection();
|
||||
} else {
|
||||
/* Retransmit join request */
|
||||
if (!capwap_crypt_sendto_fragmentpacket(&g_wtp.ctrldtls, g_wtp.acctrlsock.socket[g_wtp.acctrlsock.type], g_wtp.requestfragmentpacket, &g_wtp.wtpctrladdress, &g_wtp.acctrladdress)) {
|
||||
capwap_logging_debug("Warning: error to send join request packet");
|
||||
}
|
||||
/* TODO: gestione richiesta CAPWAP_IMAGE_DATA_STATE <-> CAPWAP_CONFIGURE_STATE */
|
||||
|
||||
/* Update timeout */
|
||||
capwap_timeout_set(g_wtp.dfa.rfcRetransmitInterval, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
/* Check DTLS data policy */
|
||||
acdescriptor = (struct capwap_acdescriptor_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_ACDESCRIPTION);
|
||||
if (g_wtp.validdtlsdatapolicy & acdescriptor->dtlspolicy) {
|
||||
/* AC name associated */
|
||||
acname = (struct capwap_acname_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_ACNAME);
|
||||
g_wtp.acname.name = (uint8_t*)capwap_duplicate_string((const char*)acname->name);
|
||||
|
||||
/* DTLS data policy */
|
||||
g_wtp.dtlsdatapolicy = acdescriptor->dtlspolicy & g_wtp.validdtlsdatapolicy;
|
||||
|
||||
/* Binding values */
|
||||
if (!wtp_radio_setconfiguration(packet)) {
|
||||
wtp_send_configure(); /* Send configuration packet */
|
||||
} else {
|
||||
capwap_logging_warning("Receive Join Response with invalid elements");
|
||||
wtp_teardown_connection();
|
||||
}
|
||||
} else {
|
||||
capwap_logging_warning("Receive Join Response with invalid DTLS data policy");
|
||||
wtp_teardown_connection();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "wtp_dfa.h"
|
||||
|
||||
/* */
|
||||
void wtp_dfa_state_reset(struct capwap_parsed_packet* packet) {
|
||||
void wtp_dfa_state_reset(void) {
|
||||
/* Teardown connection and close application */
|
||||
g_wtp.running = 0;
|
||||
wtp_teardown_connection();
|
||||
|
@ -179,8 +179,8 @@ static void send_data_keepalive_request() {
|
||||
if (txfragpacket->count == 1) {
|
||||
/* Send Data keepalive to AC */
|
||||
if (capwap_crypt_sendto_fragmentpacket(&g_wtp.datadtls, g_wtp.acdatasock.socket[g_wtp.acdatasock.type], txfragpacket, &g_wtp.wtpdataaddress, &g_wtp.acdataaddress)) {
|
||||
capwap_timeout_kill(g_wtp.timeout, CAPWAP_TIMER_DATA_KEEPALIVE);
|
||||
capwap_timeout_set(g_wtp.dfa.rfcDataChannelDeadInterval, g_wtp.timeout, CAPWAP_TIMER_DATA_KEEPALIVEDEAD);
|
||||
capwap_timeout_unset(g_wtp.timeout, g_wtp.idtimerkeepalive);
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimerkeepalivedead, WTP_DATACHANNEL_KEEPALIVEDEAD, wtp_dfa_state_run_keepalivedead_timeout, NULL, NULL);
|
||||
} else {
|
||||
/* Error to send packets */
|
||||
capwap_logging_debug("Warning: error to send data channel keepalive packet");
|
||||
@ -226,118 +226,99 @@ void wtp_send_data_wireless_packet(uint8_t radioid, uint8_t wlanid, const struct
|
||||
capwap_packet_txmng_free(txmngpacket);
|
||||
}
|
||||
|
||||
/* */
|
||||
void wtp_dfa_state_run_echo_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param) {
|
||||
if (!send_echo_request()) {
|
||||
g_wtp.retransmitcount = 0;
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, WTP_RETRANSMIT_INTERVAL, wtp_dfa_retransmition_timeout, NULL, NULL);
|
||||
} else {
|
||||
wtp_teardown_connection();
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
void wtp_dfa_state_run_keepalive_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param) {
|
||||
send_data_keepalive_request();
|
||||
}
|
||||
|
||||
/* */
|
||||
void wtp_dfa_state_run_keepalivedead_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param) {
|
||||
wtp_teardown_connection();
|
||||
}
|
||||
|
||||
/* */
|
||||
void wtp_dfa_state_run(struct capwap_parsed_packet* packet) {
|
||||
if (packet) {
|
||||
if (packet->rxmngpacket->isctrlpacket) {
|
||||
if (capwap_is_request_type(packet->rxmngpacket->ctrlmsg.type) || ((g_wtp.localseqnumber - 1) == packet->rxmngpacket->ctrlmsg.seq)) {
|
||||
switch (packet->rxmngpacket->ctrlmsg.type) {
|
||||
case CAPWAP_CONFIGURATION_UPDATE_REQUEST: {
|
||||
/* TODO */
|
||||
break;
|
||||
}
|
||||
ASSERT(packet != NULL);
|
||||
|
||||
case CAPWAP_CHANGE_STATE_EVENT_RESPONSE: {
|
||||
/* TODO */
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_ECHO_RESPONSE: {
|
||||
if (!receive_echo_response(packet)) {
|
||||
capwap_timeout_kill(g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
capwap_timeout_set(g_wtp.dfa.rfcEchoInterval, g_wtp.timeout, CAPWAP_TIMER_CONTROL_ECHO);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_CLEAR_CONFIGURATION_REQUEST: {
|
||||
/* TODO */
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_WTP_EVENT_RESPONSE: {
|
||||
/* TODO */
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_DATA_TRANSFER_REQUEST: {
|
||||
/* TODO */
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_DATA_TRANSFER_RESPONSE: {
|
||||
/* TODO */
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_STATION_CONFIGURATION_REQUEST: {
|
||||
/* TODO */
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_RESET_REQUEST: {
|
||||
receive_reset_request(packet);
|
||||
capwap_timeout_set(0, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
wtp_dfa_change_state(CAPWAP_RESET_STATE);
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_IEEE80211_WLAN_CONFIGURATION_REQUEST: {
|
||||
receive_ieee80211_wlan_configuration_request(packet);
|
||||
break;
|
||||
}
|
||||
if (packet->rxmngpacket->isctrlpacket) {
|
||||
if (capwap_is_request_type(packet->rxmngpacket->ctrlmsg.type) || ((g_wtp.localseqnumber - 1) == packet->rxmngpacket->ctrlmsg.seq)) {
|
||||
switch (packet->rxmngpacket->ctrlmsg.type) {
|
||||
case CAPWAP_CONFIGURATION_UPDATE_REQUEST: {
|
||||
/* TODO */
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (IS_FLAG_K_HEADER(packet->rxmngpacket->header) && capwap_timeout_isenable(g_wtp.timeout, CAPWAP_TIMER_DATA_KEEPALIVEDEAD)) {
|
||||
if (!memcmp(capwap_get_message_element_data(packet, CAPWAP_ELEMENT_SESSIONID), &g_wtp.sessionid, sizeof(struct capwap_sessionid_element))) {
|
||||
/* Receive Data Keep-Alive, wait for next packet */
|
||||
capwap_timeout_kill(g_wtp.timeout, CAPWAP_TIMER_DATA_KEEPALIVEDEAD);
|
||||
capwap_timeout_set(g_wtp.dfa.rfcDataChannelKeepAlive, g_wtp.timeout, CAPWAP_TIMER_DATA_KEEPALIVE);
|
||||
}
|
||||
} else {
|
||||
/* TODO */
|
||||
|
||||
/* Update data keep-alive timeout */
|
||||
if (!capwap_timeout_isenable(g_wtp.timeout, CAPWAP_TIMER_DATA_KEEPALIVEDEAD)) {
|
||||
capwap_timeout_set(g_wtp.dfa.rfcDataChannelKeepAlive, g_wtp.timeout, CAPWAP_TIMER_DATA_KEEPALIVE);
|
||||
case CAPWAP_CHANGE_STATE_EVENT_RESPONSE: {
|
||||
/* TODO */
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_ECHO_RESPONSE: {
|
||||
if (!receive_echo_response(packet)) {
|
||||
capwap_timeout_unset(g_wtp.timeout, g_wtp.idtimercontrol);
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimerecho, g_wtp.echointerval, wtp_dfa_state_run_echo_timeout, NULL, NULL);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_CLEAR_CONFIGURATION_REQUEST: {
|
||||
/* TODO */
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_WTP_EVENT_RESPONSE: {
|
||||
/* TODO */
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_DATA_TRANSFER_REQUEST: {
|
||||
/* TODO */
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_DATA_TRANSFER_RESPONSE: {
|
||||
/* TODO */
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_STATION_CONFIGURATION_REQUEST: {
|
||||
/* TODO */
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_RESET_REQUEST: {
|
||||
receive_reset_request(packet);
|
||||
wtp_dfa_change_state(CAPWAP_RESET_STATE);
|
||||
wtp_dfa_state_reset();
|
||||
break;
|
||||
}
|
||||
|
||||
case CAPWAP_IEEE80211_WLAN_CONFIGURATION_REQUEST: {
|
||||
receive_ieee80211_wlan_configuration_request(packet);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (capwap_timeout_hasexpired(g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION)) {
|
||||
/* No response received */
|
||||
g_wtp.dfa.rfcRetransmitCount++;
|
||||
if (g_wtp.dfa.rfcRetransmitCount >= g_wtp.dfa.rfcMaxRetransmit) {
|
||||
/* Timeout run state */
|
||||
wtp_free_reference_last_request();
|
||||
wtp_teardown_connection();
|
||||
} else {
|
||||
/* Retransmit request */
|
||||
if (!capwap_crypt_sendto_fragmentpacket(&g_wtp.ctrldtls, g_wtp.acctrlsock.socket[g_wtp.acctrlsock.type], g_wtp.requestfragmentpacket, &g_wtp.wtpctrladdress, &g_wtp.acctrladdress)) {
|
||||
capwap_logging_debug("Warning: error to send request packet");
|
||||
}
|
||||
|
||||
/* Update timeout */
|
||||
capwap_timeout_set(g_wtp.dfa.rfcRetransmitInterval, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
if (IS_FLAG_K_HEADER(packet->rxmngpacket->header)) {
|
||||
if (!memcmp(capwap_get_message_element_data(packet, CAPWAP_ELEMENT_SESSIONID), &g_wtp.sessionid, sizeof(struct capwap_sessionid_element))) {
|
||||
/* Receive Data Keep-Alive, wait for next packet */
|
||||
capwap_timeout_unset(g_wtp.timeout, g_wtp.idtimerkeepalivedead);
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimerkeepalive, WTP_DATACHANNEL_KEEPALIVE_INTERVAL, wtp_dfa_state_run_keepalive_timeout, NULL, NULL);
|
||||
}
|
||||
} else if (capwap_timeout_hasexpired(g_wtp.timeout, CAPWAP_TIMER_CONTROL_ECHO)) {
|
||||
/* Disable echo timer */
|
||||
capwap_timeout_kill(g_wtp.timeout, CAPWAP_TIMER_CONTROL_ECHO);
|
||||
|
||||
if (!send_echo_request()) {
|
||||
g_wtp.dfa.rfcRetransmitCount = 0;
|
||||
capwap_timeout_set(g_wtp.dfa.rfcRetransmitInterval, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
} else {
|
||||
wtp_teardown_connection();
|
||||
}
|
||||
} else if (capwap_timeout_hasexpired(g_wtp.timeout, CAPWAP_TIMER_DATA_KEEPALIVE)) {
|
||||
send_data_keepalive_request();
|
||||
} else if (capwap_timeout_hasexpired(g_wtp.timeout, CAPWAP_TIMER_DATA_KEEPALIVEDEAD)) {
|
||||
/* Data Keep-Alive timeout */
|
||||
capwap_timeout_kill(g_wtp.timeout, CAPWAP_TIMER_DATA_KEEPALIVEDEAD);
|
||||
wtp_teardown_connection();
|
||||
} else {
|
||||
/* TODO */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,14 +3,16 @@
|
||||
#include "wtp_dfa.h"
|
||||
|
||||
/* */
|
||||
void wtp_dfa_state_sulking(struct capwap_parsed_packet* packet) {
|
||||
if (!packet) {
|
||||
g_wtp.dfa.rfcDiscoveryCount = 0;
|
||||
g_wtp.dfa.rfcFailedDTLSSessionCount = 0;
|
||||
g_wtp.dfa.rfcFailedDTLSAuthFailCount = 0;
|
||||
void wtp_dfa_state_sulking_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param) {
|
||||
g_wtp.discoverycount = 0;
|
||||
g_wtp.faileddtlssessioncount = 0;
|
||||
g_wtp.faileddtlsauthfailcount = 0;
|
||||
|
||||
/* */
|
||||
capwap_timeout_set(0, g_wtp.timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
|
||||
wtp_dfa_change_state(CAPWAP_IDLE_STATE);
|
||||
}
|
||||
/* */
|
||||
wtp_dfa_change_state(CAPWAP_IDLE_STATE);
|
||||
wtp_dfa_state_idle();
|
||||
}
|
||||
|
||||
/* */
|
||||
void wtp_dfa_state_sulking(struct capwap_parsed_packet* packet) {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user