rework overly deep if statement in wtp_dfa_run

This commit is contained in:
Andreas Schultz 2016-03-26 20:28:32 +01:00
parent 73afba9a6d
commit 7eddb74767

View File

@ -63,19 +63,30 @@ static int receive_echo_response(struct capwap_parsed_packet* packet) {
static void receive_reset_request(struct capwap_parsed_packet* packet) static void receive_reset_request(struct capwap_parsed_packet* packet)
{ {
unsigned short binding; unsigned short binding;
struct capwap_header_data capwapheader;
struct capwap_packet_txmng* txmngpacket;
struct capwap_resultcode_element resultcode = { .code = CAPWAP_RESULTCODE_SUCCESS };
ASSERT(packet != NULL); ASSERT(packet != NULL);
/* */ /* */
binding = GET_WBID_HEADER(packet->rxmngpacket->header); binding = GET_WBID_HEADER(packet->rxmngpacket->header);
if ((binding == g_wtp.binding) && IS_SEQUENCE_SMALLER(g_wtp.remoteseqnumber, packet->rxmngpacket->ctrlmsg.seq)) { if (binding != g_wtp.binding) {
struct capwap_header_data capwapheader; capwap_logging_debug("Reset Request for invalid binding");
struct capwap_packet_txmng* txmngpacket; return;
struct capwap_resultcode_element resultcode = { .code = CAPWAP_RESULTCODE_SUCCESS }; }
if (!IS_SEQUENCE_SMALLER(g_wtp.remoteseqnumber, packet->rxmngpacket->ctrlmsg.seq)) {
capwap_logging_debug("Reset Request with invalid sequence (%d < %d)",
g_wtp.remoteseqnumber, packet->rxmngpacket->ctrlmsg.seq);
return;
}
/* Build packet */ /* Build packet */
capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, g_wtp.binding); capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, g_wtp.binding);
txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, CAPWAP_RESET_RESPONSE, packet->rxmngpacket->ctrlmsg.seq, g_wtp.mtu); txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader,
CAPWAP_RESET_RESPONSE,
packet->rxmngpacket->ctrlmsg.seq, g_wtp.mtu);
/* Add message element */ /* Add message element */
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_RESULTCODE, &resultcode); capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_RESULTCODE, &resultcode);
@ -84,9 +95,8 @@ static void receive_reset_request(struct capwap_parsed_packet* packet)
/* Reset response complete, get fragment packets */ /* Reset response complete, get fragment packets */
wtp_free_reference_last_response(); wtp_free_reference_last_response();
capwap_packet_txmng_get_fragment_packets(txmngpacket, g_wtp.responsefragmentpacket, g_wtp.fragmentid); capwap_packet_txmng_get_fragment_packets(txmngpacket, g_wtp.responsefragmentpacket, g_wtp.fragmentid);
if (g_wtp.responsefragmentpacket->count > 1) { if (g_wtp.responsefragmentpacket->count > 1)
g_wtp.fragmentid++; g_wtp.fragmentid++;
}
/* Free packets manager */ /* Free packets manager */
capwap_packet_txmng_free(txmngpacket); capwap_packet_txmng_free(txmngpacket);
@ -100,21 +110,29 @@ static void receive_reset_request(struct capwap_parsed_packet* packet)
capwap_logging_debug("Warning: error to send reset response packet"); capwap_logging_debug("Warning: error to send reset response packet");
} }
} }
}
/* */ /* */
static void receive_station_configuration_request(struct capwap_parsed_packet* packet) static void receive_station_configuration_request(struct capwap_parsed_packet* packet)
{ {
unsigned short binding; unsigned short binding;
struct capwap_header_data capwapheader;
struct capwap_packet_txmng* txmngpacket;
struct capwap_resultcode_element resultcode = { .code = CAPWAP_RESULTCODE_FAILURE };
ASSERT(packet != NULL); ASSERT(packet != NULL);
/* */ /* */
binding = GET_WBID_HEADER(packet->rxmngpacket->header); binding = GET_WBID_HEADER(packet->rxmngpacket->header);
if ((binding == g_wtp.binding) && IS_SEQUENCE_SMALLER(g_wtp.remoteseqnumber, packet->rxmngpacket->ctrlmsg.seq)) { if (binding != g_wtp.binding) {
struct capwap_header_data capwapheader; capwap_logging_debug("Station Configuration Request for invalid binding");
struct capwap_packet_txmng* txmngpacket; return;
struct capwap_resultcode_element resultcode = { .code = CAPWAP_RESULTCODE_FAILURE }; }
if (!IS_SEQUENCE_SMALLER(g_wtp.remoteseqnumber, packet->rxmngpacket->ctrlmsg.seq)) {
capwap_logging_debug("Station Configuration Request with invalid sequence (%d < %d)",
g_wtp.remoteseqnumber, packet->rxmngpacket->ctrlmsg.seq);
return;
}
/* Parsing request message */ /* Parsing request message */
if (capwap_get_message_element(packet, CAPWAP_ELEMENT_ADDSTATION)) { if (capwap_get_message_element(packet, CAPWAP_ELEMENT_ADDSTATION)) {
@ -125,7 +143,9 @@ static void receive_station_configuration_request(struct capwap_parsed_packet* p
/* Build packet */ /* Build packet */
capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, g_wtp.binding); capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, g_wtp.binding);
txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, CAPWAP_STATION_CONFIGURATION_RESPONSE, packet->rxmngpacket->ctrlmsg.seq, g_wtp.mtu); txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader,
CAPWAP_STATION_CONFIGURATION_RESPONSE,
packet->rxmngpacket->ctrlmsg.seq, g_wtp.mtu);
/* Add message element */ /* Add message element */
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_RESULTCODE, &resultcode); capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_RESULTCODE, &resultcode);
@ -134,9 +154,8 @@ static void receive_station_configuration_request(struct capwap_parsed_packet* p
/* Station Configuration response complete, get fragment packets */ /* Station Configuration response complete, get fragment packets */
wtp_free_reference_last_response(); wtp_free_reference_last_response();
capwap_packet_txmng_get_fragment_packets(txmngpacket, g_wtp.responsefragmentpacket, g_wtp.fragmentid); capwap_packet_txmng_get_fragment_packets(txmngpacket, g_wtp.responsefragmentpacket, g_wtp.fragmentid);
if (g_wtp.responsefragmentpacket->count > 1) { if (g_wtp.responsefragmentpacket->count > 1)
g_wtp.fragmentid++; g_wtp.fragmentid++;
}
/* Free packets manager */ /* Free packets manager */
capwap_packet_txmng_free(txmngpacket); capwap_packet_txmng_free(txmngpacket);
@ -150,24 +169,32 @@ static void receive_station_configuration_request(struct capwap_parsed_packet* p
capwap_logging_debug("Warning: error to send Station Configuration response packet"); capwap_logging_debug("Warning: error to send Station Configuration response packet");
} }
} }
}
/* */ /* */
static void receive_ieee80211_wlan_configuration_request(struct capwap_parsed_packet* packet) static void receive_ieee80211_wlan_configuration_request(struct capwap_parsed_packet* packet)
{ {
unsigned short binding; unsigned short binding;
ASSERT(packet != NULL);
/* */
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
if ((binding == g_wtp.binding) && IS_SEQUENCE_SMALLER(g_wtp.remoteseqnumber, packet->rxmngpacket->ctrlmsg.seq)) {
struct capwap_message_element_id action = {0, 0}; struct capwap_message_element_id action = {0, 0};
struct capwap_header_data capwapheader; struct capwap_header_data capwapheader;
struct capwap_packet_txmng* txmngpacket; struct capwap_packet_txmng* txmngpacket;
struct capwap_80211_assignbssid_element bssid; struct capwap_80211_assignbssid_element bssid;
struct capwap_resultcode_element resultcode = { .code = CAPWAP_RESULTCODE_FAILURE }; struct capwap_resultcode_element resultcode = { .code = CAPWAP_RESULTCODE_FAILURE };
ASSERT(packet != NULL);
/* */
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
if (binding != g_wtp.binding) {
capwap_logging_debug("IEEE 802.11 WLAN Configuration Request for invalid binding");
return;
}
if (!IS_SEQUENCE_SMALLER(g_wtp.remoteseqnumber, packet->rxmngpacket->ctrlmsg.seq)) {
capwap_logging_debug("IEEE 802.11 WLAN Configuration Request with invalid sequence (%d < %d)",
g_wtp.remoteseqnumber, packet->rxmngpacket->ctrlmsg.seq);
return;
}
/* Parsing request message */ /* Parsing request message */
if (capwap_get_message_element(packet, CAPWAP_ELEMENT_80211_ADD_WLAN)) { if (capwap_get_message_element(packet, CAPWAP_ELEMENT_80211_ADD_WLAN)) {
action = CAPWAP_ELEMENT_80211_ADD_WLAN; action = CAPWAP_ELEMENT_80211_ADD_WLAN;
@ -182,7 +209,9 @@ static void receive_ieee80211_wlan_configuration_request(struct capwap_parsed_pa
/* Build packet */ /* Build packet */
capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, g_wtp.binding); capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, g_wtp.binding);
txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, CAPWAP_IEEE80211_WLAN_CONFIGURATION_RESPONSE, packet->rxmngpacket->ctrlmsg.seq, g_wtp.mtu); txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader,
CAPWAP_IEEE80211_WLAN_CONFIGURATION_RESPONSE,
packet->rxmngpacket->ctrlmsg.seq, g_wtp.mtu);
/* Add message element */ /* Add message element */
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_RESULTCODE, &resultcode); capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_RESULTCODE, &resultcode);
@ -195,9 +224,8 @@ static void receive_ieee80211_wlan_configuration_request(struct capwap_parsed_pa
/* IEEE802.11 WLAN Configuration response complete, get fragment packets */ /* IEEE802.11 WLAN Configuration response complete, get fragment packets */
wtp_free_reference_last_response(); wtp_free_reference_last_response();
capwap_packet_txmng_get_fragment_packets(txmngpacket, g_wtp.responsefragmentpacket, g_wtp.fragmentid); capwap_packet_txmng_get_fragment_packets(txmngpacket, g_wtp.responsefragmentpacket, g_wtp.fragmentid);
if (g_wtp.responsefragmentpacket->count > 1) { if (g_wtp.responsefragmentpacket->count > 1)
g_wtp.fragmentid++; g_wtp.fragmentid++;
}
/* Free packets manager */ /* Free packets manager */
capwap_packet_txmng_free(txmngpacket); capwap_packet_txmng_free(txmngpacket);
@ -211,7 +239,6 @@ static void receive_ieee80211_wlan_configuration_request(struct capwap_parsed_pa
capwap_logging_debug("Warning: error to send IEEE802.11 WLAN Configuration response packet"); capwap_logging_debug("Warning: error to send IEEE802.11 WLAN Configuration response packet");
} }
} }
}
/* */ /* */
void wtp_dfa_state_run_echo_timeout(struct capwap_timeout* timeout, unsigned long index, void wtp_dfa_state_run_echo_timeout(struct capwap_timeout* timeout, unsigned long index,
@ -285,70 +312,62 @@ void wtp_dfa_state_run(struct capwap_parsed_packet* packet)
{ {
ASSERT(packet != NULL); ASSERT(packet != NULL);
if (capwap_is_request_type(packet->rxmngpacket->ctrlmsg.type) || (g_wtp.localseqnumber == packet->rxmngpacket->ctrlmsg.seq)) { if (!capwap_is_request_type(packet->rxmngpacket->ctrlmsg.type) &&
g_wtp.localseqnumber != packet->rxmngpacket->ctrlmsg.seq)
return;
/* Update sequence */ /* Update sequence */
if (!capwap_is_request_type(packet->rxmngpacket->ctrlmsg.type)) { if (!capwap_is_request_type(packet->rxmngpacket->ctrlmsg.type))
g_wtp.localseqnumber++; g_wtp.localseqnumber++;
}
/* Parsing message */ /* Parsing message */
switch (packet->rxmngpacket->ctrlmsg.type) { switch (packet->rxmngpacket->ctrlmsg.type) {
case CAPWAP_CONFIGURATION_UPDATE_REQUEST: { case CAPWAP_CONFIGURATION_UPDATE_REQUEST:
/* TODO */ /* TODO */
break; break;
}
case CAPWAP_CHANGE_STATE_EVENT_RESPONSE: { case CAPWAP_CHANGE_STATE_EVENT_RESPONSE:
/* TODO */ /* TODO */
break; break;
}
case CAPWAP_ECHO_RESPONSE: { case CAPWAP_ECHO_RESPONSE:
if (!receive_echo_response(packet)) { if (!receive_echo_response(packet)) {
capwap_logging_debug("Receive Echo Response"); capwap_logging_debug("Receive Echo Response");
capwap_timeout_unset(g_wtp.timeout, g_wtp.idtimercontrol); 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.idtimerecho, g_wtp.echointerval,
wtp_dfa_state_run_echo_timeout, NULL, NULL);
} }
break; break;
}
case CAPWAP_CLEAR_CONFIGURATION_REQUEST: { case CAPWAP_CLEAR_CONFIGURATION_REQUEST:
/* TODO */ /* TODO */
break; break;
}
case CAPWAP_WTP_EVENT_RESPONSE: { case CAPWAP_WTP_EVENT_RESPONSE:
/* TODO */ /* TODO */
break; break;
}
case CAPWAP_DATA_TRANSFER_REQUEST: { case CAPWAP_DATA_TRANSFER_REQUEST:
/* TODO */ /* TODO */
break; break;
}
case CAPWAP_DATA_TRANSFER_RESPONSE: { case CAPWAP_DATA_TRANSFER_RESPONSE:
/* TODO */ /* TODO */
break; break;
}
case CAPWAP_STATION_CONFIGURATION_REQUEST: { case CAPWAP_STATION_CONFIGURATION_REQUEST:
receive_station_configuration_request(packet); receive_station_configuration_request(packet);
break; break;
}
case CAPWAP_RESET_REQUEST: { case CAPWAP_RESET_REQUEST:
receive_reset_request(packet); receive_reset_request(packet);
wtp_dfa_change_state(CAPWAP_RESET_STATE); wtp_dfa_change_state(CAPWAP_RESET_STATE);
wtp_dfa_state_reset(); wtp_dfa_state_reset();
break; break;
}
case CAPWAP_IEEE80211_WLAN_CONFIGURATION_REQUEST: { case CAPWAP_IEEE80211_WLAN_CONFIGURATION_REQUEST:
receive_ieee80211_wlan_configuration_request(packet); receive_ieee80211_wlan_configuration_request(packet);
break; break;
} }
} }
}
}