Improved handling of message elements parsed. Reduces the memory occupied but
it introduces a small overhead in retrieving of message elements parsed.
This commit is contained in:
@ -25,9 +25,9 @@ static int wtp_init(void) {
|
||||
memset(&g_wtp, 0, sizeof(struct wtp_t));
|
||||
|
||||
/* Standard name */
|
||||
strcpy((char*)g_wtp.name.name, WTP_STANDARD_NAME);
|
||||
strcpy((char*)g_wtp.location.value, WTP_STANDARD_LOCATION);
|
||||
|
||||
g_wtp.name.name = (uint8_t*)capwap_duplicate_string(WTP_STANDARD_NAME);
|
||||
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;
|
||||
@ -44,7 +44,7 @@ static int wtp_init(void) {
|
||||
|
||||
/* Socket */
|
||||
capwap_network_init(&g_wtp.net);
|
||||
|
||||
|
||||
/* Standard configuration */
|
||||
g_wtp.boarddata.boardsubelement = capwap_array_create(sizeof(struct capwap_wtpboarddata_board_subelement), 0, 1);
|
||||
g_wtp.descriptor.encryptsubelement = capwap_array_create(sizeof(struct capwap_wtpdescriptor_encrypt_subelement), 0, 0);
|
||||
@ -58,17 +58,17 @@ static int wtp_init(void) {
|
||||
|
||||
g_wtp.mactype.type = CAPWAP_LOCALMAC;
|
||||
g_wtp.mactunnel.mode = CAPWAP_WTP_LOCAL_BRIDGING;
|
||||
|
||||
|
||||
/* DTLS */
|
||||
g_wtp.validdtlsdatapolicy = CAPWAP_ACDESC_CLEAR_DATA_CHANNEL_ENABLED;
|
||||
|
||||
|
||||
/* Tx fragment packets */
|
||||
g_wtp.mtu = CAPWAP_MTU_DEFAULT;
|
||||
g_wtp.requestfragmentpacket = capwap_list_create();
|
||||
g_wtp.responsefragmentpacket = capwap_list_create();
|
||||
|
||||
/* AC information */
|
||||
g_wtp.discoverytype.type = CAPWAP_ELEMENT_DISCOVERYTYPE_TYPE_UNKNOWN;
|
||||
g_wtp.discoverytype.type = CAPWAP_DISCOVERYTYPE_TYPE_UNKNOWN;
|
||||
g_wtp.acdiscoveryrequest = 1;
|
||||
g_wtp.acdiscoveryarray = capwap_array_create(sizeof(struct sockaddr_storage), 0, 0);
|
||||
g_wtp.acpreferedarray = capwap_array_create(sizeof(struct sockaddr_storage), 0, 0);
|
||||
@ -82,25 +82,48 @@ static int wtp_init(void) {
|
||||
|
||||
/* Destroy WTP */
|
||||
static void wtp_destroy(void) {
|
||||
int i;
|
||||
|
||||
/* Dtls */
|
||||
capwap_crypt_freecontext(&g_wtp.dtlscontext);
|
||||
|
||||
|
||||
/* Free standard configuration */
|
||||
capwap_array_free(g_wtp.descriptor.encryptsubelement);
|
||||
|
||||
for (i = 0; i < g_wtp.descriptor.descsubelement->count; i++) {
|
||||
struct capwap_wtpdescriptor_desc_subelement* element = (struct capwap_wtpdescriptor_desc_subelement*)capwap_array_get_item_pointer(g_wtp.descriptor.descsubelement, i);
|
||||
|
||||
if (element->data) {
|
||||
capwap_free(element->data);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < g_wtp.boarddata.boardsubelement->count; i++) {
|
||||
struct capwap_wtpboarddata_board_subelement* element = (struct capwap_wtpboarddata_board_subelement*)capwap_array_get_item_pointer(g_wtp.boarddata.boardsubelement, i);
|
||||
|
||||
if (element->data) {
|
||||
capwap_free(element->data);
|
||||
}
|
||||
}
|
||||
|
||||
capwap_array_free(g_wtp.descriptor.descsubelement);
|
||||
capwap_array_free(g_wtp.boarddata.boardsubelement);
|
||||
|
||||
|
||||
/* Free fragments packet */
|
||||
capwap_list_free(g_wtp.requestfragmentpacket);
|
||||
capwap_list_free(g_wtp.responsefragmentpacket);
|
||||
|
||||
|
||||
/* Free list AC */
|
||||
capwap_array_free(g_wtp.acdiscoveryarray);
|
||||
capwap_array_free(g_wtp.acpreferedarray);
|
||||
|
||||
|
||||
wtp_free_discovery_response_array();
|
||||
capwap_array_free(g_wtp.acdiscoveryresponse);
|
||||
|
||||
|
||||
/* Free local message elements */
|
||||
capwap_free(g_wtp.name.name);
|
||||
capwap_free(g_wtp.location.value);
|
||||
|
||||
/* Free radios */
|
||||
capwap_array_free(g_wtp.radios);
|
||||
}
|
||||
@ -221,7 +244,8 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
strcpy((char*)g_wtp.name.name, configString);
|
||||
capwap_free(g_wtp.name.name);
|
||||
g_wtp.name.name = (uint8_t*)capwap_duplicate_string(configString);
|
||||
}
|
||||
|
||||
/* Set location of WTP */
|
||||
@ -231,7 +255,8 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
strcpy((char*)g_wtp.location.value, configString);
|
||||
capwap_free(g_wtp.location.value);
|
||||
g_wtp.location.value = (uint8_t*)capwap_duplicate_string(configString);
|
||||
}
|
||||
|
||||
/* Set binding of WTP */
|
||||
@ -327,29 +352,34 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
|
||||
if (!strcmp(configName, "model")) {
|
||||
element->type = CAPWAP_BOARD_SUBELEMENT_MODELNUMBER;
|
||||
element->length = lengthValue;
|
||||
strcpy((char*)element->data, configValue);
|
||||
element->data = (uint8_t*)capwap_clone((void*)configValue, lengthValue);
|
||||
} else if (!strcmp(configName, "serial")) {
|
||||
element->type = CAPWAP_BOARD_SUBELEMENT_SERIALNUMBER;
|
||||
element->length = lengthValue;
|
||||
strcpy((char*)element->data, configValue);
|
||||
element->data = (uint8_t*)capwap_clone((void*)configValue, lengthValue);
|
||||
} else if (!strcmp(configName, "id")) {
|
||||
element->type = CAPWAP_BOARD_SUBELEMENT_ID;
|
||||
element->length = lengthValue;
|
||||
strcpy((char*)element->data, configValue);
|
||||
element->data = (uint8_t*)capwap_clone((void*)configValue, lengthValue);
|
||||
} else if (!strcmp(configName, "revision")) {
|
||||
element->type = CAPWAP_BOARD_SUBELEMENT_REVISION;
|
||||
element->length = lengthValue;
|
||||
strcpy((char*)element->data, configValue);
|
||||
element->data = (uint8_t*)capwap_clone((void*)configValue, lengthValue);
|
||||
} else if (!strcmp(configName, "macaddress")) {
|
||||
const char* configType;
|
||||
if (config_setting_lookup_string(configElement, "type", &configType) == CONFIG_TRUE) {
|
||||
if (!strcmp(configType, "interface")) {
|
||||
char macaddress[MACADDRESS_EUI64_LENGTH];
|
||||
|
||||
/* Retrieve macaddress */
|
||||
element->type = CAPWAP_BOARD_SUBELEMENT_MACADDRESS;
|
||||
element->length = capwap_get_macaddress_from_interface(configValue, (char*)element->data);
|
||||
if (!element->length) {
|
||||
element->length = capwap_get_macaddress_from_interface(configValue, macaddress);
|
||||
if (!element->length || ((element->length != MACADDRESS_EUI64_LENGTH) && (element->length != MACADDRESS_EUI48_LENGTH))) {
|
||||
capwap_logging_error("Invalid configuration file, unable found macaddress of interface: '%s'", configValue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
element->data = (uint8_t*)capwap_clone((void*)macaddress, element->length);
|
||||
} else {
|
||||
capwap_logging_error("Invalid configuration file, unknown application.boardinfo.element.type value");
|
||||
return 0;
|
||||
@ -566,7 +596,7 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
|
||||
desc->vendor = (unsigned long)configVendor;
|
||||
desc->type = type;
|
||||
desc->length = lengthValue;
|
||||
strcpy((char*)desc->data, configValue);
|
||||
desc->data = (uint8_t*)capwap_clone((void*)configValue, lengthValue);
|
||||
} else {
|
||||
capwap_logging_error("Invalid configuration file, application.descriptor.info.value string length exceeded");
|
||||
return 0;
|
||||
@ -824,7 +854,7 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
|
||||
}
|
||||
|
||||
wtp_add_acaddress(&acaddr, g_wtp.acdiscoveryarray);
|
||||
g_wtp.discoverytype.type = CAPWAP_ELEMENT_DISCOVERYTYPE_TYPE_STATIC;
|
||||
g_wtp.discoverytype.type = CAPWAP_DISCOVERYTYPE_TYPE_STATIC;
|
||||
} else {
|
||||
capwap_logging_error("Invalid configuration file, invalid application.acdiscovery.host value");
|
||||
return 0;
|
||||
|
||||
@ -7,11 +7,14 @@
|
||||
|
||||
/* */
|
||||
static unsigned long wtp_configure_ac(struct capwap_parsed_packet* packet) {
|
||||
struct capwap_timers_element* timers;
|
||||
|
||||
/* TODO: gestione richiesta */
|
||||
|
||||
/* */
|
||||
g_wtp.dfa.rfcMaxDiscoveryInterval = packet->messageelements.timers->discovery;
|
||||
g_wtp.dfa.rfcEchoInterval = packet->messageelements.timers->echorequest;
|
||||
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;
|
||||
|
||||
return CAPWAP_CONFIGURE_TO_DATA_CHECK_STATE;
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ void wtp_free_discovery_response_array(void) {
|
||||
|
||||
/* */
|
||||
int wtp_dfa_state_discovery(struct capwap_parsed_packet* packet, struct timeout_control* timeout) {
|
||||
struct capwap_array* controlip;
|
||||
int status = WTP_DFA_ACCEPT_PACKET;
|
||||
|
||||
ASSERT(timeout != NULL);
|
||||
@ -36,21 +37,27 @@ int wtp_dfa_state_discovery(struct capwap_parsed_packet* packet, struct timeout_
|
||||
struct wtp_discovery_response* response = (struct wtp_discovery_response*)capwap_array_get_item_pointer(g_wtp.acdiscoveryresponse, g_wtp.acdiscoveryresponse->count);
|
||||
|
||||
/* Create controlipv4 */
|
||||
response->controlipv4 = capwap_array_create(sizeof(struct capwap_controlipv4_element), 0, 0);
|
||||
for (i = 0; i < packet->messageelements.controlipv4->count; i++) {
|
||||
struct capwap_controlipv4_element* src = *(struct capwap_controlipv4_element**)capwap_array_get_item_pointer(packet->messageelements.controlipv4, i);
|
||||
struct capwap_controlipv4_element* dst = (struct capwap_controlipv4_element*)capwap_array_get_item_pointer(response->controlipv4, i);
|
||||
controlip = (struct capwap_array*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_CONTROLIPV4);
|
||||
if (controlip) {
|
||||
response->controlipv4 = capwap_array_create(sizeof(struct capwap_controlipv4_element), 0, 0);
|
||||
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);
|
||||
|
||||
memcpy(dst, src, sizeof(struct capwap_controlipv4_element));
|
||||
memcpy(dst, src, sizeof(struct capwap_controlipv4_element));
|
||||
}
|
||||
}
|
||||
|
||||
/* Create controlipv4 */
|
||||
response->controlipv6 = capwap_array_create(sizeof(struct capwap_controlipv6_element), 0, 0);
|
||||
for (i = 0; i < packet->messageelements.controlipv6->count; i++) {
|
||||
struct capwap_controlipv6_element* src = *(struct capwap_controlipv6_element**)capwap_array_get_item_pointer(packet->messageelements.controlipv6, i);
|
||||
struct capwap_controlipv6_element* dst = (struct capwap_controlipv6_element*)capwap_array_get_item_pointer(response->controlipv6, i);
|
||||
/* Create controlipv6 */
|
||||
controlip = (struct capwap_array*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_CONTROLIPV6);
|
||||
if (controlip) {
|
||||
response->controlipv6 = capwap_array_create(sizeof(struct capwap_controlipv6_element), 0, 0);
|
||||
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);
|
||||
|
||||
memcpy(dst, src, sizeof(struct capwap_controlipv6_element));
|
||||
memcpy(dst, src, sizeof(struct capwap_controlipv6_element));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (g_wtp.acdiscoveryresponse->count > 0) {
|
||||
|
||||
@ -87,6 +87,12 @@ int wtp_dfa_state_dtlsteardown(struct capwap_parsed_packet* packet, struct timeo
|
||||
capwap_crypt_freesession(&g_wtp.datadtls);
|
||||
}
|
||||
|
||||
/* */
|
||||
if (g_wtp.acname.name) {
|
||||
capwap_free(g_wtp.acname.name);
|
||||
g_wtp.acname.name = NULL;
|
||||
}
|
||||
|
||||
/* */
|
||||
wtp_free_reference_last_request();
|
||||
wtp_free_reference_last_response();
|
||||
|
||||
@ -7,20 +7,25 @@
|
||||
|
||||
/* */
|
||||
static unsigned long wtp_join_ac(struct capwap_parsed_packet* packet) {
|
||||
struct capwap_acdescriptor_element* acdescriptor;
|
||||
struct capwap_acname_element* acname;
|
||||
|
||||
/* TODO: gestione richiesta
|
||||
CAPWAP_JOIN_TO_IMAGE_DATA_STATE <-> CAPWAP_JOIN_TO_CONFIGURE_STATE
|
||||
*/
|
||||
|
||||
/* Check DTLS data policy */
|
||||
if (!(g_wtp.validdtlsdatapolicy & packet->messageelements.acdescriptor->dtlspolicy)) {
|
||||
acdescriptor = (struct capwap_acdescriptor_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_ACDESCRIPTION);
|
||||
if (!(g_wtp.validdtlsdatapolicy & acdescriptor->dtlspolicy)) {
|
||||
return CAPWAP_JOIN_TO_DTLS_TEARDOWN_STATE;
|
||||
}
|
||||
|
||||
/* AC name associated */
|
||||
strcpy((char*)g_wtp.acname.name, (char*)packet->messageelements.acname->name);
|
||||
|
||||
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 = packet->messageelements.acdescriptor->dtlspolicy & g_wtp.validdtlsdatapolicy;
|
||||
g_wtp.dtlsdatapolicy = acdescriptor->dtlspolicy & g_wtp.validdtlsdatapolicy;
|
||||
|
||||
return CAPWAP_JOIN_TO_CONFIGURE_STATE;
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ int wtp_dfa_state_run(struct capwap_parsed_packet* packet, struct timeout_contro
|
||||
}
|
||||
} else {
|
||||
if (IS_FLAG_K_HEADER(packet->rxmngpacket->header) && capwap_is_enable_timeout(timeout, CAPWAP_TIMER_DATA_KEEPALIVEDEAD)) {
|
||||
if (!memcmp(packet->messageelements.sessionid, &g_wtp.sessionid, sizeof(struct capwap_sessionid_element))) {
|
||||
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_kill_timeout(timeout, CAPWAP_TIMER_DATA_KEEPALIVEDEAD);
|
||||
capwap_set_timeout(g_wtp.dfa.rfcDataChannelKeepAlive, timeout, CAPWAP_TIMER_DATA_KEEPALIVE);
|
||||
|
||||
Reference in New Issue
Block a user