freewtp/src/dfa_datacheck.c

95 lines
2.9 KiB
C
Raw Normal View History

2013-05-01 14:52:55 +02:00
#include "wtp.h"
#include "capwap_dfa.h"
2016-08-22 16:59:55 +02:00
#include "element.h"
#include "dfa.h"
2013-05-01 14:52:55 +02:00
/* */
void wtp_dfa_state_datacheck_enter(void)
2016-03-26 17:20:50 +01:00
{
2013-11-07 22:06:29 +01:00
struct capwap_header_data capwapheader;
struct capwap_packet_txmng* txmngpacket;
struct capwap_resultcode_element resultcode = { .code = CAPWAP_RESULTCODE_SUCCESS };
/* Build packet */
capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, g_wtp.binding);
2016-03-26 17:20:50 +01:00
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)
2013-11-07 22:06:29 +01:00
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.dtls, g_wtp.requestfragmentpacket)) {
2013-11-07 22:06:29 +01:00
/* Error to send packets */
log_printf(LOG_DEBUG, "Warning: error to send change state event request packet");
2013-11-07 22:06:29 +01:00
wtp_free_reference_last_request();
wtp_teardown_connection();
return;
2013-11-07 22:06:29 +01:00
}
g_wtp.retransmitcount = 0;
wtp_dfa_start_retransmition_timer();
2013-05-01 14:52:55 +02:00
}
/* */
2016-03-26 17:20:50 +01:00
void wtp_dfa_state_datacheck(struct capwap_parsed_packet* packet)
{
2013-11-07 22:06:29 +01:00
unsigned short binding;
struct capwap_resultcode_element* resultcode;
if (packet->rxmngpacket->ctrlmsg.type != CAPWAP_CHANGE_STATE_EVENT_RESPONSE) {
log_printf(LOG_DEBUG, "Unexpected message %d in state Data Check",
packet->rxmngpacket->ctrlmsg.type);
return;
}
/* */
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
if (binding != g_wtp.binding) {
log_printf(LOG_DEBUG, "Change State Event for invalid binding");
return;
}
if (g_wtp.localseqnumber != packet->rxmngpacket->ctrlmsg.seq) {
log_printf(LOG_DEBUG, "Configuration Status Response with invalid sequence (%d != %d)",
g_wtp.localseqnumber, packet->rxmngpacket->ctrlmsg.seq);
return;
}
2013-05-01 14:52:55 +02:00
wtp_dfa_stop_retransmition_timer();
g_wtp.localseqnumber++;
/* 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)) {
log_printf(LOG_WARNING, "Receive Data Check Response with error: %d",
(int)resultcode->code);
wtp_teardown_connection();
return;
2013-05-01 14:52:55 +02:00
}
wtp_start_datachannel();
2013-05-01 14:52:55 +02:00
}