freewtp/src/wtp/wtp_dfa_datacheck.c

90 lines
3.5 KiB
C
Raw Normal View History

2013-05-01 14:52:55 +02:00
#include "wtp.h"
#include "capwap_dfa.h"
#include "capwap_element.h"
#include "wtp_dfa.h"
/* */
2013-11-07 22:06:29 +01:00
void wtp_send_datacheck(struct timeout_control* timeout) {
struct capwap_header_data capwapheader;
struct capwap_packet_txmng* txmngpacket;
struct capwap_resultcode_element resultcode = { .code = CAPWAP_RESULTCODE_SUCCESS };
ASSERT(timeout != NULL);
/* Build packet */
capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, g_wtp.binding);
txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, CAPWAP_CHANGE_STATE_EVENT_REQUEST, g_wtp.localseqnumber++, g_wtp.mtu);
2013-11-07 22:06:29 +01:00
/* Add message element */
wtp_create_radioopsstate_element(txmngpacket);
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_RESULTCODE, &resultcode);
/* CAPWAP_ELEMENT_RETURNEDMESSAGE */ /* TODO */
/* CAPWAP_ELEMENT_80211_WTP_RADIO_FAIL_ALARM */ /* TODO */
/* CAPWAP_ELEMENT_VENDORPAYLOAD */ /* TODO */
/* Change State Event 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++;
}
2013-11-07 22:06:29 +01:00
/* Free packets manager */
capwap_packet_txmng_free(txmngpacket);
2013-05-01 14:52:55 +02:00
2013-11-07 22:06:29 +01:00
/* 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_set_timeout(g_wtp.dfa.rfcRetransmitInterval, timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
wtp_dfa_change_state(CAPWAP_DATA_CHECK_STATE);
} else {
/* Error to send packets */
capwap_logging_debug("Warning: error to send change state event request packet");
wtp_free_reference_last_request();
wtp_teardown_connection(timeout);
}
2013-05-01 14:52:55 +02:00
}
/* */
2013-11-07 22:06:29 +01:00
void wtp_dfa_state_datacheck(struct capwap_parsed_packet* packet, struct timeout_control* timeout) {
unsigned short binding;
struct capwap_resultcode_element* resultcode;
2013-05-01 14:52:55 +02:00
ASSERT(timeout != NULL);
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();
2013-05-01 14:52:55 +02:00
2013-11-07 22:06:29 +01:00
/* 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(timeout);
} else {
/* TODO: gestione richiesta */
wtp_start_datachannel(timeout);
}
2013-05-01 14:52:55 +02:00
}
} 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();
2013-11-07 22:06:29 +01:00
wtp_teardown_connection(timeout);
2013-05-01 14:52:55 +02:00
} else {
2013-11-07 22:06:29 +01:00
/* 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");
2013-05-01 14:52:55 +02:00
}
2013-05-01 14:52:55 +02:00
/* Update timeout */
capwap_set_timeout(g_wtp.dfa.rfcRetransmitInterval, timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
}
}
}