reformat WTP config file reader
This commit is contained in:
parent
2b489947c2
commit
d93cd1044d
291
src/wtp/wtp.c
291
src/wtp/wtp.c
@ -159,7 +159,7 @@ static void wtp_print_usage(void) {
|
||||
|
||||
/* */
|
||||
static int wtp_parsing_radio_configuration(config_setting_t* configElement, struct wtp_radio* radio) {
|
||||
int i;
|
||||
int i, len, cnt;
|
||||
int configBool;
|
||||
LIBCONFIG_LOOKUP_INT_ARG configInt;
|
||||
const char* configString;
|
||||
@ -168,55 +168,49 @@ static int wtp_parsing_radio_configuration(config_setting_t* configElement, stru
|
||||
|
||||
/* Physical radio mode */
|
||||
radio->radioinformation.radioid = radio->radioid;
|
||||
if (config_setting_lookup_string(configElement, "mode", &configString) == CONFIG_TRUE) {
|
||||
int length = strlen(configString);
|
||||
if (!length) {
|
||||
if (config_setting_lookup_string(configElement, "mode", &configString) != CONFIG_TRUE)
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
len = strlen(configString);
|
||||
if (!len)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
switch (configString[i]) {
|
||||
case 'a': {
|
||||
case 'a':
|
||||
radio->radioinformation.radiotype |= CAPWAP_RADIO_TYPE_80211A;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'b': {
|
||||
case 'b':
|
||||
radio->radioinformation.radiotype |= CAPWAP_RADIO_TYPE_80211B;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'g': {
|
||||
case 'g':
|
||||
radio->radioinformation.radiotype |= CAPWAP_RADIO_TYPE_80211G;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'n': {
|
||||
case 'n':
|
||||
radio->radioinformation.radiotype |= CAPWAP_RADIO_TYPE_80211N;
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Antenna */
|
||||
configSection = config_setting_get_member(configElement, "antenna");
|
||||
if (configSection) {
|
||||
if (!configSection)
|
||||
return 0;
|
||||
|
||||
radio->antenna.radioid = radio->radioid;
|
||||
|
||||
if (config_setting_lookup_bool(configSection, "diversity", &configBool) == CONFIG_TRUE) {
|
||||
radio->antenna.diversity = (configBool ? CAPWAP_ANTENNA_DIVERSITY_ENABLE : CAPWAP_ANTENNA_DIVERSITY_DISABLE);
|
||||
} else {
|
||||
if (config_setting_lookup_bool(configSection, "diversity", &configBool) != CONFIG_TRUE)
|
||||
return 0;
|
||||
}
|
||||
radio->antenna.diversity = (configBool ? CAPWAP_ANTENNA_DIVERSITY_ENABLE : CAPWAP_ANTENNA_DIVERSITY_DISABLE);
|
||||
|
||||
if (config_setting_lookup_string(configSection, "combiner", &configString) == CONFIG_TRUE) {
|
||||
if (config_setting_lookup_string(configSection, "combiner", &configString) != CONFIG_TRUE)
|
||||
return 0;
|
||||
if (!strcmp(configString, "left")) {
|
||||
radio->antenna.combiner = CAPWAP_ANTENNA_COMBINER_SECT_LEFT;
|
||||
} else if (!strcmp(configString, "right")) {
|
||||
@ -230,10 +224,14 @@ static int wtp_parsing_radio_configuration(config_setting_t* configElement, stru
|
||||
}
|
||||
|
||||
configItems = config_setting_get_member(configSection, "selection");
|
||||
if (configItems != NULL) {
|
||||
int count = config_setting_length(configItems);
|
||||
if ((count > 0) && (count <= CAPWAP_ANTENNASELECTIONS_MAXLENGTH)) {
|
||||
for (i = 0; i < count; i++) {
|
||||
if (!configItems)
|
||||
return 0;
|
||||
|
||||
cnt = config_setting_length(configItems);
|
||||
if (cnt == 0 || cnt > CAPWAP_ANTENNASELECTIONS_MAXLENGTH)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
uint8_t* selection = (uint8_t*)capwap_array_get_item_pointer(radio->antenna.selections, i);
|
||||
|
||||
configString = config_setting_get_string_elem(configItems, i);
|
||||
@ -245,125 +243,75 @@ static int wtp_parsing_radio_configuration(config_setting_t* configElement, stru
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Multi-Domain Capability */
|
||||
configSection = config_setting_get_member(configElement, "multidomaincapability");
|
||||
if (configSection) {
|
||||
radio->multidomaincapability.radioid = radio->radioid;
|
||||
|
||||
if (config_setting_lookup_int(configSection, "firstchannel", &configInt) == CONFIG_TRUE) {
|
||||
if ((configInt > 0) && (configInt < 65536)) {
|
||||
if (config_setting_lookup_int(configSection, "firstchannel", &configInt) != CONFIG_TRUE ||
|
||||
configInt == 0 || configInt > 65535)
|
||||
return 0;
|
||||
radio->multidomaincapability.firstchannel = (uint16_t)configInt;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (config_setting_lookup_int(configSection, "numberchannels", &configInt) == CONFIG_TRUE) {
|
||||
if ((configInt > 0) && (configInt < 65536)) {
|
||||
if (config_setting_lookup_int(configSection, "numberchannels", &configInt) != CONFIG_TRUE ||
|
||||
configInt == 0 || configInt > 65535)
|
||||
return 0;
|
||||
radio->multidomaincapability.numberchannels = (uint16_t)configInt;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (config_setting_lookup_int(configSection, "maxtxpower", &configInt) == CONFIG_TRUE) {
|
||||
if ((configInt >= 0) && (configInt < 65536)) {
|
||||
radio->multidomaincapability.maxtxpowerlevel = (uint16_t)configInt;
|
||||
}
|
||||
} else {
|
||||
if (config_setting_lookup_int(configSection, "maxtxpower", &configInt) != CONFIG_TRUE ||
|
||||
configInt == 0 || configInt > 65535)
|
||||
return 0;
|
||||
}
|
||||
radio->multidomaincapability.maxtxpowerlevel = (uint16_t)configInt;
|
||||
}
|
||||
|
||||
/* MAC Operation */
|
||||
radio->macoperation.radioid = radio->radioid;
|
||||
|
||||
if (config_setting_lookup_int(configElement, "rtsthreshold", &configInt) == CONFIG_TRUE) {
|
||||
if ((configInt > 0) && (configInt <= 2347)) {
|
||||
if (config_setting_lookup_int(configElement, "rtsthreshold", &configInt) != CONFIG_TRUE ||
|
||||
configInt == 0 || configInt > 2347)
|
||||
return 0;
|
||||
radio->macoperation.rtsthreshold = (uint16_t)configInt;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (config_setting_lookup_int(configElement, "shortretry", &configInt) == CONFIG_TRUE) {
|
||||
if ((configInt > 1) && (configInt < 256)) {
|
||||
if (config_setting_lookup_int(configElement, "shortretry", &configInt) != CONFIG_TRUE ||
|
||||
configInt < 2 || configInt > 255)
|
||||
return 0;
|
||||
radio->macoperation.shortretry = (uint8_t)configInt;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (config_setting_lookup_int(configElement, "longretry", &configInt) == CONFIG_TRUE) {
|
||||
if ((configInt > 1) && (configInt < 256)) {
|
||||
if (config_setting_lookup_int(configElement, "longretry", &configInt) != CONFIG_TRUE ||
|
||||
configInt < 2 || configInt > 255)
|
||||
return 0;
|
||||
radio->macoperation.longretry = (uint8_t)configInt;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (config_setting_lookup_int(configElement, "fragmentationthreshold", &configInt) == CONFIG_TRUE) {
|
||||
if ((configInt >= 256) && (configInt <= 2346)) {
|
||||
if (config_setting_lookup_int(configElement, "fragmentationthreshold", &configInt) != CONFIG_TRUE ||
|
||||
configInt < 256 || configInt > 2346)
|
||||
return 0;
|
||||
radio->macoperation.fragthreshold = (uint16_t)configInt;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (config_setting_lookup_int(configElement, "txmsdulifetime", &configInt) == CONFIG_TRUE) {
|
||||
if (configInt > 0) {
|
||||
if (config_setting_lookup_int(configElement, "txmsdulifetime", &configInt) != CONFIG_TRUE ||
|
||||
configInt == 0)
|
||||
return 0;
|
||||
radio->macoperation.txmsdulifetime = (uint32_t)configInt;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (config_setting_lookup_int(configElement, "rxmsdulifetime", &configInt) == CONFIG_TRUE) {
|
||||
if (configInt > 0) {
|
||||
if (config_setting_lookup_int(configElement, "rxmsdulifetime", &configInt) != CONFIG_TRUE ||
|
||||
configInt == 0)
|
||||
return 0;
|
||||
radio->macoperation.rxmsdulifetime = (uint32_t)configInt;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Supported rate */
|
||||
radio->supportedrates.radioid = radio->radioid;
|
||||
|
||||
configItems = config_setting_get_member(configElement, "supportedrates");
|
||||
if (configItems != NULL) {
|
||||
int count = config_setting_length(configItems);
|
||||
if ((count >= CAPWAP_SUPPORTEDRATES_MINLENGTH) && (count <= CAPWAP_SUPPORTEDRATES_MAXLENGTH)) {
|
||||
radio->supportedrates.supportedratescount = (uint8_t)count;
|
||||
for (i = 0; i < count; i++) {
|
||||
if (!configItems)
|
||||
return 0;
|
||||
|
||||
cnt = config_setting_length(configItems);
|
||||
if (cnt < CAPWAP_SUPPORTEDRATES_MINLENGTH ||
|
||||
cnt > CAPWAP_SUPPORTEDRATES_MAXLENGTH)
|
||||
return 0;
|
||||
|
||||
radio->supportedrates.supportedratescount = (uint8_t)cnt;
|
||||
for (i = 0; i < cnt; i++) {
|
||||
config_setting_t *elem;
|
||||
int value;
|
||||
|
||||
@ -378,17 +326,9 @@ static int wtp_parsing_radio_configuration(config_setting_t* configElement, stru
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
if ((value >= 2) && (value <= 127)) {
|
||||
if (value < 2 || value > 127)
|
||||
return 0;
|
||||
radio->supportedrates.supportedrates[i] = (uint8_t)value;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* TX Power */
|
||||
@ -396,33 +336,25 @@ static int wtp_parsing_radio_configuration(config_setting_t* configElement, stru
|
||||
if (configSection) {
|
||||
radio->txpower.radioid = radio->radioid;
|
||||
|
||||
if (config_setting_lookup_int(configSection, "current", &configInt) == CONFIG_TRUE) {
|
||||
if ((configInt >= 0) && (configInt <= 10000)) {
|
||||
if (config_setting_lookup_int(configSection, "current", &configInt) != CONFIG_TRUE ||
|
||||
configInt == 0 || configInt > 10000)
|
||||
return 0;
|
||||
radio->txpower.currenttxpower = (uint16_t)configInt;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
configItems = config_setting_get_member(configSection, "supported");
|
||||
if (configItems != NULL) {
|
||||
int count = config_setting_length(configItems);
|
||||
if ((count > 0) && (count <= CAPWAP_TXPOWERLEVEL_MAXLENGTH)) {
|
||||
radio->txpowerlevel.radioid = radio->radioid;
|
||||
radio->txpowerlevel.numlevels = (uint8_t)count;
|
||||
cnt = config_setting_length(configItems);
|
||||
if (cnt == 0 || cnt > CAPWAP_TXPOWERLEVEL_MAXLENGTH)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
radio->txpowerlevel.radioid = radio->radioid;
|
||||
radio->txpowerlevel.numlevels = (uint8_t)cnt;
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
int value = config_setting_get_int_elem(configItems, i);
|
||||
if ((configInt >= 0) && (configInt <= 10000)) {
|
||||
if (value < 0 || value > 10000)
|
||||
return 0;
|
||||
radio->txpowerlevel.powerlevel[i] = (uint8_t)value;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -430,68 +362,41 @@ static int wtp_parsing_radio_configuration(config_setting_t* configElement, stru
|
||||
/* WTP Radio Configuration */
|
||||
radio->radioconfig.radioid = radio->radioid;
|
||||
|
||||
if (config_setting_lookup_bool(configElement, "shortpreamble", &configBool) == CONFIG_TRUE) {
|
||||
if (config_setting_lookup_bool(configElement, "shortpreamble", &configBool) != CONFIG_TRUE)
|
||||
return 0;
|
||||
radio->radioconfig.shortpreamble = (configBool ? CAPWAP_WTP_RADIO_CONF_SHORTPREAMBLE_ENABLE : CAPWAP_WTP_RADIO_CONF_SHORTPREAMBLE_DISABLE);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (config_setting_lookup_int(configElement, "maxbssid", &configInt) == CONFIG_TRUE) {
|
||||
if ((configInt > 0) && (configInt <= 16)) {
|
||||
if (config_setting_lookup_int(configElement, "maxbssid", &configInt) != CONFIG_TRUE ||
|
||||
configInt == 0 || configInt > 16)
|
||||
return 0;
|
||||
radio->radioconfig.maxbssid = (uint8_t)configInt;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (config_setting_lookup_string(configElement, "bssprefixname", &configString) == CONFIG_TRUE) {
|
||||
if (strlen(configString) < IFNAMSIZ) {
|
||||
if (config_setting_lookup_string(configElement, "bssprefixname", &configString) != CONFIG_TRUE ||
|
||||
strlen(configString) >= IFNAMSIZ)
|
||||
return 0;
|
||||
strcpy(radio->wlanprefix, configString);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (config_setting_lookup_int(configElement, "dtimperiod", &configInt) == CONFIG_TRUE) {
|
||||
if ((configInt > 0) && (configInt < 256)) {
|
||||
if (config_setting_lookup_int(configElement, "dtimperiod", &configInt) != CONFIG_TRUE ||
|
||||
configInt == 0 || configInt > 256)
|
||||
return 0;
|
||||
radio->radioconfig.dtimperiod = (uint8_t)configInt;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (config_setting_lookup_int(configElement, "beaconperiod", &configInt) == CONFIG_TRUE) {
|
||||
if ((configInt > 0) && (configInt < 65536)) {
|
||||
if (config_setting_lookup_int(configElement, "beaconperiod", &configInt) != CONFIG_TRUE ||
|
||||
configInt == 0 ||configInt > 65535)
|
||||
return 0;
|
||||
radio->radioconfig.beaconperiod = (uint16_t)configInt;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (config_setting_lookup_string(configElement, "country", &configString) == CONFIG_TRUE) {
|
||||
if (strlen(configString) == 2) {
|
||||
if (config_setting_lookup_string(configElement, "country", &configString) != CONFIG_TRUE ||
|
||||
strlen(configString) != 2)
|
||||
return 0;
|
||||
|
||||
radio->radioconfig.country[0] = (uint8_t)configString[0];
|
||||
radio->radioconfig.country[1] = (uint8_t)configString[1];
|
||||
|
||||
if (config_setting_lookup_bool(configElement, "shortpreamble", &configBool) == CONFIG_TRUE) {
|
||||
if (config_setting_lookup_bool(configElement, "shortpreamble", &configBool) == CONFIG_TRUE)
|
||||
radio->radioconfig.country[2] = (uint8_t)(configBool ? 'O' : 'I');
|
||||
} else {
|
||||
else
|
||||
radio->radioconfig.country[2] = (uint8_t)' ';
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user